[RFC PATCH v1 3/3] common: spl: Add spl NVMe boot support

Simon Glass sjg at chromium.org
Fri Sep 30 01:55:52 CEST 2022


Hi Mayuresh,

On Thu, 29 Sept 2022 at 03:57, Mayuresh Chitale
<mchitale at ventanamicro.com> wrote:
>
> Add spl_nvme to read a fat partition from a bootable NVMe device.
>
> Signed-off-by: Mayuresh Chitale <mchitale at ventanamicro.com>
> ---
>  arch/riscv/include/asm/spl.h |  1 +
>  common/spl/Makefile          |  1 +
>  common/spl/spl_nvme.c        | 44 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 46 insertions(+)
>  create mode 100644 common/spl/spl_nvme.c

Reviewed-by: Simon Glass <sjg at chromium.org>

(but see below)

>
> diff --git a/arch/riscv/include/asm/spl.h b/arch/riscv/include/asm/spl.h
> index e8a94fcb1f..5d0ba4b034 100644
> --- a/arch/riscv/include/asm/spl.h
> +++ b/arch/riscv/include/asm/spl.h
> @@ -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,
> diff --git a/common/spl/Makefile b/common/spl/Makefile
> index 13db3df993..4bcc3d7e68 100644
> --- a/common/spl/Makefile
> +++ b/common/spl/Makefile
> @@ -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
> diff --git a/common/spl/spl_nvme.c b/common/spl/spl_nvme.c
> new file mode 100644
> index 0000000000..d8a9dba845
> --- /dev/null
> +++ b/common/spl/spl_nvme.c
> @@ -0,0 +1,44 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2022
> + * Ventana Micro Systems Inc.
> + *
> + * Derived work from spl_sata.c
> + */
> +
> +#include <common.h>
> +#include <spl.h>
> +#include <errno.h>
> +#include <fat.h>
> +#include <nvme.h>
> +#include <init.h>

Should go above 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(IF_TYPE_NVME, CONFIG_SPL_NVME_BOOT_DEVICE);
> +       blk_desc = blk_get_devnum_by_type(IF_TYPE_NVME,
> +                                         CONFIG_SPL_NVME_BOOT_DEVICE);

I think we need to move this to device tree, but it is OK for now.

> +       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);
> --
> 2.25.1
>

Regards,
Simon


More information about the U-Boot mailing list