[WIP] How to Write an Updater-Script with Edify Code

Karadorde

Senior Member
Aug 27, 2010
488
159
0
Sugar Creek
First and foremost I take no credit for the majority of this thread. I am merely posting this here as a reference for you all. I had to dig around a lot for this information and piece it together from several different threads as well as pull examples from updater-scripts in several different roms/theme/etc. Everyone else put in the work, I am just trying to make it easier for the rest of us :D.

Mounting Partitions:
MTD:
Code:
mount("MTD", "system", "/system");
mount("MTD", "userdata", "/data");
mount("MTD", "cache", "/cache");
mount("MTD", "sdcard", "/sdcard");
EMMC with EXT3 and EXT4 file systems:
Code:
mount("ext4", "EMMC", "/dev/block/mountpoint", "/system");
mount("ext4", "EMMC", "/dev/block/mountpoint", "/data");
mount("ext4", "EMMC", "/dev/block/mountpoint", "/cache");
Code:
mount("ext3", "EMMC", "/dev/block/mountpoint", "/system");
mount("ext3", "EMMC", "/dev/block/mountpoint", "/data");
mount("ext3", "EMMC", "/dev/block/mountpoint", "/cache");
“mountpoint” will vary from device to device. Decide what partition you want to mount, find where it mounts (there will be resources in the second post, and paste it in place of “mountpoint” in your script.

Mounting system, data, and cache on the EVO 3D
Code:
mount("ext4", "EMMC", "/dev/block/mmcblk0p23", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p24", "/data");
mount("ext4", "EMMC", "/dev/block/mmcblk0p25", "/cache");
Amend
Code:
[I][COLOR="Gray"]none[/COLOR][/I]



Unmounting Partitions:
MTD and EMMC:
Code:
unmount("/system");
unmount("/data"); [COLOR="Red"]OR[/COLOR] unmount("/userdata");
unmount("/cache");
unmount("/sdcard");
Amend
Code:
[I][COLOR="Gray"]none[/COLOR][/I]



Format Partitions:
MTD:
Code:
format("MTD", "system");
format("MTD", "cache");
format("MTD", "data");
format("MTD", "boot");
EMMC EXT3/4:
Code:
format("ext4", "EMMC", "/dev/block/mountpoint");
Code:
format("ext3", "EMMC", "/dev/block/mountpoint");
Formatting system, data, cache, and boot on EVO 3D.
Code:
format("ext4", "EMMC", "/dev/block/mmcblk0p23");
format("ext4", "EMMC", "/dev/block/mmcblk0p24");
format("ext4", "EMMC", "/dev/block/mmcblk0p25");
format("ext4", "EMMC", "/dev/block/mmcblk0p22");
Amend:
Code:
[I][COLOR="Gray"]format SYSTEM:
format DATA:
format BOOT:
format CACHE:[/COLOR][/I]



Copy files from .zip file to phone partition or sd card:
Code:
package_extract_dir("Source", "Destination");
“Source” = folder in .zip file. "Destination" = partition to copy to,
Code:
package_extract_dir("system", "/system");
package_extract_dir("data", "/data");
package_extract_dir("sdcard", "/sdcard");
Amend:
Code:
[I][COLOR="Gray"]copy_dir PACKAGE:system SYSTEM:
copy_dir PACKAGE:data DATA:
copy_dir PACKAGE:sdcard SDCARD:
[/COLOR][/I]



Write an .img file:
MTD:
Code:
assert(package_extract_file("boot.img", "/tmp/boot.img"),
write_raw_image("/tmp/boot.img", "boot"),
delete("/tmp/boot.img"));
EMMC:
Code:
package_extract_file("boot.img", "/dev/block/mountpoint");
Amend
Code:
[I][COLOR="Gray"]write_raw_image PACKAGE:boot.img BOOT:[/COLOR][/I]



Output a line of text:
MTD/EMMC:
Code:
ui_print("Text Here");
Amend
Code:
[I][COLOR="Gray"]none[/COLOR][/I]



Delete a file:

Use delete for a single file. Use delete recursive for an entire folder.

Code:
delete_recursive("file/path");
Code:
delete("/path/to/file");
Amend
Code:
[I][COLOR="Gray"]delete_recursive PARTITION:path/to/file[/COLOR][/I]
Code:
[I][COLOR="Gray"]delete PARTITION:path/to/file[/COLOR][/I]



Set ownership and permissions for folder:
Code:
set_perm_recursive(uid, gid, dmode, fmode, “/path/to/folder”);
Amend
Code:
[COLOR="Gray"]set_perm_recursive uid gid dmode fmode PARTITION:path[/COLOR]



Set ownership and permissions for a file:
Code:
set_perm(uid, gid, mode, “/path/to/file”);
Amend
Code:
[COLOR="Gray"]set_perm uid gid mode PARTITION:file[/COLOR]



Run a program:
Code:
run_program("programtorun");
Amend
Code:
[I][COLOR="gray"]run_program PACKAGE:programtorun[/COLOR][/I]



Creating symlinks:
Code:
symlink("/path/to/file", "/path/tofile");
Amend
Code:
[COLOR="gray"][I]symlink /path/to/file PARTITION:path/to/file[/I][/COLOR]



Progress bar:
Code:
show_progress(fraction, duration);
Amend
Code:
[COLOR="gray"][I]show_progress fraction, duration[/I][/COLOR]
 
Last edited:

Karadorde

Senior Member
Aug 27, 2010
488
159
0
Sugar Creek
Mount points for selected devices:

Evo 3D
Code:
mmcblk0p21          /boot
mmcblk0p23          /system
mmcblk0p24          /data
mmcblk0p25          /cache
Evo Shift 4G
Code:
mmcblk0p22          /boot
mmcblk0p26          /system
mmcblk0p27          /data
mmcblk0p28          /cache
Nexus S
Code:
mtdblock4				/cache
platform/s3c-sdhci.0/by-name		/system
platform/s3c-sdhci.0/by-name		/userdata
 
Last edited:

Karadorde

Senior Member
Aug 27, 2010
488
159
0
Sugar Creek
Last edited:

nubecoder

Inactive Recognized Developer
Dec 5, 2010
569
556
0
Is there any way to change the color of text output in ui_print? :)
I believe that is dependent on how your recovery is built.
If you rebuild the recovery it can be changed, but there are no options built in that will allow you to change the colors.
I'm of course referring to ClockworkMod recovery, since Amon_RA's github is outdated, I haven't really looked through his code.

=]
 

drmacinyasha

Senior Member
Jun 4, 2010
1,699
276
0
Sacramento
denh.am
One trick I used in creating the superuser and gapps ZIPs:
Code:
run_program("/sbin/busybox", "mount", "/system");
It runs just fine on both eMMC and MTD devices, and the only prerequisites are that the recovery has busybox, and already knows the mount points (which any good recovery should). Been working on Amon_RA, ClockworkMod 2-4, and TWRP.
 

splattx_x

Senior Member
Mar 31, 2011
204
31
0
Yes, if the 1st char in the line is '#' that line is a comment.

=]
Awesome! Thanks. Now I have to figure out why I can't flash any zip in my phone with CWM.

This guide is very helpful. Any chance anyone knows where to get the update-binary? I know I can get it from a ROM but I'd like to learn so I can cook my own ROM from scratch.