Skip to contentSkip to conversation

Add RAUC boot logic for phycore_imx8mp

PATCH New Leonard Anderweit 1 participant 6 messages Mar 12, 2024 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

v3 cover Add RAUC boot logic for phycore_imx8mp

This series adds RAUC boot logic for the phycore_imx8mp.
The first patch converts the environment from a CFG_EXTRA_ENV_SETTINGS #define to a text environment for better readability and maintainability. The second patch moves the default bootcmd from the defconfig to the board environment.
The third patch enables the redundant environment on phycore_imx8mp. Patch 4 adds RAUC boot logic common to all phytec boards.
Patch 5 adds the RAUC boot logic to phycore_imx8mp.

v3:
- swap loadimage and loadfdt in first patch
- add Tested-by and Reviewed-by

v2:
- rebase on next

Leonard Anderweit (5):
phycore_imx8mp: Move environment from include/config to board
phycore_imx8mp: Move default bootcmd to board env
configs: phycore-imx8mp_defconfig: Use redundant environment
include: env: Add phytec RAUC boot logic
board: phytec: phycore_imx8mp: Add RAUC boot logic to environment

 .../phytec/phycore_imx8mp/phycore_imx8mp.env  | 62 +++++++++++++++++++
 configs/phycore-imx8mp_defconfig              |  4 +-
 include/configs/phycore_imx8mp.h              | 43 -------------
 include/env/phytec/rauc.env                   | 52 ++++++++++++++++
 4 files changed, 116 insertions(+), 45 deletions(-)
 create mode 100644 board/phytec/phycore_imx8mp/phycore_imx8mp.env
 create mode 100644 include/env/phytec/rauc.env
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/5 phycore_imx8mp: Move environment from include/config to board

Move the environment into the board directory and convert it from a C header to a text file. Sort the variables alphabetically. No functional changes.

---
 .../phytec/phycore_imx8mp/phycore_imx8mp.env  | 45 +++++++++++++++++++
 include/configs/phycore_imx8mp.h              | 43 ------------------
 2 files changed, 45 insertions(+), 43 deletions(-)
 create mode 100644 board/phytec/phycore_imx8mp/phycore_imx8mp.env
board/phytec/phycore_imx8mp/phycore_imx8mp.env new file +45 -0
new file mode 100644
index 000000000000..32513e70fec2
@@ -0,0 +1,45 @@
+console=ttymxc0,115200
+dofastboot=0
+emmc_dev=2
+fastboot_raw_partition_all=0 4194304
+fastboot_raw_partition_bootloader=64 8128
+fdt_addr=0x48000000
+fdt_file=CONFIG_DEFAULT_FDT_FILE
+image=Image
+ip_dyn=yes
+loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
+loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
+mmcargs=
+	setenv bootargs console=${console}
+	root=/dev/mmcblk${mmcdev}p${mmcroot} rootwait rw
+mmcautodetect=yes
+mmcboot=
+	echo Booting from mmc ...;
+	run mmcargs;
+	if run loadfdt; then
+		booti ${loadaddr} - ${fdt_addr};
+	else
+		echo WARN: Cannot load the DT;
+	fi;
+mmcdev=CONFIG_SYS_MMC_ENV_DEV
+mmcpart=1
+mmcroot=2
+netargs=
+	setenv bootargs console=${console} root=/dev/nfs ip=dhcp
+	nfsroot=${serverip}:${nfsroot},v3,tcp
+netboot=
+	echo Booting from net ...;
+	run netargs;
+	if test ${ip_dyn} = yes; then
+		setenv get_cmd dhcp;
+	else
+		setenv get_cmd tftp;
+	fi;
+	${get_cmd} ${loadaddr} ${image};
+	if ${get_cmd} ${fdt_addr} ${fdt_file}; then
+		booti ${loadaddr} - ${fdt_addr};
+	else
+		echo WARN: Cannot load the DT;
+	fi;
+nfsroot=/nfs
+sd_dev=1
include/configs/phycore_imx8mp.h +0 -43

49 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 2/5 phycore_imx8mp: Move default bootcmd to board env

In reply to Leonard Anderweit

Move the default bootcmd from the defconfig to the board environment. No change in functionality.

---
 board/phytec/phycore_imx8mp/phycore_imx8mp.env | 12 ++++++++++++
 configs/phycore-imx8mp_defconfig               |  2 --
 2 files changed, 12 insertions(+), 2 deletions(-)
board/phytec/phycore_imx8mp/phycore_imx8mp.env +12 -0
index 32513e70fec2..dc9ad0fe9d15 100644
@@ -1,3 +1,15 @@
+bootcmd=
+	if test ${dofastboot} = 1; then
+		fastboot 0;
+	fi;
+	mmc dev ${mmcdev};
+	if mmc rescan; then
+		if run loadimage; then
+			run mmcboot;
+		else
+			run netboot;
+		fi;
+	fi;
 console=ttymxc0,115200
 dofastboot=0
 emmc_dev=2
configs/phycore-imx8mp_defconfig +0 -2
index b3a7bbd79bb6..fd492eba3c10 100644
@@ -25,8 +25,6 @@ CONFIG_FIT=y
 CONFIG_FIT_EXTERNAL_OFFSET=0x3000
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_OF_SYSTEM_SETUP=y
-CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="if test ${dofastboot} = 1; then fastboot 0; fi; mmc dev ${mmcdev}; if mmc rescan; then if run loadimage; then run mmcboot; else run netboot; fi; fi;"
 CONFIG_DEFAULT_FDT_FILE="oftree"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2074
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 3/5 configs: phycore-imx8mp_defconfig: Use redundant environment

In reply to Leonard Anderweit

Add support for the redundant environment.

---
 configs/phycore-imx8mp_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/phycore-imx8mp_defconfig +2 -0
index fd492eba3c10..6c67f14b5559 100644
@@ -19,6 +19,7 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_STACK=0x960000
 CONFIG_SPL=y
+CONFIG_ENV_OFFSET_REDUND=0x3e0000
 CONFIG_SPL_IMX_ROMAPI_LOADADDR=0x48000000
 CONFIG_SYS_LOAD_ADDR=0x40480000
 CONFIG_FIT=y
@@ -77,6 +78,7 @@ CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
+CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_SYS_MMC_ENV_DEV=2
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
Signature · 1 line
2.25.1
#5 lore raw

PATCH v3 5/5 board: phytec: phycore_imx8mp: Add RAUC boot logic to environment

In reply to Leonard Anderweit

Add RAUC boot logic to the environment. This is the first board to utilize this environment.

---
 board/phytec/phycore_imx8mp/phycore_imx8mp.env | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
board/phytec/phycore_imx8mp/phycore_imx8mp.env +6 -1
index dc9ad0fe9d15..fae3e992654f 100644
@@ -1,9 +1,14 @@
+#include <env/phytec/rauc.env>
+
 bootcmd=
 	if test ${dofastboot} = 1; then
 		fastboot 0;
 	fi;
 	mmc dev ${mmcdev};
 	if mmc rescan; then
+		if test ${doraucboot} = 1; then
+			run raucinit;
+		fi;
 		if run loadimage; then
 			run mmcboot;
 		else
@@ -23,7 +28,7 @@ loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
 loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
 mmcargs=
 	setenv bootargs console=${console}
-	root=/dev/mmcblk${mmcdev}p${mmcroot} rootwait rw
+	root=/dev/mmcblk${mmcdev}p${mmcroot} ${raucargs} rootwait rw
 mmcautodetect=yes
 mmcboot=
 	echo Booting from mmc ...;
Signature · 1 line
2.25.1
#4 lore raw

PATCH v3 4/5 include: env: Add phytec RAUC boot logic

In reply to Leonard Anderweit

Add logic for booting systems with the RAUC update mechanism. This can be reused by other phytec boards.

---
 include/env/phytec/rauc.env | 52 +++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 include/env/phytec/rauc.env
include/env/phytec/rauc.env new file +52 -0
new file mode 100644
index 000000000000..89e17ff70ec6
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+/* Logic to select a boot partition based on environment variables and switch
+ * to the other if the boot fails. */
+
+doraucboot=0
+
+raucbootpart0=1
+raucrootpart0=5
+raucbootpart1=2
+raucrootpart1=6
+
+raucinit=
+	echo Booting RAUC A/B system;
+	test -n "${BOOT_ORDER}" || env set BOOT_ORDER "system0 system1";
+	test -n "${BOOT_system0_LEFT}" || env set BOOT_system0_LEFT 3;
+	test -n "${BOOT_system1_LEFT}" || env set BOOT_system1_LEFT 3;
+	env set raucstatus;
+	for BOOT_SLOT in "${BOOT_ORDER}"; do
+		if test "x${raucstatus}" != "x"; then
+			echo Skipping remaing slots!;
+		elif test "x${BOOT_SLOT}" = "xsystem0"; then
+			if test ${BOOT_system0_LEFT} -gt 0; then
+				echo Found valid slot A, ${BOOT_system0_LEFT} attempts remaining;
+				setexpr BOOT_system0_LEFT ${BOOT_system0_LEFT} - 1;
+				env set mmcpart ${raucbootpart0};
+				env set mmcroot ${raucrootpart0};
+				env set raucargs rauc.slot=system0;
+				env set raucstatus success;
+			fi;
+		elif test "x${BOOT_SLOT}" = "xsystem1"; then
+			if test ${BOOT_system1_LEFT} -gt 0; then
+				echo Found valid slot B, ${BOOT_system1_LEFT} attempts remaining;
+				setexpr BOOT_system1_LEFT ${BOOT_system1_LEFT} - 1;
+				env set mmcpart ${raucbootpart1};
+				env set mmcroot ${raucrootpart1};
+				env set raucargs rauc.slot=system1;
+				env set raucstatus success;
+			fi;
+		fi;
+	done;
+	if test -n "${raucstatus}"; then
+		env delete raucstatus;
+		env save;
+	else
+		echo WARN: No valid slot found;
+		env set BOOT_system0_LEFT 3;
+		env set BOOT_system1_LEFT 3;
+		env delete raucstatus;
+		env save;
+		reset;
+	fi;
Signature · 1 line
2.25.1