Skip to content

Commit a531fff

Browse files
committed
AK2: add ELF support (repacks as boot.img for unlocked bootloaders)
- add built-in support for unpackelf for Sony ELF devices (see: https://github.com/osm0sis/unpackelf) - kernel section is not gzipped on ELF devices with non-QCDT/non-ELF dtb, which needs compression and the dtb appended before it can be repacked (thanks @tobiaswaldvogel)
1 parent 6fa951e commit a531fff

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

tools/ak2-core.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,28 @@ contains() { test "${1#*$2}" != "$1" && return 0 || return 1; }
2828
# dump boot and extract ramdisk
2929
dump_boot() {
3030
dd if=$block of=/tmp/anykernel/boot.img;
31-
$bin/unpackbootimg -i /tmp/anykernel/boot.img -o $split_img;
31+
if [ -f "$bin/unpackelf" ]; then
32+
$bin/unpackelf -i /tmp/anykernel/boot.img -o $split_img;
33+
mv -f $split_img/boot.img-ramdisk.cpio.gz $split_img/boot.img-ramdisk.gz;
34+
else
35+
$bin/unpackbootimg -i /tmp/anykernel/boot.img -o $split_img;
36+
fi;
3237
if [ $? != 0 ]; then
3338
ui_print " "; ui_print "Dumping/splitting image failed. Aborting..."; exit 1;
3439
fi;
3540
if [ -f "$bin/mkmtkhdr" ]; then
3641
dd bs=512 skip=1 conv=notrunc if=$split_img/boot.img-ramdisk.gz of=$split_img/temprd;
3742
mv -f $split_img/temprd $split_img/boot.img-ramdisk.gz;
3843
fi;
44+
if [ -f "$bin/unpackelf" -a -f "$split_img/boot.img-dtb" ]; then
45+
case $(od -ta -An -N4 $split_img/boot.img-dtb | sed -e 's/del //' -e 's/ //g') in
46+
QCDT|ELF) ;;
47+
*) gzip $split_img/boot.img-zImage;
48+
mv -f $split_img/boot.img-zImage.gz $split_img/boot.img-zImage;
49+
cat $split_img/boot.img-dtb >> $split_img/boot.img-zImage;
50+
rm -f $split_img/boot.img-dtb;;
51+
esac;
52+
fi;
3953
mv -f $ramdisk /tmp/anykernel/rdtmp;
4054
mkdir -p $ramdisk;
4155
cd $ramdisk;
@@ -49,15 +63,25 @@ dump_boot() {
4963
# repack ramdisk then build and write image
5064
write_boot() {
5165
cd $split_img;
52-
cmdline=`cat *-cmdline`;
53-
board=`cat *-board`;
66+
if [ -f *-cmdline ]; then
67+
cmdline=`cat *-cmdline`;
68+
fi;
69+
if [ -f *-board ]; then
70+
board=`cat *-board`;
71+
fi;
5472
base=`cat *-base`;
5573
pagesize=`cat *-pagesize`;
5674
kerneloff=`cat *-kerneloff`;
5775
ramdiskoff=`cat *-ramdiskoff`;
58-
tagsoff=`cat *-tagsoff`;
59-
osver=`cat *-osversion`;
60-
oslvl=`cat *-oslevel`;
76+
if [ -f *-tagsoff ]; then
77+
tagsoff=`cat *-tagsoff`;
78+
fi;
79+
if [ -f *-osversion ]; then
80+
osver=`cat *-osversion`;
81+
fi;
82+
if [ -f *-oslevel ]; then
83+
oslvl=`cat *-oslevel`;
84+
fi;
6185
if [ -f *-second ]; then
6286
second=`ls *-second`;
6387
second="--second $split_img/$second";
@@ -98,7 +122,7 @@ write_boot() {
98122
*) $bin/mkmtkhdr --kernel $kernel; kernel=$kernel-mtk;;
99123
esac;
100124
fi;
101-
$bin/mkbootimg --kernel $kernel --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 --os_version "$osver" --os_patch_level "$oslvl" $dtb --output /tmp/anykernel/boot-new.img;
125+
$bin/mkbootimg --kernel $kernel --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" --os_version "$osver" --os_patch_level "$oslvl" $dtb --output /tmp/anykernel/boot-new.img;
102126
if [ $? != 0 ]; then
103127
ui_print " "; ui_print "Repacking image failed. Aborting..."; exit 1;
104128
elif [ `wc -c < /tmp/anykernel/boot-new.img` -gt `wc -c < /tmp/anykernel/boot.img` ]; then

0 commit comments

Comments
 (0)