From ec9a4e863a25de19f261d2b9fbd7415a4e684aa5 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Wed, 12 Jan 2022 23:45:40 -0800 Subject: [PATCH] temp/u-boot-librem5: enable efidebug, enable auto update (MR 2842) This enables an auto-update mechanism on post-upgrade for the u-boot firmware on the librem 5 and librem 5 devkit. This mechanism is largely copied from the implementation in the pinephone u-boot package. efidebug is useful for booting the kernel via EFI mode in u-boot. --- .../0001-Enable-efidebug-command.patch | 37 ++++++++++++ temp/u-boot-librem5/APKBUILD | 15 +++-- .../u-boot-librem5-devkit.post-upgrade | 1 + .../u-boot-librem5.post-upgrade | 8 +-- temp/u-boot-librem5/update-u-boot | 59 +++++++++++++++---- 5 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 temp/u-boot-librem5/0001-Enable-efidebug-command.patch create mode 120000 temp/u-boot-librem5/u-boot-librem5-devkit.post-upgrade diff --git a/temp/u-boot-librem5/0001-Enable-efidebug-command.patch b/temp/u-boot-librem5/0001-Enable-efidebug-command.patch new file mode 100644 index 000000000..0d843c5df --- /dev/null +++ b/temp/u-boot-librem5/0001-Enable-efidebug-command.patch @@ -0,0 +1,37 @@ +From 6984c79c9a7a5952ffe324a0a378281d80d1b738 Mon Sep 17 00:00:00 2001 +From: Clayton Craft +Date: Wed, 12 Jan 2022 22:41:59 -0800 +Subject: [PATCH] Enable efidebug command + +--- + configs/librem5_defconfig | 1 + + configs/librem5_devkit_defconfig | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/configs/librem5_defconfig b/configs/librem5_defconfig +index 3ec5ddc155..45f1b3b545 100644 +--- a/configs/librem5_defconfig ++++ b/configs/librem5_defconfig +@@ -21,6 +21,7 @@ CONFIG_CMD_GPIO=y + CONFIG_CMD_I2C=y + CONFIG_CMD_SF=y + CONFIG_CMD_CACHE=y ++CONFIG_CMD_EFIDEBUG=y + CONFIG_CMD_REGULATOR=y + CONFIG_CMD_EXT4_WRITE=y + CONFIG_OF_CONTROL=y +diff --git a/configs/librem5_devkit_defconfig b/configs/librem5_devkit_defconfig +index ec9e74feb8..2f76984860 100644 +--- a/configs/librem5_devkit_defconfig ++++ b/configs/librem5_devkit_defconfig +@@ -21,6 +21,7 @@ CONFIG_CMD_GPIO=y + CONFIG_CMD_I2C=y + CONFIG_CMD_SF=y + CONFIG_CMD_CACHE=y ++CONFIG_CMD_EFIDEBUG=y + CONFIG_CMD_REGULATOR=y + CONFIG_CMD_EXT4_WRITE=y + CONFIG_OF_CONTROL=y +-- +2.34.1 + diff --git a/temp/u-boot-librem5/APKBUILD b/temp/u-boot-librem5/APKBUILD index 1501977ae..a1d328107 100644 --- a/temp/u-boot-librem5/APKBUILD +++ b/temp/u-boot-librem5/APKBUILD @@ -1,6 +1,6 @@ # Forked from Alpine, so we can build it with Librem 5 phone support pkgname=u-boot-librem5 -pkgver=0.11 +pkgver=0.12 pkgrel=0 # 'librem5' branch in atf repo _atfversion="92c2de12d36b31938ce940d5cac3c30a98665237" @@ -20,8 +20,9 @@ source=" arm-trusted-firmware-${_atfversion}.tar.gz::https://source.puri.sm/Librem5/arm-trusted-firmware/-/archive/${_atfversion}/arm-trusted-firmware-${_atfversion}.tar.gz https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-${_firmwareversion}.bin update-u-boot + 0001-Enable-efidebug-command.patch " -install="$pkgname.post-upgrade" +install="$pkgname.post-upgrade $pkgname-devkit.post-upgrade" subpackages="$pkgname-devkit" _ubootbuilddir="$srcdir"/uboot-imx-${_ubootversion} @@ -74,17 +75,20 @@ build() { dd if=/dev/zero of=devkit-boot.img bs=1024 count=1055 dd if="$_m4builddir"/m4.bin conv=notrunc of="$_ubootbuilddir"/devkit-boot.img bs=1024 dd if="$_ubootbuilddir"/devkit-flash.bin conv=notrunc of="$_ubootbuilddir"/devkit-boot.img bs=1024 seek=31 + sha512sum -b "$_ubootbuilddir"/devkit-boot.img > "$_ubootbuilddir"/devkit-boot.img.sha512 # phone dd if=/dev/zero of=phone-boot.img bs=1024 count=1055 dd if="$_m4builddir"/m4.bin conv=notrunc of="$_ubootbuilddir"/phone-boot.img bs=1024 dd if="$_ubootbuilddir"/phone-flash.bin conv=notrunc of="$_ubootbuilddir"/phone-boot.img bs=1024 seek=31 - msg "done!" + sha512sum -b "$_ubootbuilddir"/phone-boot.img > "$_ubootbuilddir"/phone-boot.img.sha512 } package() { install -D -m644 "$_ubootbuilddir"/phone-boot.img \ "$pkgdir/usr/share/u-boot/librem5/phone-boot.img" + install -D -m644 "$_ubootbuilddir"/phone-boot.img.sha512 \ + "$pkgdir/usr/share/u-boot/librem5/phone-boot.img.sha512" install -D -m 755 "$srcdir"/update-u-boot \ "$pkgdir"/usr/sbin/update-u-boot } @@ -93,6 +97,8 @@ devkit() { pkgdesc="u-boot bootloader for the Purism Librem5 devkit" install -D -m644 "$_ubootbuilddir"/devkit-boot.img \ "$subpkgdir/usr/share/u-boot/librem5/devkit-boot.img" + install -D -m644 "$_ubootbuilddir"/devkit-boot.img.sha512 \ + "$subpkgdir/usr/share/u-boot/librem5/devkit-boot.img.sha512" install -D -m 755 "$srcdir"/update-u-boot \ "$subpkgdir"/usr/sbin/update-u-boot } @@ -103,5 +109,6 @@ ee540631b4bc0a33dfb29d9ba6e1dcd6a5cb1d43a4bc1ab2c7a29637d9c141d1c6559c933a48b8ce 035a4358ddf586c829da7fa2fb0d9d1df913c0c454f2d0e57ff0c6794552e49950fb6373f9aaf72e0e4c78ab411496aabbc60bf66cd76e35053f7a2d77911735 m4-a017421c340a69f2392086da93841244f78a03c5.tar.gz cd8c9411ae0e57d2c8c700bf3e8c8d03e7dab955ace249a00911dd8c42b42929e0de3a5885eb9b1d945174abc8cfb177595d83c235e757c70640f451b62547ba arm-trusted-firmware-92c2de12d36b31938ce940d5cac3c30a98665237.tar.gz 1f968558bf158401ee5afe1c67e67bdd8ca2cb5d07029e78c745e751c665b68fa74128fca8b7161501a6445bbb18e8d463b42d787a61132db5c8778703462668 firmware-imx-8.12.bin -63b6339d2a06b58f47d0f0b6f9a2c0fe25aa8edd523599b630ee3ea683f24ce31150a012e6ec5313b9c247529d0b8813d0c87cb6d0d2e91321c1cf7864cca475 update-u-boot +8eb2793814e53752ba8635694094ea43234ed6411ff4fd3e39c970fd4c4fa1b515b292a6d34b6e9a4ffbb573b1cf18a043f6be4e5cf95fa0ff4b9df9afe05c63 update-u-boot +24883f7293ebe7995aca8caae872a9c192b56651bfce9f408e5c9d001eda4df59fe755c006e737ff3ca42041577f711e4e600bd71629c2abad4b4a593062906c 0001-Enable-efidebug-command.patch " diff --git a/temp/u-boot-librem5/u-boot-librem5-devkit.post-upgrade b/temp/u-boot-librem5/u-boot-librem5-devkit.post-upgrade new file mode 120000 index 000000000..8225e0355 --- /dev/null +++ b/temp/u-boot-librem5/u-boot-librem5-devkit.post-upgrade @@ -0,0 +1 @@ +u-boot-librem5.post-upgrade \ No newline at end of file diff --git a/temp/u-boot-librem5/u-boot-librem5.post-upgrade b/temp/u-boot-librem5/u-boot-librem5.post-upgrade index 3e729005b..07137aeae 100644 --- a/temp/u-boot-librem5/u-boot-librem5.post-upgrade +++ b/temp/u-boot-librem5/u-boot-librem5.post-upgrade @@ -1,9 +1,3 @@ #!/bin/sh -cat 1>&2 </dev/null)" in purism,librem5r*) board=librem5;; + purism,librem5-devkit*) board=librem5-devkit;; esac fi if [ -z "$device" ]; then case "$board" in - librem5) device=/dev/mmcblk0 ;; + librem5*) device=/dev/mmcblk0 ;; esac fi @@ -37,7 +38,7 @@ usage() { get_defaults cat <] [-b|--board ] [-d|--device ] +usage: $0 [-n,--dry-run] [-i,--imagedir ] [-b|--board ] [-d|--device ] [-s|--skip-delay] options: @@ -52,9 +53,30 @@ options: -n,--dry-run Print commands but don't execute them + -s,--skip-delay Skip delay and flash the image immediately + EOF } +validate_checksum() { + file="$1" + file_sha512="$file.sha512" + file_size=$(stat -c%s $file) + device="$2" + bs="$3" + seek="$4" + + checksum0=$(cat $file_sha512 | awk {'print $1'}) + checksum1=$(dd if=$device bs=1 skip=$(($seek * $bs)) count=$file_size status=none | sha512sum | awk {'print $1'}) + if [ "$checksum0" != "$checksum1" ]; then + echo "File: $checksum0" + echo "Part: $checksum1" + die "Checksum failed" + fi + echo "Successful U-Boot image checksum verification on $device :" + echo -e "\t$checksum1" +} + while [ $# -gt 0 ]; do opt="$1" shift @@ -77,13 +99,16 @@ while [ $# -gt 0 ]; do -n|--dry-run) dryrun="echo" ;; - --) - break - ;; - -*) - usage - exit 1 - ;; + -s|--skip-delay) + skip_delay="yes" + ;; + --) + break + ;; + -*) + usage + exit 1 + ;; esac done @@ -94,8 +119,12 @@ if [ -z "$board" -o -z "$device" -o -z "$imagedir" -o ! -e "$imagedir" ]; then fi if [ -z "$dryrun" ]; then - echo "Updating $board u-boot in $device in 3 seconds..." - sleep 3 + if [ -z "$skip_delay" ]; then + echo "Updating $board u-boot in $device in 3 seconds..." + sleep 3 + else + echo "Updating $board u-boot in $device" + fi fi ( @@ -103,7 +132,13 @@ set -e case "$board" in librem5) [ -e "$imagedir/librem5" ] || die "librem5 images not installed, apk add u-boot-librem5" - $dryrun dd if=$imagedir/librem5/phone-boot.img of=$device bs=1k seek=2 status=none + $dryrun dd if=$imagedir/librem5/phone-boot.img of=$device bs=1024 seek=2 oflag=direct status=none + [ -z "$dryrun" ] && validate_checksum $imagedir/librem5/phone-boot.img $device 1024 2 + ;; +librem5-devkit) + [ -e "$imagedir/librem5" ] || die "librem5-devkit images not installed, apk add u-boot-librem5-devkit" + $dryrun dd if=$imagedir/librem5/devkit-boot.img of=$device bs=1024 seek=2 oflag=direct status=none + [ -z "$dryrun" ] && validate_checksum $imagedir/librem5/devkit-boot.img $device 1024 2 ;; esac $dryrun sync