All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mayuresh Chitale <mchitale@ventanamicro.com>
To: Bin Meng <bmeng.cn@gmail.com>, Simon Glass <sjg@chromium.org>
Cc: Mayuresh Chitale <mchitale@ventanamicro.com>,
	u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Rick Chen <rick@andestech.com>, Leo <ycliang@andestech.com>
Subject: [PATCH v4 4/4] common: spl: Add spl NVMe boot support
Date: Sat,  3 Jun 2023 19:32:56 +0530	[thread overview]
Message-ID: <20230603140256.2443518-5-mchitale@ventanamicro.com> (raw)
In-Reply-To: <20230603140256.2443518-1-mchitale@ventanamicro.com>

Add support to load the next stage image from an NVMe disk which may
be formatted as an EXT or FAT filesystem. Also protect the call to
env_get in blk_get_device_part_str with CONFIG_SPL_ENV_SUPPORT macro to
avoid link error when SPL_ENV_SUPPORT is not enabled.

Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
---
 arch/riscv/include/asm/spl.h |  1 +
 common/spl/Makefile          |  1 +
 common/spl/spl_nvme.c        | 32 ++++++++++++++++++++++++++++++++
 disk/part.c                  | 10 ++++++----
 4 files changed, 40 insertions(+), 4 deletions(-)
 create mode 100644 common/spl/spl_nvme.c

diff --git a/arch/riscv/include/asm/spl.h b/arch/riscv/include/asm/spl.h
index 2898a770ee..9c0bf9755c 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 5210ad0248..bad2bbf6cf 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -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
diff --git a/common/spl/spl_nvme.c b/common/spl/spl_nvme.c
new file mode 100644
index 0000000000..2af63f1dc8
--- /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);
diff --git a/disk/part.c b/disk/part.c
index 35300df590..d330c57ab4 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -467,10 +467,12 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 	}
 #endif
 
-	/* If no dev_part_str, use bootdevice environment variable */
-	if (!dev_part_str || !strlen(dev_part_str) ||
-	    !strcmp(dev_part_str, "-"))
-		dev_part_str = env_get("bootdevice");
+	if (IS_ENABLED(CONFIG_SPL_ENV_SUPPORT)) {
+		/* If no dev_part_str, use bootdevice environment variable */
+		if (!dev_part_str || !strlen(dev_part_str) ||
+		    !strcmp(dev_part_str, "-"))
+			dev_part_str = env_get("bootdevice");
+	}
 
 	/* If still no dev_part_str, it's an error */
 	if (!dev_part_str) {
-- 
2.34.1


  parent reply	other threads:[~2023-06-03 14:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-03 14:02 [PATCH v4 0/4] SPL NVMe support Mayuresh Chitale
2023-06-03 14:02 ` [PATCH v4 1/4] spl: Add Kconfig options for NVME Mayuresh Chitale
2023-06-03 14:02 ` [PATCH v4 2/4] spl: blk: Support loading images from fs Mayuresh Chitale
2023-06-03 14:02 ` [PATCH v4 3/4] nvme: pci: Enable for SPL Mayuresh Chitale
2023-06-03 14:02 ` Mayuresh Chitale [this message]
2023-06-20 13:37 ` [PATCH v4 0/4] SPL NVMe support Tom Rini
2023-07-12 13:06   ` mchitale
2023-07-12 13:27     ` Heinrich Schuchardt
2023-07-12 17:12       ` Tom Rini
2023-07-17  8:09         ` mchitale
2023-07-17 15:12           ` Tom Rini
2023-07-20  6:17             ` mchitale

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230603140256.2443518-5-mchitale@ventanamicro.com \
    --to=mchitale@ventanamicro.com \
    --cc=bmeng.cn@gmail.com \
    --cc=rick@andestech.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    --cc=ycliang@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.