1. Are you ready for the Galaxy S20? Here is everything we know so far!

Creating Custom ROMs/Backups for Odin

Discussion in 'Android Devices' started by Nu11u5, Mar 18, 2010.

  1. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Here is a brief much more complete guide to creating your own Odin images for distributing custom ROMs or making backups. Thanks to kam197, BH_MAN, chadmd23, SoulCreator, and all the other community members.


    • A Samsung Behold 2 to backup/edit/test ROMs on
    • Root via try3/asroot2, persistent su, or modified kernel
    • Working ADB connection
    • SD Card with ~300MB free
    • Cygwin - if you are working in Windows
    • Basic knowledge of a command line

    Making the ROM Dump:

    The Behold 2 has 14 partitions in its flash memory, but only a few of these are useful to modify. You will want to focus on different partitions depending on what you want to do.
    After you make a ROM dump you will need to package it using the instructions in the following section before you can flash it.

    Backup your personal data?

    You may want to backup your data while trying out a different ROM.
    It is simple to do.

    1. Start an ADB shell session and obtain root access.
    2. Run the following command to dump the UserData partition:
      Code (Text):
      1. # dd if=/dev/block/stl14 of=/sdcard/userdata bs=4096
    3. Retrieve the dumped file from the SD Card.
    4. Don't include userdata in a distribution unless you don't mind everyone knowing your email, passwords, app choices, web history, etc!

    Make a custom system image (ROM)?

    Creating a custom ROM can involve no more than changing out a few included applications to modifying advanced features of the phone. A lot of testing should be performed before distributing a heavily customized system image. It is recommended to make multiple system image dumps as "in-progress" snapshots or saves as you work on the ROM. Otherwise messing up normally means starting over!

    1. Once dumped a system ROM cannot be edited, so you must work with it directly on the phone (recommended while in Recovery Mode). The System dump will be an exact copy of what is already loaded so get everything set up first and test that the phone can reboot.
    2. Start an ADB shell session and obtain root access.
    3. Run the following command to dump the System partition:
      Code (Text):
      1. # dd if=/dev/block/stl9 of=/sdcard/system bs=4096
    4. Retrieve the dumped file from the SD Card.

    If you want to get files out of another system image (or userdata image) without flashing, open them in an archive program that can read FAT disk image files - 7-Zip is recommended - or mount them read-only under Linux. Trying to write to the image with these methods will corrupt it as its non-standard.

    Make a custom kernel or recovery image (ROM)?

    ADVANCED: Modifying the kernel or recovery image can allow you to enable root, change startup logos, and tweak environment settings for boot. In addition to the other requirements you will need an decent understanding of Linux file permissions, startup, and mount process, as well as a hex editor

    1. Start an ADB shell session and obtain root access.
    2. Run the following command to dump the kernel partition:
      Code (Text):
      1. # dd if=/dev/block/bml8 of=/sdcard/kernel bs=4096
    3. Run the following command to dump the recovery partition:
      Code (Text):
      1. # dd if=/dev/block/bml6 of=/sdcard/recovery bs=4096
    4. Retrieve the dumped file from the SD Card.
    5. Make a copy for backup purposes! We will be editing these.
    6. Create a working folder for each of the dumped kernel and/or recovery images and move them there.
    7. Split the images in each working folder into the binary and ramdisk.
      Code (Text):
      1. $ head -c 1785856 kernel > krnl.bin
      2. $ tail -c +1785857 kernel > rd.cgz
      Code (Text):
      1. $ head -c 1937408 recovery > krnl.bin
      2. $ tail -c +1937409 recovery > rd.cgz
    8. In each working folder extract the initramfs filesystem.
      Code (Text):
      1. $ mkdir initramfs
      2. $ cd initramfs
      3. $ gzip -cd ../rd.cgz | cpio -imv
    9. Modify, add, or remove files as need. Check that permissions are appropriate - all files will be owned by root.root after the ramdisk file is remade.
    10. Recreate the compressed ramdisk and then the kernel/recovery image with the following:
      Code (Text):
      1. $ find | cpio -H newc -R 0.0 -oa | gzip -cn1 > ../rd.cgz
      2. $ cat rd.cgz >> krnl.bin
    11. Edit the kernel/recovery image in a hex editor. Change the 4 bytes starting at offset 0x10 to be the size of the rd.cgz file in hex, little endian format. So if your compressed ramdisk size is 1647744 bytes that would be 0x192480 in hex and therefore "80 24 19 00" in little endian format.
    12. Save the completed custom kernel/recovery image as "kernel" or "recovery".

    Building the Odin Packages:

    Odin technically allows you to use two types of packages - Specific and OnePackage.

    Specific packages are labeled "BOOT", "PHONE", "PDA", and "CSC" in the software. Selecting these in Odin checks that they contain exactly the expected flash images and presents an error if anything is out of place (extra or missing files, mislabeled files).
    The CSC specific package is currently not used for the Behold 2.

    Since you will rarely want to flash the entire phone at once the Specific Packages are not always appropriate. When someone else goes to flash your ROM they may get an ambiguous error and not know for sure why.

    OnePackage allows any the partition flash files to be included with each other in one Odin package. These are easier to distribute and will not cause odd errors when someone loads them into Odin.

    TL;DR: Use OnePackage to distribute ROMs!

    Note: Errors during flashing are normally recoverable unless the error occurred while flashing the boot partitions (arm9boot and arm11boot). NEVER include these files in an Odin package - they do not need updating!

    1. Open a Cygwin or *nix console and change directory to where you are storing your ROM dumps.
    2. Run the following command to build a package tarball. Be sure to use identifiable names with versions or dates:
      Code (Text):
      1. $ [B]tar -H ustar -c[/B] [I]image_1 [image_2 ...][/I] [B]>[/B] [I]your_odin_package.tar[/I]
    3. Run the following command to sign each tarball with an md5 tail:
      Code (Text):
      1. $ [B]md5sum -t[/B] [I]your_odin_package.tar[/I] [B]>>[/B] [I]your_odin_package.tar[/I]
      2. $ [B]mv[/B] [I]your_odin_package.tar[/I] [I]your_odin_package.tar[/I][B].md5[/B]
    Please sign your Odin Packages - its the easiest way to tell if the download corrupted them!

    Testing your Odin Packages:

    1. Without clicking Start in Odin, load each of the packages you made to see if there are any errors. Be sure to mark the One Package checkbox under Options if you are using one.
    2. If everything loads correctly you can test if Odin will flash them properly - click Start.
    3. If your packages flashed correctly post them online or archive them for backup :)

    driftinanomaly, lych, yahma and 10 others like this.
  2. BH_MAN

    BH_MAN Android Expert

    Can a Mod Sticky this?

    Thank you,
  3. spinwizard

    spinwizard Newbie

    How do I open the Cygwin, when I click on the shortcut on my desktop, I get a quick command prompt, then it's gone :thinking:
    I've gotten the 3 dumps, and am stuck here. Any help would be appreciated.
  4. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Cygwin is a command prompt, but instead of Windows it works like Linux.

    It should not be closing as soon as it opens. Did you install to the default location or move the install folder afterward?
  5. lviv73

    lviv73 Well-Known Member

    Could you explain this in greater detail,the 2nd "cygwin" part,and give some real commands examples for Cygwin,thanx in advance.
  6. BH_MAN

    BH_MAN Android Expert

    ?? He did, those are the Commands you Run...
  7. lviv73

    lviv73 Well-Known Member

    Im not Linux user,but computer literate and i could not even make a .tar file,lol.

    tar --format=ustar -cf [name_of_odin_package.tar] [image_1] [image_2] [...]

    tar --format=ustar -cf [name of .tar file} and then what? what do i put for [image_1],etc?
    I succeeded creating empty .tar,could you explain this step in more detail,the rest i understand.
    Can i use a program such as 7zip or Power Archiver to create the .tar file or it has to be done from linux command prompt?
  8. BH_MAN

    BH_MAN Android Expert

    I didn't think it was to hard to do, but here's an exp. for you...

    lviv73 likes this.
  9. lviv73

    lviv73 Well-Known Member

    I have also noticed a cache file in you roms.This tutorial only mentions on how to dump UserData,System and Kernel.Could you give us the command to create Cache dump also.
    I just thought it must be important sense you include it in your roms,thanx.
  10. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Odin needs the tar files to be in the USTAR format. I haven't seen a free program that can write these other than the gnu linux tools - hence why I use Cygwin.

    'cache' is on /dev/block/stl12

    The cache images T-Mobile provide are pretty much blank, with just a few KB of locality info on it, so I was only including copies of those.
    lviv73 likes this.
  11. lviv73

    lviv73 Well-Known Member

    Thanx,so cache partition i can do without or is it needed for things like settings and wallpapers on first boot?

    I have also tryed to dump other partitions,and noticed that almost all of them are are over 50mb,whats on them?I have made my custom rom sucessfuly,i removed alot of things i dint want,but when i flashed the rom i had double ringrltones in settings!So i did factory reset and it dint help,so i did another flash and i had triple ringtones in my settings,lol.Now after numerous flashes to stock and back they disapeared,but i dont know exactly what i did to make them disapear.
    To make a long story short,is there a way to do a clean flash where everything is wiped clean?cause i noticed that even after stock flash there is still files left over on some of the partitions(18 partititions).
  12. equinox

    equinox Lurker

    Awesome, I'll check this out later on. Gonna toss my linux drive in and give it a shot
  13. DGarmon

    DGarmon Member

    I was wondering, If I use this method to create a backup of my phone (System, UserData and Kernel), is it possible to create an android AVD emulator and Odin the files into the emulator? I would like to do some testing, but for safety reasons...run in this mode....

  14. rleal2010

    rleal2010 Android Enthusiast

    still waiting on the table.....lol


    I sometimes need visuals :)
  15. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Thanks for reminding me lol!

    I'll get that updated with more information, maybe a few scripts too!

    Putting this here so people can kick me in the pants if I slack off again :p
  16. tb813

    tb813 Lurker

    Sorry if this is the wrong thread for this question, and thanks a lot guys for what you're doing here for the BH2 community!..

    I tried a few different ROMs, and finally decided on using the official OTA 1.6 from this thread. Although I like the BH' mods a lot, there are a few issues with these mods that might be insignificant for some but very annoying for me...

    Unfortunately, the stock ROM has a problem with wifi driver. Normally I run my home N/G router in 40MHz mode, but BH2 with the stock driver can't connect to it in this mode - I have to switch the router to 20MHz to be able to connect. This problem exists in all stock T-Mobile ROMs - the original 1.5 and the new 1.6 OTA - as well as in the tweaked 1.6 OTA by microhaxo.
    However, the wifi driver used in this BH_MAN' mod doesn't have this problem - it works perfectly, and with this driver I can connect to the router even when it runs in 40MHz mode. The BH_MAN mod' change log mentions the "WiFi fix" - I assume that is what makes it to work properly?

    Anyway, since the WiFi works for me in BH_MAN' mod but doesn't work in the stock ROM, my question is - is it possible to replace the wifi driver in the stock ROM by the one used in the BH_MAN's mod, and if so - how to do it? The instructions in this thread don't go that deep... I'd appreciate any help - thank you!
  17. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Updated the guide with "almost everything". I've combined and streamlined some commands, corrected some wrong descriptions from before, and added a section on making a custom kernel or recovery image.

    Let me know if anything isn't clear or just doesn't work. If there is a wiki somewhere this type of thing would be appropriate for point it out.

    Enjoy and happy hacking.
  18. microhaxo

    microhaxo Well-Known Member

    tar --format=ustar -cf [name_of_odin_package.tar] [image_1] [image_2] [...]

    Correct way *
  19. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    tar -H ustar -c file_1 [file_2 ...] > tarball.tar

    ..is correct too. It uses the short option for --format which is -H, and leaving out -f lets you have the output file name at the end. I just thought it looked more logical.

    EDIT: I saw that I did indeed have it wrong in the main post, the option -H does not take "=" as part of the argument. Fixed.
  20. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Someone can try using my kernel/recovery customization instructions to extract and rebuild the image leaving the files untouched. Let me know if its clear enough.
  21. microhaxo

    microhaxo Well-Known Member

    I'd give it a try, had some problems with the hex portion. I put that aside to work on this Dialer / contacts problem that will most likely never get solved.
  22. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    I'm working to see if I can make a shell script to handle the hex editing. Right now I can read the file size, convert that to hex, and (a few steps later) overwrite the byte range with dd. I still need to get the size into little endian format, and output that as binary instead of ASCII.

    An alternative would be to make a few simple modifications to Google's mkbootfs program that would do everything for us. I think already know what needs changing, but for whatever reason I haven't done that yet.
  23. slmar123

    slmar123 Member

    I'm giving it a go but I am running into problems after splitting the kernel/recovery images.

    When I run:
    $ gzip -cd ../rd.cgz | cpio -imv 2> ../rd.lst
    on the recovery image I get:
    gzip: ../rd.cgz: not in the gzip format

    also the rd.lst file in both kernel and recovery working folders contians only the following line:
    bash: cpio: command not found

    I'm using Cygwin to run the commands, maybe I have something configured incorrectly? Can you shed any light on the issue?
  24. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    Its possible the recovery image isn't in the exact same layout as the kernel iamge. I'll confirm this and make any necessary changes to the script tomorrow.

    You are probably missing the cpio program. Run the Cygwin installer again and when prompted to choose packages search for "cpio" and add it. It should be listed under the Archive category.

    Its a shame they don't include a package manager as part of the Cygwin install. Or do they?

    I've updated the script to use "find" instead of redirecting the cpio directory to the rd.lst file and reloading that. Its easier and cleaner, but there is a hitch... Windows has its own "find" program that is not compatible with the operation of GNU find. If you are not running in the default bash shell or don't have the PATH environment variable set right it'll use the wrong one and fail.

    Try "$ which find" to see what ones you will be using.
  25. Nu11u5

    Nu11u5 Android Enthusiast
    Thread Starter

    I had a fresh recovery dump laying around. The ramdisk starts at offset 0x1D9000 which is different than the kernel image. I've updated the instructions to reflect that.

Samsung Behold 2 Forum

Features and specs are not yet known.

Release Date

Share This Page