Skip to contentSkip to conversation

Enable SPI NOR flash for SpacemiT K3 in main app

PATCH Superseded E Shattow 2 participants 11 messages Oct 20 – Oct 22

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

E Shattow

author
#0 lore raw

cover Enable SPI NOR flash for SpacemiT K3 in main app

Enable SPI Flash command, mtd part names and locations, and store U-Boot environment in SPI NOR flash.

E Shattow (2):
configs: spacemit: k3: enable spi nor flash in main app
configs: spacemit: k3: enable mtdparts on Pico-ITX in main app

 arch/riscv/cpu/k3/Kconfig     |  1 +
 configs/spacemit_k3_defconfig | 11 +++++++++++
 2 files changed, 12 insertions(+)

base-commit: 40988fb81ef17c15c36aab94297f5a7a6bc79671

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/2 configs: spacemit: k3: enable spi nor flash in main app

Enable sf command and env storage in SPI NOR flash. SPL is not yet upstream so this is only in the main app, and depends on vendor SPL for clocks setup ahead of SPI NOR flash probe.

---
 arch/riscv/cpu/k3/Kconfig     | 1 +
 configs/spacemit_k3_defconfig | 6 ++++++
 2 files changed, 7 insertions(+)
arch/riscv/cpu/k3/Kconfig +1 -0
index 5474ac112437..07b490a718dd 100644
@@ -14,5 +14,6 @@ config SPACEMIT_K3
 	imply RISCV_TIMER if RISCV_SMODE
 	imply CMD_CPU
 	imply OF_UPSTREAM
+	imply SPI
 
 endif
configs/spacemit_k3_defconfig +6 -0
index 586305c62322..b333e708d01b 100644
@@ -4,6 +4,8 @@ CONFIG_SYS_MALLOC_F_LEN=0x80000
 CONFIG_NR_DRAM_BANKS=2
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x102300000
+CONFIG_ENV_SIZE=0x10000
+CONFIG_ENV_OFFSET=0xa0000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="spacemit/k3-pico-itx"
 CONFIG_SYS_BOOTM_LEN=0xa000000
@@ -35,6 +37,8 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi"
+CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_LWIP=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SYSCON=y
@@ -44,6 +48,7 @@ CONFIG_SPACEMIT_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
+CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
@@ -61,4 +66,5 @@ CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
+CONFIG_FSL_QSPI=y
 CONFIG_TIMER_EARLY=y
Signature · 1 line
2.53.0
author
#6 lore raw

PATCH 2/2 configs: spacemit: k3: enable mtdparts on Pico-ITX in main app

In reply to E Shattow

add default mtdparts and mtdids consistent with k3-pico-itx.dts

---
 configs/spacemit_k3_defconfig | 5 +++++
 1 file changed, 5 insertions(+)
configs/spacemit_k3_defconfig +5 -0
index b333e708d01b..2ca912556a88 100644
@@ -26,6 +26,7 @@ CONFIG_SYS_PBSIZE=276
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MTD=y
 CONFIG_CMD_DHCP=y
 CONFIG_CMD_DNS=y
 CONFIG_CMD_MII=y
@@ -36,6 +37,9 @@ CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
+CONFIG_MTDPARTS_DEFAULT="spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot)"
 CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
@@ -49,6 +53,7 @@ CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [PATCH 1/2] configs: spacemit: k3: enable spi nor flash in main app

In reply to E Shattow

Hi E Shattow,

Thanks for the patch

Quoted 1 line · E Shattow

Enable sf command and env storage in SPI NOR flash.

..

Quoted 4 lines

SPL is not yet
upstream so this is only in the main app, and depends on vendor SPL for clocks setup ahead of SPI NOR flash probe.

This could be added as additional info, but I'd rather not put in commit meassage, maybe just put it under "---" scissors line for reference

For why depend on SPL for clock, reset setup.. I checked fsl_qspi.c, there is no clock & reset enabling support currently, although SpacemiT do provide those support, but I think it's another item need to improve, and we could definitely address it in a separate thread..

Quoted 11 lines
---
 arch/riscv/cpu/k3/Kconfig     | 1 +
 configs/spacemit_k3_defconfig | 6 ++++++
 2 files changed, 7 insertions(+)
arch/riscv/cpu/k3/Kconfig +0 -0
index 5474ac112437..07b490a718dd 100644

arch/riscv/cpu/k3/Kconfig config SPACEMIT_K3 · line 17

Quoted 4 lines
arch/riscv/cpu/k3/Kconfig +1 -0
@@ -14,5 +14,6 @@ config SPACEMIT_K3
 	imply RISCV_TIMER if RISCV_SMODE
 	imply CMD_CPU
 	imply OF_UPSTREAM
+	imply SPI

Any reason to add this dependency?

I'd prefer to put this config in defconfig, As I see K3 has no hard requirement for SPI support from architecture perspective

Quoted 41 lines
arch/riscv/cpu/k3/Kconfig +0 -0
 endif
configs/spacemit_k3_defconfig +6 -0
index 586305c62322..b333e708d01b 100644
@@ -4,6 +4,8 @@ CONFIG_SYS_MALLOC_F_LEN=0x80000
 CONFIG_NR_DRAM_BANKS=2
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x102300000
+CONFIG_ENV_SIZE=0x10000
+CONFIG_ENV_OFFSET=0xa0000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="spacemit/k3-pico-itx"
 CONFIG_SYS_BOOTM_LEN=0xa000000
@@ -35,6 +37,8 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi"
+CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_LWIP=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SYSCON=y
@@ -44,6 +48,7 @@ CONFIG_SPACEMIT_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
+CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
@@ -61,4 +66,5 @@ CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
+CONFIG_FSL_QSPI=y
 CONFIG_TIMER_EARLY=y
Signature · 1 line
2.53.0
Signature · 1 line
Yixun Lan (dlan)
author
#3 lore raw

Re: [PATCH 1/2] configs: spacemit: k3: enable spi nor flash in main app

Hi Yixun,

Quoted 25 lines · Yixun Lan

Hi E Shattow,

Thanks for the patch

Quoted 1 line · E Shattow

Enable sf command and env storage in SPI NOR flash.

..

Quoted 4 lines

SPL is not yet
upstream so this is only in the main app, and depends on vendor SPL for clocks setup ahead of SPI NOR flash probe.

This could be added as additional info, but I'd rather not put in commit meassage, maybe just put it under "---" scissors line for reference

For why depend on SPL for clock, reset setup.. I checked fsl_qspi.c, there is no clock & reset enabling support currently, although SpacemiT do provide those support, but I think it's another item need to improve, and we could definitely address it in a separate thread..

Quoted 6 lines
---
 arch/riscv/cpu/k3/Kconfig     | 1 +
 configs/spacemit_k3_defconfig | 6 ++++++
 2 files changed, 7 insertions(+)
Quoted 10 lines

arch/riscv/cpu/k3/Kconfig config SPACEMIT_K3 · line 17

Quoted 9 lines
arch/riscv/cpu/k3/Kconfig +1 -0
index 5474ac112437..07b490a718dd 100644
@@ -14,5 +14,6 @@ config SPACEMIT_K3
 	imply RISCV_TIMER if RISCV_SMODE
 	imply CMD_CPU
 	imply OF_UPSTREAM
+	imply SPI

Any reason to add this dependency?

It is a guess, that when SPL may be loaded by K3 SoC BootROM from SPI NOR flash then there should be an 'imply SPI' for what is needed to have SPI support in SPL here on selecting the K3 SoC or in BOARD_SPECIFIC_OPTIONS.

Quoted 4 lines

I'd prefer to put this config in defconfig, As I see K3 has no hard requirement for SPI support from architecture perspective

Okay, no objection to to move 'imply SPI' as '=y' in spacemit_k3_defconfig for v2 revision.

Quoted 33 lines
Quoted 33 lines
arch/riscv/cpu/k3/Kconfig +0 -0
 endif
configs/spacemit_k3_defconfig +5 -0
index 586305c62322..b333e708d01b 100644
@@ -4,6 +4,8 @@ CONFIG_SYS_MALLOC_F_LEN=0x80000
 CONFIG_NR_DRAM_BANKS=2
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x102300000
+CONFIG_ENV_SIZE=0x10000
+CONFIG_ENV_OFFSET=0xa0000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="spacemit/k3-pico-itx"
 CONFIG_SYS_BOOTM_LEN=0xa000000
@@ -35,6 +37,8 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi"
+CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_LWIP=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SYSCON=y
@@ -44,6 +48,7 @@ CONFIG_SPACEMIT_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
+CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
@@ -61,4 +66,5 @@ CONFIG_DEBUG_UART_SHIFT=2
Quoted 9 lines
Quoted 8 lines
configs/spacemit_k3_defconfig +1 -0
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
+CONFIG_FSL_QSPI=y
 CONFIG_TIMER_EARLY=y
Signature · 1 line
2.53.0

Thanks for the review,

-E

maintainer
#7 lore raw

Re: [PATCH 2/2] configs: spacemit: k3: enable mtdparts on Pico-ITX in main app

In reply to E Shattow

Hi E Shattow,

Quoted 20 lines · E Shattow

add default mtdparts and mtdids consistent with k3-pico-itx.dts

---
 configs/spacemit_k3_defconfig | 5 +++++
 1 file changed, 5 insertions(+)
configs/spacemit_k3_defconfig +1 -0
index b333e708d01b..2ca912556a88 100644
@@ -26,6 +26,7 @@ CONFIG_SYS_PBSIZE=276
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MTD=y
 CONFIG_CMD_DHCP=y
 CONFIG_CMD_DNS=y
 CONFIG_CMD_MII=y

configs/spacemit_k3_defconfig CONFIG_CMD_PMIC=y · line 42

Quoted 6 lines
configs/spacemit_k3_defconfig +3 -0
@@ -36,6 +37,9 @@ CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
+CONFIG_MTDPARTS_DEFAULT="spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot)"

or make it more specific? s/spi0.0/d420c000.spi/

Quoted 14 lines
configs/spacemit_k3_defconfig +1 -0
 CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
@@ -49,6 +53,7 @@ CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
Signature · 1 line
2.53.0
Signature · 1 line
Yixun Lan (dlan)
maintainer
#4 lore raw

Re: [PATCH 1/2] configs: spacemit: k3: enable spi nor flash in main app

In reply to E Shattow

Hi E Shattow,

one more comment

Quoted 10 lines · E Shattow

Enable sf command and env storage in SPI NOR flash. SPL is not yet upstream so this is only in the main app, and depends on vendor SPL for clocks setup ahead of SPI NOR flash probe.

---
 arch/riscv/cpu/k3/Kconfig     | 1 +
 configs/spacemit_k3_defconfig | 6 ++++++
 2 files changed, 7 insertions(+)

..

configs/spacemit_k3_defconfig CONFIG_SPACEMIT_GPIO=y · line 51

Quoted 6 lines

CONFIG_SYSCON=y

configs/spacemit_k3_defconfig +1 -0
@@ -44,6 +48,7 @@ CONFIG_SPACEMIT_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
+CONFIG_SPI_FLASH_WINBOND=y

I've also tested on com260 board which use GD25LQ64C chip, same 8MiB but need to enable CONFIG_SPI_FLASH_GIGADEVICE=y, the patch 2/2 also works on com260, so I'd suggest to make the commit message slightly
more generic? not specific for Pico-ITX board

Signature · 1 line
Yixun Lan (dlan)
author
#8 lore raw

Re: [PATCH 2/2] configs: spacemit: k3: enable mtdparts on Pico-ITX in main app

In reply to Yixun Lan

Hi Yixun,

Quoted 24 lines · Yixun Lan

Hi E Shattow,

Quoted 20 lines · E Shattow

add default mtdparts and mtdids consistent with k3-pico-itx.dts

---
 configs/spacemit_k3_defconfig | 5 +++++
 1 file changed, 5 insertions(+)
configs/spacemit_k3_defconfig +1 -0
index b333e708d01b..2ca912556a88 100644
@@ -26,6 +26,7 @@ CONFIG_SYS_PBSIZE=276
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MTD=y
 CONFIG_CMD_DHCP=y
 CONFIG_CMD_DNS=y
 CONFIG_CMD_MII=y
@@ -36,6 +37,9 @@ CONFIG_CMD_PMIC=y
Quoted 8 lines

configs/spacemit_k3_defconfig CONFIG_CMD_PMIC=y · line 42

Quoted 6 lines
configs/spacemit_k3_defconfig +3 -0
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
+CONFIG_MTDPARTS_DEFAULT="spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot)"

or make it more specific? s/spi0.0/d420c000.spi/

Yes and no, I do prefer an automatic layout (and layout name) be generated from device tree at runtime. I guess that may possibly become "qspi.flash0", or "fdt.soc.d420c000.spi.qspi.flash.0", etc.

The output of 'mtd list' tells us the parent:

=> mtd list
List of MTD devices:
* nor0
- device: flash@0
- parent: spi@d420c000

Also, then, the output of 'mtdparts' tells us the partition layout:

=> mtdpart

device nor0 <spi0.0>, # parts = 6

 #: name                size            offset          mask_flags
 0: bootinfo            0x00020000      0x00000000      0
 1: fsbl                0x00080000      0x00020000      0
 2: env                 0x00010000      0x000a0000      0
 3: esos                0x00100000      0x000b0000      0
 4: opensbi             0x00060000      0x001b0000      0
 5: uboot               0x005f0000      0x00210000      0

active partition: nor0,0 - (bootinfo) 0x00020000 @ 0x00000000

defaults:
mtdids : nor0=spi0.0
mtdparts:
spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot)

I consider the partition layout identifier style as you suggest:

$ egrep --exclude-dir=.git -or 'mtdparts=[^ ]+)' | cut -d: -f2 | sort |
uniq -c | egrep -v '[0-9a-fA-F]{7}' | sort -k1,1 -n

...

      3 mtdparts=nand_mtd
      3 mtdparts=uniphier-nand.0
      4 mtdparts=nand0
      4 mtdparts=spi-flash.0
      5 mtdparts=nor0
      5 mtdparts=spi_flash
      7 mtdparts=boot
      7 mtdparts=omap2-nand.0
      8 mtdparts=nand
     11 mtdparts=nand.0
     12 mtdparts=orion_nand
     13 mtdparts=spi0.0
     16 mtdparts=gpmi-nand
     50 mtdparts=atmel_nand
$ egrep --exclude-dir=.git -or 'mtdparts=[^ ]+)' | cut -d: -f2 | sort |
uniq -c | egrep '[0-9a-fA-F]{7}' | sort -k1,1 -n
      1 mtdparts=10b80000.nand.0
      1 mtdparts=1fc000000.nor_flash
      1 mtdparts=21e0000.qspi
      1 mtdparts=30bb0000.qspi
      1 mtdparts=30bb0000.spi
      1 mtdparts=8000000.nand
      1 mtdparts=fe000000.nor_flash
      1 mtdparts=ffb90000.nand.0
      1 mtdparts=mtdparts=47040000.spi.0
      1 mtdparts=[mtdparts=]edb7312-nor
      1 mtdparts=mtdparts=edb7312-nor
      2 mtdparts=02008000.spi.1
      2 mtdparts=8000000.nor
      4 mtdparts=1550000.spi
      4 mtdparts=1550000.spi-0
      4 mtdparts=47040000.spi.0
      4 mtdparts=ec000000.nor
      4 mtdparts=ef000000.nor
      4 mtdparts=fef000000.nor
     10 mtdparts=ff705000.spi.0
     16 mtdparts=60000000.nor
     16 mtdparts=ff800000.flash
     22 mtdparts=fe8000000.nor

For the initial patch here I instead prefer the minimal and simple style for mtdparts layout template names and to re-use what is popular in U-Boot source tree. The use of hexadecimal bus address for the layout name is difficult for me to read, and not clear to me what is the benefit to doing this manually-entered data address?

=> env print
...
mtddevnum=0
mtdids=nor0=spi0.0 mtdparts=spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot) partition=nor0,0
...

Compared to a style of repeating the bus address:

=> env print
...
mtddevnum=0
mtdids=nor0=d420c000.spi mtdparts=d420c000.spi:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot) partition=nor0,0
...

Let me know if you do yet prefer the bus address repeated for the name of partition layout. I'd like to see this as part of a runtime-generated mtdparts configuration, so anything is okay with me for the initial manual layout here.

Quoted 16 lines
Quoted 15 lines

CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi" CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_SPI_FLASH=y

configs/spacemit_k3_defconfig +1 -0
@@ -49,6 +53,7 @@ CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
Signature · 1 line
2.53.0

Thanks,

-E

author
#5 lore raw

Re: [PATCH 1/2] configs: spacemit: k3: enable spi nor flash in main app

In reply to Yixun Lan

Hi Yixun,

Quoted 6 lines · Yixun Lan

Hi E Shattow,

one more comment

Quoted 1 line · E Shattow

Enable sf command and env storage in SPI NOR flash. SPL is not yet

Okay, I will adjust the commit message. Thanks for looking at fsl_qspi.c this is a good report to learn it will need some work.

I have carefully constructed a build of SPL from spacemit-com/uboot-2022.10 that is reduced to a minimum of build config options. I'll make the requested changes and send a short write-up of how I build this reduced vendor SPL, for a baseline of testing.

Quoted 10 lines
Quoted 9 lines

upstream so this is only in the main app, and depends on vendor SPL for clocks setup ahead of SPI NOR flash probe.

---
 arch/riscv/cpu/k3/Kconfig     | 1 +
 configs/spacemit_k3_defconfig | 6 ++++++
 2 files changed, 7 insertions(+)

..

Quoted 11 lines

configs/spacemit_k3_defconfig CONFIG_SPACEMIT_GPIO=y · line 51

Quoted 6 lines

CONFIG_SYSCON=y

configs/spacemit_k3_defconfig +1 -0
@@ -44,6 +48,7 @@ CONFIG_SPACEMIT_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
+CONFIG_SPI_FLASH_WINBOND=y

I've also tested on com260 board which use GD25LQ64C chip, same 8MiB but need to enable CONFIG_SPI_FLASH_GIGADEVICE=y, the patch 2/2 also works on com260, so I'd suggest to make the commit message slightly
more generic? not specific for Pico-ITX board

Great, adding this for extending support to CoM260, thank you.

-E

maintainer
#9 lore raw

Re: [PATCH 2/2] configs: spacemit: k3: enable mtdparts on Pico-ITX in main app

In reply to E Shattow

Hi E

Quoted 141 lines · E Shattow

Hi Yixun,

Quoted 24 lines · Yixun Lan

Hi E Shattow,

Quoted 20 lines · E Shattow

add default mtdparts and mtdids consistent with k3-pico-itx.dts

---
 configs/spacemit_k3_defconfig | 5 +++++
 1 file changed, 5 insertions(+)
configs/spacemit_k3_defconfig +1 -0
index b333e708d01b..2ca912556a88 100644
@@ -26,6 +26,7 @@ CONFIG_SYS_PBSIZE=276
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MTD=y
 CONFIG_CMD_DHCP=y
 CONFIG_CMD_DNS=y
 CONFIG_CMD_MII=y
@@ -36,6 +37,9 @@ CONFIG_CMD_PMIC=y
Quoted 8 lines

configs/spacemit_k3_defconfig CONFIG_CMD_PMIC=y · line 42

Quoted 6 lines
configs/spacemit_k3_defconfig +3 -0
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
+CONFIG_MTDPARTS_DEFAULT="spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot)"

or make it more specific? s/spi0.0/d420c000.spi/

Yes and no, I do prefer an automatic layout (and layout name) be generated from device tree at runtime. I guess that may possibly become "qspi.flash0", or "fdt.soc.d420c000.spi.qspi.flash.0", etc.

The output of 'mtd list' tells us the parent:

=> mtd list
List of MTD devices:
* nor0
- device: flash@0
- parent: spi@d420c000

Also, then, the output of 'mtdparts' tells us the partition layout:

=> mtdpart

device nor0 <spi0.0>, # parts = 6

 #: name                size            offset          mask_flags
 0: bootinfo            0x00020000      0x00000000      0
 1: fsbl                0x00080000      0x00020000      0
 2: env                 0x00010000      0x000a0000      0
 3: esos                0x00100000      0x000b0000      0
 4: opensbi             0x00060000      0x001b0000      0
 5: uboot               0x005f0000      0x00210000      0

active partition: nor0,0 - (bootinfo) 0x00020000 @ 0x00000000

defaults:
mtdids : nor0=spi0.0
mtdparts:
spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot)

I consider the partition layout identifier style as you suggest:

$ egrep --exclude-dir=.git -or 'mtdparts=[^ ]+)' | cut -d: -f2 | sort |
uniq -c | egrep -v '[0-9a-fA-F]{7}' | sort -k1,1 -n

...

      3 mtdparts=nand_mtd
      3 mtdparts=uniphier-nand.0
      4 mtdparts=nand0
      4 mtdparts=spi-flash.0
      5 mtdparts=nor0
      5 mtdparts=spi_flash
      7 mtdparts=boot
      7 mtdparts=omap2-nand.0
      8 mtdparts=nand
     11 mtdparts=nand.0
     12 mtdparts=orion_nand
     13 mtdparts=spi0.0
     16 mtdparts=gpmi-nand
     50 mtdparts=atmel_nand
$ egrep --exclude-dir=.git -or 'mtdparts=[^ ]+)' | cut -d: -f2 | sort |
uniq -c | egrep '[0-9a-fA-F]{7}' | sort -k1,1 -n
      1 mtdparts=10b80000.nand.0
      1 mtdparts=1fc000000.nor_flash
      1 mtdparts=21e0000.qspi
      1 mtdparts=30bb0000.qspi
      1 mtdparts=30bb0000.spi
      1 mtdparts=8000000.nand
      1 mtdparts=fe000000.nor_flash
      1 mtdparts=ffb90000.nand.0
      1 mtdparts=mtdparts=47040000.spi.0
      1 mtdparts=[mtdparts=]edb7312-nor
      1 mtdparts=mtdparts=edb7312-nor
      2 mtdparts=02008000.spi.1
      2 mtdparts=8000000.nor
      4 mtdparts=1550000.spi
      4 mtdparts=1550000.spi-0
      4 mtdparts=47040000.spi.0
      4 mtdparts=ec000000.nor
      4 mtdparts=ef000000.nor
      4 mtdparts=fef000000.nor
     10 mtdparts=ff705000.spi.0
     16 mtdparts=60000000.nor
     16 mtdparts=ff800000.flash
     22 mtdparts=fe8000000.nor

For the initial patch here I instead prefer the minimal and simple style for mtdparts layout template names and to re-use what is popular in U-Boot source tree. The use of hexadecimal bus address for the layout name is difficult for me to read, and not clear to me what is the benefit to doing this manually-entered data address?

=> env print
...
mtddevnum=0
mtdids=nor0=spi0.0 mtdparts=spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot) partition=nor0,0
...

Compared to a style of repeating the bus address:

=> env print
...
mtddevnum=0
mtdids=nor0=d420c000.spi mtdparts=d420c000.spi:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot) partition=nor0,0
...

Quoted 5 lines

Let me know if you do yet prefer the bus address repeated for the name of partition layout. I'd like to see this as part of a runtime-generated mtdparts configuration, so anything is okay with me for the initial manual layout here.

I've done a further check.. so quote from <uboot>/cmd/mtdparts.c

* mtdparts=[mtdparts=]<mtd-def>[;<mtd-def>...] *
* <mtd-def> := <mtd-id>:<part-def>[,<part-def>...]
* <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)

from kernel side, check file drivers/mtd/parsers/cmdlinepart.c which has the same format, on the linux console (if no mtdparts enabled)

# cat /sys/class/mtd/mtd0/name
d420c000.spi

so with bus address it's able to support cmdlinepart, although we currently use ofpart, but IMO, it's correct and in case people need it

Quoted 20 lines
Quoted 16 lines
Quoted 15 lines

CONFIG_DEVICE_TREE_INCLUDES="spacemit-k3-u-boot.dtsi" CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_SPI_FLASH=y

configs/spacemit_k3_defconfig +1 -0
@@ -49,6 +53,7 @@ CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_SPACEMIT_K1=y
 CONFIG_MISC=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_GIGE=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_SPACEMIT=y
Signature · 1 line
2.53.0

Thanks,

-E

Signature · 1 line
Yixun Lan (dlan)
author
#10 lore raw

Re: [PATCH 2/2] configs: spacemit: k3: enable mtdparts on Pico-ITX in main app

Hi Yixun,

Quoted 12 lines · Yixun Lan

Hi E

Quoted 7 lines · E Shattow

Hi Yixun,
...
Let me know if you do yet prefer the bus address repeated for the name of partition layout. I'd like to see this as part of a runtime-generated mtdparts configuration, so anything is okay with me for the initial manual layout here.

I've done a further check.. so quote from <uboot>/cmd/mtdparts.c

Quoted 7 lines

* mtdparts=[mtdparts=]<mtd-def>[;<mtd-def>...] *
* <mtd-def> := <mtd-id>:<part-def>[,<part-def>...]
* <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)

from kernel side, check file drivers/mtd/parsers/cmdlinepart.c which has the same format, on the linux console (if no mtdparts enabled)

Have a look also at comments in Linux function atmel_nand_attach_chip():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/nand/raw/atmel/nand-controller.c#n2008

"We keep the MTD name unchanged to avoid breaking platforms where the MTD cmdline parser is used and the bootloader has not been updated to use the new naming scheme."
"If the new bindings are used and the bootloader has not been updated to pass a new mtdparts parameter on the cmdline, you should define the following property in your nand node:"
label = "atmel_nand";
"This way, mtd->name will be set by the core when nand_set_flash_node() is called."

The examples I can find of CONFIG_BOOTARGS in U-Boot source tree are:

      1 mtdparts=mtdparts=atmel_nand
      1 mtdparts=s3c-onenand
      2 mtdparts=1550000.spi
      2 mtdparts=1550000.spi-0
      6 mtdparts=60000000.nor
     45 mtdparts=atmel_nand
Quoted 6 lines
# cat /sys/class/mtd/mtd0/name
d420c000.spi

so with bus address it's able to support cmdlinepart, although we currently use ofpart, but IMO, it's correct and in case people need it

Yes, although I will be clear to say this is some form of Linux dev_name() and not the bus address, if that is yet a correct thing to say. I'm only sure to confirm what you describe by running a build of mainline Linux kernel with this configuration. For example:

# With StarFive JH-7110 SoC and mtdparts test Linux kernel

$ cat /sys/class/mtd/mtd0/name
13010000.spi.0

# With SpacemiT K3 SoC and mtdparts test Linux kernel

$ cat /sys/class/mtd/mtd0/name
d420c000.spi

If mtdparts=spi0.0... is on the commandline then it is not matched. Else I use instead of spi0.0 the form of dev_name() as alluded to in the mdtparts.c code then I do see the partitions appear in /proc/mtd

I would like to make a more exact description of where in mainline Linux code that causes "d420c000.spi" (is this exactly the dev_name? and from what code?) but it is at least enough for me now to confirm the effect it has in testing and how to get this outcome without guessing.

Thanks again, and I'll send the requested changes shortly,

-E