postmarketos-update-kernel: support A/B devices (MR 2214)

Add support for detecting A/B devices and cleanup the script a bit.
This commit is contained in:
Caleb Connolly 2021-06-01 22:26:45 +01:00 committed by Dylan Van Assche
parent d677f1ed32
commit d0d6372405
No known key found for this signature in database
GPG key ID: 8642571587897EA1
2 changed files with 40 additions and 18 deletions

View file

@ -1,5 +1,5 @@
pkgname=postmarketos-update-kernel pkgname=postmarketos-update-kernel
pkgver=0.0.4 pkgver=0.0.5
pkgrel=0 pkgrel=0
pkgdesc="kernel updater script for postmarketOS" pkgdesc="kernel updater script for postmarketOS"
url="https://postmarketos.org" url="https://postmarketos.org"
@ -12,4 +12,7 @@ package() {
install -Dm755 "$srcdir/update-kernel.sh" \ install -Dm755 "$srcdir/update-kernel.sh" \
"$pkgdir/sbin/pmos-update-kernel" "$pkgdir/sbin/pmos-update-kernel"
} }
sha512sums="17de682e88fec2632cb51c6b034e7b9c27e77736d5943906a57e276fb4c594af7af93e411e8cdb1ea2aeefb8d7f231408195102b02af3e8e55d594d1c812ff16 update-kernel.sh"
sha512sums="
256892629581fb9813ef9e7aa5bc18e7c1b80c88b97baeb96d7d432418f4cba79e0687193d7eca48bb3dba1543a3b7d1685f686206497c82df2e1ef80e026eb1 update-kernel.sh
"

View file

@ -15,15 +15,24 @@ deviceinfo_append_dtb=""
# shellcheck disable=SC1091 # shellcheck disable=SC1091
. /etc/deviceinfo . /etc/deviceinfo
FLAVOR=$1 # On A/B devices with bootloader cmdline ON this will return the slot suffix
METHOD=${deviceinfo_flash_method:?} # if booting with an alternate method which erases the stock bootloader cmdline
case $METHOD in # this will be empty and the update will fail.
fastboot|heimdall-bootimg) # https://source.android.com/devices/bootloader/updating#slots
BOOT_PARTITION=$(findfs PARTLABEL="boot") # On non-A/B devices this will be empty
echo "Flashing boot.img..." ab_get_slot() {
ab_slot_suffix=$(grep -o 'androidboot\.slot_suffix=..' /proc/cmdline | cut -d "=" -f2) || :
echo "$ab_slot_suffix"
}
update_android_fastboot() {
BOOT_PART_SUFFIX=$(ab_get_slot) # Empty for non-A/B devices
BOOT_PARTITION=$(findfs PARTLABEL="boot${BOOT_PART_SUFFIX}")
echo "Flashing boot.img to 'boot${BOOT_PART_SUFFIX}'"
dd if=/boot/boot.img-"$FLAVOR" of="$BOOT_PARTITION" bs=1M dd if=/boot/boot.img-"$FLAVOR" of="$BOOT_PARTITION" bs=1M
;; }
heimdall-isorec)
update_android_split_kernel_initfs() {
KERNEL_PARTITION=$(findfs PARTLABEL="${deviceinfo_flash_heimdall_partition_kernel:?}") KERNEL_PARTITION=$(findfs PARTLABEL="${deviceinfo_flash_heimdall_partition_kernel:?}")
INITFS_PARTITION=$(findfs PARTLABEL="${deviceinfo_flash_heimdall_partition_initfs:?}") INITFS_PARTITION=$(findfs PARTLABEL="${deviceinfo_flash_heimdall_partition_initfs:?}")
@ -37,6 +46,16 @@ case $METHOD in
echo "Flashing initramfs..." echo "Flashing initramfs..."
gunzip -c /boot/initramfs-"$FLAVOR" | lzop | dd of="$INITFS_PARTITION" bs=1M gunzip -c /boot/initramfs-"$FLAVOR" | lzop | dd of="$INITFS_PARTITION" bs=1M
}
FLAVOR=$1
METHOD=${deviceinfo_flash_method:?}
case $METHOD in
fastboot|heimdall-bootimg)
update_android_fastboot
;;
heimdall-isorec)
update_android_split_kernel_initfs
;; ;;
0xffff) 0xffff)
echo -n "No need to use this utility, since uboot loads the kernel directly from" echo -n "No need to use this utility, since uboot loads the kernel directly from"