SPL NVme support
v2 cover SPL NVme support
This patchset adds support to load images of the SPL's next booting stage from a NVMe device.
Changes in v2:
- Rebase on v2023.07-rc1
- Use uclass ID for blk APIs
- Add support to load FIT images from ext filesystem
Mayuresh Chitale (4):
spl: Add Kconfig options for NVME
nvme: pci: Enable for SPL
spl: Support loading a FIT from ext FS
common: spl: Add spl NVMe boot support
arch/riscv/include/asm/spl.h | 1 + common/spl/Kconfig | 30 +++++++++++++++++++++ common/spl/Makefile | 1 + common/spl/spl_ext.c | 33 +++++++++++++++++++++++ common/spl/spl_nvme.c | 52 ++++++++++++++++++++++++++++++++++++ drivers/Makefile | 1 + drivers/nvme/Makefile | 2 +- drivers/pci/Kconfig | 7 +++++ drivers/pci/pci-uclass.c | 3 ++- 9 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 common/spl/spl_nvme.c
Signature · 1 line
2.34.1
PATCH v2 1/4 spl: Add Kconfig options for NVME
Add kconfig options to enable NVME and PCI NVMe support in SPL
--- common/spl/Kconfig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
common/spl/Kconfig +20 -0
@@ -1263,6 +1263,26 @@ config SPL_SATA_RAW_U_BOOT_SECTOR Sector on the SATA disk to load U-Boot from, when the SATA disk is being used in raw mode. Units: SATA disk sectors (1 sector = 512 bytes). +config SPL_NVME + bool "NVM Express device support" + depends on BLK + select HAVE_BLOCK_DEVICE + help + This option enables support for NVM Express devices. + It supports basic functions of NVMe (read/write). + +config SPL_NVME_PCI + bool "NVM Express PCI device support for SPL" + depends on SPL_PCI && SPL_NVME + help + This option enables support for NVM Express PCI devices. + This allows use of NVMe devices for loading u-boot. + +config SPL_NVME_BOOT_DEVICE + hex "NVMe boot device number" + depends on SPL_NVME + default 0x0 + config SPL_SERIAL bool "Support serial" select SPL_PRINTF
Signature · 1 line
2.34.1
PATCH v2 2/4 nvme: pci: Enable for SPL
In reply to Mayuresh ChitaleEnable NVME and PCI NVMe drivers for SPL builds. Also enable PCI_PNP for SPL which is required to auto configure the PCIe devices.
--- drivers/Makefile | 1 + drivers/nvme/Makefile | 2 +- drivers/pci/Kconfig | 7 +++++++ drivers/pci/pci-uclass.c | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-)
drivers/Makefile +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/ obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/ obj-$(CONFIG_$(SPL_)SYSINFO) += sysinfo/ obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm/ +obj-$(CONFIG_$(SPL_)NVME) += nvme/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_$(SPL_)FPGA) += fpga/ obj-y += bus/
drivers/nvme/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y += nvme-uclass.o nvme.o nvme_show.o obj-$(CONFIG_NVME_APPLE) += nvme_apple.o -obj-$(CONFIG_NVME_PCI) += nvme_pci.o +obj-$(CONFIG_$(SPL_)NVME_PCI) += nvme_pci.o
drivers/pci/Kconfig +7 -0
@@ -40,6 +40,13 @@ config PCI_PNP help Enable PCI memory and I/O space resource allocation and assignment. +config SPL_PCI_PNP + bool "Enable Plug & Play support for PCI" + default n + help + Enable PCI memory and I/O space resource allocation and assignment. + This is required to auto configure the enumerated devices. + config PCI_REGION_MULTI_ENTRY bool "Enable Multiple entries of region type MEMORY in ranges for PCI" help
drivers/pci/pci-uclass.c +2 -1
@@ -1140,7 +1140,8 @@ static int pci_uclass_post_probe(struct udevice *bus)if (ret)return log_msg_ret ("bind" , ret); -if (CONFIG_IS_ENABLED (PCI_PNP ) &&ll_boot_init () && +if ((CONFIG_IS_ENABLED (PCI_PNP ) ||CONFIG_IS_ENABLED (SPL_PCI_PNP )) && +ll_boot_init () && (!hose->skip_auto_config_until_reloc || (gd->flags &GD_FLG_RELOC ))) { ret =pci_auto_config_devices (bus);
Signature · 1 line
2.34.1
Re: [PATCH v2 2/4] nvme: pci: Enable for SPL
Hi Mayuresh,
Quoted 57 lines · Mayuresh Chitale
Enable NVME and PCI NVMe drivers for SPL builds. Also enable
PCI_PNPfor SPL which is required to auto configure the PCIe devices.Signed-off-by Mayuresh Chitale <[email protected]>--- drivers/Makefile | 1 + drivers/nvme/Makefile | 2 +- drivers/pci/Kconfig | 7 +++++++ drivers/pci/pci-uclass.c | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-)drivers/Makefile +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/ obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/ obj-$(CONFIG_$(SPL_)SYSINFO) += sysinfo/ obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm/ +obj-$(CONFIG_$(SPL_)NVME) += nvme/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_$(SPL_)FPGA) += fpga/ obj-y += bus/drivers/nvme/Makefile +1
-1@@ -4,4 +4,4 @@ obj-y += nvme-uclass.o nvme.o nvme_show.o obj-$(CONFIG_NVME_APPLE) += nvme_apple.o -obj-$(CONFIG_NVME_PCI) += nvme_pci.o +obj-$(CONFIG_$(SPL_)NVME_PCI) += nvme_pci.odrivers/pci/Kconfig +7
-0@@ -40,6 +40,13 @@ config PCI_PNP help Enable PCI memory and I/O space resource allocation and assignment. +config SPL_PCI_PNP + bool "Enable Plug & Play support for PCI" + default n + help + Enable PCI memory and I/O space resource allocation and assignment. + This is required to auto configure the enumerated devices. + config PCI_REGION_MULTI_ENTRY bool "Enable Multiple entries of region type MEMORY in ranges for PCI" helpdrivers/pci/pci-uclass.c +0
-0
drivers/pci/pci-uclass.c static int pci_uclass_post_probe(struct udevice *bus) · line 1143
Quoted 5 lines
drivers/pci/pci-uclass.c +1
-1@@ -1140,7 +1140,8 @@ static int pci_uclass_post_probe(struct udevice *bus)if (ret)return log_msg_ret ("bind" , ret); - if (CONFIG_IS_ENABLED(PCI_PNP) && ll_boot_init() && + if ((CONFIG_IS_ENABLED(PCI_PNP) || CONFIG_IS_ENABLED(SPL_PCI_PNP)) &&
The CONFIG_IS_ENABLED() macro checks SPL_PCI_PNP when used in an SPL build, so you should not need this change.
Quoted 7 lines
drivers/pci/pci-uclass.c +1
-1+ ll_boot_init() && (!hose->skip_auto_config_until_reloc || (gd->flags & GD_FLG_RELOC))) { ret =pci_auto_config_devices (bus); --2.34.1
Regards,
Simon
Re: [PATCH v2 2/4] nvme: pci: Enable for SPL
Hi Simon,
Quoted 64 lines · Simon Glass
Hi Mayuresh,
Quoted 60 lines · Mayuresh Chitale
Enable NVME and PCI NVMe drivers for SPL builds. Also enable
PCI_PNPfor SPL which is required to auto configure the PCIe devices.Signed-off-by Mayuresh Chitale <[email protected]>--- drivers/Makefile | 1 + drivers/nvme/Makefile | 2 +- drivers/pci/Kconfig | 7 +++++++ drivers/pci/pci-uclass.c | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-)drivers/Makefile +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/ obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/ obj-$(CONFIG_$(SPL_)SYSINFO) += sysinfo/ obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm/ +obj-$(CONFIG_$(SPL_)NVME) += nvme/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_$(SPL_)FPGA) += fpga/ obj-y += bus/drivers/nvme/Makefile +1
-1@@ -4,4 +4,4 @@ obj-y += nvme-uclass.o nvme.o nvme_show.o obj-$(CONFIG_NVME_APPLE) += nvme_apple.o -obj-$(CONFIG_NVME_PCI) += nvme_pci.o +obj-$(CONFIG_$(SPL_)NVME_PCI) += nvme_pci.odrivers/pci/Kconfig +7
-0@@ -40,6 +40,13 @@ config PCI_PNP help Enable PCI memory and I/O space resource allocation and assignment. +config SPL_PCI_PNP + bool "Enable Plug & Play support for PCI" + default n + help + Enable PCI memory and I/O space resource allocation and assignment. + This is required to auto configure the enumerated devices. + config PCI_REGION_MULTI_ENTRY bool "Enable Multiple entries of region type MEMORY in ranges for PCI" helpdrivers/pci/pci-uclass.c +0
-0@@ -1140,7 +1140,8 @@ static int pci_uclass_post_probe(struct udevice *bus)if (ret)return log_msg_ret ("bind" , ret);
Quoted 5 lines
drivers/pci/pci-uclass.c static int pci_uclass_post_probe(struct udevice *bus) · line 1143
Quoted 2 lines
drivers/pci/pci-uclass.c +1
-1- if (CONFIG_IS_ENABLED(PCI_PNP) && ll_boot_init() && + if ((CONFIG_IS_ENABLED(PCI_PNP) || CONFIG_IS_ENABLED(SPL_PCI_PNP)) &&The
CONFIG_IS_ENABLED()macro checksSPL_PCI_PNPwhen used in an SPL build, so you should not need this change.
Ok. Will remove it in the next version.
Quoted 11 lines
Quoted 8 lines
drivers/pci/pci-uclass.c +1
-1+ ll_boot_init() && (!hose->skip_auto_config_until_reloc || (gd->flags & GD_FLG_RELOC))) { ret =pci_auto_config_devices (bus); --2.34.1
Regards,
Simon
Thanks,
Mayuresh.
PATCH v2 3/4 spl: Support loading a FIT from ext FS
In reply to Mayuresh ChitaleDetect a FIT when loading from an ext File system and handle it using the FIT SPL support.
--- common/spl/spl_ext.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
common/spl/spl_ext.c +33 -0
@@ -8,6 +8,26 @@#include <ext4fs.h> #include <errno.h> #include <image.h> +#include <linux/libfdt.h> + +static ulong spl_fit_read (struct spl_load_info *load,ulong file_offset, +ulong size,void *buf) +{ +loff_t filelen = (loff_t )load->priv, actlen; +char *filename = (char *)load->filename; +int ret; + + ret =ext4fs_read (buf, file_offset, filelen, &actlen); +if (ret <0 ) { +if (IS_ENABLED (CONFIG_SPL_LIBCOMMON_SUPPORT )) { +printf ("%s: error reading image %s, err - %d\n" , + __func__, filename, ret); + } +return ret; + } + +return actlen; +} int spl_load_image_ext(struct spl_image_info *spl_image, struct spl_boot_device *bootdev,
@@ -47,6 +67,19 @@ int spl_load_image_ext(struct spl_image_info *spl_image, goto end; } +if (IS_ENABLED (CONFIG_SPL_LOAD_FIT ) && +image_get_magic (header) ==FDT_MAGIC ) { +struct spl_load_info load; + +debug ("Found FIT\n" ); + load.read = spl_fit_read; + load.bl_len =1 ; + load.filename = (void *)filename; + load.priv = (void *)filelen; + +return spl_load_simple_fit (spl_image, &load,0 , header); + } + err =spl_parse_image_header (spl_image, bootdev, header);if (err <0 ) {puts ("spl: ext: failed to parse image header\n" );
Signature · 1 line
2.34.1
PATCH v2 4/4 common: spl: Add spl NVMe boot support
In reply to Mayuresh ChitaleAdd support to load the next stage image from an NVMe disk which may be formatted as an EXT or FAT filesystem.
--- arch/riscv/include/asm/spl.h | 1 + common/spl/Kconfig | 10 +++++++ common/spl/Makefile | 1 + common/spl/spl_nvme.c | 52 ++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 common/spl/spl_nvme.c
arch/riscv/include/asm/spl.h +1 -0
@@ -20,6 +20,7 @@ enum {BOOT_DEVICE_SPI ,BOOT_DEVICE_USB ,BOOT_DEVICE_SATA , +BOOT_DEVICE_NVME ,BOOT_DEVICE_I2C ,BOOT_DEVICE_BOARD , BOOT_DEVICE_DFU,
common/spl/Kconfig +10 -0
@@ -1283,6 +1283,16 @@ config SPL_NVME_BOOT_DEVICE depends on SPL_NVME default 0x0 +config SYS_NVME_EXT_BOOT_PARTITION + hex "NVMe ext boot partition number" + depends on SPL_NVME + default 0x2 + +config SYS_NVME_FAT_BOOT_PARTITION + hex "NVMe boot partition number" + depends on SPL_NVME + default 0x1 + config SPL_SERIAL bool "Support serial" select SPL_PRINTF
common/spl/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o +obj-$(CONFIG_$(SPL_TPL_)NVME) += spl_nvme.o obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.o
common/spl/spl_nvme.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 4/4] common: spl: Add spl NVMe boot support
Hi Mayuresh,
Quoted 117 lines · Mayuresh Chitale
Add support to load the next stage image from an NVMe disk which may be formatted as an EXT or FAT filesystem.
Signed-off-by Mayuresh Chitale <[email protected]>--- arch/riscv/include/asm/spl.h | 1 + common/spl/Kconfig | 10 +++++++ common/spl/Makefile | 1 + common/spl/spl_nvme.c | 52 ++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 common/spl/spl_nvme.carch/riscv/include/asm/spl.h +1
-0@@ -20,6 +20,7 @@ enum {BOOT_DEVICE_SPI ,BOOT_DEVICE_USB ,BOOT_DEVICE_SATA , +BOOT_DEVICE_NVME ,BOOT_DEVICE_I2C ,BOOT_DEVICE_BOARD , BOOT_DEVICE_DFU,common/spl/Kconfig +10
-0@@ -1283,6 +1283,16 @@ config SPL_NVME_BOOT_DEVICE depends on SPL_NVME default 0x0 +config SYS_NVME_EXT_BOOT_PARTITION + hex "NVMe ext boot partition number" + depends on SPL_NVME + default 0x2 + +config SYS_NVME_FAT_BOOT_PARTITION + hex "NVMe boot partition number" + depends on SPL_NVME + default 0x1 + config SPL_SERIAL bool "Support serial" select SPL_PRINTFcommon/spl/Makefile +1
-0@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o +obj-$(CONFIG_$(SPL_TPL_)NVME) += spl_nvme.o obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.ocommon/spl/spl_nvme.c new file +52
-1@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2023 +* Ventana Micro Systems Inc. +* +* Derived work from spl_sata.c +*/ + +#include <common.h> +#include <spl.h> +#include <errno.h> +#include <fat.h> +#include <init.h> +#include <nvme.h> + +static int spl_nvme_load_image (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev) +{ +int ret; +struct blk_desc *blk_desc; + + ret =pci_init (); +if (ret <0 ) + goto out; + + ret =nvme_scan_namespace (); +if (ret <0 ) + goto out; + +blk_show_device (UCLASS_NVME ,CONFIG_SPL_NVME_BOOT_DEVICE ); + blk_desc =blk_get_devnum_by_uclass_id (UCLASS_NVME , +CONFIG_SPL_NVME_BOOT_DEVICE ); +if (IS_ENABLED (CONFIG_SPL_FS_EXT4 )) { + ret =spl_load_image_ext (spl_image, bootdev, blk_desc, +CONFIG_SYS_NVME_EXT_BOOT_PARTITION , +CONFIG_SPL_PAYLOAD ); +if (!ret) +return ret; + } + +if (IS_ENABLED (CONFIG_SPL_FS_FAT )) + ret =spl_load_image_fat (spl_image, bootdev, blk_desc, +CONFIG_SYS_NVME_FAT_BOOT_PARTITION , +CONFIG_SPL_PAYLOAD ); +else + ret = -ENOSYS ; + +out: +return ret; +} + +SPL_LOAD_IMAGE_METHOD ("NVME" ,0 ,BOOT_DEVICE_NVME , spl_nvme_load_image); --
Quoted 2 lines
2.34.1
All of this code looks generic except:
UCLASS_NVMECONFIG_SPL_NVME_BOOT_DEVICECONFIG_SYS_NVME_EXT_BOOT_PARTITION
so please move the code inside your new function into a generic file like spl_blk_fs.c or similar and pass these parameters to it. Then we can use the same function for other device types.
Regards,
SImon
Re: [PATCH v2 4/4] common: spl: Add spl NVMe boot support
Hi Simon,
Quoted 126 lines · Simon Glass
Hi Mayuresh,
Quoted 117 lines · Mayuresh Chitale
Add support to load the next stage image from an NVMe disk which may be formatted as an EXT or FAT filesystem.
Signed-off-by Mayuresh Chitale <[email protected]>--- arch/riscv/include/asm/spl.h | 1 + common/spl/Kconfig | 10 +++++++ common/spl/Makefile | 1 + common/spl/spl_nvme.c | 52 ++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 common/spl/spl_nvme.carch/riscv/include/asm/spl.h +1
-0@@ -20,6 +20,7 @@ enum {BOOT_DEVICE_SPI ,BOOT_DEVICE_USB ,BOOT_DEVICE_SATA , +BOOT_DEVICE_NVME ,BOOT_DEVICE_I2C ,BOOT_DEVICE_BOARD , BOOT_DEVICE_DFU,common/spl/Kconfig +10
-0@@ -1283,6 +1283,16 @@ config SPL_NVME_BOOT_DEVICE depends on SPL_NVME default 0x0 +config SYS_NVME_EXT_BOOT_PARTITION + hex "NVMe ext boot partition number" + depends on SPL_NVME + default 0x2 + +config SYS_NVME_FAT_BOOT_PARTITION + hex "NVMe boot partition number" + depends on SPL_NVME + default 0x1 + config SPL_SERIAL bool "Support serial" select SPL_PRINTFcommon/spl/Makefile +1
-0@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o +obj-$(CONFIG_$(SPL_TPL_)NVME) += spl_nvme.o obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.ocommon/spl/spl_nvme.c new file +52
-1@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2023 +* Ventana Micro Systems Inc. +* +* Derived work from spl_sata.c +*/ + +#include <common.h> +#include <spl.h> +#include <errno.h> +#include <fat.h> +#include <init.h> +#include <nvme.h> + +static int spl_nvme_load_image (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev) +{ +int ret; +struct blk_desc *blk_desc; + + ret =pci_init (); +if (ret <0 ) + goto out; + + ret =nvme_scan_namespace (); +if (ret <0 ) + goto out; + +blk_show_device (UCLASS_NVME ,CONFIG_SPL_NVME_BOOT_DEVICE ); + blk_desc =blk_get_devnum_by_uclass_id (UCLASS_NVME , +CONFIG_SPL_NVME_BOOT_DEVICE ); +if (IS_ENABLED (CONFIG_SPL_FS_EXT4 )) { + ret =spl_load_image_ext (spl_image, bootdev, blk_desc, +CONFIG_SYS_NVME_EXT_BOOT_PARTITION , +CONFIG_SPL_PAYLOAD ); +if (!ret) +return ret; + } + +if (IS_ENABLED (CONFIG_SPL_FS_FAT )) + ret =spl_load_image_fat (spl_image, bootdev, blk_desc, +CONFIG_SYS_NVME_FAT_BOOT_PARTITION , +CONFIG_SPL_PAYLOAD ); +else + ret = -ENOSYS ; + +out: +return ret; +} + +SPL_LOAD_IMAGE_METHOD ("NVME" ,0 ,BOOT_DEVICE_NVME , spl_nvme_load_image); --Quoted 2 lines
2.34.1
All of this code looks generic except:
Quoted 7 lines
UCLASS_NVMECONFIG_SPL_NVME_BOOT_DEVICECONFIG_SYS_NVME_EXT_BOOT_PARTITION
so please move the code inside your new function into a generic file likespl_blk_fs.cor similar and pass these parameters to it. Then we can use the same function for other device types.
Ok. WIll do it in the next version.
Quoted 2 lines
Regards,
SImon
Thanks,
Mayuresh.