diff options
| author | Tom Rini <[email protected]> | 2023-06-20 09:35:16 -0400 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2023-06-20 09:35:16 -0400 |
| commit | 571d8e57345dd35525bab2b3b47638792b960252 (patch) | |
| tree | 9074635ccd9362356f04ab59bcf23bb1867c1ea5 /common | |
| parent | bb922ca3eb4b92a27e98fb5d81bf22242e9d4f0e (diff) | |
| parent | 02d9c0b0e5c95b0c8af475c4b8821abe62478419 (diff) | |
Merge branch '2023-06-19-spl-nvme-support' into next
To quote the author:
This patchset adds support to load images of the SPL's next booting
stage from a NVMe device
Diffstat (limited to 'common')
| -rw-r--r-- | common/spl/Kconfig | 27 | ||||
| -rw-r--r-- | common/spl/Makefile | 2 | ||||
| -rw-r--r-- | common/spl/spl_blk_fs.c | 134 | ||||
| -rw-r--r-- | common/spl/spl_nvme.c | 32 |
4 files changed, 195 insertions, 0 deletions
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 6774ba5b42e..865571d4579 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -1263,6 +1263,33 @@ 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 FS_LOADER + 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 SYS_NVME_BOOT_PARTITION + hex "NVMe boot partition number" + depends on SPL_NVME + default 0x1 + config SPL_SERIAL bool "Support serial" select SPL_PRINTF diff --git a/common/spl/Makefile b/common/spl/Makefile index 13db3df9933..bad2bbf6cf1 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -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 @@ -28,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 diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c new file mode 100644 index 00000000000..d97adc4d39a --- /dev/null +++ b/common/spl/spl_blk_fs.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 + * Ventana Micro Systems Inc. + * + */ + +#include <common.h> +#include <spl.h> +#include <image.h> +#include <fs.h> + +struct blk_dev { + const char *ifname; + char dev_part_str[8]; +}; + +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, + ulong size, void *buf) +{ + loff_t actlen; + int ret; + struct blk_dev *dev = (struct blk_dev *)load->priv; + + ret = fs_set_blk_dev(dev->ifname, dev->dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev->ifname, dev->dev_part_str, ret); + return ret; + } + + ret = fs_read(load->filename, (ulong)buf, file_offset, size, &actlen); + if (ret < 0) { + printf("spl: error reading image %s. Err - %d\n", + load->filename, ret); + return ret; + } + + return actlen; +} + +int spl_blk_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev, + enum uclass_id uclass_id, int devnum, int partnum) +{ + const char *filename = CONFIG_SPL_PAYLOAD; + struct disk_partition part_info = {}; + struct legacy_img_hdr *header; + struct blk_desc *blk_desc; + loff_t actlen, filesize; + struct blk_dev dev; + int ret; + + blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum); + if (!blk_desc) { + printf("blk desc for %d %d not found\n", uclass_id, devnum); + goto out; + } + + blk_show_device(uclass_id, devnum); + header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + ret = part_get_info(blk_desc, 1, &part_info); + if (ret) { + printf("spl: no partition table found. Err - %d\n", ret); + goto out; + } + + dev.ifname = blk_get_uclass_name(uclass_id); + snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%d:%d", + devnum, partnum); + ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev.ifname, dev.dev_part_str, ret); + goto out; + } + + ret = fs_read(filename, (ulong)header, 0, + sizeof(struct legacy_img_hdr), &actlen); + if (ret) { + printf("spl: unable to read file %s. Err - %d\n", filename, + ret); + goto out; + } + + 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 = &dev; + + return spl_load_simple_fit(spl_image, &load, 0, header); + } + + ret = spl_parse_image_header(spl_image, bootdev, header); + if (ret) { + printf("spl: unable to parse image header. Err - %d\n", + ret); + goto out; + } + + ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev.ifname, dev.dev_part_str, ret); + goto out; + } + + ret = fs_size(filename, &filesize); + if (ret) { + printf("spl: unable to get file size: %s. Err - %d\n", + filename, ret); + goto out; + } + + ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev.ifname, dev.dev_part_str, ret); + goto out; + } + + ret = fs_read(filename, (ulong)spl_image->load_addr, 0, filesize, + &actlen); + if (ret) + printf("spl: unable to read file %s. Err - %d\n", + filename, ret); +out: + return ret; +} diff --git a/common/spl/spl_nvme.c b/common/spl/spl_nvme.c new file mode 100644 index 00000000000..2af63f1dc8c --- /dev/null +++ b/common/spl/spl_nvme.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 + * Ventana Micro Systems Inc. + * + */ + +#include <common.h> +#include <spl.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, + CONFIG_SYS_NVME_BOOT_PARTITION); + return ret; +} + +SPL_LOAD_IMAGE_METHOD("NVME", 0, BOOT_DEVICE_NVME, spl_nvme_load_image); |
