Skip to contentSkip to conversation

SPL NVMe support

PATCH Superseded Mayuresh Chitale 4 participants 17 messages May 4, 2023 – Jun 3, 2023

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover SPL NVMe support

This patchset adds support to load images of the SPL's next booting stage from a NVMe device.

Changes in v3:
- Add generic API to fetch payload from Ext or FAT filesystems
- Remove reduntant SPL_PCI_PNP config check

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 (5):
spl: Add Kconfig options for NVME
spl: blk: Support loading images from fs
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           | 31 +++++++++++++++++++++
 common/spl/Makefile          |  2 ++
 common/spl/spl_blk_fs.c      | 54 ++++++++++++++++++++++++++++++++++++
 common/spl/spl_ext.c         | 33 ++++++++++++++++++++++
 common/spl/spl_nvme.c        | 34 +++++++++++++++++++++++
 drivers/Makefile             |  1 +
 drivers/block/Kconfig        |  7 +++++
 drivers/nvme/Makefile        |  2 +-
 drivers/pci/Kconfig          |  7 +++++
 include/spl.h                |  3 ++
 11 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 common/spl/spl_blk_fs.c
 create mode 100644 common/spl/spl_nvme.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/5 spl: Add Kconfig options for NVME

Add kconfig options to enable NVME and PCI NVMe support in SPL

---
 common/spl/Kconfig | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
common/spl/Kconfig +21 -0
index 2c042ad306..515e8f2c66 100644
@@ -1263,6 +1263,27 @@ 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
+	select SPL_BLK_FS
+	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
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] spl: Add Kconfig options for NVME

Quoted 13 lines · Mayuresh Chitale

Add kconfig options to enable NVME and PCI NVMe support in SPL

---
 common/spl/Kconfig | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
common/spl/Kconfig +0 -0
index 2c042ad306..515e8f2c66 100644

common/spl/Kconfig config SPL_SATA_RAW_U_BOOT_SECTOR · line 1265

Quoted 3 lines
common/spl/Kconfig +0 -0
@@ -1263,6 +1263,27 @@ 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).
 
Quoted 27 lines
common/spl/Kconfig +21 -1
+config SPL_NVME
+       bool "NVM Express device support"
+       depends on BLK
+       select HAVE_BLOCK_DEVICE
+       select SPL_BLK_FS
+       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
--

2.34.1

#3 lore raw

PATCH v3 2/5 spl: blk: Support loading images from fs

In reply to Mayuresh Chitale

Add a generic API to support loading of SPL payload from EXT or FAT filesystem on a given partition of a block device.

---
 common/spl/Makefile     |  1 +
 common/spl/spl_blk_fs.c | 54 +++++++++++++++++++++++++++++++++++++++++
 drivers/block/Kconfig   |  7 ++++++
 include/spl.h           |  3 +++
 4 files changed, 65 insertions(+)
 create mode 100644 common/spl/spl_blk_fs.c
common/spl/Makefile +1 -0
index 13db3df993..5210ad0248 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTROM_SUPPORT) += spl_bootrom.o
 obj-$(CONFIG_$(SPL_TPL_)LOAD_FIT) += spl_fit.o
+obj-$(CONFIG_$(SPL_TPL_)BLK_FS) += spl_blk_fs.o
 obj-$(CONFIG_$(SPL_TPL_)LEGACY_IMAGE_FORMAT) += spl_legacy.o
 obj-$(CONFIG_$(SPL_TPL_)NOR_SUPPORT) += spl_nor.o
 obj-$(CONFIG_$(SPL_TPL_)XIP_SUPPORT) += spl_xip.o
common/spl/spl_blk_fs.c new file +54 -0

54 lines not on this page · raw message

drivers/block/Kconfig +7 -0
index 5a1aeb3d2b..6baaa6f071 100644
@@ -107,6 +107,13 @@ config EFI_MEDIA
 
 	  For sandbox there is a test driver.
 
+config SPL_BLK_FS
+	bool "Load images from filesystems on block devices"
+	depends on SPL_BLK
+	help
+	  Use generic support to load images from fat/ext filesystems on
+	  different types of block devices such as NVMe.
+
 if EFI_MEDIA
 
 config EFI_MEDIA_SANDBOX
include/spl.h +3 -0
index 7e0f5ac63b..4546648394 100644
@@ -672,6 +672,9 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 int spl_load_image_ext_os(struct spl_image_info *spl_image,
 			  struct spl_boot_device *bootdev,
 			  struct blk_desc *block_dev, int partition);
+int spl_blk_load_image(struct spl_image_info *spl_image,
+		       struct spl_boot_device *bootdev,
+		       enum uclass_id uclass_id, int devnum);
 
 /**
  * spl_early_init() - Set up device tree and driver model in SPL if enabled
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v3 2/5] spl: blk: Support loading images from fs

Hi Mayuresh,

Quoted 46 lines · Mayuresh Chitale

Add a generic API to support loading of SPL payload from EXT or FAT filesystem on a given partition of a block device.

---
 common/spl/Makefile     |  1 +
 common/spl/spl_blk_fs.c | 54 +++++++++++++++++++++++++++++++++++++++++
 drivers/block/Kconfig   |  7 ++++++
 include/spl.h           |  3 +++
 4 files changed, 65 insertions(+)
 create mode 100644 common/spl/spl_blk_fs.c
common/spl/Makefile +1 -0
index 13db3df993..5210ad0248 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTROM_SUPPORT) += spl_bootrom.o
 obj-$(CONFIG_$(SPL_TPL_)LOAD_FIT) += spl_fit.o
+obj-$(CONFIG_$(SPL_TPL_)BLK_FS) += spl_blk_fs.o
 obj-$(CONFIG_$(SPL_TPL_)LEGACY_IMAGE_FORMAT) += spl_legacy.o
 obj-$(CONFIG_$(SPL_TPL_)NOR_SUPPORT) += spl_nor.o
 obj-$(CONFIG_$(SPL_TPL_)XIP_SUPPORT) += spl_xip.o
common/spl/spl_blk_fs.c new file +15 -0
new file mode 100644
index 0000000000..fb2e8bbea7
@@ -0,0 +1,54 @@
+// 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>
+
+int spl_blk_load_image(struct spl_image_info *spl_image,
+                      struct spl_boot_device *bootdev,
+                      enum uclass_id uclass_id, int devnum)
+{

common/spl/spl_blk_fs.c line 25

Quoted 10 lines
common/spl/spl_blk_fs.c new file +10 -0
+       int ret = -ENOSYS, part;
+       struct blk_desc *blk_desc;
+
+       blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
+       if (!blk_desc)
+               return ret;
+
+       blk_show_device(uclass_id, devnum);
+
+       if (IS_ENABLED(CONFIG_SPL_FS_EXT4)) {

Can you use the fs.h layer so it can work with any FS?

Quoted 62 lines
common/spl/spl_blk_fs.c new file +29 -0
+               switch (uclass_id) {
+               case UCLASS_NVME:
+                       part = CONFIG_SYS_NVME_EXT_BOOT_PARTITION;
+                       break;
+               default:
+                       return ret;
+               }
+               ret = spl_load_image_ext(spl_image, bootdev, blk_desc, part,
+                                        CONFIG_SPL_PAYLOAD);
+               if (!ret)
+                       return ret;
+       }
+
+       if (IS_ENABLED(CONFIG_SPL_FS_FAT)) {
+               switch (uclass_id) {
+               case UCLASS_NVME:
+                       part = CONFIG_SYS_NVME_FAT_BOOT_PARTITION;
+                       break;
+               default:
+                       return ret;
+               }
+               ret = spl_load_image_fat(spl_image, bootdev, blk_desc, part,
+                                        CONFIG_SPL_PAYLOAD);
+               if (!ret)
+                       return ret;
+       }
+
+       return ret;
+}
drivers/block/Kconfig +7 -0
index 5a1aeb3d2b..6baaa6f071 100644
@@ -107,6 +107,13 @@ config EFI_MEDIA
 
          For sandbox there is a test driver.
 
+config SPL_BLK_FS
+       bool "Load images from filesystems on block devices"
+       depends on SPL_BLK
+       help
+         Use generic support to load images from fat/ext filesystems on
+         different types of block devices such as NVMe.
+
 if EFI_MEDIA
 
 config EFI_MEDIA_SANDBOX
include/spl.h +3 -1
index 7e0f5ac63b..4546648394 100644
@@ -672,6 +672,9 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 int spl_load_image_ext_os(struct spl_image_info *spl_image,
                          struct spl_boot_device *bootdev,
                          struct blk_desc *block_dev, int partition);
+int spl_blk_load_image(struct spl_image_info *spl_image,
+                      struct spl_boot_device *bootdev,
+                      enum uclass_id uclass_id, int devnum);
 
 /**
  * spl_early_init() - Set up device tree and driver model in SPL if enabled
--
Quoted 2 lines

2.34.1

Regards,
Simon

#5 lore raw

Re: [PATCH v3 2/5] spl: blk: Support loading images from fs

Hi Simon,

Quoted 54 lines · Simon Glass

Hi Mayuresh,

Quoted 50 lines · Mayuresh Chitale

Add a generic API to support loading of SPL payload from EXT or FAT filesystem on a given partition of a block device.

---
 common/spl/Makefile     |  1 +
 common/spl/spl_blk_fs.c | 54 +++++++++++++++++++++++++++++++++++++++++
 drivers/block/Kconfig   |  7 ++++++
 include/spl.h           |  3 +++
 4 files changed, 65 insertions(+)
 create mode 100644 common/spl/spl_blk_fs.c
common/spl/Makefile +1 -0
index 13db3df993..5210ad0248 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTROM_SUPPORT) += spl_bootrom.o
 obj-$(CONFIG_$(SPL_TPL_)LOAD_FIT) += spl_fit.o
+obj-$(CONFIG_$(SPL_TPL_)BLK_FS) += spl_blk_fs.o
 obj-$(CONFIG_$(SPL_TPL_)LEGACY_IMAGE_FORMAT) += spl_legacy.o
 obj-$(CONFIG_$(SPL_TPL_)NOR_SUPPORT) += spl_nor.o
 obj-$(CONFIG_$(SPL_TPL_)XIP_SUPPORT) += spl_xip.o
common/spl/spl_blk_fs.c new file +19 -0
new file mode 100644
index 0000000000..fb2e8bbea7
@@ -0,0 +1,54 @@
+// 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>
+
+int spl_blk_load_image(struct spl_image_info *spl_image,
+                      struct spl_boot_device *bootdev,
+                      enum uclass_id uclass_id, int devnum)
+{
+       int ret = -ENOSYS, part;
+       struct blk_desc *blk_desc;
+
+       blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
Quoted 8 lines

common/spl/spl_blk_fs.c line 25

Quoted 6 lines
common/spl/spl_blk_fs.c new file +6 -0
+       if (!blk_desc)
+               return ret;
+
+       blk_show_device(uclass_id, devnum);
+
+       if (IS_ENABLED(CONFIG_SPL_FS_EXT4)) {

Can you use the fs.h layer so it can work with any FS?

Ok

Quoted 69 lines
Quoted 64 lines
common/spl/spl_blk_fs.c new file +29 -0
+               switch (uclass_id) {
+               case UCLASS_NVME:
+                       part = CONFIG_SYS_NVME_EXT_BOOT_PARTITION;
+                       break;
+               default:
+                       return ret;
+               }
+               ret = spl_load_image_ext(spl_image, bootdev, blk_desc, part,
+                                        CONFIG_SPL_PAYLOAD);
+               if (!ret)
+                       return ret;
+       }
+
+       if (IS_ENABLED(CONFIG_SPL_FS_FAT)) {
+               switch (uclass_id) {
+               case UCLASS_NVME:
+                       part = CONFIG_SYS_NVME_FAT_BOOT_PARTITION;
+                       break;
+               default:
+                       return ret;
+               }
+               ret = spl_load_image_fat(spl_image, bootdev, blk_desc, part,
+                                        CONFIG_SPL_PAYLOAD);
+               if (!ret)
+                       return ret;
+       }
+
+       return ret;
+}
drivers/block/Kconfig +7 -0
index 5a1aeb3d2b..6baaa6f071 100644
@@ -107,6 +107,13 @@ config EFI_MEDIA
 
          For sandbox there is a test driver.
 
+config SPL_BLK_FS
+       bool "Load images from filesystems on block devices"
+       depends on SPL_BLK
+       help
+         Use generic support to load images from fat/ext filesystems on
+         different types of block devices such as NVMe.
+
 if EFI_MEDIA
 
 config EFI_MEDIA_SANDBOX
include/spl.h +3 -1
index 7e0f5ac63b..4546648394 100644
@@ -672,6 +672,9 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 int spl_load_image_ext_os(struct spl_image_info *spl_image,
                          struct spl_boot_device *bootdev,
                          struct blk_desc *block_dev, int partition);
+int spl_blk_load_image(struct spl_image_info *spl_image,
+                      struct spl_boot_device *bootdev,
+                      enum uclass_id uclass_id, int devnum);
 
 /**
  * spl_early_init() - Set up device tree and driver model in SPL if enabled
--
Quoted 2 lines

2.34.1

Regards,
Simon

#6 lore raw

PATCH v3 3/5 nvme: pci: Enable for SPL

In reply to Mayuresh Chitale

Enable 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 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/Makefile +1 -0
index 58be410135..dc559ea7f7 100644
@@ -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
index fa7b619446..fd3e68a91d 100644
@@ -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
index ef328d2652..ecab6ddc7e 100644
@@ -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
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v3 3/5] nvme: pci: Enable for SPL

Quoted 38 lines · Mayuresh Chitale

Enable 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 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/Makefile +1 -0
index 58be410135..dc559ea7f7 100644
@@ -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
index fa7b619446..fd3e68a91d 100644
@@ -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 +0 -0
index ef328d2652..ecab6ddc7e 100644

drivers/pci/Kconfig config PCI_PNP · line 45

Quoted 6 lines
drivers/pci/Kconfig +3 -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

Drop that as the default is n and it confuses people into thinking the default is y....

Quoted 10 lines
drivers/pci/Kconfig +4 -1
+       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
--

2.34.1

Regards,
Simon

#8 lore raw

Re: [PATCH v3 3/5] nvme: pci: Enable for SPL

Quoted 43 lines · Simon Glass
Quoted 41 lines · Mayuresh Chitale

Enable 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 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/Makefile +1 -0
index 58be410135..dc559ea7f7 100644
@@ -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
index fa7b619446..fd3e68a91d 100644
@@ -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 +0 -0
index ef328d2652..ecab6ddc7e 100644
@@ -40,6 +40,13 @@ config PCI_PNP
        help
          Enable PCI memory and I/O space resource allocation and assignment.
 
Quoted 6 lines

drivers/pci/Kconfig config PCI_PNP · line 45

Quoted 3 lines
drivers/pci/Kconfig +3 -0
+config SPL_PCI_PNP
+       bool "Enable Plug & Play support for PCI"
+       default n

Drop that as the default is n and it confuses people into thinking the default is y....

Ok.

Quoted 14 lines
Quoted 11 lines
drivers/pci/Kconfig +4 -1
+       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
--

2.34.1

Regards,
Simon

#9 lore raw

PATCH v3 4/5 spl: Support loading a FIT from ext FS

In reply to Mayuresh Chitale

Detect 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
index f117c630bf..7b771c41e9 100644
@@ -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
#10 lore raw

Re: [PATCH v3 4/5] spl: Support loading a FIT from ext FS

Hi Mayuresh,

Quoted 17 lines · Mayuresh Chitale

Detect 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 +0 -0
index f117c630bf..7b771c41e9 100644
@@ -8,6 +8,26 @@
 #include <ext4fs.h>
 #include <errno.h>
 #include <image.h>

common/spl/spl_ext.c line 20

Quoted 10 lines
common/spl/spl_ext.c +10 -0
+#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 you use the fs_...() interface instead, can you make this function generic for all filesystems?

common/spl/spl_ext.c line 24

Quoted 4 lines
common/spl/spl_ext.c +4 -0
+       if (ret < 0) {
+               if (IS_ENABLED(CONFIG_SPL_LIBCOMMON_SUPPORT)) {
+                       printf("%s: error reading image %s, err - %d\n",
+                              __func__, filename, ret);

I could be wrong, but I think printf() is silently dropped if that option is not enabled, so maybe you don't need the if() checK?

common/spl/spl_ext.c int spl_load_image_ext(struct spl_image_info *spl_image,

Quoted 10 lines
common/spl/spl_ext.c +6 -0
+               }
+               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,

Really this should not be different from FAT and other filesystems. I'm not sure what is involved in making it common, though.

Quoted 20 lines
common/spl/spl_ext.c +13 -1
                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");
--
Quoted 2 lines

2.34.1

Regards,
Simon

#11 lore raw

Re: [PATCH v3 4/5] spl: Support loading a FIT from ext FS

Quoted 26 lines · Simon Glass

Hi Mayuresh,

Quoted 22 lines · Mayuresh Chitale

Detect 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 +5 -0
index f117c630bf..7b771c41e9 100644
@@ -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)
+{
Quoted 8 lines

common/spl/spl_ext.c line 20

Quoted 5 lines
common/spl/spl_ext.c +5 -0
+       loff_t filelen = (loff_t)load->priv, actlen;
+       char *filename = (char *)load->filename;
+       int ret;
+
+       ret = ext4fs_read(buf, file_offset, filelen, &actlen);

If you use the fs_...() interface instead, can you make this function generic for all filesystems?

Ok.

Quoted 16 lines

common/spl/spl_ext.c line 24

Quoted 5 lines
common/spl/spl_ext.c +4 -0
+       if (ret < 0) {
+               if (IS_ENABLED(CONFIG_SPL_LIBCOMMON_SUPPORT)) {
+                       printf("%s: error reading image %s, err - %d\n",
+                              __func__, filename, ret);

I could be wrong, but I think printf() is silently dropped if that option is not enabled, so maybe you don't need the if() checK?

Quoted 7 lines
common/spl/spl_ext.c +6 -0
+               }
+               return ret;
+       }
+
+       return actlen;
+}
 
Quoted 6 lines

common/spl/spl_ext.c int spl_load_image_ext(struct spl_image_info *spl_image,

Quoted 3 lines
common/spl/spl_ext.c +0 -0
 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,

Really this should not be different from FAT and other filesystems. I'm not sure what is involved in making it common, though.

Yes, it can be made generic.

Quoted 26 lines
Quoted 21 lines
common/spl/spl_ext.c +13 -1
                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");
--
Quoted 2 lines

2.34.1

Regards,
Simon

#12 lore raw

Re: [PATCH v3 4/5] spl: Support loading a FIT from ext FS

In reply to Mayuresh Chitale
Quoted 13 lines · Mayuresh Chitale

Detect 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 +0 -0
index f117c630bf..7b771c41e9 100644

common/spl/spl_ext.c line 17

Quoted 10 lines
common/spl/spl_ext.c +7 -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;

Please build on 32bit platforms such as j721e_evm_r5 as well:
+common/spl/spl_ext.c:16:26: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
+ 16 | loff_t filelen = (loff_t)load->priv, actlen;

Signature · 1 line
Tom
#13 lore raw

Re: [PATCH v3 4/5] spl: Support loading a FIT from ext FS

Am 17. Mai 2023 16:41:47 MESZ schrieb Tom Rini <[email protected]>:

Quoted 10 lines · Mayuresh Chitale
Quoted 9 lines

Detect 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(+)
Quoted 14 lines
Quoted 5 lines
common/spl/spl_ext.c +0 -0
index f117c630bf..7b771c41e9 100644

common/spl/spl_ext.c line 16

Quoted 9 lines
common/spl/spl_ext.c +6 -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;

The comma seems to be incorrect.

Quoted 6 lines

common/spl/spl_ext.c line 17

Quoted 1 line
common/spl/spl_ext.c +1 -0
+	char *filename = (char *)load->filename;

Please build on 32bit platforms such as j721e_evm_r5 as well:

(quoted diff) +2 -0
+common/spl/spl_ext.c:16:26: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
+   16 |         loff_t filelen = (loff_t)load->priv, actlen;
#14 lore raw

Re: [PATCH v3 4/5] spl: Support loading a FIT from ext FS

In reply to Tom Rini
Quoted 28 lines · Tom Rini
Quoted 13 lines · Mayuresh Chitale

Detect 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 +0 -0
index f117c630bf..7b771c41e9 100644

common/spl/spl_ext.c line 17

Quoted 10 lines
common/spl/spl_ext.c +7 -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;

Please build on 32bit platforms such as j721e_evm_r5 as well:

Review

Quoted 2 lines
(quoted diff) +2 -0
+common/spl/spl_ext.c:16:26: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
+   16 |         loff_t filelen = (loff_t)load->priv, actlen;

Ok.

Quoted 3 lines

--
Tom

#15 lore raw

PATCH v3 5/5 common: spl: Add spl NVMe boot support

In reply to Mayuresh Chitale

Add 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        | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+)
 create mode 100644 common/spl/spl_nvme.c
arch/riscv/include/asm/spl.h +1 -0
index 2898a770ee..9c0bf9755c 100644
@@ -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
index 515e8f2c66..6e41ac4e56 100644
@@ -1284,6 +1284,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
index 5210ad0248..bad2bbf6cf 100644
@@ -29,6 +29,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 +34 -0
new file mode 100644
index 0000000000..82b2bf3493
@@ -0,0 +1,34 @@
+// 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;
+
+	ret = pci_init();
+	if (ret < 0)
+		return ret;
+
+	ret = nvme_scan_namespace();
+	if (ret < 0)
+		return ret;
+
+	ret = spl_blk_load_image(spl_image, bootdev, UCLASS_NVME,
+				 CONFIG_SPL_NVME_BOOT_DEVICE);
+	return ret;
+}
+
+SPL_LOAD_IMAGE_METHOD("NVME", 0, BOOT_DEVICE_NVME, spl_nvme_load_image);
Signature · 1 line
2.34.1
Reviewed-by on v3 5/5
#16 lore raw

Re: [PATCH v3 5/5] common: spl: Add spl NVMe boot support

Quoted 4 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.

Quoted 9 lines
---
 arch/riscv/include/asm/spl.h |  1 +
 common/spl/Kconfig           | 10 ++++++++++
 common/spl/Makefile          |  1 +
 common/spl/spl_nvme.c        | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+)
 create mode 100644 common/spl/spl_nvme.c

BTW you should also be able to add a test for this using sandbox_spl