From cc5313c98df8592464095947ad068b0ee85306f7 Mon Sep 17 00:00:00 2001
From: Anton Bambura <jenneron@protonmail.com>
Date: Sun, 23 Jul 2023 19:54:36 +0300
Subject: [PATCH] purism-librem5: use extlinux instead of u-boot script

---
 device/main/device-purism-librem5/APKBUILD    | 15 +++--
 device/main/device-purism-librem5/deviceinfo  |  2 +
 .../device-purism-librem5/uboot-script.cmd    | 55 -------------------
 3 files changed, 9 insertions(+), 63 deletions(-)
 delete mode 100644 device/main/device-purism-librem5/uboot-script.cmd

diff --git a/device/main/device-purism-librem5/APKBUILD b/device/main/device-purism-librem5/APKBUILD
index bf496c93d12..b3f2e005bcc 100644
--- a/device/main/device-purism-librem5/APKBUILD
+++ b/device/main/device-purism-librem5/APKBUILD
@@ -4,7 +4,7 @@
 # Co-Maintainer: Newbyte <newbyte@postmarketos.org>
 pkgname=device-purism-librem5
 pkgver=1.50
-pkgrel=0
+pkgrel=1
 _confver=61
 _purismrel=1
 # <librem5-base ver>.<purism release>
@@ -23,7 +23,6 @@ depends="
 	mesa-egl
 	postmarketos-base
 	u-boot-librem5
-	u-boot-tools
 "
 makedepends="devicepkg-dev"
 builddir=$srcdir/librem5-base-pureos-$_confver
@@ -38,7 +37,6 @@ source="
 	modules-load.d_librem5.conf
 	pcscd-librem5-reader.conf
 	pcscd-librem5.initd
-	uboot-script.cmd
 	xorg.conf
 	70-librem5-xwayland-accel.sh
 	0001-udev-cameras-use-correct-path-for-modprobe-on-Alpine.patch
@@ -64,7 +62,6 @@ install="$pkgname.post-install $pkgname.post-upgrade"
 builddir="$srcdir/librem5-base-pureos-$_purismver"
 
 build() {
-	mkimage -A arm64 -C none -O linux -T script -d "$srcdir/uboot-script.cmd" "$srcdir/boot.scr"
 	devicepkg_build $startdir $pkgname
 }
 
@@ -128,8 +125,11 @@ x11() {
 }
 
 package() {
-	install -D -m644 "$srcdir"/boot.scr \
-		"$pkgdir"/boot/boot.scr
+	# Workaround for https://gitlab.com/postmarketOS/pmaports/-/issues/2228
+	touch "$pkgname"-trigger
+	install -Dm644 "$pkgname"-trigger \
+		"$pkgdir"/usr/share/mkinitfs-triggers/"$pkgname"
+
 	install -D -m644 "$srcdir"/modprobe.d_rsi.conf "$pkgdir"/etc/modprobe.d/rsi.conf
 	install -D -m644 "$srcdir"/modules-load.d_librem5.conf "$pkgdir"/etc/modules-load.d/librem5.conf
 	install -D -m644 "$srcdir"/00-mesa.sh "$pkgdir"/etc/profile.d/00-mesa.sh
@@ -188,13 +188,12 @@ sha512sums="
 2e72d9a084ecd6c96cafbbd8fda461ae8b2ebd14ffda601d9f36d73f08f04088213de17da078293ddd958d4c76d33148c7af6e252eb0709f6934855a55578509  00-mesa.sh
 8b6fa7b12c15f439c561901f3ffe24a1ef2a0c343401c0a79281060854ab29e08a1fb5e7adae8684b12aa9f535ed99e2dad993dce9724822cb0fbf2497dd86e5  70-wifi-pm.rules
 00355d9ad085a77e157f3c62eb4f1bcac2823d3b341e34d1128edbfb1444fba83e8eacd263ea61da9f6d853f1328ab7fbe5ea63bd08c8a1bc9b8eaf44ae1f1c6  77-mm-broadmobi-port-types.rules
-3a5ded0cc86a0c3cb0b1fd91816a0b3479ab8eb8eae09494b7db5b778fc73e449bec29d983930e0b1425826a47fd91c3f093e1aff7eb877f7993701ea5cca70c  deviceinfo
+63281ae35821bc1ce1d3a2de41fcc4d17c5f01ab135ce5d8ff259c5dae953724521a8410b094ef591f2fb1288507ca3d5057e09bbd238be6b73ac9458b825486  deviceinfo
 ccb47fd421c5e35a8def8e6fb61dad99e42cf542690068a68f90c257e41d33f45f1069db0a8d89372d9029681812957033995639a6a8a5e3eed48019325e0f4d  flash_script.lst
 3f62c04eb92d850e32d5e1b17534dec753563342ea6c4f9dc2572700d4f6eeb8ae8cd8e8e4f1b0f5c61f21d87bc61c02212f27313986157220003d78e2d69505  modprobe.d_rsi.conf
 a0740e405781ec6ef765fdc9f5700c95adbb241c45c97b9384ba68cdece662cb216ca5918640042f6e65a5d1b1a9099936382c99b49a44303f7b6d77a075a471  modules-load.d_librem5.conf
 8ef4ec7a9e9a4fb801d207e7d94b627aacc9243a93b0ec28e0823a6f44b8102416c040e4ddf499f87bb9dfa960cf6f627b008b79f197f6814b3fd881e18ae8ef  pcscd-librem5-reader.conf
 2618b40eebd3602066ee75ab85cbdbb4cfee498def9879c95a304f05a6eeedf1ab28c5dd9fa5efc8f88c790f49c96458c61d5dfe8a3ca0f96bcc0e244313ab01  pcscd-librem5.initd
-659c1801b6172c137db091a5850b467b5c667a5d0392c3d4f9cd767916ded20f09a494ad3c07cae09e9151909aca13208d3d0c681e9d4ec15681078c7046444b  uboot-script.cmd
 1cbc65cf2cb8fad4b0332d012a0256a266205b9b64371f5c0dae09dbb7f1e45b254e8c43993b896097e9d7035a72d547d9bce1ab2133addc56a5abdb80b44616  xorg.conf
 fad386071fc45f9880a94cc8004fabd5d98b3e6a12606c98d8e72e0208f22ab54f03b921f5967a959782507e2bff67d2fa92e46d8cd242011a3afcdbda529279  70-librem5-xwayland-accel.sh
 b45749fcddfd65a302b502bcabfa5828d1b63e45d844fd50e44009a756b919db20fe9526102947c0f0dfcdffe4a037e5050fe1b24fb915933ce0837f49759378  0001-udev-cameras-use-correct-path-for-modprobe-on-Alpine.patch
diff --git a/device/main/device-purism-librem5/deviceinfo b/device/main/device-purism-librem5/deviceinfo
index 8cd7f7372aa..2faf2923071 100644
--- a/device/main/device-purism-librem5/deviceinfo
+++ b/device/main/device-purism-librem5/deviceinfo
@@ -25,3 +25,5 @@ deviceinfo_flash_method="uuu"
 deviceinfo_generate_legacy_uboot_initfs="false"
 deviceinfo_sd_embed_firmware="u-boot/librem5/phone-boot.img:33"
 deviceinfo_boot_part_start="4096"
+deviceinfo_kernel_cmdline="init=/init.sh rw console=ttymxc0,115200 PMOS_NO_OUTPUT_REDIRECT PMOS_FORCE_PARTITION_RESIZE"
+deviceinfo_generate_extlinux_config="true"
diff --git a/device/main/device-purism-librem5/uboot-script.cmd b/device/main/device-purism-librem5/uboot-script.cmd
deleted file mode 100644
index 9200846a574..00000000000
--- a/device/main/device-purism-librem5/uboot-script.cmd
+++ /dev/null
@@ -1,55 +0,0 @@
-# Uses the following env. vars:
-#  devtype              e.g. mmc/scsi etc
-#  devnum               The device number of the given type
-#  bootpart             The partition containing the boot files
-#  board_rev            Librem 5 board revision
-
-
-# Default to devtype=mmc, devnum=0, bootpart=1 if they are unset in the
-# environment. For supporting older u-boot where these may not be configured.
-if itest.s "x" == "x$devtype" ; then
-        devtype="mmc"
-fi
-if itest.s "x" == "x$devnum" ; then
-        devnum=0
-fi
-if itest.s "x" == "x$bootpart" ; then
-        bootpart=1
-fi
-
-setenv bootargs init=/init.sh rw console=ttymxc0,115200 PMOS_NO_OUTPUT_REDIRECT PMOS_FORCE_PARTITION_RESIZE
-
-# Select the correct dtb based on device revision
-# Default to "-r4" if board_rev isn't set, since there are apparently Evergreen
-# boards that either 1) identify as r4, 2) identify as r5 (or something else?),
-# or 3) don't identify as anything(?).
-# See: https://gitlab.com/postmarketOS/pmaports/-/issues/1643#note_1147248594
-dtb_file=imx8mq-librem5-r4.dtb
-if itest.s "x3" == "x$board_rev" ; then
-        dtb_file=imx8mq-librem5-r3.dtb
-elif itest.s "x2" == "x$board_rev" ; then
-        dtb_file=imx8mq-librem5-r2.dtb
-elif itest.s "x1" == "x$board_rev" ; then
-        dtb_file=imx8mq-librem5-r2.dtb
-elif itest.s "x0" == "x$board_rev" ; then
-        dtb_file=imx8mq-librem5-r2.dtb
-fi
-
-echo Loading DTB
-ext2load $devtype ${devnum}:${bootpart} ${fdt_addr_r} ${dtb_file}
-
-echo Loading Initramfs
-ext2load $devtype ${devnum}:${bootpart} ${ramdisk_addr_r} initramfs
-
-echo Loading Kernel
-ext2load $devtype ${devnum}:${bootpart} ${kernel_addr_r} vmlinuz
-
-echo Resizing FDT
-fdt addr ${fdt_addr_r}
-fdt resize
-
-# For debug
-printenv
-
-echo Booting kernel
-booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
-- 
GitLab