Update Bootloader In An OTA Using The updater_script

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update Bootloader In An OTA Using The updater_script

7,898 Views
freewaymad
Contributor IV

Hi,

Maybe some one can Help me with this. I am trying to update the bootloader in an OTA (update.zip). I added the "u-boot-no-padding.bin" to the update zip, and then modified the updater_script. Is there anyone who might be able to tell if this updater_script is correct? I added the section at the end about u-boot.


show_progress(0.1, 0);
format("ext4", "EMMC", "/dev/block/mmcblk0p5");
mount("ext4", "EMMC", "/dev/block/mmcblk0p5", "/system");
package_extract_dir("system", "/system");
symlink("toolbox", "/system/bin/ifconfig");
symlink("toolbox", "/system/bin/hd");
symlink("toolbox", "/system/bin/setprop");
symlink("toolbox", "/system/bin/dmesg");
symlink("toolbox", "/system/bin/load_policy");
symlink("toolbox", "/system/bin/kill");
symlink("toolbox", "/system/bin/reboot");
symlink("toolbox", "/system/bin/top");
symlink("toolbox", "/system/bin/getevent");
symlink("toolbox", "/system/bin/clear");
symlink("toolbox", "/system/bin/setsebool");
symlink("toolbox", "/system/bin/setconsole");
symlink("toolbox", "/system/bin/mount");
symlink("toolbox", "/system/bin/md5");
symlink("toolbox", "/system/bin/wipe");
symlink("toolbox", "/system/bin/newfs_msdos");
symlink("toolbox", "/system/bin/cat");
symlink("toolbox", "/system/bin/renice");
symlink("toolbox", "/system/bin/chmod");
symlink("toolbox", "/system/bin/runcon");
symlink("toolbox", "/system/bin/log");
symlink("toolbox", "/system/bin/start");
symlink("toolbox", "/system/bin/ionice");
symlink("toolbox", "/system/bin/printenv");
symlink("mksh", "/system/bin/sh");
symlink("toolbox", "/system/bin/du");
symlink("toolbox", "/system/bin/nandread");
symlink("toolbox", "/system/bin/mv");
symlink("toolbox", "/system/bin/df");
symlink("toolbox", "/system/bin/dd");
symlink("toolbox", "/system/bin/chcon");
symlink("toolbox", "/system/bin/restorecon");
symlink("toolbox", "/system/bin/cp");
symlink("toolbox", "/system/bin/watchprops");
symlink("toolbox", "/system/bin/rm");
symlink("toolbox", "/system/bin/vmstat");
symlink("toolbox", "/system/bin/ioctl");
symlink("toolbox", "/system/bin/notify");
symlink("toolbox", "/system/bin/lsmod");
symlink("toolbox", "/system/bin/iftop");
symlink("toolbox", "/system/bin/touch");
symlink("toolbox", "/system/bin/chown");
symlink("toolbox", "/system/bin/uptime");
symlink("toolbox", "/system/bin/ln");
symlink("toolbox", "/system/bin/umount");
symlink("toolbox", "/system/bin/ps");
symlink("toolbox", "/system/bin/smd");
symlink("toolbox", "/system/bin/getsebool");
symlink("toolbox", "/system/bin/grep");
symlink("toolbox", "/system/bin/ls");
symlink("toolbox", "/system/bin/date");
symlink("toolbox", "/system/bin/getprop");
symlink("toolbox", "/system/bin/sync");
symlink("toolbox", "/system/bin/sleep");
symlink("toolbox", "/system/bin/insmod");
symlink("toolbox", "/system/bin/lsof");
symlink("toolbox", "/system/bin/mkdir");
symlink("toolbox", "/system/bin/route");
symlink("toolbox", "/system/bin/schedtop");
symlink("toolbox", "/system/bin/id");
symlink("toolbox", "/system/bin/setenforce");
symlink("toolbox", "/system/bin/getenforce");
symlink("toolbox", "/system/bin/sendevent");
symlink("toolbox", "/system/bin/rmdir");
symlink("toolbox", "/system/bin/rmmod");
symlink("toolbox", "/system/bin/netstat");
symlink("toolbox", "/system/bin/cmp");
symlink("toolbox", "/system/bin/stop");
set_perm_recursive(0, 0, 0755, 0644, "/system");
set_perm_recursive(0, 0, 0777, 0777, "/system/etc/init.d");
set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
set_perm(0, 3003, 06755, "/system/bin/ip");
set_perm(0, 3003, 02750, "/system/bin/netcfg");
set_perm(0, 3004, 02755, "/system/bin/ping");
set_perm(0, 2000, 06750, "/system/bin/run-as");
set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");
set_perm(0, 0, 0755, "/system/etc/bluetooth");
set_perm(1000, 1000, 0640, "/system/etc/bluetooth/auto_pair_devlist.conf");
set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor/etc");
set_perm(0, 2000, 0755, "/system/vendor/lib");
set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
set_perm(0, 0, 06755, "/system/xbin/su");
symlink("/system/xbin/su", "/system/bin/su");
show_progress(0.1, 10);
show_progress(0.2, 0);
package_extract_file("boot.img", "/dev/block/mmcblk0p1");
show_progress(0.2, 10);
# Write u-boot to 1K position.
# u-boot binary should be a no padding uboot!
# For eMMC(iNand) device, needs to unlock boot partition.
ui_print("writting u-boot...");
package_extract_file("files/u-boot-no-padding.bin", "/tmp/u-boot-no-padding.bin");
sysfs_file_write("class/mmc_host/mmc0/mmc0:0001/boot_config", "1");
simple_dd("/tmp/u-boot-no-padding.bin", "/dev/block/mmcblk0", 1024);
sysfs_file_write("class/mmc_host/mmc0/mmc0:0001/boot_config", "8");
show_progress(0.1, 5);
unmount("/system");


I really need help with this. Please help.

Thank-you,

Dave

Labels (3)
13 Replies

4,342 Views
mixa
Contributor III

Hi all,

I`m having problem with this script for u-boot update. I thnik that update binary does not have commands sysfs_file_write or simple_dd. I have looked in recovery sources and these are the supported commands:

RegisterFunction("mount", MountFn);
RegisterFunction("is_mounted", IsMountedFn);
RegisterFunction("unmount", UnmountFn);
RegisterFunction("format", FormatFn);
RegisterFunction("show_progress", ShowProgressFn);
RegisterFunction("set_progress", SetProgressFn);
RegisterFunction("delete", DeleteFn);
RegisterFunction("delete_recursive", DeleteFn);
RegisterFunction("package_extract_dir", PackageExtractDirFn);
RegisterFunction("package_extract_file", PackageExtractFileFn);
RegisterFunction("symlink", SymlinkFn);
RegisterFunction("set_perm", SetPermFn);
RegisterFunction("set_perm_recursive", SetPermFn);
RegisterFunction("getprop", GetPropFn);
RegisterFunction("file_getprop", FileGetPropFn);
RegisterFunction("write_raw_image", WriteRawImageFn);
RegisterFunction("apply_patch", ApplyPatchFn);
RegisterFunction("apply_patch_check", ApplyPatchCheckFn);
RegisterFunction("apply_patch_space", ApplyPatchSpaceFn);
RegisterFunction("read_file", ReadFileFn);
RegisterFunction("sha1_check", Sha1CheckFn);
RegisterFunction("wipe_cache", WipeCacheFn);
RegisterFunction("ui_print", UIPrintFn);

RegisterFunction("run_program", RunProgramFn);

Where do I find updater binary that supports these commands?

0 Kudos
Reply

4,342 Views
gary_bisson
Senior Contributor III

Hi Mihailo,

You can find the simple_dd function here:

t80_platform_bootable/install.c at master · onyx-intl/t80_platform_bootable · GitHub

Same for the sysfs write:

t80_platform_bootable/install.c at master · onyx-intl/t80_platform_bootable · GitHub

But instead of modifying the recovery project directly you should create your own libupdater which would contain those two functions. Here is an example of a custom libupdater which add a bootloader update command (from the AOSP source tree):

Cross Reference: /device/samsung/manta/BoardConfig.mk

Cross Reference: /device/samsung/manta/recovery/

Hope this helps.

Regards,

Gary

0 Kudos
Reply

4,342 Views
mixa
Contributor III

Hi, thanks for fast reply.

In the meanwhile I have found this functions on T80, and just for the test I have added two functions (sysfs_file_write and simple_dd) to recovery project. It compiled fine, and I have used u-boot-no-padding.bin in OTA. But when I flash it over OTA, my device gets bricked. And now when it powers on it goes immediately to Mfg download mode. No activity on UART. I tried full flash with MfgTool but it still won`t boot.

How can I unbrick it?

0 Kudos
Reply

4,342 Views
mixa
Contributor III

The problem was in sysfs_file_write("class/mmc_host/mmc0/mmc0:0001/boot_config", "8"). On our custom device it seems device is using boot1 partition so boot_config must be set to 0x10 instead of 8.

Nonetheless, I`m still unable to update bootloader through OTA. I have tried with dd from shell when device boots and it works, but from OTA update it stays the same.

0 Kudos
Reply

4,342 Views
mixa
Contributor III

Again, copy/paste is developers worst nightmare. In the script there is command to extract uboot to tmp: package_extract_file("files/u-boot-no-padding.bin", "/tmp/u-boot-no-padding.bin"). I have not put u-boot-no-padding.bin to directory files and simple_dd function was failing but because it is not printing anything or return with error, everything passed correctly. Now it works :smileywink:

@Gary The only question for you is, if I make the updater binary as a custom updater in device do I have to implement all the functions or just new ones?

0 Kudos
Reply

4,342 Views
gary_bisson
Senior Contributor III

Hi Mihailo,

What I suggested is to make a custom update *library* which will be link against the rest of the updater tool thanks to its declaration as a "TARGET_RECOVERY_UPDATER_LIBS". This library should therefore only contain the extra functions you want to add to the updater tool.

Really the best is to follow what is done in the AOSP for other products like the manta.

Regards,

Gary

0 Kudos
Reply

4,342 Views
mixa
Contributor III

Thanks Gary.


I did that way and it is good. I`m just having trouble how to put u-boot.bin during build into OTA zip file. As our u-boot is built with android build (called in Makefile) and it is copied in device out directory I`m not sure how to include it in target_files dir which will be zipped during OTA build.

0 Kudos
Reply

4,342 Views
mixa
Contributor III

I succeeded to include u-boot in OTA file. I hade to modify build/core/Makefile and add this line:$(hide) $(ACP) $(PRODUCT_OUT)/u-boot-6dl.bin $(zip_root)/BOOT/u-boot-6dl.bin

Then I have made device specific releasetools.py that will add commands to update-script:

def FullOTA_InstallEnd(info):

  # copy the data into the package.

  u_boot_bin = info.input_zip.read("BOOT/u-boot-6dl.bin")

  common.ZipWriteStr(info.output_zip, "u-boot-6dl.bin", u_boot_bin)

  # emit the script code to install this data on the device

  info.script.AppendExtra("""ui_print("Upgrading u-boot...");""")

  info.script.AppendExtra("""package_extract_file("u-boot-6dl.bin", "/tmp/u-boot-6dl.bin");""")

  info.script.AppendExtra("""simple_dd("/tmp/u-boot-6dl.bin", "/dev/block/mmcblk0", 1024, 1024);""") 

  info.script.AppendExtra("""ui_print("Finished upgrading u-boot...");""")

I have also modified simple_dd to skip first 1K bytes from input file so that I do not have to make u-boot without padding.

4,342 Views
ningli
Contributor III

Hi Mihailo,

I am using OTA to update uboot, but it doesn't work. I think my problem is same as yours and your code is helpful to me .

BTW, I want to know how do you modify simple_dd to skip first 1K bytes from input file, can you share your code to me?

Thanks very much!

0 Kudos
Reply

4,341 Views
igorpadykov
NXP Employee
NXP Employee

Hi Dave, could you provide more details

what are you doing and what board and software using.

BTW what is "OTA" ?

0 Kudos
Reply

4,342 Views
freewaymad
Contributor IV

Hi Chip,

This is for android JB4.3_1.1.0 GA release. I am using Ubuntu 14.04 (Trusty). According to the documentation with this release the bootloader needs to be upgraded (ICS to Jellybean). This is what is in FAQ of the documentation:

How do I customize the update script to update uboot?

Because Android only upgrades the boot.img, system.img, and recovery partitions, the automatically generated update

package does not support upgrading bootloader. If you need to upgrade the bootloader, you need to modify the update

package and perform the signing work manually.

1. Unzip the update.zip, and then modify the updater_script by implementing the following operations.

To upgrade uboot to NOR flash, refer to this script:

ui_print("writting u-boot...");

write_raw_image("u-boot.bin", "/dev/mtd0");

show_progress(0.1, 5);

To upgrade uboot for eMMC storage, because u-boot may be stored in the "boot partition" of eMMC, you need to

perform some system file operations before dd, for example,

# Write u-boot to 1K position.

# u-boot binary should be a no padding uboot!

# For eMMC(iNand) device, needs to unlock boot partition.

ui_print("writting u-boot...");

package_extract_file("files/u-boot-no-padding.bin", "/tmp/u-boot-no-padding.bin");

sysfs_file_write("class/mmc_host/mmc0/mmc0:0001/boot_config", "1");

simple_dd("/tmp/u-boot-no-padding.bin", "/dev/block/mmcblk0", 1024);

sysfs_file_write("class/mmc_host/mmc0/mmc0:0001/boot_config", "8");

show_progress(0.1, 5);

2. Resign the update package by using the following command:

$ make_update_zip.sh ~/mydroid ~/update-dir

I did that but it will not update. I get that the signature fails and the update stops. I cannot even do an adb sideload. I even tried with a custom recovery (TWRP) and I get the same thing, but with this recovery I can turn the signature verification off. So I did, but I get flash error Status 7. It just seems like trying to do this in an OTA (over the air or update.zip) does not work.

Regards,

Dave

0 Kudos
Reply

4,342 Views
alejandrolozan1
NXP Employee
NXP Employee

Let me try that, but would you be nice to explain the process of OTA?

Regards

Alejandro

0 Kudos
Reply

4,342 Views
freewaymad
Contributor IV

Hi Alejandro,

You have make the package as a "update.zip". There are two ways that I know of; the first way is right in the documentation FAQ.

35 How do I build an OTA package?

The Android build system supports auto generation of update.zip. It can generate the updater_script and all system.img files.

You can use the following command to generate an OTA package.

$ make dist

For example, you use this command to build sabresd_6dq product after the build finish.

$ make PRODUCT=sabresd_6dq-eng dist -j4

You can find a few packages in the following path for the OTA update.zip to do the OTA and make a different package.

• out/dist/sabresd_6dq-ota-eng.xxx.zip

• out/target/proudct/sabresd_6dq/sabresd_6dq-ota-eng.xxx.zip

The package we used before R13.1 was update.zip. In this package, however, everything is automatically generated.

You would then sign the update.zip with your digital keys (also in the FAQ).

The second way would be to use "Dsixda's Kitchen". This is a whole tutorial in itself, but a very awesome tool.

Next you would unzip the update and navigate to the updater_script in the "META-INF folder:

META-INF/com/google/android

Update the updater script to load the new bootloader if needed and zip the update back up.

Put the update on a sdcard (not in any folder) and update through the recovery, adb, or fastboot.

TIP: updating the updater_script in windows: do not use notepad, use notepad++.

        updating the updater_script in Ubuntu: you can use gedit, but I prefer Geany or SciTE.

Hope this helps,

Dave

0 Kudos
Reply