Enable SPI NOR flash for SpacemiT K3 in main app
v3 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. Selected for Winbond and GigaDevice parts.
Changes since v2:
- use Linux v7.3 fsl_qspi_get_name() typical result for mtdparts layout name; this is done for compatibility in the non-default configuration of matching cmdline mtdparts mtd-id when Linux MTD_OF_PARTS is disabled
E Shattow (2):
configs: spacemit: k3: enable spi nor flash in main app
configs: spacemit: k3: enable mtdparts in main app
configs/spacemit_k3_defconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+)
base-commit: 903c9578eeb36d72f087082da494c605ddaed3b2
Signature · 1 line
2.53.0
PATCH v3 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.
--- configs/spacemit_k3_defconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
configs/spacemit_k3_defconfig +8 -0
@@ -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,8 @@ CONFIG_SPACEMIT_GPIO=y CONFIG_DM_I2C=y CONFIG_SYS_I2C_SPACEMIT_K1=y CONFIG_MISC=y +CONFIG_SPI_FLASH_GIGADEVICE=y +CONFIG_SPI_FLASH_WINBOND=y CONFIG_PHY_GIGE=y CONFIG_DWC_ETH_QOS=y CONFIG_DWC_ETH_QOS_SPACEMIT=y
@@ -61,4 +67,6 @@ CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_SYS_NS16550=y CONFIG_SYS_NS16550_MEM32=y +CONFIG_SPI=y +CONFIG_FSL_QSPI=y CONFIG_TIMER_EARLY=y
Signature · 1 line
2.53.0
PATCH v3 2/2 configs: spacemit: k3: enable mtdparts in main app
In reply to E Shattowadd default mtdids and mtdparts consistent with Linux v7.3 FSL QSPI "new" driver .get_name() handler fsl_qspi_get_name() and k3-pico-itx.dts
---
Write-up about testing methodology and the decision of what how MTDIDS_DEFAULT is written for compatibility, follows.
With Debian 13 Trixie Linux as a baseline distro and build Linux v7.3:
tar Jxf /usr/src/linux-source-7.3.tar.xz && cd linux-source-7.3
xzcat /usr/src/linux-config-7.2/config.riscv64_none_riscv64.xz > .configscripts/config --enable DEBUG_INFO_NONE --undefine CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULTscripts/config --set-val CMDLINE_PARTITION y --set-val MTD y --set-val MTD_BLOCK y --set-val MTD_CMDLINE_PARTS y --set-val MTD_OF_PARTS n make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- olddefconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- KDEB_CHANGELOG_DIST=unreleased -j$(nproc) bindeb-pkg LOCALVERSION=-mtdparts
# K3 append linux cmdline: mtdparts=
Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
Removing MTD device #0 (nor0) with use count 1
[ 9.946726] mtd: no mtd-id $ cat /sys/class/mtd/mtd0/name /proc/mtd d420c000.spi dev: size erasesize name mtd0: 00800000 00001000 "d420c000.spi"
# K3 append linux cmdline: mtdparts=spi0.0:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot) Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
Removing MTD device #0 (nor0) with use count 1
$ cat /sys/class/mtd/mtd0/name /proc/mtd d420c000.spi dev: size erasesize name mtd0: 00800000 00001000 "d420c000.spi"
# K3 append linux cmdline: mtdparts=d420c000.spi:128k(bootinfo),512k(fsbl),64k(env),1024k(esos),384k(opensbi),-(uboot) Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
Removing MTD device #0 (nor0) with use count 1
$ cat /sys/class/mtd/mtd0/name /proc/mtd bootinfo dev: size erasesize name mtd0: 00020000 00001000 "bootinfo" mtd1: 00080000 00001000 "fsbl" mtd2: 00010000 00001000 "env" mtd3: 00100000 00001000 "esos" mtd4: 00060000 00001000 "opensbi" mtd5: 005f0000 00001000 "uboot"
# JH-7110 append linux cmdline: mtdparts=
Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
[ 16.626705] mtd: no mtd-id $ cat /sys/class/mtd/mtd0/name /proc/mtd 13010000.spi.0 dev: size erasesize name mtd0: 01000000 00001000 "13010000.spi.0"
# JH-7110 append linux cmdline: mtdparts=spi0.0:960k(spl),64k(uboot-env),-(uboot) Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
$ cat /sys/class/mtd/mtd0/name /proc/mtd 13010000.spi.0 dev: size erasesize name mtd0: 01000000 00001000 "13010000.spi.0"
# JH-7110 append linux cmdline: mtdparts=13010000.spi:960k(spl),64k(uboot-env),-(uboot) Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
$ cat /sys/class/mtd/mtd0/name /proc/mtd 13010000.spi.0 dev: size erasesize name mtd0: 01000000 00001000 "13010000.spi.0"
# JH-7110 append linux cmdline: mtdparts=13010000.spi.0:960k(spl),64k(uboot-env),-(uboot) Loading Linux 7.3.0-rc7-mtdparts ...
Loading initial ramdisk ...
$ cat /sys/class/mtd/mtd0/name /proc/mtd spl dev: size erasesize name mtd0: 000f0000 00001000 "spl" mtd1: 00010000 00001000 "uboot-env" mtd2: 00f00000 00001000 "uboot"
# K3
$ ls -d /sys/bus/platform/drivers/*/*/spi_master /sys/bus/platform/drivers/fsl-quadspi/d420c000.spi/spi_master
# JH-7110
$ ls -d /sys/bus/platform/drivers/*/*/spi_master /sys/bus/platform/drivers/cadence-qspi/13010000.spi/spi_master
static const char *fsl_qspi_get_name(struct spi_mem *mem)
{
struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->controller);
struct device *dev = &mem->spi->dev;
const char *name;
/*
* In order to keep mtdparts compatible with the old MTD driver at
* mtd/spi-nor/fsl-quadspi.c, we set a custom name derived from the
* platform_device of the controller.
*/
if (of_get_available_child_count(q->dev->of_node) == 1)
return dev_name(q->dev);
name = devm_kasprintf(dev, GFP_KERNEL,
"%s-%d", dev_name(q->dev),
spi_get_chipselect(mem->spi, 0));
if (!name) {
dev_err(dev, "failed to get memory for custom flash name\n");
return ERR_PTR(-ENOMEM);
}
return name;
}static const char *cqspi_get_name(struct spi_mem *mem)
{
struct cqspi_st *cqspi = spi_controller_get_devdata(mem->spi->controller);
struct device *dev = &cqspi->pdev->dev;
return devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev),
spi_get_chipselect(mem->spi, 0));
}In summary of the above, for compatibility with certain non-default use of 'mtdparts=' on kernel commandline we look to what each Linux driver returns for its assigned .dev_name() handler, as the mtd-id name.
-E
--- configs/spacemit_k3_defconfig | 5 +++++ 1 file changed, 5 insertions(+)
configs/spacemit_k3_defconfig +5 -0
@@ -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=d420c000.spi" +CONFIG_MTDPARTS_DEFAULT="d420c000.spi: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
@@ -50,6 +54,7 @@ CONFIG_SYS_I2C_SPACEMIT_K1=y CONFIG_MISC=y CONFIG_SPI_FLASH_GIGADEVICE=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
Hi E Shattow,
Quoted 12 lines · E Shattow
Enable SPI Flash command, mtd part names and locations, and store U-Boot environment in SPI NOR flash. Selected for Winbond and GigaDevice parts.
Changes since v2:
- use Linux v7.3fsl_qspi_get_name()typical result for mtdparts layout name; this is done for compatibility in the non-default configuration of matching cmdline mtdparts mtd-id when LinuxMTD_OF_PARTSis disabledE Shattow (2):
configs: spacemit: k3: enable spi nor flash in main app
configs: spacemit: k3: enable mtdparts in main app
Quoted 8 lines
configs/spacemit_k3_defconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+)base-commit:
903c9578eeb36d72f087082da494c605ddaed3b2Signature · 1 line
2.53.0
Thanks for the new version
Signature · 1 line
Yixun Lan (dlan)
Quoted 9 lines · E Shattow
Enable SPI Flash command, mtd part names and locations, and store U-Boot environment in SPI NOR flash. Selected for Winbond and GigaDevice parts.
Changes since v2:
- use Linux v7.3fsl_qspi_get_name()typical result for mtdparts layout name; this is done for compatibility in the non-default configuration of matching cmdline mtdparts mtd-id when LinuxMTD_OF_PARTSis disabled[...]
Applied, thanks!
[1/2] configs: spacemit: k3: enable spi nor flash in main app
https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/f2b91ab4a84f0e6262f5f925b513344e1c236e1d [2/2] configs: spacemit: k3: enable mtdparts in main app https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/9cefa267d999750e8415da1df5da9c9e22b47871
Best regards,
Signature · 1 line
Yixun Lan <[email protected]>