2017-10-14 23:17:49 +00:00
|
|
|
#!/bin/ash
|
|
|
|
# shellcheck shell=dash
|
|
|
|
set -e
|
|
|
|
|
2020-10-26 11:55:43 +00:00
|
|
|
# Declare used deviceinfo variables to pass shellcheck
|
|
|
|
deviceinfo_append_dtb=""
|
|
|
|
|
2017-10-14 23:17:49 +00:00
|
|
|
# shellcheck disable=SC1091
|
|
|
|
. /etc/deviceinfo
|
|
|
|
|
2021-06-01 21:26:45 +00:00
|
|
|
# On A/B devices with bootloader cmdline ON this will return the slot suffix
|
|
|
|
# if booting with an alternate method which erases the stock bootloader cmdline
|
|
|
|
# this will be empty and the update will fail.
|
|
|
|
# https://source.android.com/devices/bootloader/updating#slots
|
|
|
|
# On non-A/B devices this will be empty
|
|
|
|
ab_get_slot() {
|
|
|
|
ab_slot_suffix=$(grep -o 'androidboot\.slot_suffix=..' /proc/cmdline | cut -d "=" -f2) || :
|
|
|
|
echo "$ab_slot_suffix"
|
|
|
|
}
|
|
|
|
|
2021-12-24 09:02:48 +00:00
|
|
|
# $1: partition to flash from deviceinfo
|
2021-06-01 21:26:45 +00:00
|
|
|
update_android_fastboot() {
|
|
|
|
BOOT_PART_SUFFIX=$(ab_get_slot) # Empty for non-A/B devices
|
2021-12-24 09:02:48 +00:00
|
|
|
BOOT_PARTITION=$(findfs PARTLABEL="$1${BOOT_PART_SUFFIX}")
|
|
|
|
echo "Flashing boot.img to '$1${BOOT_PART_SUFFIX}'"
|
2021-08-17 23:48:49 +00:00
|
|
|
dd if=/boot/boot.img of="$BOOT_PARTITION" bs=1M
|
2021-06-01 21:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_android_split_kernel_initfs() {
|
|
|
|
KERNEL_PARTITION=$(findfs PARTLABEL="${deviceinfo_flash_heimdall_partition_kernel:?}")
|
|
|
|
INITFS_PARTITION=$(findfs PARTLABEL="${deviceinfo_flash_heimdall_partition_initfs:?}")
|
|
|
|
|
2021-08-17 23:48:49 +00:00
|
|
|
KERNEL="vmlinuz"
|
2021-06-01 21:26:45 +00:00
|
|
|
if [ "${deviceinfo_append_dtb}" = "true" ]; then
|
|
|
|
KERNEL="$KERNEL-dtb"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Flashing kernel ($KERNEL)..."
|
|
|
|
dd if=/boot/"$KERNEL" of="$KERNEL_PARTITION" bs=1M
|
|
|
|
|
|
|
|
echo "Flashing initramfs..."
|
2021-08-17 23:48:49 +00:00
|
|
|
gunzip -c /boot/initramfs | lzop | dd of="$INITFS_PARTITION" bs=1M
|
2021-06-01 21:26:45 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 22:12:52 +00:00
|
|
|
METHOD=${deviceinfo_flash_method:?}
|
2017-10-14 23:17:49 +00:00
|
|
|
case $METHOD in
|
2021-12-24 09:02:48 +00:00
|
|
|
fastboot)
|
2022-04-27 13:27:58 +00:00
|
|
|
update_android_fastboot "${deviceinfo_flash_fastboot_partition_kernel:-boot}"
|
2021-12-24 09:02:48 +00:00
|
|
|
;;
|
|
|
|
heimdall-bootimg)
|
2022-04-27 13:27:58 +00:00
|
|
|
update_android_fastboot "${deviceinfo_flash_heimdall_partition_kernel:-KERNEL}"
|
2017-10-14 23:17:49 +00:00
|
|
|
;;
|
|
|
|
heimdall-isorec)
|
2021-06-01 21:26:45 +00:00
|
|
|
update_android_split_kernel_initfs
|
2017-10-14 23:17:49 +00:00
|
|
|
;;
|
2017-10-30 19:56:38 +00:00
|
|
|
0xffff)
|
2017-10-14 23:17:49 +00:00
|
|
|
echo -n "No need to use this utility, since uboot loads the kernel directly from"
|
|
|
|
echo " the boot partition. Your kernel should be updated already."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Devices with flash method: $METHOD are not supported."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo "Done."
|