Skip to contentSkip to conversation

allow boot firmware to go in user/boot0/boot1

PATCH New Tim Harvey 2 participants 11 messages May 3, 2023 – Jul 11, 2023 Arm i.MX and Layerscape

lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

cover allow boot firmware to go in user/boot0/boot1

The Gateworks Venice board family uses a combination of imx8mm, imx8mn, and imx8mp SoC's. Because boot firmware for these are not binary compatible and have different flash offsets it is highly desirable to place boot firmware in an emmc boot partition instead of the current user hardware partition to minimize unintended corruption of boot firmware by flashing the wrong image or to the wrong location.

This series of patches allows the same boot firmware to be placed in either boot0, boot1, or user hardware partition by detecting the boot device and adjusting env device as well as u-boot sector.

Additionally the firmware script is updated to automate device, offset, and soc.

Tim Harvey (5):
board: gateworks: venice: dynamically determine U-Boot raw sector
board: gateworks: venice: dynamically determine U-Boot env partition
board: gateworks: venice: dynamically update the update_firmware
script
board: gateworks: venice: move env location
board: gateworks: venice: update board doc to show other emmc parts

 board/gateworks/venice/spl.c          | 15 +++++
 board/gateworks/venice/venice.c       | 86 +++++++++++++++++++++++++++
 board/gateworks/venice/venice.env     |  6 +-
 configs/imx8mm_venice_defconfig       |  4 +-
 configs/imx8mn_venice_defconfig       |  4 +-
 configs/imx8mp_venice_defconfig       |  4 +-
 doc/board/gateworks/imx8mm_venice.rst |  4 +-
 doc/board/gateworks/imx8mn_venice.rst |  4 +-
 doc/board/gateworks/imx8mp_venice.rst |  4 +-
 include/configs/imx8mm_venice.h       |  1 -
 include/configs/imx8mn_venice.h       |  1 -
 include/configs/imx8mp_venice.h       |  1 -
 12 files changed, 119 insertions(+), 15 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/5 board: gateworks: venice: dynamically determine U-Boot raw sector

CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR needs to adjust for IMX8MN and IMX8MP when booting from an eMMC boot partition due to IMX BOOTROM v2 using an SPL offset of 0 for boot partitions and 32K for the user partition.

In order to allow the same firmware to run on both user and boot hardware partitions adjust raw_sect dynamically at runtime.

---
 board/gateworks/venice/spl.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
board/gateworks/venice/spl.c +15 -0
index 4eb7bdfcee67..50056da3ee0f 100644
@@ -327,6 +327,21 @@ int spl_board_boot_device(enum boot_device boot_dev_spl)
 	}
 }
 
+unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc, unsigned long raw_sect)
+{
+	if (!IS_SD(mmc)) {
+		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+		case 1:
+		case 2:
+			if (IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP))
+				raw_sect -= 32 * 2;
+			break;
+		}
+	}
+
+	return raw_sect;
+}
+
 const char *spl_board_loader_name(u32 boot_device)
 {
 	switch (boot_device) {
Signature · 1 line
2.25.1
#2 lore raw

PATCH 1/5 board: gateworks: venice: dynamically determine U-Boot raw sector

Quoted 7 lines

CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR needs to adjust for IMX8MN and IMX8MP when booting from an eMMC boot partition due to IMX BOOTROM v2 using an SPL offset of 0 for boot partitions and 32K for the user partition.
In order to allow the same firmware to run on both user and boot hardware partitions adjust raw_sect dynamically at runtime.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author
#3 lore raw

PATCH 2/5 board: gateworks: venice: dynamically determine U-Boot env partition

In reply to Tim Harvey

Determine the U-Boot env hardware partition depending on the boot device.

This allows the same boot firmware image to be placed on user, boot0, or boot1 without changing CONFIG_SYS_MMC_ENV_PART.

---
 board/gateworks/venice/venice.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
board/gateworks/venice/venice.c +15 -0
index ca62f0be6d25..7aca75503846 100644
@@ -7,6 +7,7 @@
 #include <init.h>
 #include <led.h>
 #include <miiphy.h>
+#include <mmc.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/sys_proto.h>
 
@@ -139,6 +140,20 @@ int board_mmc_get_env_dev(int devno)
 	return devno;
 }
 
+uint mmc_get_env_part(struct mmc *mmc)
+{
+	if (!IS_SD(mmc)) {
+		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+		case 1:
+			return 1;
+		case 2:
+			return 2;
+		}
+	}
+
+	return 0;
+}
+
 int ft_board_setup(void *fdt, struct bd_info *bd)
 {
 	const char *base_model = eeprom_get_baseboard_model();
Signature · 1 line
2.25.1
#4 lore raw

PATCH 2/5 board: gateworks: venice: dynamically determine U-Boot env partition

Quoted 5 lines

Determine the U-Boot env hardware partition depending on the boot device.
This allows the same boot firmware image to be placed on user, boot0, or boot1 without changing CONFIG_SYS_MMC_ENV_PART.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author
#5 lore raw

PATCH 3/5 board: gateworks: venice: dynamically update the update_firmware script

In reply to Tim Harvey

The update_firmware script is intended to update the boot firmware but the details including the offset and hardware partition are dependent on the boot device.

Specifically:
- IMX8MM/IMX8MP (BOOTROM v2) the offset is 32KiB for SD and eMMC user hardware partition and 0KiB for eMMC boot partitions.
- IMX8MM the offset is 33KiB for SD and eMMC regardless of hardware partition.

Dynamically set soc, dev, bootpart, and bootblk env vars at runtime and use these in the update_firmware script. Remove the splblk env var from config files as its no longer needed.

---
 board/gateworks/venice/venice.c   | 71 +++++++++++++++++++++++++++++++
 board/gateworks/venice/venice.env |  6 +--
 include/configs/imx8mm_venice.h   |  1 -
 include/configs/imx8mn_venice.h   |  1 -
 include/configs/imx8mp_venice.h   |  1 -
 5 files changed, 74 insertions(+), 6 deletions(-)
board/gateworks/venice/venice.c +71 -0
index 7aca75503846..803582c55b99 100644
@@ -6,10 +6,12 @@
 #include <fdt_support.h>
 #include <init.h>
 #include <led.h>
+#include <mmc.h>
 #include <miiphy.h>
 #include <mmc.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/sys_proto.h>
+#include <asm/mach-imx/boot_mode.h>
 
 #include "eeprom.h"
 
@@ -94,10 +96,12 @@ int board_init(void)
 int board_late_init(void)
 {
 	const char *str;
+	struct mmc *mmc = NULL;
 	char env[32];
 	int ret, i;
 	u8 enetaddr[6];
 	char fdt[64];
+	int bootdev;
 
 	/* Set board serial/model */
 	if (!env_get("serial#"))
@@ -132,6 +136,73 @@ int board_late_init(void)
 		i++;
 	} while (!ret);
 
+	/*
+	 * set bootdev/bootblk/bootpart (used in firmware_update script)
+	 * dynamically depending on boot device and SoC
+	 */
+	bootdev = -1;
+	switch (get_boot_device()) {
+	case SD1_BOOT:
+	case MMC1_BOOT: /* SDHC1 */
+		bootdev = 0;
+		break;
+	case SD2_BOOT:
+	case MMC2_BOOT: /* SDHC2 */
+		bootdev = 1;
+		break;
+	case SD3_BOOT:
+	case MMC3_BOOT: /* SDHC3 */
+		bootdev = 2;
+		break;
+	default:
+		break;
+	}
+	if (bootdev != -1)
+		mmc = find_mmc_device(bootdev);
+	if (mmc) {
+		int bootblk;
+
+		if (IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP))
+			bootblk = 32 * SZ_1K / 512;
+		else
+			bootblk = 33 * SZ_1K / 512;
+		mmc_init(mmc);
+		if (!IS_SD(mmc)) {
+			int bootpart;
+
+			switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+			case 1: /* boot0 */
+				bootpart = 1;
+				break;
+			case 2: /* boot1 */
+				bootpart = 2;
+				break;
+			case 7: /* user */
+			default:
+				bootpart = 0;
+				break;
+			}
+			/* IMX8MP/IMX8MN BOOTROM v2 uses offset=0 for boot parts */
+			if ((IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP)) &&
+			    (bootpart == 1 || bootpart == 2))
+				bootblk = 0;
+			env_set_hex("bootpart", bootpart);
+			env_set_hex("bootblk", bootblk);
+		} else { /* SD */
+			env_set("bootpart", "");
+			env_set_hex("bootblk", bootblk);
+		}
+		env_set_hex("dev", bootdev);
+	}
+
+	/* override soc=imx8m to provide a more specific soc name */
+	if (IS_ENABLED(CONFIG_IMX8MN))
+		env_set("soc", "imx8mn");
+	else if (IS_ENABLED(CONFIG_IMX8MP))
+		env_set("soc", "imx8mp");
+	else if (IS_ENABLED(CONFIG_IMX8MM))
+		env_set("soc", "imx8mm");
+
 	return 0;
 }
 
board/gateworks/venice/venice.env +3 -3
index 2054c029a3e9..a0d6c43325cf 100644
@@ -8,11 +8,11 @@ bootm_size=0x10000000
 dev=2
 preboot=gsc wd-disable
 console=ttymxc1,115200
-update_firmware=tftpboot $loadaddr $image &&
+update_firmware=tftpboot $loadaddr $dir/venice-$soc-flash.bin &&
 	setexpr blkcnt $filesize + 0x1ff &&
 	setexpr blkcnt $blkcnt / 0x200 &&
-	mmc dev $dev &&
-	mmc write $loadaddr $splblk $blkcnt
+	mmc dev $dev $bootpart &&
+	mmc write $loadaddr $bootblk $blkcnt
 loadfdt=if $fsload $fdt_addr_r $dir/$fdt_file1;
 	then echo loaded $fdt_file1;
 	elif $fsload $fdt_addr_r $dir/$fdt_file2;
include/configs/imx8mm_venice.h +0 -1
index 5579a05d165f..b33b8283085f 100644
@@ -26,7 +26,6 @@
 	func(DHCP, dhcp, na)
 #include <config_distro_bootcmd.h>
 #define CFG_EXTRA_ENV_SETTINGS \
-	"splblk=0x42\0" \
 	BOOTENV
 
 #define CFG_SYS_INIT_RAM_ADDR        0x40000000
include/configs/imx8mn_venice.h +0 -1
index 80c2df9f30ff..3db997e9e7f4 100644
@@ -20,7 +20,6 @@
 	func(DHCP, dhcp, na)
 #include <config_distro_bootcmd.h>
 #define CFG_EXTRA_ENV_SETTINGS \
-	"splblk=0x40\0" \
 	BOOTENV
 
 #define CFG_SYS_INIT_RAM_ADDR        0x40000000
include/configs/imx8mp_venice.h +0 -1
index 4b32d5a77ef6..b5ee8c98fbbe 100644
@@ -20,7 +20,6 @@
 	func(DHCP, dhcp, na)
 #include <config_distro_bootcmd.h>
 #define CFG_EXTRA_ENV_SETTINGS \
-	"splblk=0x40\0" \
 	BOOTENV
 
 #define CFG_SYS_INIT_RAM_ADDR        0x40000000
Signature · 1 line
2.25.1
#6 lore raw

PATCH 3/5 board: gateworks: venice: dynamically update the update_firmware script

Quoted 11 lines

The update_firmware script is intended to update the boot firmware but the details including the offset and hardware partition are dependent on the boot device.
Specifically:
- IMX8MM/IMX8MP (BOOTROM v2) the offset is 32KiB for SD and eMMC user hardware partition and 0KiB for eMMC boot partitions.
- IMX8MM the offset is 33KiB for SD and eMMC regardless of hardware partition.
Dynamically set soc, dev, bootpart, and bootblk env vars at runtime and use these in the update_firmware script. Remove the splblk env var from config files as its no longer needed.

Quoted 1 line

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author
#7 lore raw

PATCH 4/5 board: gateworks: venice: move env location

In reply to Tim Harvey

To allow U-Boot to fit within emmc boot partitions move the env from just under 16MiB to just under 4MiB as some emmc devices used on venice boards have 4MiB boot partitions. This still leaves plenty of room for U-Boot.

---
 configs/imx8mm_venice_defconfig | 4 ++--
 configs/imx8mn_venice_defconfig | 4 ++--
 configs/imx8mp_venice_defconfig | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
configs/imx8mm_venice_defconfig +2 -2
index ad5b7616f30a..427d0572c5fe 100644
@@ -6,7 +6,7 @@ CONFIG_SPL_GPIO=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x8000
-CONFIG_ENV_OFFSET=0xff0000
+CONFIG_ENV_OFFSET=0x3f0000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="imx8mm-venice"
 CONFIG_SPL_TEXT_BASE=0x7E1000
@@ -17,7 +17,7 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_STACK=0x920000
 CONFIG_SPL=y
-CONFIG_ENV_OFFSET_REDUND=0xff8000
+CONFIG_ENV_OFFSET_REDUND=0x3f8000
 CONFIG_SYS_LOAD_ADDR=0x48200000
 CONFIG_SYS_MEMTEST_START=0x40000000
 CONFIG_SYS_MEMTEST_END=0x80000000
configs/imx8mn_venice_defconfig +2 -2
index 0742fa759b08..26c264512a13 100644
@@ -6,7 +6,7 @@ CONFIG_SPL_GPIO=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x8000
-CONFIG_ENV_OFFSET=0xff0000
+CONFIG_ENV_OFFSET=0x3f0000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="imx8mn-venice"
 CONFIG_SPL_TEXT_BASE=0x912000
@@ -17,7 +17,7 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_STACK=0x980000
 CONFIG_SPL=y
-CONFIG_ENV_OFFSET_REDUND=0xff8000
+CONFIG_ENV_OFFSET_REDUND=0x3f8000
 CONFIG_SPL_IMX_ROMAPI_LOADADDR=0x48000000
 CONFIG_SYS_LOAD_ADDR=0x48200000
 CONFIG_SYS_MEMTEST_START=0x40000000
configs/imx8mp_venice_defconfig +2 -2
index ae0c0120d107..8b5a8c86e6f7 100644
@@ -6,7 +6,7 @@ CONFIG_SPL_GPIO=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x8000
-CONFIG_ENV_OFFSET=0xff0000
+CONFIG_ENV_OFFSET=0x3f0000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="imx8mp-venice"
 CONFIG_SPL_TEXT_BASE=0x920000
@@ -17,7 +17,7 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_STACK=0x960000
 CONFIG_SPL=y
-CONFIG_ENV_OFFSET_REDUND=0xff8000
+CONFIG_ENV_OFFSET_REDUND=0x3f8000
 CONFIG_SPL_IMX_ROMAPI_LOADADDR=0x48000000
 CONFIG_SYS_LOAD_ADDR=0x40480000
 CONFIG_SYS_MEMTEST_START=0x40000000
Signature · 1 line
2.25.1
#8 lore raw

PATCH 4/5 board: gateworks: venice: move env location

Quoted 5 lines

To allow U-Boot to fit within emmc boot partitions move the env from just under 16MiB to just under 4MiB as some emmc devices used on venice boards have 4MiB boot partitions. This still leaves plenty of room for U-Boot.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author
#9 lore raw

PATCH 5/5 board: gateworks: venice: update board doc to show other emmc parts

In reply to Tim Harvey

Update the venice board documentation to show how to install to the various eMMC hardware partitions available as the same binary firmware can be placed in either user/boot0/boot1 without build-time config changes. Note that the boot offsets differ depending on the SoC and the eMMC hardware partition.

---
 doc/board/gateworks/imx8mm_venice.rst | 4 +++-
 doc/board/gateworks/imx8mn_venice.rst | 4 +++-
 doc/board/gateworks/imx8mp_venice.rst | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)
doc/board/gateworks/imx8mm_venice.rst +3 -1
index f1e7e4994458..ea78dfd7ae6b 100644
@@ -47,4 +47,6 @@ Update eMMC
 
    => tftpboot $loadaddr flash.bin
    => setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
-   => mmc dev 2 && mmc write $loadaddr 0x42 $blkcnt
+   => mmc dev 2 0 && mmc write $loadaddr 0x42 $blkcnt # emmc user hw part
+   => mmc dev 2 1 && mmc write $loadaddr 0x42 $blkcnt # or emmc boot0 hw part
+   => mmc dev 2 2 && mmc write $loadaddr 0x42 $blkcnt # or emmc boot1 hw part
doc/board/gateworks/imx8mn_venice.rst +3 -1
index 7ba953a4a85c..7015f4ef31c7 100644
@@ -47,4 +47,6 @@ Update eMMC
 
    => tftpboot $loadaddr flash.bin
    => setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
-   => mmc dev 2 && mmc write $loadaddr 0x40 $blkcnt
+   => mmc dev 2 0 && mmc write $loadaddr 0x40 $blkcnt # emmc user hw part
+   => mmc dev 2 1 && mmc write $loadaddr 0 $blkcnt # or emmc boot0 hw part
+   => mmc dev 2 2 && mmc write $loadaddr 0 $blkcnt # or emmc boot1 hw part
doc/board/gateworks/imx8mp_venice.rst +3 -1
index 632cd742d1f8..a219caadff26 100644
@@ -47,4 +47,6 @@ Update eMMC
 
    => tftpboot $loadaddr flash.bin
    => setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
-   => mmc dev 2 && mmc write $loadaddr 0x40 $blkcnt
+   => mmc dev 2 0 && mmc write $loadaddr 0x40 $blkcnt # emmc user hw part
+   => mmc dev 2 1 && mmc write $loadaddr 0 $blkcnt # or emmc boot0 hw part
+   => mmc dev 2 2 && mmc write $loadaddr 0 $blkcnt # or emmc boot1 hw part
Signature · 1 line
2.25.1
#10 lore raw

PATCH 5/5 board: gateworks: venice: update board doc to show other emmc parts

Quoted 6 lines

Update the venice board documentation to show how to install to the various eMMC hardware partitions available as the same binary firmware can be placed in either user/boot0/boot1 without build-time config changes. Note that the boot offsets differ depending on the SoC and the eMMC hardware partition.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================