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 2/4] spl: blk: Support loading images from fs
Date: Sat, 3 Jun 2023 19:32:54 +0530 [thread overview]
Message-ID: <20230603140256.2443518-3-mchitale@ventanamicro.com> (raw)
In-Reply-To: <20230603140256.2443518-1-mchitale@ventanamicro.com>
Add a generic API to support loading of SPL payload from any supported
filesystem on a given partition of a block device.
Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
---
common/spl/Kconfig | 1 +
common/spl/Makefile | 1 +
common/spl/spl_blk_fs.c | 134 ++++++++++++++++++++++++++++++++++++++++
drivers/block/Kconfig | 7 +++
include/spl.h | 3 +
5 files changed, 146 insertions(+)
create mode 100644 common/spl/spl_blk_fs.c
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 94b13f7a7f..3f705f4fb8 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1268,6 +1268,7 @@ config SPL_NVME
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).
diff --git a/common/spl/Makefile b/common/spl/Makefile
index 13db3df993..5210ad0248 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
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
new file mode 100644
index 0000000000..d97adc4d39
--- /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/drivers/block/Kconfig b/drivers/block/Kconfig
index 5a1aeb3d2b..6baaa6f071 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -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
diff --git a/include/spl.h b/include/spl.h
index 7e0f5ac63b..20e1eb32a4 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -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
--
2.34.1
next prev parent reply other threads:[~2023-06-03 14:04 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 ` Mayuresh Chitale [this message]
2023-06-03 14:02 ` [PATCH v4 3/4] nvme: pci: Enable for SPL Mayuresh Chitale
2023-06-03 14:02 ` [PATCH v4 4/4] common: spl: Add spl NVMe boot support Mayuresh Chitale
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-3-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.