AK3: allow ChromeOS auto-detect, clean up signing, fixes

- since magiskboot has built-in detection for the ChromeOS image pre-header signature, allow it to be auto-detected and if futility and signing files are present re-sign automatically (thanks @Zackptg5 for the nudge)
- simplify signing and error catching
- fix typo breaking ramdisk_recovery partition detection
- hide expected stderr for formats where some files may not exist (cmdline for ELF, etc.)
This commit is contained in:
osm0sis committed 2019-06-10 23:12:00 -03:00
1 parent a48ce68a7c
commit 6d25afd03a
1 file changed
+15 -12
+15 -12
View File
@@ -69,7 +69,7 @@ split_boot() {
test $? != 0 && dumpfail=1; test $? != 0 && dumpfail=1;
mv -f boot.img-zImage kernel.gz; mv -f boot.img-zImage kernel.gz;
mv -f boot.img-ramdisk.cpio.gz ramdisk.cpio.gz; mv -f boot.img-ramdisk.cpio.gz ramdisk.cpio.gz;
mv -f boot.img-cmdline cmdline.txt; mv -f boot.img-cmdline cmdline.txt 2>/dev/null;
if [ -f boot.img-dt -a ! -f "$bin/elftool" ]; then if [ -f boot.img-dt -a ! -f "$bin/elftool" ]; then
case $(od -ta -An -N4 boot.img-dt | sed -e 's/ del//' -e 's/ //g') in case $(od -ta -An -N4 boot.img-dt | sed -e 's/ del//' -e 's/ //g') in
QCDT|ELF) mv -f boot.img-dt dt;; QCDT|ELF) mv -f boot.img-dt dt;;
@@ -102,6 +102,10 @@ split_boot() {
dd bs=4096 skip=8 iflag=skip_bytes conv=notrunc if=$bootimg of=ramdisk.cpio.gz; dd bs=4096 skip=8 iflag=skip_bytes conv=notrunc if=$bootimg of=ramdisk.cpio.gz;
else else
$bin/magiskboot unpack -h $bootimg; $bin/magiskboot unpack -h $bootimg;
case $? in
1) dumpfail=1;;
2) touch chromeos;;
esac;
fi; fi;
if [ $? != 0 -o "$dumpfail" ]; then if [ $? != 0 -o "$dumpfail" ]; then
@@ -205,13 +209,13 @@ repack_ramdisk() {
# flash_boot (build, sign and write image only) # flash_boot (build, sign and write image only)
flash_boot() { flash_boot() {
local varlist kernel ramdisk cmdline part0 part1 pk8 cert avbtype; local varlist kernel ramdisk cmdline part0 part1 signfail pk8 cert avbtype;
cd $split_img; cd $split_img;
if [ -f "$bin/mkimage" ]; then if [ -f "$bin/mkimage" ]; then
varlist="name arch os type comp addr ep"; varlist="name arch os type comp addr ep";
elif [ -f "$bin/mkbootimg" -a -f "$bin/unpackelf" -a -f boot.img-base ]; then elif [ -f "$bin/mkbootimg" -a -f "$bin/unpackelf" -a -f boot.img-base ]; then
mv -f cmdline.txt boot.img-cmdline; mv -f cmdline.txt boot.img-cmdline 2>/dev/null;
varlist="cmdline base pagesize kerneloff ramdiskoff tagsoff"; varlist="cmdline base pagesize kerneloff ramdiskoff tagsoff";
fi; fi;
for i in $varlist; do for i in $varlist; do
@@ -291,11 +295,10 @@ flash_boot() {
cd $home; cd $home;
if [ -f "$bin/futility" -a -d "$bin/chromeos" ]; then if [ -f "$bin/futility" -a -d "$bin/chromeos" ]; then
$bin/futility vbutil_kernel --pack boot-new-signed.img --keyblock $bin/chromeos/kernel.keyblock --signprivate $bin/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz boot-new.img --bootloader $bin/chromeos/empty --config $bin/chromeos/empty --arch arm --flags 0x1; if [ -f "$split_img/chromeos" ]; then
if [ $? != 0 ]; then $bin/futility vbutil_kernel --pack boot-new-signed.img --keyblock $bin/chromeos/kernel.keyblock --signprivate $bin/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz boot-new.img --bootloader $bin/chromeos/empty --config $bin/chromeos/empty --arch arm --flags 0x1;
abort "Signing image failed. Aborting...";
fi; fi;
mv -f boot-new-signed.img boot-new.img; test $? != 0 && signfail=1;
fi; fi;
if [ -f "$bin/BootSignature_Android.jar" -a -d "$bin/avb" ]; then if [ -f "$bin/BootSignature_Android.jar" -a -d "$bin/avb" ]; then
pk8=$(ls $bin/avb/*.pk8); pk8=$(ls $bin/avb/*.pk8);
@@ -306,12 +309,12 @@ flash_boot() {
esac; esac;
if [ "$(/system/bin/dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then if [ "$(/system/bin/dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then
/system/bin/dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img; /system/bin/dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img;
if [ $? != 0 ]; then
abort "Signing image failed. Aborting...";
fi;
fi; fi;
mv -f boot-new-signed.img boot-new.img;
fi; fi;
if [ $? != 0 -o "$signfail"]; then
abort "Signing image failed. Aborting...";
fi;
mv -f boot-new-signed.img boot-new.img 2>/dev/null;
if [ ! -f boot-new.img ]; then if [ ! -f boot-new.img ]; then
abort "No repacked image found to flash. Aborting..."; abort "No repacked image found to flash. Aborting...";
@@ -635,7 +638,7 @@ setup_ak() {
boot|recovery) boot|recovery)
case $block in case $block in
boot) parttype="ramdisk boot BOOT LNX android_boot bootimg KERN-A kernel KERNEL";; boot) parttype="ramdisk boot BOOT LNX android_boot bootimg KERN-A kernel KERNEL";;
recovery) parttype="ramdisk_recovey recovery RECOVERY SOS android_recovery";; recovery) parttype="ramdisk_recovery recovery RECOVERY SOS android_recovery";;
esac; esac;
for name in $parttype; do for name in $parttype; do
for part in $name$slot $name; do for part in $name$slot $name; do