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

[Tutorial] How to make a Flashable Zip

Discussion in 'Android Devices' started by ModdingMyMind, Feb 13, 2014.

  1. ModdingMyMind

    Thread Starter

    This tutorial will help you to understand the making of a flashable zip or also known as an update zip

    Setting up your zip directories:

    You will need to create the following folder structure inside of your flashable zip (The flashable zip can be called whatever it is you want it to be. (These subfolders are case sensitive)):

    Code (Text):
    1. /META-INF/com/google/android
    All flashable zips include this file structure. The final folder, android, will contain two files within it:

    Code (Text):
    1. update-binary
    2. updater-script
    Note: The update-binary is specific to our devices based on built API mostly, but with other factors as well. It is currently open source and therefore possible to be built on a personal basis. However, to insure you are using the correct one, I can suggest taking it from the most recent OTA available for your device.



    Setting up the updater-script:

    -- This we can create ourselves, to ensure it works properly we will use Notepad++ for Window Users, and Gedit for those using Linux.

    Open the text editor and start a new file, with the following settings for Window Users:

    Save this file as:

    And for Linux users:

    Just leave it as is.

    You can now edit this file, so from here I will be providing some examples:

    Code (Text):
    1. [COLOR="Red"]assert(getprop("ro.product.device") == "k2cl" || getprop("ro.build.product") == "k2cl");[/COLOR]
    2. [COLOR="brown"]ui_print(" ");[/COLOR]
    3. [COLOR="brown"]ui_print("Checking Device");[/COLOR]
    4. [COLOR="brown"]ui_print(" ");[/COLOR]
    5. [COLOR="brown"]ui_print("Success");[/COLOR]
    6. [COLOR="brown"]ui_print(" ");[/COLOR]
    7. [COLOR="green"]show_progress(0.200000, 5);[/COLOR]
    8. [COLOR="brown"]ui_print("Mounting System");[/COLOR]
    9. [COLOR="red"]mount("ext4", "EMMC", "/dev/block/mmcblk0p35", "/system");[/COLOR]
    10. [COLOR="brown"]ui_print(" ");[/COLOR]
    11. [COLOR="green"]show_progress(0.200000, 5);[/COLOR]
    12. [COLOR="brown"]ui_print("Updating System Files");[/COLOR]
    13. [COLOR="red"]package_extract_dir("system", "/system");[/COLOR]
    14. [COLOR="brown"]ui_print(" ");[/COLOR]
    15. [COLOR="green"]show_progress(0.200000, 5);[/COLOR]
    16. [COLOR="brown"]ui_print("unmounting system");[/COLOR]
    17. [COLOR="red"]unmount("/system");[/COLOR]
    18. [COLOR="brown"]ui_print(" ");[/COLOR]
    19. [COLOR="green"]show_progress(0.200000, 5);[/COLOR]
    20. [COLOR="brown"]ui_print("Complete!");[/COLOR]
    21. [COLOR="green"]show_progress(0.200000, 5);[/COLOR]
    22. [COLOR="brown"]ui_print(" ");[/COLOR]
    23. ***EMPTY LINE***

    Ok, I've color coded this so we can break it down, the lines of code in RED are the actual commands, everything else is for visual appearance.

    This is checking to see if you are flashing the correct handset, this is not a requirement, but it insures that the flashable zip will only work for the specified device as to not be accidently flashed by others and to help prevent causing any possible damage to those who do not qualify to use that particular zip. Just insert another device name in the place of "k2cl" if you so wish, or remove the command all together.

    To explain this a little further, you have told the script to check certain properties within your 'build.prop' file located in your /system folder. The above command ensures the following categories have the correct definitions before proceeding with the flash:
    Take note, that if you apply this to a full rom which result you having to wipe out the system partition before flashing then this will obviously not work, because you also wiped out the build.prop file along with the /system, so the zip will be aborted due to an error by not being able to verify as instructed to do in the syntax.

    Here are the main build properties within your build.prop (may slightly vary):

    To mount a partition you need to use the following syntax. Below, will visually show you what each arguement represents:

    filesystem-type: "ext4" or "yaffs2" (k2cl is ext4)
    partition-type: "EMMC" or "MTD" (k2cl is EMMC)
    DSM: Device specific address - this will be your specified partition
    mount-point: /system, /data, /userdata, /cache, etc

    This is the specific mount point for the k2cl system partition, if you wish to flash a different partition, data for instance, you can get the mount points for your device by entering the following code over ADB via PC or on our phone via terminal emulator:

    This will place a text file on your sdcard with the mount points for your specific device. (Remember to swap 'PHONENAME' with your device name e.g. 'k2cl', as a means of remembrance and for record keeping).

    This command extracts the files you wish to flash from the zip and flashes them to the phone, it is formatted as follows ("package-path", "/destination-path"). So for this example you are telling it to flash everything from the 'system' folder in your zip to the /system partition of your handset. You can obviously change these values for different partitions.

    To flash an entire directory:

    Code (Text):
    1. package_extract_dir("system", "/system");
    To flash a single file:

    Code (Text):
    1. package_extract_file("boot.img", "/dev/block/mmcblk0p20");

    These commands are structured as follows:

    Entire directory: ("zipfileSource", "destination-partition");
    Single File: ("file", "device-specific-mountpoint");

    This simply unmounts whatever partition you previously mounted.

    Shows text in the recovery while the flash is currently taking place. You would just enter what ever text you feel is necessary to be displayed on the screen.

    Controls what the progress bar in the background is displaying, it is formatted as follows (fragment, seconds).

    This is not actually a text, you simply need to leave a blank line at the end of your script before you save it for it to work properly.



    Some Additional commands


    Deleting folders & files:

    You can delete multiple folders or files using just one command, as follows:

    To delete files:

    Code (Text):
    1. delete("file-path-1", "file-path-2", "file-path-3);
    Example:
    Code (Text):
    1. delete("/system/bin/su","/system/xbin/su","/system/app/Superuser.apk");
    You can list as many file-path's as needed in the script. Three is not its limit.

    To delete folders/directories:

    Code (Text):
    1. delete_recursive("directory-path-1", "directory-path-2", "directory-path-3");
    This is also not limited to three directory-path's.



    Setting Permissions:

    Set permissions of a file or set of files:

    Code (Text):
    1. set_perm(uid, gid, mode, "filepath1", "filepath2")
    Example:
    Code (Text):
    1. set_perm(0, 0, 06755, "/system/xbin/su");
    uid - user id
    gid - group id
    mode - permission mode
    filepath... - file to set permission on

    Setting permissions of a directory or a set of directories and all files and folders within them:

    Code (Text):
    1. set_perm_recursive(uid, gid, dirmode, filemode, "dirpath1", "dirpath2")
    Example:
    Code (Text):
    1. set_perm_recursive(0, 0, 0755, 0644, "/system");
    uid - user id
    gid - group id
    dirmode - permission to set to directories contained within the specified directory
    filemode - permission to set to files contained within the specified directory
    dirpath... - directory to set permission on

    You will need to also understand the way file permissions are represented:

    Example = drwxrwxrwx

    -- Use a Root Explorer to find the UID, GID, and permissions for a file. Permissions are the string that looks like some variation on 'rwxr-xr--' next to each file. Long press and choose "change owner" to get the UID and GID. You just want the number next to "owner" and "group", respectively.

    -- If you're replacing a file, look up these settings for the existing copy and use them. If you're adding a file, just find a file that does the same functions and copy what it has (for example, installing an app to /system/app? Just look at these settings for any other app in that directory).

    -- MODE is technically a 4-bit string, but the first character can be omitted. There doesn't seem to be any android file permissions with the first character set. For good practice, I think it's safe to assume you can always use a leading 0 unless you know otherwise for something specific. Or, just use a 3-digit MODE, which says to leave those settings as they are (disabled by default). (I.e. 0644=644).

    The next 9 characters define the file permissions. These permissions are
    given in groups of 3 each.

    The first 3 characters are the permissions for the owner of the file or directory.
    Example = -rwx------

    The next 3 are permissions for the group that the file is owned by.
    Example = ----rwx---

    The final 3 characters define the access permissions for everyone not part of the group.
    Example = -------rwx

    There are 3 possible attributes that make up file access permissions.

    r -- Read permission. Whether the file may be read. In the case of a
    directory* this would mean the ability to list the contents of the
    directory.

    w -- Write permission. Whether the file may be written to or modified. For
    a directory this defines whether you can make any changes to the contents
    of the directory. If write permission is not set then you will not be able
    to delete rename or create a file.

    x -- Execute permission. Whether the file may be executed. In the case of a
    directory this attribute decides whether you have permission to enter,
    run a search through that directory or execute some program from that
    directory

    You set these permissions using the following binary based numerical system:
    Default Linux permissions:

    For Files:
    "Read" means to be able to open and view the file
    "Write" means to overwrite or modify the file
    "eXecute" means to run the file as a binary

    For Directories:
    "Read" means to be able to view the contents of the directory
    "Write" means to be able to create new files/directories within the directory
    "eXecute" means to be able to "Change Directory" (cd) into the directory

    For further understanding on calculating CHMOD permissions, then click on the following link to another thread here on XDA:
    CHMOD Permissions - Reference Guide


    Here are two examples of using edify scripting to help give a better visual on all of this:

    Example 1:

    Example 2:
    Code (Text):
    1. ui_print("****************************************");
    2. ui_print("                                        ");
    3. ui_print("          4.2.2 CCONVERSIONN            ");
    4. ui_print("    Modding.MyMind - XDA Senior Member  ");
    5. ui_print("                                        ");
    6. ui_print("****************************************");
    7. ui_print("");
    8. ui_print("");
    9.  
    10. #MOUNTING
    11. show_progress(0.1, 0);
    12. ui_print("MOUNTING /system");
    13. mount("ext4", "EMMC", "/dev/block/mmcblk0p35", "/system");
    14. delete_recursive("/system");
    15.  
    16. #EXTRACTING
    17. ui_print("EXTRACTING SYSTEM FOLDER TO /system");
    18. package_extract_dir("system", "/system");
    19.  
    20. #SYMLINKING
    21. ui_print("SYMLINKING");
    22. symlink("dumpstate", "/system/bin/dumpcrash");
    23. symlink("toolbox", "/system/bin/cat");
    24. symlink("toolbox", "/system/bin/chmod");
    25. symlink("toolbox", "/system/bin/chown");
    26. symlink("toolbox", "/system/bin/cmp");
    27. symlink("debuggerd", "/system/bin/csview");
    28. symlink("toolbox", "/system/bin/date");
    29. symlink("toolbox", "/system/bin/dd");
    30. symlink("toolbox", "/system/bin/df");
    31. symlink("toolbox", "/system/bin/dmesg");
    32. symlink("toolbox", "/system/bin/getevent");
    33. symlink("toolbox", "/system/bin/getprop");
    34. symlink("toolbox", "/system/bin/hd");
    35. symlink("toolbox", "/system/bin/id");
    36. symlink("toolbox", "/system/bin/ifconfig");
    37. symlink("toolbox", "/system/bin/iftop");
    38. symlink("toolbox", "/system/bin/insmod");
    39. symlink("toolbox", "/system/bin/ioctl");
    40. symlink("toolbox", "/system/bin/ionice");
    41. symlink("toolbox", "/system/bin/kill");
    42. symlink("toolbox", "/system/bin/ln");
    43. symlink("toolbox", "/system/bin/log");
    44. symlink("toolbox", "/system/bin/ls");
    45. symlink("toolbox", "/system/bin/lsmod");
    46. symlink("toolbox", "/system/bin/lsof");
    47. symlink("toolbox", "/system/bin/mkdir");
    48. symlink("toolbox", "/system/bin/mount");
    49. symlink("toolbox", "/system/bin/mv");
    50. symlink("toolbox", "/system/bin/nandread");
    51. symlink("toolbox", "/system/bin/netstat");
    52. symlink("toolbox", "/system/bin/newfs_msdos");
    53. symlink("toolbox", "/system/bin/notify");
    54. symlink("toolbox", "/system/bin/printenv");
    55. symlink("toolbox", "/system/bin/ps");
    56. symlink("toolbox", "/system/bin/renice");
    57. symlink("toolbox", "/system/bin/rm");
    58. symlink("toolbox", "/system/bin/rmdir");
    59. symlink("toolbox", "/system/bin/rmmod");
    60. symlink("toolbox", "/system/bin/route");
    61. symlink("toolbox", "/system/bin/schedtop");
    62. symlink("toolbox", "/system/bin/sendevent");
    63. symlink("toolbox", "/system/bin/setconsole");
    64. symlink("toolbox", "/system/bin/setprop");
    65. symlink("mksh", "/system/bin/sh");
    66. symlink("toolbox", "/system/bin/sleep");
    67. symlink("toolbox", "/system/bin/smd");
    68. symlink("toolbox", "/system/bin/start");
    69. symlink("toolbox", "/system/bin/stop");
    70. symlink("toolbox", "/system/bin/sync");
    71. symlink("toolbox", "/system/bin/top");
    72. symlink("toolbox", "/system/bin/touch");
    73. symlink("toolbox", "/system/bin/umount");
    74. symlink("toolbox", "/system/bin/uptime");
    75. symlink("toolbox", "/system/bin/vmstat");
    76. symlink("toolbox", "/system/bin/watchprops");
    77. symlink("toolbox", "/system/bin/wipe");
    78. symlink("wiperiface_v02.so", "/system/bin/wiperiface");
    79. symlink("libwiperjni_v02.so", "/system/lib/libwiperjni.so");
    80.  
    81. #PERMISSIONS
    82. ui_print("SETTING PERMISSIONS TO /system");
    83. set_perm_recursive(0, 0, 0755, 0644, "/system");
    84. set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
    85. set_perm(0, 3003, 06755, "/system/bin/ip");
    86. set_perm(0, 3003, 02750, "/system/bin/netcfg");
    87. set_perm(0, 3004, 02755, "/system/bin/ping");
    88. set_perm(0, 2000, 06750, "/system/bin/run-as");
    89. set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");
    90. set_perm(0, 0, 0755, "/system/etc/bluetooth");
    91. set_perm(3002, 3002, 0444, "/system/etc/bluetooth/blacklist.conf");
    92. set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
    93. set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
    94. set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
    95. set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
    96. set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
    97. set_perm_recursive(0, 0, 0755, 0644, "/system/vendor/firmware");
    98. set_perm(0, 2000, 0755, "/system/vendor/firmware");
    99. set_perm(0, 2000, 0755, "/system/vendor/lib");
    100. set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
    101. show_progress(0.1, 10);
    102.  
    103. #EXTRACTING
    104. ui_print("INSTALLING boot.img TO mmcblk0p20");
    105. show_progress(0.2, 0);
    106. package_extract_file("boot.img", "/dev/block/mmcblk0p20");
    107. show_progress(0.2, 10);
    108.  
    109. #UNMOUNTING
    110. ui_print("UNMOUNTING /system");
    111. unmount("/system");
    112. ui_print("****************************************");
    113. ui_print("*        CconversionN Complete!        *");
    114. ui_print("****************************************");

    Files to flash:

    You now need to create some other folder(s), this needs to be named based on where within the system you are flashing to help keep it simple (you can technically name them whatever, just as long as they are placed in the proper location of your current daily rom); for the sake of this example we are flashing to the system partition, so:

    Place whatever files you wish to flash within this file. For example:



    Creating your .zip file:

    Select both of your top directories and their contents 'META-INF' and 'system' and package them into a .zip file with 7zip or any other method you may currently use, using the following settings:

    Archive: name_of_your_file
    Archive Format: zip
    Compression level: Store
    Update mode: Add and replace files

    And there you have it, your very own flashable .zip file.



    How to sign your flashable zip:

    You don't actually need to sign your zip file for it to work as most custom recoveries like, TWRP, now support unsigned zips. For the learning developers and the more cautious among us though, here is how. First, go ahead and place your newly made flashable zip on to your device. I preferably place it on the root of my internal sdcard, though the choice is ultimately yours.

    Download the free application on the playstore called, zipsigner. Open it up and select the option for, Choose In/Out....

    Go and select your zip, and then select, auto-testkey, under where it says, Key/mode. Once done, proceed to sign it. You will recieve an output zip file with the same name as the previous unsigned zip but with it ending in *-signed.zip. At this point, you are now good and you can either apply your zip to your device, or share your work with others.

    There are so many different ways you can go about signing the zip, but for something like a simple flashable zip file, I will normally always go this route.

    -- Happy Hunting!!!
     

    Attached Files:




    1. Download the Forums for Android™ app!


      Download

       
  2. irishobo

    irishobo Android Enthusiast

    Nice work!
     
  3. russellvone

    russellvone Android Enthusiast

    we don't exactly have to have root for this......but most things that are flashed through custom recovery usually/sometimes need root

    nice layout, very good job
     
  4. russellvone

    russellvone Android Enthusiast

    always educational...all your threads never need questions answered, always very clear explanations
     
  5. ModdingMyMind

    Thread Starter

    That's usually what I aim for lol. Saves people time, and mine haha.
     
    russellvone likes this.
  6. Lordvincent 90

    Lordvincent 90 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

    Added to all things root guide :)
     
  7. ModdingMyMind

    Thread Starter

    Thanks, as russellvone once said... I'm a script guru haha.
     
    russellvone likes this.
  8. russellvone

    russellvone Android Enthusiast

    TaDa! [the guru reveals himself]
     
  9. Lordvincent 90

    Lordvincent 90 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

    irishobo and russellvone like this.
  10. ModdingMyMind

    Thread Starter

  11. ModdingMyMind

    Thread Starter

    So, I went ahead and took the idea found in his second post because it gives so much clearer visual on the structure, and I applied it in the OP for Example 1. Though, I used green, cuz I like the color lol.
     
    russellvone and Kreatur3 like this.
  12. Deleted User

    Deleted User Guest
    Thread Starter

    :) you can also use busybox to mount. busybox mount system /system :)
     
  13. ModdingMyMind

    Thread Starter

    Definitely need to get around to updating it with reference of using busybox lol. But then again, most zips these days are far past just these simple basic instructions with much more intelligent scripts nowadays :).
     

HTC One SV Forum

The HTC One SV release date was January 2013. Features and Specs include a 4.3" inch screen, 5MP camera, 1GB RAM, Snapdragon S4 Plus processor, and 1800mAh battery.

January 2013
Release Date
0
Reviews
Loading...

Share This Page

Loading...