Introduction ___________________________________
Android, as it is on HTC devices, has quite an advanced system for installing the OS and updates thereof, not unlike install systems for PC's, like the Windows installer system and NullSoft Install System (NSIS).
"ROM"s for Android aren't necessarily ROMs, but packages. containing files. Technically, a Nandroid backup of a clean install could be considered a ROM.
The update-script file, found in /META-INF/com/google/android/update-script (relative to the package), is necessary for any ROM, no matter how simplistic, to be flashed through the recovery.
(Nandroid-style, or ROM Flash-images, found in a collection with [system|data|cache|boot|recovery|radio|bootloader|splash|etc.].img files, can usually be flashed using fastboot, or adb/terminal via flash_image, but that is out of the scope of this guide.
They can, however, be flashed through an update.zip file, which will be discussed in detail below.
Goldcards, .nbh files and flashing from the bootloader is not covered; see an unbrick/root guide for details.)
Examples! __________________________
Now that we got that out of the way, let's take a look at an update-script file, from KiNgxKxKlair-Hero-Eclair-v1.3_signed (since I have this readily at hand.) Code abridged somewhat (thousands of symlink commands trimmed off).
Highlight syntax:
Commands bold, black
Functions light-blue
Strings red
Integers/numbers and booleans orange
Variables dark-blue
ROOT: green, bold, path/path green
Equal signs, etc pink
Parentheses light-purple
Whoa . Lotsa weird numbers and long commands. But it installs a functioning, rooted Eclair Hero, with busybox, on the G1 with all the right permissions, with no hiccups.
How It Works ________________________
The update-script seems greatly over-complicated, but a lot of it is simple (and some can just be copy-pasted as-is to make up the skeleton of the script.
The first line here is an "assert", a boolean condition.
If the argument following the assert (a function, command, or "variable" condition) is true, the script continues, otherwise it halts.
If you are writing an update-script for a recovery that's compatible with specification v0.2 (which I cover here, and is on most modded post-Cupcake recovery systems to date), you MUST include this first line.
The compatible_with() is a function, which itself returns true if "0.2" OR "0.1" is passed to it, in a v0.2-spec recovery (post-Cupcake).
The second line changes the progress-bar fill. It takes two arguments, a fraction and a duration. Half of the progress bar is taken by verification before this point, so the remaining fraction is relative to the second half (1.0 is half, 0.5 is a quarter, and so forth.)
The fraction is relative to 1.0, which is the post-verification progress.
The duration is in seconds, and specifies how slowly the fraction fills.
This looks easy. Because it is.
The format command takes a "root", a.k.a partition name, as its only argument, and does exactly what it says on the tin - formats a "root" clean.
FORMATTING ERASES DATA IRREVERSIBLY. Just wanted to make that clear, in case it wasn't already.
The available roots are listed in the appendix.
The copy_dir command is also fairly simple. It copies the contents of a folder from one place, to another, making the folder if it doesn't exist.
In this case, it copies from the update package's system folder to /system/.
These are important, too, especially for a rooted/modded rom. The symlink command takes two arguments. Not quite like your Linux/Unix/POSIX "ln -s" command, since it accepts a ROOT: path syntax. The first argument is taken as-is, though, and can be either of:
- A linux executable that's in the $PATH environment (such as SYSTEM:/bin, :/sbin, :/xbin
- A file somewhere.
The command, in the source code, does the following:
- Counts arguments. Exactly two taken, or fail with error.
- Translates the ROOT: path notation into something POSIX compatible, or fails with an error
- Double-checks that ROOT: is mounted, and mounts, otherwise throws an error and stops
- symlink(argv[0], path) - standard C. Takes the first argument, and the translated ROOT: path, and links the path to the first argument. Or fails with an error.
The first argument is the target, i.e., what to link to.
The second argument is the link itself.
Permissions. Ugggh. Probably one of the more confusing things here, since if they're set wrong, some parts of, if not the entire Android system, will fail hard.
You have two commands, set_perm and set_perm_recursive. They both set the ownership and UNIX permissions on files; one on a single file, or a folder (not its contents), and the other acts on everything within the folder.
Changelog:
v0.1: Initial version, explanation of recovery system and parts of the update-script from King's eclair hero
v0.2: Incomplete still, added more tear-apart of the King update-script. And... SYNTAX HIGLIGHTING!
Will continue on explaining set_perm/_recursive in v0.3, expected later tonight.
Android, as it is on HTC devices, has quite an advanced system for installing the OS and updates thereof, not unlike install systems for PC's, like the Windows installer system and NullSoft Install System (NSIS).
"ROM"s for Android aren't necessarily ROMs, but packages. containing files. Technically, a Nandroid backup of a clean install could be considered a ROM.
The update-script file, found in /META-INF/com/google/android/update-script (relative to the package), is necessary for any ROM, no matter how simplistic, to be flashed through the recovery.
They can, however, be flashed through an update.zip file, which will be discussed in detail below.
Goldcards, .nbh files and flashing from the bootloader is not covered; see an unbrick/root guide for details.)
Now that we got that out of the way, let's take a look at an update-script file, from KiNgxKxKlair-Hero-Eclair-v1.3_signed (since I have this readily at hand.) Code abridged somewhat (thousands of symlink commands trimmed off).
Highlight syntax:
Commands bold, black
Functions light-blue
Strings red
Integers/numbers and booleans orange
Variables dark-blue
ROOT: green, bold, path/path green
Equal signs, etc pink
Parentheses light-purple
Code:
[B]assert[/B] [COLOR=DeepSkyBlue]compatible_with[/COLOR][COLOR=Plum]([/COLOR][COLOR=Red]"0.2"[/COLOR][COLOR=Plum])[/COLOR] [COLOR=Magenta]==[/COLOR] [COLOR=Red]"true"[/COLOR]
[B]show_progress[/B] [COLOR=DarkOrange]0.1 0[/COLOR]
[B]format[/B] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]copy_dir[/B] [B][COLOR=YellowGreen]PACKAGE:[/COLOR][/B][COLOR=YellowGreen]system[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]symlink[/B][COLOR=YellowGreen] dumpstate [B]SYSTEM:[/B]bin/dumpcrash[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/newfs_msdos[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/renice[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox[B] SYSTEM:[/B]bin/notify[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcip[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcat[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/yes[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/xargs[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0644[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 2000 0755 0755 [/COLOR][COLOR=YellowGreen][B]SYSTEM[/B]:bin[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 2000 0755 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]xbin[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 3004 02755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]bin/ping[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]bin/su[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]xbin/busybox[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen] [B]SYSTEM:[/B]xbin/iptables[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]xbin/dnsmasq[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 1002 1002 0755 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR][B]
set_perm[/B][COLOR=DarkOrange] 0 0 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1002 1002 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dbus.conf[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1014 2000 0550[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dhcpcd/dhcpcd-run-hooks[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 2000 0550 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]etc/init.goldfish.sh[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0555[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]etc/ppp
[/COLOR]
[B]format[COLOR=YellowGreen] DATA:[/COLOR][/B]
[B]copy_dir[/B][COLOR=YellowGreen][B] PACKAGE:[/B]data [B]DATA:[/B][/COLOR]
[B]symlink[/B][COLOR=YellowGreen] /data/app_s[B] SYSTEM:[/B]app[/COLOR]
[B]symlink[/B] [COLOR=YellowGreen]/data/system-framework[B] SYSTEM:[/B]framework[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1000 1000 0771[/COLOR][COLOR=YellowGreen][B] DATA:[/B]app
[/COLOR]
[B]show_progress[/B][COLOR=DarkOrange] 0.2 0[/COLOR]
[B]format[COLOR=YellowGreen] BOOT:[/COLOR][/B]
[B]write_raw_image[COLOR=YellowGreen] PACKAGE:[/COLOR][/B][COLOR=YellowGreen]boot.img [/COLOR][B][COLOR=YellowGreen]BOOT:[/COLOR][/B]
[B]show_progress[/B][COLOR=DarkOrange] 0.2 10[/COLOR]
[B]format[COLOR=YellowGreen] CACHE:[/COLOR][/B]
Let's pull it apart.
How It Works ________________________
The update-script seems greatly over-complicated, but a lot of it is simple (and some can just be copy-pasted as-is to make up the skeleton of the script.
Code:
[B]assert[/B] [COLOR=DeepSkyBlue]compatible_with[/COLOR][COLOR=Plum]([/COLOR][COLOR=Red]"0.2"[/COLOR][COLOR=Plum])[/COLOR] [COLOR=Magenta]==[/COLOR] [COLOR=Red]"true"[/COLOR]
[B]show_progress[/B] [COLOR=DarkOrange]0.1 0[/COLOR]
If the argument following the assert (a function, command, or "variable" condition) is true, the script continues, otherwise it halts.
The second line changes the progress-bar fill. It takes two arguments, a fraction and a duration. Half of the progress bar is taken by verification before this point, so the remaining fraction is relative to the second half (1.0 is half, 0.5 is a quarter, and so forth.)
The fraction is relative to 1.0, which is the post-verification progress.
The duration is in seconds, and specifies how slowly the fraction fills.
Code:
[B]format[/B] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]copy_dir[/B] [B][COLOR=YellowGreen]PACKAGE:[/COLOR][/B][COLOR=YellowGreen]system[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
The format command takes a "root", a.k.a partition name, as its only argument, and does exactly what it says on the tin - formats a "root" clean.
The copy_dir command is also fairly simple. It copies the contents of a folder from one place, to another, making the folder if it doesn't exist.
In this case, it copies from the update package's system folder to /system/.
Code:
[B]symlink[/B][COLOR=YellowGreen] dumpstate [B]SYSTEM:[/B]bin/dumpcrash[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/newfs_msdos[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/renice[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox[B] SYSTEM:[/B]bin/notify[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcip[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcat[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/yes[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/xargs[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]
- A linux executable that's in the $PATH environment (such as SYSTEM:/bin, :/sbin, :/xbin
- A file somewhere.
The command, in the source code, does the following:
- Counts arguments. Exactly two taken, or fail with error.
- Translates the ROOT: path notation into something POSIX compatible, or fails with an error
- Double-checks that ROOT: is mounted, and mounts, otherwise throws an error and stops
- symlink(argv[0], path) - standard C. Takes the first argument, and the translated ROOT: path, and links the path to the first argument. Or fails with an error.
The first argument is the target, i.e., what to link to.
The second argument is the link itself.
Code:
[B]set_perm_recursive[/B][COLOR=DarkOrange] 1002 1002 0755 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR][B]
set_perm[/B][COLOR=DarkOrange] 0 0 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1002 1002 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dbus.conf[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1014 2000 0550[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dhcpcd/dhcpcd-run-hooks[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 2000 0550 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]etc/init.goldfish.sh[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0555[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]etc/ppp
[/COLOR]
You have two commands, set_perm and set_perm_recursive. They both set the ownership and UNIX permissions on files; one on a single file, or a folder (not its contents), and the other acts on everything within the folder.
______________________________________________________
Changelog:
v0.1: Initial version, explanation of recovery system and parts of the update-script from King's eclair hero
v0.2: Incomplete still, added more tear-apart of the King update-script. And... SYNTAX HIGLIGHTING!
Will continue on explaining set_perm/_recursive in v0.3, expected later tonight.
Last edited: