Skip to contentSkip to conversation

ARM: stm32: Add script to install U-Boot from SD/eMMC to SPI NOR on DH STM32MP15xx DHSOM

PATCH Superseded Marek Vasut 2 participants 5 messages Sep 30, 2024 – Oct 17, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: stm32: Add script to install U-Boot from SD/eMMC to SPI NOR on DH STM32MP15xx DHSOM

Make the dh_update_sd_to_sf script generic, rename it to dh_update_sdmmc_to_sf and implement two specific dh_update_sd_to_sf and dh_update_emmc_to_sf scripts which load U-Boot from either SD or eMMC and install it into SPI NOR.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 include/configs/stm32mp15_dh_dhsom.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
include/configs/stm32mp15_dh_dhsom.h +13 -3
index de39b19219d..fa759c938b3 100644
@@ -38,16 +38,26 @@
 		"setenv loadaddr1 && "					\
 		"setenv sblkcnt && "					\
 		"setenv ublkcnt\0"					\
-	"dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from SD */ \
+	"dh_update_sdmmc_to_sf=" /* Erase SPI NOR and install U-Boot from SD/eMMC */ \
 		"setexpr loadaddr1 ${loadaddr} + 0x1000000 && "		\
-		"load mmc 0:4 ${loadaddr1} /boot/u-boot-spl.stm32 && "	\
+		"load ${dh_update_iface} ${dh_update_dev} "		\
+			"${loadaddr1} /boot/u-boot-spl.stm32 && "	\
 		"env set filesize1 ${filesize} && "			\
-		"load mmc 0:4 ${loadaddr} /boot/u-boot.itb && "		\
+		"load ${dh_update_iface} ${dh_update_dev} "		\
+			"${loadaddr} /boot/u-boot.itb && "		\
 		"sf probe && sf erase 0 0x200000 && "			\
 		"sf update ${loadaddr1} 0 ${filesize1} && "		\
 		"sf update ${loadaddr1} 0x40000 ${filesize1} && "	\
 		"sf update ${loadaddr} 0x80000 ${filesize} && "		\
 		"env set filesize1 && env set loadaddr1\0"		\
+	"dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from SD */ \
+		"setenv dh_update_iface mmc && "			\
+		"setenv dh_update_dev 0:4 && "				\
+		"run dh_update_sdmmc_to_sf\0"				\
+	"dh_update_emmc_to_sf=" /* Erase SPI NOR and install U-Boot from eMMC */ \
+		"setenv dh_update_iface mmc && "			\
+		"setenv dh_update_dev 1:4 && "				\
+		"run dh_update_sdmmc_to_sf\0"				\
 	"stdin=serial\0"						\
 	"stdout=serial\0"						\
 	"stderr=serial\0"						\
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 41 lines · Marek Vasut

Make the dh_update_sd_to_sf script generic, rename it to dh_update_sdmmc_to_sf and implement two specific dh_update_sd_to_sf and dh_update_emmc_to_sf scripts which load U-Boot from either SD or eMMC and install it into SPI NOR.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
  include/configs/stm32mp15_dh_dhsom.h | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)
include/configs/stm32mp15_dh_dhsom.h +6 -3
index de39b19219d..fa759c938b3 100644
@@ -38,16 +38,26 @@
  		"setenv loadaddr1 && "					\
  		"setenv sblkcnt && "					\
  		"setenv ublkcnt\0"					\
-	"dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from SD */ \
+	"dh_update_sdmmc_to_sf=" /* Erase SPI NOR and install U-Boot from SD/eMMC */ \
  		"setexpr loadaddr1 ${loadaddr} + 0x1000000 && "		\
-		"load mmc 0:4 ${loadaddr1} /boot/u-boot-spl.stm32 && "	\
+		"load ${dh_update_iface} ${dh_update_dev} "		\
+			"${loadaddr1} /boot/u-boot-spl.stm32 && "	\
  		"env set filesize1 ${filesize} && "			\
-		"load mmc 0:4 ${loadaddr} /boot/u-boot.itb && "		\
+		"load ${dh_update_iface} ${dh_update_dev} "		\
+			"${loadaddr} /boot/u-boot.itb && "		\
  		"sf probe && sf erase 0 0x200000 && "			\
  		"sf update ${loadaddr1} 0 ${filesize1} && "		\
  		"sf update ${loadaddr1} 0x40000 ${filesize1} && "	\
  		"sf update ${loadaddr} 0x80000 ${filesize} && "		\
  		"env set filesize1 && env set loadaddr1\0"		\
+	"dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from SD */ \

include/configs/stm32mp15_dh_dhsom.h line 63

Quoted 10 lines
include/configs/stm32mp15_dh_dhsom.h +7 -0
+		"setenv dh_update_iface mmc && "			\
+		"setenv dh_update_dev 0:4 && "				\
+		"run dh_update_sdmmc_to_sf\0"				\
+	"dh_update_emmc_to_sf=" /* Erase SPI NOR and install U-Boot from eMMC */ \
+		"setenv dh_update_iface mmc && "			\
+		"setenv dh_update_dev 1:4 && "				\
+		"run dh_update_sdmmc_to_sf\0"				\
  	"stdin=serial\0"						\
  	"stdout=serial\0"						\
  	"stderr=serial\0"						\

ok I will merge it as it

with 2 minor question

a) it is strange to define interface variable for macro but use only with "mmc" device with

Quoted 1 line

setenv dh_update_iface mmc

it can be simplified with

"load mmc ${dh_update_dev}

or it is to prepare other device then "mmc" .....

b) you are using "sf" command and not "mtd" to udpate SPI NOR ?

the MTD command allows to use the MTD partition name, defined in DT, so no need to know offset in script (and avoid "sf probe")

mtd erase fsbl1; mtd write fsbl1 ${loadaddr1} 0 ${filesize1} \
mtd erase fsbl2; mtd write fsbl2 ${loadaddr1} 0 ${filesize1} \
mtd erase uboot; mtd write uboot ${loadaddr} 0 ${filesize}

Thanks
Patrick

#2 lore raw
Quoted 1 line · Patrick DELAUNAY

Hi,

Hi,

Quoted 64 lines · Marek Vasut
Quoted 47 lines

Make the dh_update_sd_to_sf script generic, rename it to dh_update_sdmmc_to_sf and implement two specific dh_update_sd_to_sf and dh_update_emmc_to_sf scripts which load U-Boot from either SD or eMMC and install it into SPI NOR.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
  include/configs/stm32mp15_dh_dhsom.h | 16 +++++++++++++---

  1 file changed, 13 insertions(+), 3 deletions(-)
include/configs/stm32mp15_dh_dhsom.h +10 -3
index de39b19219d..fa759c938b3 100644
@@ -38,16 +38,26 @@
           "setenv loadaddr1 && "                    \
           "setenv sblkcnt && "                    \
           "setenv ublkcnt\0"                    \
-    "dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from SD 
 */ \
+    "dh_update_sdmmc_to_sf=" /* Erase SPI NOR and install U-Boot from 
 SD/eMMC */ \
           "setexpr loadaddr1 ${loadaddr} + 0x1000000 && "        \
-        "load mmc 0:4 ${loadaddr1} /boot/u-boot-spl.stm32 && "    \
+        "load ${dh_update_iface} ${dh_update_dev} "        \
+            "${loadaddr1} /boot/u-boot-spl.stm32 && "    \
           "env set filesize1 ${filesize} && "            \
-        "load mmc 0:4 ${loadaddr} /boot/u-boot.itb && "        \
+        "load ${dh_update_iface} ${dh_update_dev} "        \
+            "${loadaddr} /boot/u-boot.itb && "        \
           "sf probe && sf erase 0 0x200000 && "            \
           "sf update ${loadaddr1} 0 ${filesize1} && "        \
           "sf update ${loadaddr1} 0x40000 ${filesize1} && "    \
           "sf update ${loadaddr} 0x80000 ${filesize} && "        \
           "env set filesize1 && env set loadaddr1\0"        \
+    "dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from SD 
 */ \
+        "setenv dh_update_iface mmc && "            \
+        "setenv dh_update_dev 0:4 && "                \
+        "run dh_update_sdmmc_to_sf\0"                \
+    "dh_update_emmc_to_sf=" /* Erase SPI NOR and install U-Boot from 
Quoted 8 lines

eMMC */ \
+        "setenv dh_update_iface mmc && "            \
+        "setenv dh_update_dev 1:4 && "                \
+        "run dh_update_sdmmc_to_sf\0"                \
      "stdin=serial\0"                        \
      "stdout=serial\0"                        \
      "stderr=serial\0"                        \

ok I will merge it as it

with 2 minor question

a)  it is strange to define interface variable for macro
    but use only with "mmc" device with

Quoted 7 lines
Quoted 1 line

setenv dh_update_iface mmc

it can be simplified with

"load mmc ${dh_update_dev}

or it is to prepare other device then "mmc" .....

The later, I now also renamed the script in V2 to make it more obvious.

Quoted 9 lines

b) you are using "sf" command and not "mtd" to udpate SPI NOR ?

the MTD command allows to use the MTD partition name, defined in DT, so no need to know offset in script (and avoid "sf probe")

mtd erase fsbl1; mtd write fsbl1 ${loadaddr1} 0 ${filesize1} \
mtd erase fsbl2; mtd write fsbl2 ${loadaddr1} 0 ${filesize1} \
mtd erase uboot; mtd write uboot ${loadaddr} 0 ${filesize}

Can you also do 'sf update' alike operation with 'mtd' command? I don't think you can. The 'sf update' often does significantly speed up the SPI NOR update process, because SPI NOR erase operation is very slow, while SPI NOR read operation is fast, so if the update can read and then skip many blocks which are already in the SPI NOR and erase and write only the changed blocks, the update is often very fast too.

#3 lore raw

Hi,

Quoted 71 lines · Marek Vasut
Quoted 1 line · Patrick DELAUNAY

Hi,

Hi,

Quoted 66 lines · Marek Vasut
Quoted 47 lines

Make the dh_update_sd_to_sf script generic, rename it to dh_update_sdmmc_to_sf and implement two specific dh_update_sd_to_sf and dh_update_emmc_to_sf scripts which load U-Boot from either SD or eMMC and install it into SPI NOR.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
  include/configs/stm32mp15_dh_dhsom.h | 16 +++++++++++++---

  1 file changed, 13 insertions(+), 3 deletions(-)
include/configs/stm32mp15_dh_dhsom.h +10 -3
index de39b19219d..fa759c938b3 100644
@@ -38,16 +38,26 @@
           "setenv loadaddr1 && "                    \
           "setenv sblkcnt && "                    \
           "setenv ublkcnt\0"                    \
-    "dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from 
 SD */ \
+    "dh_update_sdmmc_to_sf=" /* Erase SPI NOR and install U-Boot 
 from SD/eMMC */ \
           "setexpr loadaddr1 ${loadaddr} + 0x1000000 && "        \
-        "load mmc 0:4 ${loadaddr1} /boot/u-boot-spl.stm32 && "    \
+        "load ${dh_update_iface} ${dh_update_dev} "        \
+            "${loadaddr1} /boot/u-boot-spl.stm32 && "    \
           "env set filesize1 ${filesize} && "            \
-        "load mmc 0:4 ${loadaddr} /boot/u-boot.itb && "        \
+        "load ${dh_update_iface} ${dh_update_dev} "        \
+            "${loadaddr} /boot/u-boot.itb && " \
           "sf probe && sf erase 0 0x200000 && "            \
           "sf update ${loadaddr1} 0 ${filesize1} && "        \
           "sf update ${loadaddr1} 0x40000 ${filesize1} && "    \
           "sf update ${loadaddr} 0x80000 ${filesize} && "        \
           "env set filesize1 && env set loadaddr1\0"        \
+    "dh_update_sd_to_sf=" /* Erase SPI NOR and install U-Boot from 
 SD */ \
+        "setenv dh_update_iface mmc && "            \
+        "setenv dh_update_dev 0:4 && " \
+        "run dh_update_sdmmc_to_sf\0"                \
+    "dh_update_emmc_to_sf=" /* Erase SPI NOR and install U-Boot 
Quoted 8 lines

from eMMC */ \
+        "setenv dh_update_iface mmc && "            \
+        "setenv dh_update_dev 1:4 && " \
+        "run dh_update_sdmmc_to_sf\0"                \
      "stdin=serial\0"                        \
      "stdout=serial\0"                        \
      "stderr=serial\0"                        \

ok I will merge it as it

with 2 minor question

a)  it is strange to define interface variable for macro but use only with "mmc" device with

Quoted 1 line

setenv dh_update_iface mmc

Quoted 7 lines
Quoted 5 lines

it can be simplified with

"load mmc ${dh_update_dev}

or it is to prepare other device then "mmc" .....

The later, I now also renamed the script in V2 to make it more obvious.

ok

Quoted 11 lines
Quoted 10 lines

b) you are using "sf" command and not "mtd" to udpate SPI NOR ?

the MTD command allows to use the MTD partition name, defined in DT, so no need to know offset in script (and avoid "sf probe")

mtd erase fsbl1; mtd write fsbl1 ${loadaddr1} 0 ${filesize1} \
mtd erase fsbl2; mtd write fsbl2 ${loadaddr1} 0 ${filesize1} \
mtd erase uboot; mtd write uboot ${loadaddr} 0 ${filesize}

Can you also do 'sf update' alike operation with 'mtd' command? I don't think you can. The 'sf update' often does significantly speed up the SPI NOR update process, because SPI NOR erase operation is very slow, while SPI NOR read operation is fast, so if the update can read and then skip many blocks which are already in the SPI NOR and erase and write only the changed blocks, the update is often very fast too.

Good point....

an improve place for MTD command

I will try to propose something for mtd command

and for the patch

Applied to u-boot-stm/master, thanks!

Regards
Patrick

#4 lore raw

On 10/16/24 7:59 PM, Patrick DELAUNAY wrote:

Hello Patrick,

Quoted 16 lines
Quoted 10 lines
Quoted 9 lines

b) you are using "sf" command and not "mtd" to udpate SPI NOR ?

the MTD command allows to use the MTD partition name, defined in DT, so no need to know offset in script (and avoid "sf probe")

mtd erase fsbl1; mtd write fsbl1 ${loadaddr1} 0 ${filesize1} \
mtd erase fsbl2; mtd write fsbl2 ${loadaddr1} 0 ${filesize1} \
mtd erase uboot; mtd write uboot ${loadaddr} 0 ${filesize}

Can you also do 'sf update' alike operation with 'mtd' command? I don't think you can. The 'sf update' often does significantly speed up the SPI NOR update process, because SPI NOR erase operation is very slow, while SPI NOR read operation is fast, so if the update can read and then skip many blocks which are already in the SPI NOR and erase and write only the changed blocks, the update is often very fast too.

Good point....

an improve place for MTD command

Quoted 7 lines

I will try to propose something for mtd command

and for the patch

Applied to u-boot-stm/master, thanks!

btw look at doc/README.dfutftp , I use that to update R-Car boards which also require multiple blobs at various offsets in HyperFlash (HF behaves like a regular Parallel NOR). I can generate a fitImage which contains the blobs and their offsets and then run dfu tftp to download the fitImage from TFTP server and install the blobs automatically.