From 0f350a8a46fe897f4787efa6d31a114b4e706d12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philip=20M=C3=BCller?= <philm@manjaro.org>
Date: Fri, 3 Dec 2021 02:24:41 +0100
Subject: [PATCH] [pkg-upd] 2021.01-rc3-4 - fix boot-order

---
 0008-fix-boot-order.patch                     | 44 +++++++++++++++++++
 ...Correct-boot-order-to-be-USB-SD-eMMC.patch | 28 ++++++++++++
 PKGBUILD                                      | 25 ++++++-----
 3 files changed, 87 insertions(+), 10 deletions(-)
 create mode 100644 0008-fix-boot-order.patch
 create mode 100644 0009-Correct-boot-order-to-be-USB-SD-eMMC.patch

diff --git a/0008-fix-boot-order.patch b/0008-fix-boot-order.patch
new file mode 100644
index 0000000..a18a904
--- /dev/null
+++ b/0008-fix-boot-order.patch
@@ -0,0 +1,44 @@
+From b212ad24a604b00b240add35516b7381965deb31 Mon Sep 17 00:00:00 2001
+From: Alex Bee <knaerzche@gmail.com>
+Date: Thu, 17 Jun 2021 11:01:12 +0200
+Subject: [PATCH] rockchip: Fix MMC boot order
+
+Basically all, i.e. rk3036.dtsi, rk3128.dtsi, rk3xxx.dtsi, rk322x.dtsi,
+rk3288.dtsi, rk3308-u-boot.dtsi, rk3328-u-boot.dtsi, rk3399-u-boot.dtsi
+and px30-u-boot.dtsi Rockchip SoC devicetrees which have mmc indexes
+are defining eMMC as mmc0 and sdmmc as mmc1.
+This means that the rule to try to boot from the SD card first is ignored,
+which as per comment is what we want and is important for distros, which
+rely on that.
+
+Fix this by setting the correct mmc index, i.e. first from mmc1 (SD card),
+second from mmc0 (eMMC).
+
+Signed-off-by: Alex Bee <knaerzche@gmail.com>
+Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
+---
+ include/configs/rockchip-common.h | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/include/configs/rockchip-common.h b/include/configs/rockchip-common.h
+index 0b9e24d1db..ba7061a287 100644
+--- a/include/configs/rockchip-common.h
++++ b/include/configs/rockchip-common.h
+@@ -14,11 +14,11 @@
+ 
+ #ifndef CONFIG_SPL_BUILD
+ 
+-/* First try to boot from SD (index 0), then eMMC (index 1) */
++/* First try to boot from SD (index 1), then eMMC (index 0) */
+ #if CONFIG_IS_ENABLED(CMD_MMC)
+ 	#define BOOT_TARGET_MMC(func) \
+-		func(MMC, mmc, 0) \
+-		func(MMC, mmc, 1)
++		func(MMC, mmc, 1) \
++		func(MMC, mmc, 0)
+ #else
+ 	#define BOOT_TARGET_MMC(func)
+ #endif
+-- 
+GitLab
+
diff --git a/0009-Correct-boot-order-to-be-USB-SD-eMMC.patch b/0009-Correct-boot-order-to-be-USB-SD-eMMC.patch
new file mode 100644
index 0000000..5b218b5
--- /dev/null
+++ b/0009-Correct-boot-order-to-be-USB-SD-eMMC.patch
@@ -0,0 +1,28 @@
+From f97401137daa1cb75532c373bbcb5011f1e03585 Mon Sep 17 00:00:00 2001
+From: Dan Johansen <strit@manjaro.org>
+Date: Sun, 10 Oct 2021 20:19:02 +0200
+Subject: [PATCH] Correct boot order to be USB -> SD -> eMMC
+
+Signed-off-by: Dan Johansen <strit@manjaro.org>
+---
+ include/configs/rockchip-common.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/configs/rockchip-common.h b/include/configs/rockchip-common.h
+index ba7061a287..5dc92373b2 100644
+--- a/include/configs/rockchip-common.h
++++ b/include/configs/rockchip-common.h
+@@ -55,9 +55,9 @@
+ 
+ #ifdef CONFIG_ROCKCHIP_RK3399
+ #define BOOT_TARGET_DEVICES(func) \
++	BOOT_TARGET_USB(func) \
+ 	BOOT_TARGET_MMC(func) \
+ 	BOOT_TARGET_NVME(func) \
+-	BOOT_TARGET_USB(func) \
+ 	BOOT_TARGET_PXE(func) \
+ 	BOOT_TARGET_DHCP(func) \
+ 	BOOT_TARGET_SF(func)
+-- 
+2.33.0
+
diff --git a/PKGBUILD b/PKGBUILD
index 26dfb9e..e994034 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -3,7 +3,7 @@
 
 pkgname=uboot-pinephonepro
 pkgver=2021.01rc3
-pkgrel=3
+pkgrel=4
 epoch=1
 _srcname=u-boot-pine64-pinephonepro
 _commit=0719bf42931033c3109ecc6357e8adb567cb637b
@@ -24,7 +24,9 @@ source=("u-boot-$_commit.tar.gz::https://source.denx.de/u-boot/u-boot/-/archive/
         0004-Add-kconfig-include.patch
         0005-Add-pinephone-pro-rk3399.h.patch
         0006-Added-dts-to-makefile.patch
-        0007-u-boot.dtsi-fixes.patch)
+        0007-u-boot.dtsi-fixes.patch
+        0008-fix-boot-order.patch
+        0009-Correct-boot-order-to-be-USB-SD-eMMC.patch)
 sha256sums=('6b196b6592fabed060b7c5b1fa05a743f9be131d11389b762b7d0e2beebbd381'
             '4e59f02ccb042d5d18c89c849701b96e6cf4b788709564405354b5d313d173f7'
             'f2e9d4efd24b7a6d94ccfe8c1a6fd0fac04776483be7a2d343f5b7a6b50a8ff2'
@@ -33,17 +35,20 @@ sha256sums=('6b196b6592fabed060b7c5b1fa05a743f9be131d11389b762b7d0e2beebbd381'
             'ded1b2e6effbea181ed5c875bd63905db07daba268db48f0a75e9643c830c949'
             'ba42e43fa471154f6ea4fb5f731557a5f2494668afe05797450a43b82b82ab2f'
             '0e96af517f2f7a085412c659ab672e61912ff59d92f009ed119832c7c790d6d8'
-            '3aa7c3b4aa1233d604cb9177fc9bc56f85714c5d69f9432690dc7c50e06c105b')
+            '3aa7c3b4aa1233d604cb9177fc9bc56f85714c5d69f9432690dc7c50e06c105b'
+            '4aadc4f07f4ae62d5fe11cfabe1c5f917f77ce8014800ae3a107f9bcc551bc5b'
+            '017d33aac55f8a5ed22170c97b4792ba755a4dad04f6c0cdd85119bbc81e87b3')
 
 prepare() {
   cd u-boot-${_commit}
-  patch -N -p1 < ${srcdir}/0001-PPP.patch
-  patch -N -p1 < ${srcdir}/0002-Add-ppp-dt.patch
-  patch -N -p1 < ${srcdir}/0003-Config-changes.patch
-  patch -N -p1 < ${srcdir}/0004-Add-kconfig-include.patch
-  patch -N -p1 < ${srcdir}/0005-Add-pinephone-pro-rk3399.h.patch
-  patch -N -p1 < ${srcdir}/0006-Added-dts-to-makefile.patch
-  patch -N -p1 < ${srcdir}/0007-u-boot.dtsi-fixes.patch
+  local src
+  for src in "${source[@]}"; do
+      src="${src%%::*}"
+      src="${src##*/}"
+      [[ $src = *.patch ]] || continue
+      msg2 "Applying patch: $src..."
+      patch -Np1 < "../$src"
+  done
 }
 
 build() {
-- 
GitLab