@@ -8,14 +8,21 @@ patch=/tmp/anykernel/patch;
88chmod -R 755 $bin ;
99mkdir -p $ramdisk $split_img ;
1010
11- OUTFD=/proc/self/fd/$1 ;
11+ FD=$1 ;
12+ OUTFD=/proc/self/fd/$FD ;
1213
1314# ui_print <text>
1415ui_print () { echo -e " ui_print $1 \nui_print" > $OUTFD ; }
1516
1617# contains <string> <substring>
1718contains () { test " ${1#* $2 } " ! = " $1 " && return 0 || return 1; }
1819
20+ # reset anykernel directory
21+ reset_ak () {
22+ rm -rf $ramdisk $split_img /tmp/anykernel/rdtmp /tmp/anykernel/boot.img /tmp/anykernel/* -new.* ;
23+ . /tmp/anykernel/tools/ak2-core.sh $FD ;
24+ }
25+
1926# dump boot and extract ramdisk
2027split_boot () {
2128 if [ ! -e " $( echo $block | cut -d\ -f1) " ]; then
@@ -32,6 +39,11 @@ split_boot() {
3239 dd bs=1048576 skip=1 conv=notrunc if=/tmp/anykernel/boot-orig.img of=/tmp/anykernel/boot.img;
3340 fi ;
3441 if [ -f " $bin /unpackelf" -a " $( $bin /unpackelf -i /tmp/anykernel/boot.img -h -q 2> /dev/null; echo $? ) " == 0 ]; then
42+ if [ -f " $bin /elftool" ]; then
43+ mkdir $split_img /elftool_out;
44+ $bin /elftool unpack -i /tmp/anykernel/boot.img -o $split_img /elftool_out;
45+ cp -f $split_img /elftool_out/header $split_img /boot.img-header;
46+ fi ;
3547 $bin /unpackelf -i /tmp/anykernel/boot.img -o $split_img ;
3648 mv -f $split_img /boot.img-ramdisk.cpio.gz $split_img /boot.img-ramdisk.gz;
3749 elif [ -f " $bin /dumpimage" ]; then
@@ -48,9 +60,8 @@ split_boot() {
4860 test $? ! = 0 && dumpfail=1;
4961 if [ " $( cat $split_img /boot.img-type) " == " Multi" ]; then
5062 $bin /dumpimage -i /tmp/anykernel/boot.img -p 1 $split_img /boot.img-ramdisk.gz;
51- else
52- dumpfail=1;
5363 fi ;
64+ test $? ! = 0 && dumpfail=1;
5465 elif [ -f " $bin /rkcrc" ]; then
5566 dd bs=4096 skip=8 iflag=skip_bytes conv=notrunc if=/tmp/anykernel/boot.img of=$split_img /boot.img-ramdisk.gz;
5667 elif [ -f " $bin /pxa-unpackbootimg" ]; then
@@ -197,11 +208,13 @@ flash_boot() {
197208 for i in dtb dt.img; do
198209 if [ -f /tmp/anykernel/$i ]; then
199210 dtb=" --dt /tmp/anykernel/$i " ;
211+ rpm=" /tmp/anykernel/$i ,rpm" ;
200212 break ;
201213 fi ;
202214 done ;
203215 if [ ! " $dtb " -a -f * -dtb ]; then
204216 dtb=` ls * -dtb` ;
217+ rpm=" $split_img /$dtb ,rpm" ;
205218 dtb=" --dt $split_img /$dtb " ;
206219 fi ;
207220 cd /tmp/anykernel;
@@ -212,7 +225,10 @@ flash_boot() {
212225 esac ;
213226 fi ;
214227 if [ -f " $bin /mkimage" ]; then
215- $bin /mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n " $name " -d $kernel :$rd boot-new.img;
228+ test " $type " == " Multi" && uramdisk=" :$rd " ;
229+ $bin /mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n " $name " -d $kernel$uramdisk boot-new.img;
230+ elif [ -f " $bin /elftool" ]; then
231+ $bin /elftool pack -o boot-new.img header=$split_img /boot.img-header $kernel $rd ,ramdisk $rpm $split_img /boot.img-cmdline@cmdline;
216232 elif [ -f " $bin /rkcrc" ]; then
217233 $bin /rkcrc -k $rd boot-new.img;
218234 elif [ -f " $bin /pxa-mkbootimg" ]; then
@@ -240,13 +256,19 @@ flash_boot() {
240256 mount -o ro -t auto /dev/block/bootdevice/by-name/system$slot /system_root;
241257 mount -o bind /system_root/system /system;
242258 fi ;
243- unset LD_LIBRARY_PATH;
244259 pk8=` ls $bin /avb/* .pk8` ;
245260 cert=` ls $bin /avb/* .x509.* ` ;
246- /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 /boot boot-new.img $pk8 $cert boot-new-signed.img;
261+ case $block in
262+ * recovery* |* SOS* ) avbtype=recovery;;
263+ * ) avbtype=boot;;
264+ esac ;
265+ savedpath=" $LD_LIBRARY_PATH " ;
266+ unset LD_LIBRARY_PATH;
267+ /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;
247268 if [ $? != 0 ]; then
248269 ui_print " " ; ui_print " Signing image failed. Aborting..." ; exit 1;
249270 fi ;
271+ test " $savedpath " && export LD_LIBRARY_PATH=" $savedpath " ;
250272 mv -f boot-new-signed.img boot-new.img;
251273 if [ -d " /system_root" ]; then
252274 umount /system;
@@ -362,7 +384,7 @@ insert_line() {
362384 after) offset=1;;
363385 esac ;
364386 line=$(( `grep - n "$4 " $1 | head - n1 | cut - d: - f1 ` + offset)) ;
365- if [ " $( wc -l $1 | cut -d\ -f1) " -le " $line " ]; then
387+ if [ " $( wc -l $1 | cut -d\ -f1) " -lt " $line " ]; then
366388 echo " $5 " >> $1 ;
367389 else
368390 sed -i " ${line} s;^;${5} \n;" $1 ;
@@ -438,15 +460,16 @@ patch_fstab() {
438460 fi ;
439461}
440462
441- # patch_cmdline <cmdline match string> [ <replacement string>]
463+ # patch_cmdline <cmdline entry name> <replacement string>
442464patch_cmdline () {
443465 cmdfile=` ls $split_img /* -cmdline` ;
444466 if [ -z " $( grep " $1 " $cmdfile ) " ]; then
445467 cmdtmp=` cat $cmdfile ` ;
446- echo " $cmdtmp $1 " > $cmdfile ;
468+ echo " $cmdtmp $2 " > $cmdfile ;
469+ sed -i -e ' s; *; ;g' -e ' s;[ \t]*$;;' $cmdfile ;
447470 else
448471 match=$( grep -o " $1 .*$" $cmdfile | cut -d\ -f1) ;
449- sed -i -e " s;${match} ;${2} ;" -e ' s; ; ;' -e ' s;[ \t]*$;;' $cmdfile ;
472+ sed -i -e " s;${match} ;${2} ;" -e ' s; * ; ;g ' -e ' s;[ \t]*$;;' $cmdfile ;
450473 fi ;
451474}
452475
0 commit comments