Skip to contentSkip to conversation

smegw01: Enable setting additional boot params

PATCH Superseded Fabio Estevam 2 participants 15 messages Apr 21, 2023 – Apr 24, 2023

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/13 smegw01: Enable setting additional boot params

From: Eduard Strehlau <[email protected]>

Introduce EXTRA_BOOTPARAMS to allow passing additional parameters to kernel command line. This is useful for debugging purposes.

---
Changes since v1:
- None

 include/configs/smegw01.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/configs/smegw01.h +7 -1
index 11031744be..a356f095a6 100644
@@ -17,6 +17,11 @@
 /* MMC Config*/
 #define CFG_SYS_FSL_ESDHC_ADDR	0
 
+/* default to no extra bootparams, we need an empty define for stringification*/
+#ifndef EXTRA_BOOTPARAMS
+#define EXTRA_BOOTPARAMS
+#endif
+
 #define CFG_EXTRA_ENV_SETTINGS \
 	"image=zImage\0" \
 	"console=ttymxc0\0" \
@@ -26,7 +31,8 @@
 	"mmcdev=0\0" \
 	"mmcpart=1\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
-		"root=/dev/mmcblk0p${mmcpart} rootwait rw\0" \
+		"root=/dev/mmcblk0p${mmcpart} rootwait rw " \
+		__stringify(EXTRA_BOOTPARAMS) "\0" \
 	"loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} boot/${image}\0" \
 	"loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdt_addr} boot/${fdtfile}\0" \
 	"mmcboot=echo Booting from mmc ...; " \
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 2/13 smegw01: Select CONFIG_CMD_SQUASHFS

From: Eduard Strehlau <[email protected]>

Select CONFIG_CMD_SQUASHFS so that the SquashFS U-Boot commands are available.

---
Changes since v1:
- None

 configs/smegw01_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/smegw01_defconfig +1 -0
index 1e0b9aa5be..f15291f1dd 100644
@@ -38,6 +38,7 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
Signature · 1 line
2.38.1
#2 lore raw

PATCH v2 3/13 smegw01: Select bootcount support

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Add automatic boot counter that increases after every reset. After a power-on reset, it will be initialized with 1, and each reboot will increment the value by 1. By default it is disabled if bootlimit isn't set.

---
Changes since v1:
- None

 configs/smegw01_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/smegw01_defconfig +2 -0
index f15291f1dd..5d9d419463 100644
@@ -46,6 +46,8 @@ CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_BOUNCE_BUFFER=y
+CONFIG_BOOTCOUNT_LIMIT=y
+CONFIG_BOOTCOUNT_ENV=y
 CONFIG_DFU_MMC=y
 CONFIG_DM_I2C=y
 CONFIG_SUPPORT_EMMC_BOOT=y
Signature · 1 line
2.38.1
#3 lore raw

PATCH v2 4/13 smegw01: Add altbootcmd

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Add an altbootcmd script, which is convenient way to integrate with swupdate and perform a roll back of the previous working version in the case of update failure.

---
Changes since v1:
- None

 configs/smegw01_defconfig | 2 +-
 include/configs/smegw01.h | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
configs/smegw01_defconfig +1 -1
index 5d9d419463..418151a6de 100644
@@ -18,7 +18,7 @@ CONFIG_SYS_MEMTEST_END=0xa0000000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="if run loadimage; then run mmcboot; fi; "
+CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; if run loadimage; then run mmcboot; fi; "
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_MAXARGS=32
 CONFIG_SYS_PBSIZE=532
include/configs/smegw01.h +8 -0
index a356f095a6..6ee4acc70d 100644
@@ -33,6 +33,7 @@
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
 		"root=/dev/mmcblk0p${mmcpart} rootwait rw " \
 		__stringify(EXTRA_BOOTPARAMS) "\0" \
+	"bootlimit=3\0" \
 	"loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} boot/${image}\0" \
 	"loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdt_addr} boot/${fdtfile}\0" \
 	"mmcboot=echo Booting from mmc ...; " \
@@ -40,6 +41,13 @@
 		"if run loadfdt; then " \
 			"bootz ${loadaddr} - ${fdt_addr}; " \
 		"fi;\0" \
+	"altbootcmd=echo Performing rollback...; " \
+		"if test \"${mmcpart}\" = 1; then " \
+			"setenv mmcpart 2; " \
+		"else " \
+			"setenv mmcpart 1; " \
+		"fi; setenv bootcount 0; setenv upgrade_available; setenv ustate 3; saveenv; " \
+		"run bootcmd;\0"
 
 /* Physical Memory Map */
 #define PHYS_SDRAM			MMDC0_ARB_BASE_ADDR
Signature · 1 line
2.38.1
#4 lore raw

PATCH v2 5/13 smegw01: Run altbootcmd in the case of failure

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Run the altbootcmd script if any step of bootcmd fails.

This ensures that always a valid image can be run.

---
Changes since v1:
- None

 configs/smegw01_defconfig | 2 +-
 include/configs/smegw01.h | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
configs/smegw01_defconfig +1 -1
index 418151a6de..b3580d5d6e 100644
@@ -18,7 +18,7 @@ CONFIG_SYS_MEMTEST_END=0xa0000000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; if run loadimage; then run mmcboot; fi; "
+CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; if run loadimage; then run mmcboot; else run altbootcmd; fi; "
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_MAXARGS=32
 CONFIG_SYS_PBSIZE=532
include/configs/smegw01.h +7 -1
index 6ee4acc70d..05edaac42f 100644
@@ -39,7 +39,13 @@
 	"mmcboot=echo Booting from mmc ...; " \
 		"run mmcargs; " \
 		"if run loadfdt; then " \
-			"bootz ${loadaddr} - ${fdt_addr}; " \
+			"if bootz ${loadaddr} - ${fdt_addr}; then " \
+				"; " \
+			"else " \
+				"run altbootcmd; " \
+			"fi;" \
+		"else " \
+			"run altbootcmd; " \
 		"fi;\0" \
 	"altbootcmd=echo Performing rollback...; " \
 		"if test \"${mmcpart}\" = 1; then " \
Signature · 1 line
2.38.1
#5 lore raw

PATCH v2 6/13 smegw01: Only commit to new partition if update was successful

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

When performing rootfs update via swupdate, it is convenient to check the 'ustate' variable to decide whether the update succeeded or not.

---
Changes since v1:
- None

 include/configs/smegw01.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
include/configs/smegw01.h +12 -4
index 05edaac42f..277c828d0e 100644
@@ -30,13 +30,19 @@
 	"bootm_size=0x10000000\0" \
 	"mmcdev=0\0" \
 	"mmcpart=1\0" \
+	"mmcpart_committed=1\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
-		"root=/dev/mmcblk0p${mmcpart} rootwait rw " \
+		"root=/dev/mmcblk0p${mmcpart_committed} rootwait rw " \
 		__stringify(EXTRA_BOOTPARAMS) "\0" \
+	"commit_mmc=if test \"${ustate}\" = 1 -a \"${mmcpart}\" != \"${mmcpart_committed}\"; then " \
+	              "setenv mmcpart_committed ${mmcpart};" \
+								"saveenv;" \
+						  "fi;\0" \
 	"bootlimit=3\0" \
-	"loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} boot/${image}\0" \
-	"loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdt_addr} boot/${fdtfile}\0" \
+	"loadimage=load mmc ${mmcdev}:${mmcpart_committed} ${loadaddr} boot/${image}\0" \
+	"loadfdt=load mmc ${mmcdev}:${mmcpart_committed} ${fdt_addr} boot/${fdtfile}\0" \
 	"mmcboot=echo Booting from mmc ...; " \
+	  "run commit_mmc; " \
 		"run mmcargs; " \
 		"if run loadfdt; then " \
 			"if bootz ${loadaddr} - ${fdt_addr}; then " \
@@ -48,10 +54,12 @@
 			"run altbootcmd; " \
 		"fi;\0" \
 	"altbootcmd=echo Performing rollback...; " \
-		"if test \"${mmcpart}\" = 1; then " \
+		"if test \"${mmcpart_committed}\" = 1; then " \
 			"setenv mmcpart 2; " \
+			"setenv mmcpart_committed 2;" \
 		"else " \
 			"setenv mmcpart 1; " \
+			"setenv mmcpart_committed 1;" \
 		"fi; setenv bootcount 0; setenv upgrade_available; setenv ustate 3; saveenv; " \
 		"run bootcmd;\0"
 
Signature · 1 line
2.38.1
#6 lore raw

PATCH v2 7/7 smegw01: Enable EMMC boot from multiple partitions

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

GPT Partition labels are used for determining the right root filesystem to boot from.

The U-Boot environment is configured to reside in the eMMC hardware boot partition we are currently booted from.

This should enable a dual copy approach for upgrading the bootloader. One can overwrite the inactive hardware partition with new bootloader and environment and afterwards switch the eMMC boot partition for an atomic bootloader switch.

---
Changes since v1:
- Remove custom mmc macro (Pali)
- Handle all the possible partition cases (Pali).

Cc Pali Rohár <[email protected]>
 board/storopack/smegw01/smegw01.c | 32 +++++++++++++++++++++++++++++++
 configs/smegw01_defconfig         |  2 ++
 include/configs/smegw01.h         | 12 ++++++++----
 3 files changed, 42 insertions(+), 4 deletions(-)
board/storopack/smegw01/smegw01.c +32 -0
index e6bff80e5565..db6069a02722 100644
@@ -17,6 +17,7 @@
 #include <asm/arch/crm_regs.h>
 #include <asm/setup.h>
 #include <asm/bootm.h>
+#include <mmc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -93,3 +94,34 @@ int board_late_init(void)
 
 	return 0;
 }
+
+uint mmc_get_env_part(struct mmc *mmc)
+{
+	uint part;
+
+	if (mmc->part_config == MMCPART_NOAVAILABLE) {
+		part = 0;
+	} else {
+		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+		case 0: /* Booting from this eMMC device is disabled */
+			printf("Error - Booting from this eMMC device is disabled\n");
+			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
+			return -ENODEV;
+		case 1: /* Boot partition 1 is used for booting */
+			part = 1;
+			break;
+		case 2: /* Boot partition 2 is used for booting */
+			part = 2;
+			break;
+		case 7: /* User area is used for booting */
+			part = 0;
+			break;
+		default: /* Other values are reserved / unsupported */
+			printf("Error - This eMMC device has configured Reserved boot option\n");
+			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
+			return -ENODEV;
+		}
+	}
+
+	return part;
+}
configs/smegw01_defconfig +2 -0
index b3580d5d6e54..54cf1cfc1f1b 100644
@@ -30,6 +30,7 @@ CONFIG_CMD_MEMTEST=y
 CONFIG_CMD_UNZIP=y
 CONFIG_CMD_DFU=y
 CONFIG_CMD_GPIO=y
+CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
 CONFIG_CMD_DHCP=y
@@ -44,6 +45,7 @@ CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_SYS_MMC_ENV_DEV=1
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_BOUNCE_BUFFER=y
 CONFIG_BOOTCOUNT_LIMIT=y
include/configs/smegw01.h +8 -4
index 277c828d0e07..71f2d9c8e85c 100644
@@ -32,17 +32,21 @@
 	"mmcpart=1\0" \
 	"mmcpart_committed=1\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
-		"root=/dev/mmcblk0p${mmcpart_committed} rootwait rw " \
-		__stringify(EXTRA_BOOTPARAMS) "\0" \
+		"root=/dev/mmcblk${mmcdev}p${gpt_partition_entry} rootwait rw " \
+		__stringify(EXTRA_BOOTPARAMS) " SM_ROOT_DEV=${mmcdev} SM_ROOT_PART=${gpt_partition_entry} SM_BOOT_PART=${boot_part}\0" \
 	"commit_mmc=if test \"${ustate}\" = 1 -a \"${mmcpart}\" != \"${mmcpart_committed}\"; then " \
 	              "setenv mmcpart_committed ${mmcpart};" \
 								"saveenv;" \
 						  "fi;\0" \
 	"bootlimit=3\0" \
-	"loadimage=load mmc ${mmcdev}:${mmcpart_committed} ${loadaddr} boot/${image}\0" \
-	"loadfdt=load mmc ${mmcdev}:${mmcpart_committed} ${fdt_addr} boot/${fdtfile}\0" \
+	"loadimage=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${loadaddr} boot/${image}\0" \
+	"loadfdt=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${fdt_addr} boot/${fdtfile}\0" \
+	"loadpart=gpt setenv mmc ${mmcdev} rootfs-${mmcpart_committed}\0" \
+	"loadbootpart=mmc partconf 1 boot_part\0" \
 	"mmcboot=echo Booting from mmc ...; " \
 	  "run commit_mmc; " \
+		"run loadpart; " \
+		"run loadbootpart; " \
 		"run mmcargs; " \
 		"if run loadfdt; then " \
 			"if bootz ${loadaddr} - ${fdt_addr}; then " \
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 8/13 smegw01: Change default boot device to eMMC

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Let eMMC be the default boot medium.

---
Changes since v1:
- None

 include/configs/smegw01.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/smegw01.h +1 -1
index 71f2d9c8e8..8f68472f5b 100644
@@ -28,7 +28,7 @@
 	"fdtfile=imx7d-smegw01.dtb\0" \
 	"fdt_addr=0x83000000\0" \
 	"bootm_size=0x10000000\0" \
-	"mmcdev=0\0" \
+	"mmcdev=1\0" \
 	"mmcpart=1\0" \
 	"mmcpart_committed=1\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
Signature · 1 line
2.38.1
#10 lore raw

PATCH v2 9/13 smegw01: Switch to fitImage

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Instead of loading the zImage kernel and the devicetree separately, switch to the fitImage format, which is more convenient when working with secure boot, for example.

---
Changes since v1:
- None

 include/configs/smegw01.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
include/configs/smegw01.h +5 -9
index 8f68472f5b..8521883277 100644
@@ -23,7 +23,7 @@
 #endif
 
 #define CFG_EXTRA_ENV_SETTINGS \
-	"image=zImage\0" \
+	"image=fitImage\0" \
 	"console=ttymxc0\0" \
 	"fdtfile=imx7d-smegw01.dtb\0" \
 	"fdt_addr=0x83000000\0" \
@@ -39,8 +39,8 @@
 								"saveenv;" \
 						  "fi;\0" \
 	"bootlimit=3\0" \
-	"loadimage=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${loadaddr} boot/${image}\0" \
-	"loadfdt=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${fdt_addr} boot/${fdtfile}\0" \
+	"fit_addr=0x88000000\0" \
+	"loadimage=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${fit_addr} boot/${image}\0" \
 	"loadpart=gpt setenv mmc ${mmcdev} rootfs-${mmcpart_committed}\0" \
 	"loadbootpart=mmc partconf 1 boot_part\0" \
 	"mmcboot=echo Booting from mmc ...; " \
@@ -48,12 +48,8 @@
 		"run loadpart; " \
 		"run loadbootpart; " \
 		"run mmcargs; " \
-		"if run loadfdt; then " \
-			"if bootz ${loadaddr} - ${fdt_addr}; then " \
-				"; " \
-			"else " \
-				"run altbootcmd; " \
-			"fi;" \
+		"if bootm ${fit_addr}; then " \
+			"; " \
 		"else " \
 			"run altbootcmd; " \
 		"fi;\0" \
Signature · 1 line
2.38.1
#11 lore raw

PATCH v2 10/13 smegw01: Add lockdown U-Boot env support

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Add lockdown U-Boot env support so that only certain U-Boot environment variables are allowed to be modified.

---
Changes since v1:
- None

 board/storopack/smegw01/Kconfig   |  7 +++++
 board/storopack/smegw01/smegw01.c | 17 +++++++++++
 configs/smegw01_defconfig         | 11 ++++++-
 include/configs/smegw01.h         | 48 +++++++++++++++++++++++++++++--
 4 files changed, 79 insertions(+), 4 deletions(-)
board/storopack/smegw01/Kconfig +7 -0
index d8f24695d0..390214c285 100644
@@ -12,4 +12,11 @@ config SYS_CONFIG_NAME
 config IMX_CONFIG
 	default "board/storopack/smegw01/imximage.cfg"
 
+config SYS_BOOT_LOCKED
+	bool "Lock boot process to EMMC"
+	default y
+	help
+	  Say N here if you want to boot from eMMC and SD.
+	  Say Y to boot from eMMC.
+
 endif
board/storopack/smegw01/smegw01.c +17 -0
index 9482f88773..e786429476 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <common.h>
 #include <env.h>
+#include <env_internal.h>
 #include <asm/arch/crm_regs.h>
 #include <asm/setup.h>
 #include <asm/bootm.h>
@@ -113,3 +114,19 @@ uint mmc_get_env_part(struct mmc *mmc)
 
 	return part;
 }
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+	if (op == ENVOP_SAVE || op == ENVOP_ERASE)
+		return ENVL_MMC;
+
+	switch (prio) {
+	case 0:
+		return ENVL_NOWHERE;
+
+	case 1:
+		return ENVL_MMC;
+	}
+
+	return ENVL_UNKNOWN;
+}
configs/smegw01_defconfig +10 -1
index 54cf1cfc1f..ea25b3b87c 100644
@@ -7,6 +7,7 @@ CONFIG_ENV_OFFSET=0x100000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="imx7d-smegw01"
 CONFIG_TARGET_SMEGW01=y
+# CONFIG_SYS_BOOT_LOCKED is not set
 CONFIG_ENV_OFFSET_REDUND=0x110000
 CONFIG_ARMV7_BOOT_SEC_DEFAULT=y
 # CONFIG_ARMV7_VIRT is not set
@@ -17,13 +18,18 @@ CONFIG_SYS_MEMTEST_START=0x80000000
 CONFIG_SYS_MEMTEST_END=0xa0000000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_AUTOBOOT_MENU_SHOW=y
+CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; if run loadimage; then run mmcboot; else run altbootcmd; fi; "
+CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; run mmcboot; "
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="run setup_boot_menu;"
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_MAXARGS=32
 CONFIG_SYS_PBSIZE=532
 # CONFIG_CMD_BOOTD is not set
 CONFIG_CMD_BOOTZ=y
+CONFIG_CMD_BOOTMENU=y
 # CONFIG_CMD_IMI is not set
 # CONFIG_CMD_XIMG is not set
 CONFIG_CMD_MEMTEST=y
@@ -43,9 +49,12 @@ CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_NOWHERE=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_SYS_MMC_ENV_DEV=1
+CONFIG_ENV_WRITEABLE_LIST=y
+CONFIG_ENV_ACCESS_IGNORE_FORCE=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_BOUNCE_BUFFER=y
 CONFIG_BOOTCOUNT_LIMIT=y
include/configs/smegw01.h +45 -3

71 lines not on this page · raw message

Signature · 1 line
2.38.1
#12 lore raw

PATCH v2 11/13 smegw01: Read the second MAC address

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently, only the first MAC address is read from the fuses.

The second MAC address is not read and Linux assigns a random one.

To prevent this behavior, read the second MAC address from the fuses and store it into the eth1addr environment variable so that it can be passed to Linux.

---
Changes since v1:
- Fixed typo in the Subject "smegw01".

 board/storopack/smegw01/smegw01.c | 6 ++++++
 1 file changed, 6 insertions(+)
board/storopack/smegw01/smegw01.c +6 -0
index e786429476..605253ead3 100644
@@ -82,6 +82,7 @@ int board_init(void)
 int board_late_init(void)
 {
 	struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
+	unsigned char eth1addr[6];
 
 	imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
 
@@ -93,6 +94,11 @@ int board_late_init(void)
 	 */
 	clrsetbits_le16(&wdog->wcr, 0, 0x10);
 
+	/* Get the second MAC address */
+	imx_get_mac_from_fuse(1, eth1addr);
+	if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
+		eth_env_set_enetaddr("eth1addr", eth1addr);
+
 	return 0;
 }
 
Signature · 1 line
2.38.1
#13 lore raw

PATCH v2 12/13 smegw01: Disable additional boot menu options

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

Defaults have changed, we do not want the bootmenu to contain EFI options.

---
Changes since v1:
- None

 configs/smegw01_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/smegw01_defconfig +2 -0
index ea25b3b87c..fe8152f33e 100644
@@ -19,6 +19,8 @@ CONFIG_SYS_MEMTEST_END=0xa0000000
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_AUTOBOOT_MENU_SHOW=y
+# CONFIG_BOOTSTD is not set
+# CONFIG_CMD_BOOTEFI_BOOTMGR is not set
 CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; run mmcboot; "
Signature · 1 line
2.38.1
#14 lore raw

PATCH 13/13 smegw01: Fix fallback to altbootcmd

In reply to Fabio Estevam

From: Eduard Strehlau <[email protected]>

The bootcmd/altbootcmd mechanism is not invoked for bootmenus. Manually compare bootcount and bootlimit to implement fallback on all codepaths.

---
Changes since v1:
- None

 configs/smegw01_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configs/smegw01_defconfig +1 -1
index fe8152f33e..3d2713f528 100644
@@ -23,7 +23,7 @@ CONFIG_AUTOBOOT_MENU_SHOW=y
 # CONFIG_CMD_BOOTEFI_BOOTMGR is not set
 CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; run mmcboot; "
+CONFIG_BOOTCOMMAND="if test \"${bootcount}\" -gt \"${bootlimit}\"; then run altbootcmd; else if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; run mmcboot; fi;"
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="run setup_boot_menu;"
 CONFIG_HUSH_PARSER=y
Signature · 1 line
2.38.1
#7 lore raw

Re: [PATCH v2 7/7] smegw01: Enable EMMC boot from multiple partitions

In reply to Fabio Estevam

board/storopack/smegw01/smegw01.c int board_late_init(void) · line 109

Quoted 12 lines · On Friday 21 April 2023 07:56:50 Fabio Estevam wrote:
board/storopack/smegw01/smegw01.c +12 -0
+uint mmc_get_env_part(struct mmc *mmc)
+{
+	uint part;
+
+	if (mmc->part_config == MMCPART_NOAVAILABLE) {
+		part = 0;
+	} else {
+		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+		case 0: /* Booting from this eMMC device is disabled */
+			printf("Error - Booting from this eMMC device is disabled\n");
+			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
+			return -ENODEV;

This does not look to be correct. Return type of the function is uint but here you are trying to return negative number.

I think that there is some layering or API issue. Caller of this function probably does not expect any failure and use returned value as partition number. But you are reading partition number from the source which may return failure (as the source does not have to contain it).

I'm not sure what is the correct way how to handle these kind of error. I hope that this is something which you would know.

Which partition want to choose? Same from which was u-boot/spl loaded at runtime? If yes then maybe this my patch series for mvebu may be interested for you:
https://lore.kernel.org/u-boot/[email protected]/t/#u

I added there ability to store emmc partition from which was bootloader loaded into access bits of mmc->part_config variable and then via macro EXT_CSD_EXTRACT_PARTITION_ACCESS() it can be extracted. See function spl_mmc_emmc_boot_partition() in that mvebu patch series.

But I'm not sure how reliable access bits of mmc->part_config are on other platforms. As currently only mvebu in that patch series is doing to use it.

Quoted 18 lines
board/storopack/smegw01/smegw01.c +18 -0
+		case 1: /* Boot partition 1 is used for booting */
+			part = 1;
+			break;
+		case 2: /* Boot partition 2 is used for booting */
+			part = 2;
+			break;
+		case 7: /* User area is used for booting */
+			part = 0;
+			break;
+		default: /* Other values are reserved / unsupported */
+			printf("Error - This eMMC device has configured Reserved boot option\n");
+			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
+			return -ENODEV;
+		}
+	}
+
+	return part;
+}
#8 lore raw

Re: [PATCH v2 7/7] smegw01: Enable EMMC boot from multiple partitions

Hi Pali,

Quoted 10 lines · Pali Rohár

This does not look to be correct. Return type of the function is uint but here you are trying to return negative number.

I think that there is some layering or API issue. Caller of this function probably does not expect any failure and use returned value as partition number. But you are reading partition number from the source which may return failure (as the source does not have to contain it).

I'm not sure what is the correct way how to handle these kind of error. I hope that this is something which you would know.

Thanks for your feedback.

Talked to Eduard and we prefer to go with a simpler implementation of board_mmc_get_env_part(),
just like the one from board/purism/librem5/librem5.c.

The librem5 board is based on the imx8mq, which has the same esdhc controller as the imx7d and
it works well in our case. Will send a v3.