mirror of
https://github.com/u-boot/u-boot.git
synced 2024-12-04 01:53:27 +08:00
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
This commit is contained in:
commit
571d8e5734
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
134
common/spl/spl_blk_fs.c
Normal file
134
common/spl/spl_blk_fs.c
Normal file
@ -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;
|
||||
}
|
32
common/spl/spl_nvme.c
Normal file
32
common/spl/spl_nvme.c
Normal file
@ -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);
|
@ -35,6 +35,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/
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -40,6 +40,12 @@ 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"
|
||||
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
|
||||
|
@ -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, int partnum);
|
||||
|
||||
/**
|
||||
* spl_early_init() - Set up device tree and driver model in SPL if enabled
|
||||
|
Loading…
Reference in New Issue
Block a user