From 7ffb3bb1aa0ad78dd9f8a897b69fd89e41178553 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Tue, 26 Aug 2014 16:09:16 -0300 Subject: [PATCH] anykernel.sh: add basic exit statuses - add exit codes to trigger the abort in the updater-script if something goes wrong - add ui_print function to write error message directly back to recovery - compare size of dumped image and new image and abort if the new image is oversized for the partition --- META-INF/com/google/android/updater-script | 7 ++++++- README | 2 ++ anykernel.sh | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script index 98347b6..efd208c 100644 --- a/META-INF/com/google/android/updater-script +++ b/META-INF/com/google/android/updater-script @@ -22,7 +22,12 @@ ifelse(file_getprop("/tmp/anykernel/anykernel.sh", "do.initd") == 1, ) ); ui_print("Installing kernel..."); -assert(run_program("/sbin/sh", "/tmp/anykernel/anykernel.sh")); +run_program("/sbin/sh", "/tmp/anykernel/anykernel.sh"); +ifelse(run_program("/sbin/sh", "-c", "test `cat /tmp/anykernel/exitcode` == 1") == 0, + (unmount("/system"); + abort(); + ) +); ifelse(file_getprop("/tmp/anykernel/anykernel.sh", "do.modules") == 1, (ui_print("Pushing modules..."); ui_print(" "); diff --git a/README b/README index 373a02f..35516a8 100644 --- a/README +++ b/README @@ -46,6 +46,8 @@ Similarly, "line match string" and "line replace string" are the search strings "before/after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string". +You may also use ui_print "" to write messages back to the recovery during the modification process. + // Instructions 1- Place zImage in the root diff --git a/anykernel.sh b/anykernel.sh index a1744a5..3769590 100755 --- a/anykernel.sh +++ b/anykernel.sh @@ -29,10 +29,17 @@ cd $ramdisk; chmod -R 755 $bin; mkdir -p $split_img; +OUTFD=`ps | grep -v "grep" | grep -oE "update(.*)" | cut -d" " -f3`; +ui_print() { echo "ui_print $1" >&$OUTFD; echo "ui_print" >&$OUTFD; } + # dump boot and extract ramdisk dump_boot() { dd if=$block of=/tmp/anykernel/boot.img; $bin/unpackbootimg -i /tmp/anykernel/boot.img -o $split_img; + if [ $? != 0 ]; then + ui_print " "; ui_print "Dumping/unpacking image failed. Aborting..."; + echo 1 > /tmp/anykernel/exitcode; exit; + fi; gunzip -c $split_img/boot.img-ramdisk.gz | cpio -i; } @@ -59,6 +66,10 @@ write_boot() { cd $ramdisk; find . | cpio -H newc -o | gzip > /tmp/anykernel/ramdisk-new.cpio.gz; $bin/mkbootimg --kernel /tmp/anykernel/zImage --ramdisk /tmp/anykernel/ramdisk-new.cpio.gz $second --cmdline "$cmdline" --board "$board" --base $base --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff $secondoff --tags_offset $tagsoff $dtb --output /tmp/anykernel/boot-new.img; + if [ $? != 0 -o `wc -c < /tmp/anykernel/boot-new.img` -gt `wc -c < /tmp/anykernel/boot.img` ]; then + ui_print " "; ui_print "Repacking image failed. Aborting..."; + echo 1 > /tmp/anykernel/exitcode; exit; + fi; dd if=/tmp/anykernel/boot-new.img of=$block; }