misc: fs_loader: reorg and split to FS and FW loader + FIP loader
v7 cover misc: fs_loader: reorg and split to FS and FW loader + FIP loader
This series mainly rework the FS loader to permit reading firmware from container that are not exactly a readable filesystem.
Also splitting out the generic firmware loader infra from the filesystem-specific code will make adding new loader types easier.
One scenario is when a firmware is shipped in a FIP container as a generic blob with an UUID.
FIP are mostly used on ARM in the context of ATF.
In such context U-Boot is loaded as BL31 and the PHY firmware can't be stored in the FIT image for the kernel as U-Boot should not depend on the presence of the kernel to correctly enable PHY for Ethernet port.
To handle such case the PHY firmware is stored in FIP with a predictable UUID.
One example is with Airoha 8811H firmware where the FIP can have a blob with UUID "d39d2cf2-9bd0-3ca7-93e9-e71b4f9250b2". (generated from command "uuidgen -n @dns --md5 --name en8811h.bin")
With these example DTS entry:
fs_loader0: fip-loader {
bootph-all;
compatible = "u-boot,fip-loader";
phandlepart = <&mmc0 0>;
partoffset = <0x100>;
};mdio {
en8811: ethernet-phy@f {
reg = <0xf>;
firmware-name = "d39d2cf2-9bd0-3ca7-93e9-e71b4f9250b2";
firmware-loader = <&fs_loader0>; };
};
And PHY driver using the get_fw_loader_from_node() and the common request_firmware_into_buf() it's possible to load the PHY firmware transparently by just declaring the required entry in the DTS.
get_fw_loader_from_node() is implemented to actual get the loader from DT. This was something that was already in mind from when the FS loader was implemented but then it was never implemented in favor of a single loader per device.
The first patch is a minor fixup for something that probably won't ever happen.
The second one is a good reworking of the FS and FW loader moving the internal struct to a dedicated header. (this is really to enforce what drivers should use and what driver should not mess with)
Then there is the request_firmware_size() new OP to get only the size of the firmware. Useful for case where the firmware size is not always the same and change across different version. (the patter might be get size -> alloc buffer -> get firmware).
Then the FIP loader as a basic parser of FIP. This only read the FIP header, loop all the entry and search for a matching UUID. If nothing is found then no firmware blob. Very simple implementation.
This is being CI tested on [0]
[0] https://github.com/u-boot/u-boot/pull/884
Changes v7:
- Add tests
- Rebase on top of next
- Fix compilation for vpl
Changes v6:
- Rework to generic FW loader UCLASS
- Account for firmware offset in FIP loader
- Add UBI example in documentation
- Improve variables order
Changes v5:
- Fix unment dependency for config flag
- Move request_firmware_size before FIP loader
- Add documentation patch
- Improve get_fw_loader_from_node() implementation
- use min() instead of custom MIN()
- Fix handling of some return value
Changes v4:
- Rebase on top of next
Changes v3:
- Add review tag where possible
- Check blk_dread ret
- Generalize mount_ubifs with generic_fw_loader_ubi_select
- Fix some typo
- Drop useless ubifs umount (nothing is mounted in FIP) Changes v2:
- Better handle header include to fix compilation error on some devices
- Fix typo for ubifs fix commit
Christian Marangi (7):
misc: fs_loader: fix ubifs not unmounted on dev_get_priv error
misc: fs_loader: reorganize and split to FS loader and FW UCLASS
misc: fw_loader: implement generic get_fw_loader_from_node()
misc: fw_loader: implement request_firmware_size() OP
misc: fw_loader: introduce FIP loader driver
doc: dtbinding: Update documentation for Generic Firmware loader
test: dm: Add test for FW Loader feature
arch/sandbox/dts/test.dts | 20 +
configs/sandbox64_defconfig | 1 +
configs/sandbox_defconfig | 1 +
configs/sandbox_flattree_defconfig | 1 +
configs/sandbox_noinst_defconfig | 1 +
configs/sandbox_spl_defconfig | 1 +
configs/sandbox_vpl_defconfig | 1 +
.../misc/{fs_loader.txt => fw_loader.txt} | 33 +-
drivers/misc/Kconfig | 16 +
drivers/misc/Makefile | 2 +-
drivers/misc/fs_loader.c | 326 -----------
drivers/misc/fw_loader/Makefile | 5 +
drivers/misc/fw_loader/fip_loader.c | 544 ++++++++++++++++++
drivers/misc/fw_loader/fs_loader.c | 230 ++++++++
drivers/misc/fw_loader/fw_loader-uclass.c | 204 +++++++
drivers/misc/fw_loader/internal.h | 82 +++
include/dm/uclass-id.h | 2 +-
include/fs_loader.h | 47 +-
include/fw_loader.h | 42 ++
test/boot/bootdev.c | 34 +-
test/boot/bootflow.c | 12 +-
test/dm/Makefile | 1 +
test/dm/blk.c | 41 +-
test/dm/fw_loader.c | 112 ++++
test/py/tests/test_ut.py | 18 +
25 files changed, 1373 insertions(+), 404 deletions(-)
rename doc/device-tree-bindings/misc/{fs_loader.txt => fw_loader.txt} (58%)
delete mode 100644 drivers/misc/fs_loader.c
create mode 100644 drivers/misc/fw_loader/Makefile
create mode 100644 drivers/misc/fw_loader/fip_loader.c
create mode 100644 drivers/misc/fw_loader/fs_loader.c
create mode 100644 drivers/misc/fw_loader/fw_loader-uclass.c
create mode 100644 drivers/misc/fw_loader/internal.h
create mode 100644 test/dm/fw_loader.cSignature · 1 line
2.53.0
PATCH v7 1/7 misc: fs_loader: fix ubifs not unmounted on dev_get_priv error
When dev_get_priv errors out, the ubifs is not umounted (if used).
Correctly handle this handle condition and while at it also return -EINVAL instead of -ENOMEM as a better error since no memory is allocated but is actually an invalid scenario for fw_get_filesystem_firmware().
--- drivers/misc/fs_loader.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/misc/fs_loader.c +4 -2
@@ -175,8 +175,10 @@ static int fw_get_filesystem_firmware(struct udevice *dev)struct firmware *firmwarep =dev_get_priv (dev); -if (!firmwarep) -return -ENOMEM ; +if (!firmwarep) { + ret = -EINVAL ; + goto out; + } ret =fs_read (firmwarep->name, (ulong )map_to_sysmem (firmwarep->data), firmwarep->offset, firmwarep->size, &actread);
Signature · 1 line
2.53.0
PATCH v7 2/7 misc: fs_loader: reorganize and split to FS loader and FW UCLASS
In reply to Christian MarangiIn preparation to the introduction of variant of the FS loader, reorganize and split the driver to generic fw_loader UCLASS and specific fs_loader function. Create a dedicated directory for the loader and move the internal structs and functions to a dedicated header file. While at it also drop some redundant check and rename some variables as we are updating the code for the UCLASS rework.
This will permit to reuse all the property and logic of FS loader with container that are not exactly a readable filesystem.
--- drivers/misc/Kconfig | 5 + drivers/misc/Makefile | 2 +- drivers/misc/fs_loader.c | 328 ---------------------- drivers/misc/fw_loader/Makefile | 4 + drivers/misc/fw_loader/fs_loader.c | 186 ++++++++++++ drivers/misc/fw_loader/fw_loader-uclass.c | 159 +++++++++++ drivers/misc/fw_loader/internal.h | 73 +++++ include/dm/uclass-id.h | 2 +- include/fs_loader.h | 47 +--- include/fw_loader.h | 19 ++ 10 files changed, 450 insertions(+), 375 deletions(-) delete mode 100644 drivers/misc/fs_loader.c create mode 100644 drivers/misc/fw_loader/Makefile create mode 100644 drivers/misc/fw_loader/fs_loader.c create mode 100644 drivers/misc/fw_loader/fw_loader-uclass.c create mode 100644 drivers/misc/fw_loader/internal.h
drivers/misc/Kconfig +5 -0
@@ -612,8 +612,12 @@ config MPC83XX_SERDES help Support for serdes found on MPC83xx SoCs. +config FW_LOADER_UCLASS + bool + config FS_LOADER bool "Enable loader driver for file system" + select FW_LOADER_UCLASS help This is file system generic loader which can be used to load the file image from the storage into target such as memory.
@@ -623,6 +627,7 @@ config FS_LOADER config SPL_FS_LOADER bool "Enable loader driver for file system in SPL" + select FW_LOADER_UCLASS depends on SPL help This is file system generic loader which can be used to load
drivers/misc/Makefile +1 -1
@@ -36,7 +36,7 @@ obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o obj-$(CONFIG_FSL_IFC) += fsl_ifc.o obj-$(CONFIG_FSL_IIM) += fsl_iim.o obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o -obj-$(CONFIG_$(PHASE_)FS_LOADER) += fs_loader.o +obj-$(CONFIG_FW_LOADER_UCLASS) += fw_loader/ obj-$(CONFIG_GATEWORKS_SC) += gsc.o obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o
drivers/misc/fs_loader.c deleted +0 -328
328 lines not on this page · raw message
drivers/misc/fw_loader/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += fw_loader-uclass.o +obj-$(CONFIG_$(PHASE_)FS_LOADER) += fs_loader.o
drivers/misc/fw_loader/fs_loader.c new file +186 -0
186 lines not on this page · raw message
drivers/misc/fw_loader/fw_loader-uclass.c new file +159 -0
159 lines not on this page · raw message
drivers/misc/fw_loader/internal.h new file +73 -0
73 lines not on this page · raw message
include/dm/uclass-id.h +1 -1
@@ -69,7 +69,7 @@ enum uclass_id {UCLASS_FIRMWARE ,/* Firmware */ UCLASS_FPGA ,/* FPGA device */ UCLASS_FUZZING_ENGINE ,/* Fuzzing engine */ -UCLASS_FS_FIRMWARE_LOADER ,/* Generic loader */ +UCLASS_FIRMWARE_LOADER ,/* Firmware loader */ UCLASS_FWU_MDATA ,/* FWU Metadata Access */ UCLASS_GPIO ,/* Bank of general-purpose I/O pins */ UCLASS_HASH, /* Hash device */
include/fs_loader.h +2 -45
54 lines not on this page · raw message
include/fw_loader.h +19 -0
@@ -1,10 +1,29 @@/* SPDX-License-Identifier: GPL-2.0 */ /* +* Copyright (C) 2018-2019 Intel Corporation <www.intel.com> * Copyright (C) 2025 Lucien Jheng <[email protected]> */ #ifndef _FW_LOADER_H_#define _FW_LOADER_H_ +struct udevice ; + +/** +* request_firmware_into_buf - Load firmware into a previously allocated buffer. +* @dev: An instance of a driver. +* @name: Name of firmware file. +* @buf: Address of buffer to load firmware into. +* @size: Size of buffer. +* @offset: Offset of a file for start reading into buffer. +* +* The firmware is loaded directly into the buffer pointed to by @buf. +* +* Return: Size of total read, negative value when error. +*/ +int request_firmware_into_buf (struct udevice *dev, +const char *name, +void *buf,size_t size,u32 offset); +/** * request_firmware_into_buf_via_script() - * Load firmware using a U-Boot script and copy to buffer
Signature · 1 line
2.53.0
Re: [PATCH v7 2/7] misc: fs_loader: reorganize and split to FS loader and FW UCLASS
Hi Christian,
Quoted 28 lines · Christian Marangi
misc:
fs_loader: reorganize and split to FS loader and FW UCLASSIn preparation to the introduction of variant of the FS loader, reorganize and split the driver to generic
fw_loaderUCLASS and specificfs_loaderfunction. Create a dedicated directory for the loader and move the internal structs and functions to a dedicated header file. While at it also drop some redundant check and rename some variables as we are updating the code for the UCLASS rework.This will permit to reuse all the property and logic of FS loader with container that are not exactly a readable filesystem.
Signed-off-by Christian Marangi <[email protected]>
drivers/misc/Kconfig| 5 +drivers/misc/Makefile | 2 +- drivers/misc/fs_loader.c | 328 ------------------------------ drivers/misc/fw_loader/Makefile | 4 + drivers/misc/fw_loader/fs_loader.c | 186 +++++++++++++++++ drivers/misc/fw_loader/fw_loader-uclass.c | 159 +++++++++++++++ drivers/misc/fw_loader/internal.h | 73 +++++++ include/dm/uclass-id.h | 2 +- include/fs_loader.h | 47 +---- include/fw_loader.h | 19 ++ 10 files changed, 450 insertions(+), 375 deletions(-)
include/dm/uclass-id.h enum uclass_id { · line 69
Quoted 2 lines
include/dm/uclass-id.h +1
-1@@ -69,7 +69,7 @@ enum uclass_id { - UCLASS_FS_FIRMWARE_LOADER, /* Generic loader */ + UCLASS_FIRMWARE_LOADER, /* Firmware loader */
This rename leaves doc/develop/driver-model/fs_firmware_loader.rst stale - it still has two references to UCLASS_FS_FIRMWARE_LOADER (around lines 90 and 148). Please update the rst file (or rename it) in this patch.
drivers/misc/fw_loader/fw_loader-uclass.c line 8
Quoted 10 lines
drivers/misc/fw_loader/fw_loader-uclass.c +8
-0@@ -0,0 +1,159 @@ +static int fw_loader_pre_probe (struct udevice *dev) +{ +#if CONFIG_IS_ENABLED (DM ) +struct device_plat *plat =dev_get_uclass_plat (dev); +ofnode fw_loader_node; + +if (!IS_ENABLED (CONFIG_DM )) +return 0 ;
The outer #if CONFIG_IS_ENABLED(DM) already gates this body, so the runtime if (!IS_ENABLED(CONFIG_DM)) is dead code - and it confuses the meaning, since CONFIG_IS_ENABLED() is phase-aware while IS_ENABLED(CONFIG_DM) is not. Please drop the inner check.
drivers/misc/fw_loader/fw_loader-uclass.c line 7
Quoted 9 lines
drivers/misc/fw_loader/fw_loader-uclass.c +7
-0@@ -0,0 +1,159 @@ +#else +static int fw_loader_get_blk_dev_from_node (ofnode node) +{ +debug ("fw_loader: No block device support\n" ); +return -EINVAL ; +} +#endif
This changes behaviour from the original driver. Previously the entire phandlepart block was wrapped in #if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(BLK), so a board with BLK disabled would probe with the phandle silently ignored. With this patch, the stub returns -EINVAL and pre_probe propagates it, so probe fails. If intentional, please call it out in the commit message; otherwise the stub should return 0.
drivers/misc/fw_loader/internal.h line 5
Quoted 7 lines
drivers/misc/fw_loader/internal.h +5
-0@@ -0,0 +1,73 @@ +struct device_plat { +struct phandle_part phandlepart; +char *mtdpart; +char *ubivol; +};
Please rename struct device_plat to something like struct fw_loader_plat - device_plat reads as a generic DM type and is misleading even when internal to the uclass.
drivers/misc/fw_loader/internal.h line 1
Quoted 3 lines
drivers/misc/fw_loader/internal.h +1
-0@@ -0,0 +1,73 @@ +#define fw_loader_get_ops (dev) ((struct fw_loader_ops *)(dev)->driver->ops)
The fs_loader_ops table is static const, so this macro silently casts the const away. Please return const struct fw_loader_ops * - the callers in request_firmware_into_buf() only need read access.
drivers/misc/Makefile obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o · line 36
Quoted 4 lines
drivers/misc/Makefile +1
-1@@ -36,7 +36,7 @@ obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o -obj-$(CONFIG_$(PHASE_)FS_LOADER) += fs_loader.o +obj-$(CONFIG_FW_LOADER_UCLASS) += fw_loader/
FW_LOADER_UCLASS is not phase-aware, so once any phase selects FS_LOADER the uclass object is linked into every phase that descends here. Worth making FW_LOADER_UCLASS phase-scoped (SPL_/TPL_/VPL_) and gating both the subdir and fw_loader-uclass.o on CONFIG_$(PHASE_)FW_LOADER_UCLASS.
Regards,
Simon
PATCH v7 3/7 misc: fw_loader: implement generic get_fw_loader_from_node()
In reply to Christian MarangiImplement a generic function to get a FW loader dev from a node.
There is currently only get_fs_loader() but that is limited to chosen node and is limited only to FS loader.
Introduce get_fw_loader_from_node() that will parse the "firmware-loader" from a specified node and will search and probe a matching FW loader device, if found.
--- drivers/misc/fw_loader/fw_loader-uclass.c | 23 +++++++++++++++++++++++ include/fw_loader.h | 14 ++++++++++++++ 2 files changed, 37 insertions(+)
drivers/misc/fw_loader/fw_loader-uclass.c +23 -0
@@ -9,6 +9,8 @@#include <linux/types.h> #include <dm.h> #include <dm/device.h> +#include <dm/device-internal.h> +#include <dm/uclass.h> #include <fw_loader.h> #if CONFIG_IS_ENABLED (CMD_UBIFS )
@@ -108,6 +110,27 @@ UCLASS_DRIVER(fw_loader) = { .per_device_auto = sizeof(struct firmware), }; +int get_fw_loader_from_node (ofnode node,struct udevice **dev) +{ +struct udevice *fw_dev; +int ret; + + node =ofnode_parse_phandle (node,"firmware-loader" ,0 ); +if (!ofnode_valid (node)) +return -ENODEV ; + + ret =device_find_global_by_ofnode (node, &fw_dev); +if (ret) +return ret; + + ret =device_probe (fw_dev); +if (ret) +return ret; + + *dev = fw_dev; +return 0 ; +} +/** * _request_firmware_prepare - Prepare firmware struct. *
include/fw_loader.h +14 -0
@@ -6,8 +6,22 @@#ifndef _FW_LOADER_H_#define _FW_LOADER_H_ +#include <dm/ofnode_decl.h> +struct udevice ; +/** +* get_fw_loader_from_node - Get FW loader dev from @node. +* +* @node: ofnode where "firmware-loader" phandle is stored. +* @dev: pointer where to store the FW loader dev. +* +* Search and probe a matching FW loader device, if found. +* +* Return: Negative value if fail, 0 for successful. +*/ +int get_fw_loader_from_node (ofnode node,struct udevice **dev); +/** * request_firmware_into_buf - Load firmware into a previously allocated buffer. * @dev: An instance of a driver.
Signature · 1 line
2.53.0
Re: [PATCH v7 3/7] misc: fw_loader: implement generic get_fw_loader_from_node()
Hi Christian,
Quoted 29 lines · Christian Marangi
misc:
fw_loader: implement genericget_fw_loader_from_node()Implement a generic function to get a FW loader dev from a node.
There is currently only
get_fs_loader()but that is limited to chosen node and is limited only to FS loader.Introduce
get_fw_loader_from_node()that will parse the 'firmware-loader' from a specified node and will search and probe a matching FW loader device, if found.Signed-off-by Christian Marangi <[email protected]>
drivers/misc/fw_loader/fw_loader-uclass.c| 23 +++++++++++++++++++++++include/fw_loader.h | 14 ++++++++++++++ 2 files changed, 37 insertions(+)drivers/misc/fw_loader/fw_loader-uclass.c +10
-0@@ -108,6 +110,27 @@ UCLASS_DRIVER(fw_loader) = { +int get_fw_loader_from_node (ofnode node,struct udevice **dev) +{ +struct udevice *fw_dev; +int ret; + + node =ofnode_parse_phandle (node,'firmware-loader' ,0 ); +if (!ofnode_valid (node)) +return -ENODEV ; + + ret =device_find_global_by_ofnode (node, &fw_dev);
drivers/misc/fw_loader/fw_loader-uclass.c UCLASS_DRIVER(fw_loader) = { · line 129
Quoted 10 lines
drivers/misc/fw_loader/fw_loader-uclass.c +10
-0+if (ret) +return ret; + + ret =device_probe (fw_dev); +if (ret) +return ret; + + *dev = fw_dev; +return 0 ; +}
Can you use uclass_get_device_by_ofnode(UCLASS_FIRMWARE_LOADER, node, dev) here? It is more specific.
Regards,
Simon
PATCH v7 4/7 misc: fw_loader: implement request_firmware_size() OP
In reply to Christian MarangiIt might be useful to get the firmware size before reading it to allocate the correct size. This is needed for case where the firmware size change across different firmware version and is not always the same. In such case the only way to handle this scenario is to allocate a big-enough buffer to read the firmware.
To better handle this, introduce the request_firmware_size() OP to get the firmware size before reading it. This way proper buffer can be allocated and dynamic firmware size can be better supported.
FS loader is updated to handle the new .get_size() handler.
--- drivers/misc/fw_loader/fs_loader.c | 68 +++++++++++++++++++---- drivers/misc/fw_loader/fw_loader-uclass.c | 19 +++++++ drivers/misc/fw_loader/internal.h | 7 +++ include/fw_loader.h | 9 +++ 4 files changed, 91 insertions(+), 12 deletions(-)
drivers/misc/fw_loader/fs_loader.c +56 -12
@@ -89,18 +89,10 @@ static int select_fs_dev(struct device_plat *plat)return ret; } -/** -* fw_get_filesystem_firmware - load firmware into an allocated buffer. -* @dev: An instance of a driver. -* -* Return: Size of total read, negative value when error. -*/ -static int fw_get_filesystem_firmware (struct udevice *dev) +static int fw_get_filesystem_prepare (struct udevice *dev) {char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume; -struct firmware *upriv =dev_get_uclass_priv (dev);struct device_plat *plat =dev_get_uclass_plat (dev); -loff_t actread =0 ;int ret; storage_interface =env_get ("storage_interface" );
@@ -124,6 +116,29 @@ static int fw_get_filesystem_firmware(struct udevice *dev) ret =select_fs_dev (plat); } +return ret; +} + +static void fw_get_filesystem_release (struct udevice *dev) +{ +#ifdef CONFIG_CMD_UBIFS +umount_ubifs (); +#endif +} + +/** +* fw_get_filesystem_firmware - load firmware into an allocated buffer. +* @dev: An instance of a driver. +* +* Return: Size of total read, negative value when error. +*/ +static int fw_get_filesystem_firmware (struct udevice *dev) +{ +struct firmware *upriv =dev_get_uclass_priv (dev); +loff_t actread =0 ; +int ret; + + ret =fw_get_filesystem_prepare (dev);if (ret) goto out;
@@ -138,14 +153,43 @@ static int fw_get_filesystem_firmware(struct udevice *dev) } out: -#ifdef CONFIG_CMD_UBIFS -umount_ubifs (); -#endif +fw_get_filesystem_release (dev); +return ret; +} + +/** +* fw_get_filesystem_firmware_size - get firmware size. +* @dev: An instance of a driver. +* +* Return: Size of firmware, negative value when error. +*/ +static int fw_get_filesystem_firmware_size (struct udevice *dev) +{ +struct firmware *upriv =dev_get_uclass_priv (dev); +loff_t size =0 ; +int ret; + + ret =fw_get_filesystem_prepare (dev); +if (ret) + goto out; + + ret =fs_size (upriv->name, &size); +if (ret) { +debug ("Error: %d Failed to get size for %s.\n" , + ret, upriv->name); + goto out; + } + + ret = size; + +out: +fw_get_filesystem_release (dev);return ret; }static const struct fw_loader_ops fs_loader_ops = { .get_firmware = fw_get_filesystem_firmware, + .get_size = fw_get_filesystem_firmware_size, };static const struct udevice_id fs_loader_ids[] = {
drivers/misc/fw_loader/fw_loader-uclass.c +19 -0
@@ -180,3 +180,22 @@ int request_firmware_into_buf(struct udevice *dev,return ops->get_firmware (dev); } + +int request_firmware_size (struct udevice *dev,const char *name) +{ +struct fw_loader_ops *ops; +int ret; + +if (!dev) +return -EINVAL ; + + ret =_request_firmware_prepare (dev, name,NULL ,0 ,0 ); +if (ret <0 )/* error */ +return ret; + + ops =fw_loader_get_ops (dev); +if (!ops->get_size) +return -EOPNOTSUPP ; + +return ops->get_size (dev); +}
drivers/misc/fw_loader/internal.h +7 -0
@@ -32,6 +32,13 @@ struct fw_loader_ops {* @dev: Firmware Loader device to read firmware from */ int (*get_firmware)(struct udevice *dev); + +/** +* get_size() - get firmware size from Firmware Loader driver +* +* @dev: Firmware Loader device to get firmware size from +*/ +int (*get_size)(struct udevice *dev); };#define fw_loader_get_ops (dev) ((struct fw_loader_ops *)(dev)->driver->ops)
include/fw_loader.h +9 -0
@@ -38,6 +38,15 @@ int request_firmware_into_buf(struct udevice *dev,const char *name, void *buf, size_t size, u32 offset); +/** +* request_firmware_size - Get firmware size. +* @dev: An instance of a driver. +* @name: Name of firmware file. +* +* Return: Size of firmware, negative value when error. +*/ +int request_firmware_size (struct udevice *dev,const char *name); +/** * request_firmware_into_buf_via_script() - * Load firmware using a U-Boot script and copy to buffer
Signature · 1 line
2.53.0
Re: [PATCH v7 4/7] misc: fw_loader: implement request_firmware_size() OP
Quoted 14 lines · Christian Marangi
misc:
fw_loader: implementrequest_firmware_size()OPIt might be useful to get the firmware size before reading it to allocate the correct size. This is needed for case where the firmware size change across different firmware version and is not always the same. In such case the only way to handle this scenario is to allocate a big-enough buffer to read the firmware.
To better handle this, introduce the
request_firmware_size()OP to get the firmware size before reading it. This way proper buffer can be allocated and dynamic firmware size can be better supported.FS loader is updated to handle the new .get_size() handler.
Quoted 7 lines
Signed-off-by Christian Marangi <[email protected]>
drivers/misc/fw_loader/fs_loader.c| 68 +++++++++++++++++++++++++------drivers/misc/fw_loader/fw_loader-uclass.c | 19 +++++++++ drivers/misc/fw_loader/internal.h | 7 ++++ include/fw_loader.h | 9 ++++ 4 files changed, 91 insertions(+), 12 deletions(-)
PATCH v7 5/7 misc: fw_loader: introduce FIP loader driver
In reply to Christian MarangiIntroduce a variant of the FS loader driver to extract images from FIP image. These image can contain additional binary used to init Network accelerator or PHY firmware blob.
The way FIP handle image type is with the usage of UUID.
This FIP loader driver implement a simple FIP image parser that check every entry for a matching UUID.
Similar to FS loader, this driver also support both UBI and Block devices.
Also an additional property is added to handle special case with eMMC that doesn't have a GPT partition and require a global offset to reference the FIP partition.
An example usage of this driver is the following:
Entry in DTS:
fs_loader0: fip-loader {
bootph-all;
compatible = "u-boot,fip-loader";
phandlepart = <&mmc0 0>;
partoffset = <0x100>;
};
ethernet@1fb50000 {
firmware-loader = <&fs_loader0>;
}FIP loader user:
/* get the FW loader from the ethernet node */ get_fw_loader_from_node(dev_ofnode(dev), &fw_loader); /* read the blob identified by "58704aef-389f-3e52-b475-e0bf2234a6a2" UUID */ request_firmware_into_buf(fw_loader, "58704aef-389f-3e52-b475-e0bf2234a6a2", buf, 261400, 0);
--- drivers/misc/Kconfig | 11 + drivers/misc/fw_loader/Makefile | 1 + drivers/misc/fw_loader/fip_loader.c | 544 ++++++++++++++++++++++ drivers/misc/fw_loader/fw_loader-uclass.c | 3 + drivers/misc/fw_loader/internal.h | 2 + 5 files changed, 561 insertions(+) create mode 100644 drivers/misc/fw_loader/fip_loader.c
drivers/misc/Kconfig +11 -0
@@ -615,6 +615,17 @@ config MPC83XX_SERDES config FW_LOADER_UCLASS bool +config FIP_LOADER + bool "Enable loader driver from FIP partition" + select LIB_UUID + select FW_LOADER_UCLASS + help + This is FIP partition generic loader which can be used to load + the file image from the FIP image into target such as memory. + + The consumer driver would then use this loader to program whatever, + ie. the FPGA device/PHY firmware. + config FS_LOADER bool "Enable loader driver for file system" select FW_LOADER_UCLASS
drivers/misc/fw_loader/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += fw_loader-uclass.o +obj-$(CONFIG_FIP_LOADER) += fip_loader.o obj-$(CONFIG_$(PHASE_)FS_LOADER) += fs_loader.o
drivers/misc/fw_loader/fip_loader.c new file +544 -0
544 lines not on this page · raw message
drivers/misc/fw_loader/fw_loader-uclass.c +3 -0
@@ -87,6 +87,9 @@ static int fw_loader_pre_probe(struct udevice *dev) plat->ubivol = (char *)ofnode_read_string (fw_loader_node,"ubivol" ); + +ofnode_read_u32 (fw_loader_node,"partoffset" , + &plat->partoffset); }if (plat->phandlepart.phandle) {
drivers/misc/fw_loader/internal.h +2 -0
@@ -49,11 +49,13 @@ struct fw_loader_ops {* This holds information about all supported storage devices for driver use. * * @phandlepart: Attribute data for block device. +* @partoffset: Global offset for BLK partition. * @mtdpart: MTD partition for ubi partition. * @ubivol: UBI volume-name for ubifsmount. */ struct device_plat {struct phandle_part phandlepart; +u32 partoffset;char *mtdpart;char *ubivol; };
Signature · 1 line
2.53.0
Re: [PATCH v7 5/7] misc: fw_loader: introduce FIP loader driver
Hi Christian,
Quoted 33 lines · Christian Marangi
misc:
fw_loader: introduce FIP loader driverIntroduce a variant of the FS loader driver to extract images from FIP image. These image can contain additional binary used to init Network accelerator or PHY firmware blob.
The way FIP handle image type is with the usage of UUID.
This FIP loader driver implement a simple FIP image parser that check every entry for a matching UUID.
Similar to FS loader, this driver also support both UBI and Block devices.
Also an additional property is added to handle special case with eMMC that doesn't have a GPT partition and require a global offset to reference the FIP partition.
An example usage of this driver is the following:
[...]
drivers/misc/Kconfig| 11 +drivers/misc/fw_loader/Makefile | 1 + drivers/misc/fw_loader/fip_loader.c | 544 ++++++++++++++++++++++++++++++ drivers/misc/fw_loader/fw_loader-uclass.c | 3 + drivers/misc/fw_loader/internal.h | 2 + 5 files changed, 561 insertions(+)drivers/misc/fw_loader/fip_loader.c +2
-0@@ -0,0 +1,544 @@ +static int fw_parse_storage_info (struct udevice *dev, +struct fip_storage_info *info)
drivers/misc/fw_loader/fip_loader.c line 12
Quoted 10 lines
drivers/misc/fw_loader/fip_loader.c +10
-0+{ +char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume; +struct device_plat *plat =dev_get_uclass_plat (dev); +int ret; + + storage_interface =env_get ('storage_interface' ); + dev_part =env_get ('fw_dev_part' ); + ubi_mtdpart =env_get ('fw_ubi_mtdpart' ); + ubi_volume =env_get ('fw_ubi_volume' ); + info->part_offset =env_get_hex ('fw_partoffset' ,0 );
A large chunk of this - the env lookups, the phandlepart resolution and the mtdpart/ubivol fallback - duplicates fw_get_filesystem_prepare()/select_fs_dev() in fs_loader.c almost line-for-line. Please factor the common storage-selection logic into the uclass (or into a helper in internal.h) so both drivers share one implementation.
drivers/misc/fw_loader/fip_loader.c line 7
Quoted 9 lines
drivers/misc/fw_loader/fip_loader.c +7
-0@@ -0,0 +1,544 @@ +static int blk_parse_fip_firmware (struct firmware *firmwarep, +struct blk_desc *desc, +struct disk_partition *part_info, +unsigned int part_offset, +struct fip_toc_entry *dent) +{ +unsigned int offset = part_info->start + part_offset;
part_info->start is lbaint_t, which is 64-bit on most modern targets. Storing it in unsigned int silently truncates partitions whose start LBA is beyond 4G blocks; the same applies to blkstart further down and to part_offset in struct fip_storage_info. Please use lbaint_t for the on-device block coordinates.
Quoted 6 lines
drivers/misc/fw_loader/fip_loader.c +4
-0@@ -0,0 +1,544 @@ +#define TOC_HEADER_NAME 0xaa640001 + +struct fip_toc_header { +u32 name;
drivers/misc/fw_loader/fip_loader.c line 14
Quoted 10 lines
drivers/misc/fw_loader/fip_loader.c +10
-0+u32 serial_number; +u64 flags; +}; + +struct fip_toc_entry { +struct uuid uuid; +u64 offset_address; +u64 size; +u64 flags; +};
These describe an on-disk format that TF-A defines as little-endian, but the code reads them straight into native u32/u64 and compares with TOC_HEADER_NAME directly. Do we have to worry about big-endian targets?
drivers/misc/fw_loader/fip_loader.c line 4
Quoted 6 lines
drivers/misc/fw_loader/fip_loader.c +4
-0@@ -0,0 +1,544 @@ +#ifdef CONFIG_CMD_UBIFS +static int ubi_parse_fip_firmware (struct firmware *firmwarep, +char *ubi_vol, +struct fip_toc_entry *dent)
The rest of the FW loader code gates UBI support with CONFIG_IS_ENABLED(CMD_UBIFS) so it works correctly across SPL/VPL phases. Please use the same idiom here, otherwise an SPL build with CONFIG_SPL_CMD_UBIFS but no CONFIG_CMD_UBIFS will silently drop the UBI path.
drivers/misc/fw_loader/Makefile line 5
Quoted 7 lines
drivers/misc/fw_loader/Makefile +1
-0@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += fw_loader-uclass.o +obj-$(CONFIG_FIP_LOADER) += fip_loader.o obj-$(CONFIG_$(PHASE_)FS_LOADER) += fs_loader.o
FS_LOADER uses the $(PHASE_) prefix so it can be enabled per-phase, but FIP_LOADER is gated on a single non-phased symbol. Was that intentional? If FIP is meant to be usable in SPL/TPL/VPL too (the cover letter suggests it is), this should probably be CONFIG_$(PHASE_)FIP_LOADER
drivers/misc/fw_loader/fw_loader-uclass.c static int fw_loader_pre_probe(struct udevice *dev) · line 93
Quoted 9 lines
drivers/misc/fw_loader/fw_loader-uclass.c +3
-0@@ -87,6 +87,9 @@ static int fw_loader_pre_probe(struct udevice *dev) plat->ubivol = (char *)ofnode_read_string (fw_loader_node,'ubivol' ); + +ofnode_read_u32 (fw_loader_node,'partoffset' , + &plat->partoffset); }
partoffset is a FIP-specific concept (a byte offset inside a partition where the FIP image lives), but it is being parsed in the generic uclass and stored in the common device_plat - either document it as applying to every loader and have fs_loader honour it, or move the DT read into the FIP driver so the uclass stays neutral.
Quoted 13 lines
drivers/misc/fw_loader/fip_loader.c +11
-0@@ -0,0 +1,544 @@ +static int fw_get_fip_firmware_size (struct udevice *dev) +{ +struct fip_storage_info info = { }; +struct firmware *firmwarep; +struct fip_toc_entry ent; +int ret; + + ret =fw_parse_storage_info (dev, &info); +if (ret) +return ret; +
drivers/misc/fw_loader/fip_loader.c line 21
Quoted 10 lines
drivers/misc/fw_loader/fip_loader.c +10
-0+ firmwarep =dev_get_uclass_priv (dev); +if (!firmwarep) +return -EINVAL ; + + ret =parse_fip_firmware (firmwarep, &info, &ent); +if (ret) +return ret; + +return ent.size; +}
get_size() returns ent.size, but the get_firmware() path treats the usable size as ent.size - firmwarep->offset. A caller using request_firmware_size() to size a buffer and then passing a non-zero offset to request_firmware_into_buf() will get an over-large allocation, or interpret size inconsistently between the two calls. Please pick one definition (most likely ent.size - firmwarep->offset) and use it in both ops.
Quoted 5 lines
drivers/misc/fw_loader/fip_loader.c +3
-0@@ -0,0 +1,544 @@ +#include <dm.h> +#include <div64.h> +#include <env.h>
drivers/misc/fw_loader/fip_loader.c line 13
Quoted 10 lines
drivers/misc/fw_loader/fip_loader.c +10
-0+#include <errno.h> +#include <blk.h> +#include <fs.h> +#include <linux/kernel.h> +#include <log.h> +#include <mapmem.h> +#include <malloc.h> +#include <memalign.h> +#include <part.h> +#include <u-boot/uuid.h>
map_to_sysmem()/memalign() are not used; please drop mapmem.h and memalign.h. Also please sort the includes properly - e.g. blk.h should come before dm.h
Regards,
Simon
PATCH v7 6/7 doc: dtbinding: Update documentation for Generic Firmware loader
In reply to Christian MarangiUpdate documentation for Generic Firmware loader, generalize it from FS specific and add new property and example for FIP loader.
Also add details on the usage of 'phandlepart', 'mtdpart' and 'ubivol' property.
---
.../misc/{fs_loader.txt => fw_loader.txt} | 33 +++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)
rename doc/device-tree-bindings/misc/{fs_loader.txt => fw_loader.txt} (58%)doc/device-tree-bindings/misc/fw_loader.txt renamed from doc/device-tree-bindings/misc/fs_loader.txt +30 -3
@@ -1,17 +1,27 @@ -* File system firmware loader +* Generic Firmware loader Required properties: -------------------- -- compatible: should contain "u-boot,fs-loader" +- compatible: should contain "u-boot,fs-loader" or "u-boot,fip-loader" + +Optional properties: +-------------------- + - phandlepart: which block storage device and partition the image loading from, this property is required for mmc, usb and sata. This is unsigned 32-bit array. For example phandlepart=<&mmc_0 1>, meaning use that MMC0 node pointer, partition 1. -- mdtpart: which partition of ubi the image loading from, this property is +- mtdpart: which partition of ubi the image loading from, this property is required for ubi and mounting. - ubivol: which volume of ubi the image loading from, this property is required for ubi and mounting. +- partoffset: valid ONLY for "u-boot,fip-loader". Offset of the partition to + parse the FIP partition from. + +Either 'phandlepart' or 'mtdpart' can be used. For Block device, 'phandlepart' +should be used and for MTD device, 'mtdpart' should be used. With UBI device, +in addition to 'mtdpart' also 'ubivol' is required. Example of storage device and partition search set for mmc, usb, sata and ubi in device tree source as shown in below:
@@ -46,3 +56,20 @@ ubi in device tree source as shown in below: mtdpart = "UBI", ubivol = "ubi0"; }; + + Example for FIP from eMMC: + fs_loader4: fip-loader@4 { + bootph-all; + compatible = "u-boot,fip-loader"; + phandlepart = <&mmc0 0>; + partoffset = <0x100>; + }; + + Example for FIP from ubi: + fs_loader4: fip-loader@4 { + bootph-all; + compatible = "u-boot,fip-loader"; + mtdpart = "ubi", + ubivol = "bl31"; + }; +
Signature · 1 line
2.53.0
Re: [PATCH v7 6/7] doc: dtbinding: Update documentation for Generic Firmware loader
Hi Christian,
Quoted 20 lines · Christian Marangi
doc: dtbinding: Update documentation for Generic Firmware loader
Update documentation for Generic Firmware loader, generalize it from FS specific and add new property and example for FIP loader.
Also add details on the usage of 'phandlepart', 'mtdpart' and 'ubivol' property.
Signed-off-by Christian Marangi <[email protected]>
.../misc/{fs_loader.txt=> fw_loader.txt} | 33 ++++++++++++++++++++--1 file changed, 30 insertions(+), 3 deletions(-)doc/device-tree-bindings/misc/fw_loader.txt renamed from doc/device-tree-bindings/misc/fs_loader.txt +5
-0@@ -46,3 +56,20 @@ ubi in device tree source as shown in below: + Example for FIP from eMMC: + fs_loader4: fip-loader@4 { + bootph-all; + compatible = 'u-boot,fip-loader'; + phandlepart = <&mmc0 0>;
doc/device-tree-bindings/misc/fw_loader.txt ubi in device tree source as shown in below: · line 70
Quoted 10 lines
doc/device-tree-bindings/misc/fw_loader.txt renamed from doc/device-tree-bindings/misc/fs_loader.txt +10
-0+ partoffset = <0x100>; + }; + + Example for FIP from ubi: + fs_loader4: fip-loader@4 { + bootph-all; + compatible = 'u-boot,fip-loader'; + mtdpart = 'ubi', + ubivol = 'bl31'; + };
Two issues. First, both nodes reuse the same label and unit address (fs_loader4: fip-loader@4) - please bump the second to fs_loader5:
fip-loader@5
Second, mtdpart = 'ubi', terminates the property with a comma but should be a semicolon.
doc/device-tree-bindings/misc/fw_loader.txt line 2
Quoted 4 lines
doc/device-tree-bindings/misc/fw_loader.txt renamed from doc/device-tree-bindings/misc/fs_loader.txt +2
-0@@ -1,17 +1,27 @@ +- partoffset: valid ONLY for 'u-boot,fip-loader'. Offset of the partition to + parse the FIP partition from.
Wording is confusing - partition appears twice with different meanings. I suggest "byte offset within the selected partition where the FIP header is located". Also worth stating the units (bytes) and whether the offset must be block-aligned.
doc/device-tree-bindings/misc/fw_loader.txt line 6
Quoted 9 lines
doc/device-tree-bindings/misc/fw_loader.txt renamed from doc/device-tree-bindings/misc/fs_loader.txt +5
-1@@ -1,17 +1,27 @@ -- compatible: should contain 'u-boot,fs-loader' +- compatible: should contain 'u-boot,fs-loader' or 'u-boot,fip-loader' + +Optional properties: +-------------------- + - phandlepart: which block storage device and partition the image loading from,
Just to check - phandlepart/mtdpart move from required to optional, but at least one must be present in practice. Please spell it out, e.g. "exactly one of phandlepart or mtdpart must be provided".
doc/device-tree-bindings/misc/fw_loader.txt line 1
Quoted 4 lines
doc/device-tree-bindings/misc/fw_loader.txt renamed from doc/device-tree-bindings/misc/fs_loader.txt +1
-1@@ -1,17 +1,27 @@ -* File system firmware loader +* Generic Firmware loader
BTW new bindings in U-Boot are expected to be YAML schemas (or upstreamed to dt-schema), not free-form .txt. Since you are effectively rewriting this binding for a new compatible, it would be a good opportunity to convert. What do you think?
Regards,
Simon
PATCH v7 7/7 test: dm: Add test for FW Loader feature
In reply to Christian MarangiAdd basic test for FW Loader feature for the Filesystem way.
An additional MMC testing image is added that loads a dummy firmware.bin in a fat partition. Update all the affected test for this additional eMMC node.
--- arch/sandbox/dts/test.dts | 20 ++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_noinst_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + configs/sandbox_vpl_defconfig | 1 + test/boot/bootdev.c | 34 +++++---- test/boot/bootflow.c | 12 +++- test/dm/Makefile | 1 + test/dm/blk.c | 41 +++++++---- test/dm/fw_loader.c | 112 +++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 18 +++++ 13 files changed, 216 insertions(+), 28 deletions(-) create mode 100644 test/dm/fw_loader.c
arch/sandbox/dts/test.dts +20 -0
@@ -49,6 +49,7 @@ mmc8 = "/mmc8"; mmc9 = "/mmc9"; mmc10 = "/mmc10"; + mmc11 = "/mmc11"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2;
@@ -184,6 +185,12 @@ }; }; + fs_loader: fs-loader { + bootph-all; + compatible = "u-boot,fs-loader"; + phandlepart = <&mmc11 1>; + }; + cedit: cedit { };
@@ -1348,6 +1355,12 @@ filename = "mmc10.img"; }; + /* This is used for FW Loader tests */ + mmc11: mmc11 { + compatible = "sandbox,mmc"; + filename = "mmc11.img"; + }; + pch { compatible = "sandbox,pch"; };
@@ -2081,6 +2094,13 @@ ethphy1: ethernet-phy@1 { reg = <1>; }; + + ethernet-phy@2 { + reg = <2>; + + firmware-name = "firmware.bin"; + firmware-loader = <&fs_loader>; + }; }; pm-bus-test {
configs/sandbox64_defconfig +1 -0
@@ -271,6 +271,7 @@ CONFIG_WDT_ALARM_SANDBOX=y CONFIG_FS_CBFS=y CONFIG_FS_EXFAT=y CONFIG_FS_CRAMFS=y +CONFIG_FS_LOADER=y CONFIG_CMD_DHRYSTONE=y CONFIG_TPM=y CONFIG_ERRNO_STR=y
configs/sandbox_defconfig +1 -0
@@ -379,6 +379,7 @@ CONFIG_WDT_FTWDT010=y CONFIG_FS_CBFS=y CONFIG_FS_EXFAT=y CONFIG_FS_CRAMFS=y +CONFIG_FS_LOADER=y CONFIG_ADDR_MAP=y CONFIG_PANIC_HANG=y CONFIG_CMD_DHRYSTONE=y
configs/sandbox_flattree_defconfig +1 -0
@@ -16,6 +16,7 @@ CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERITY=y CONFIG_FIT_VERBOSE=y +CONFIG_FS_LOADER=y CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y
configs/sandbox_noinst_defconfig +1 -0
@@ -21,6 +21,7 @@ CONFIG_SYS_MEMTEST_END=0x00101000 CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y +CONFIG_FS_LOADER=y CONFIG_SPL_LOAD_FIT=y CONFIG_SPL_HAS_LOAD_FIT_ADDRESS=y CONFIG_SPL_LOAD_FIT_ADDRESS=0x0
configs/sandbox_spl_defconfig +1 -0
@@ -226,6 +226,7 @@ CONFIG_OSD=y CONFIG_SANDBOX_OSD=y CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y +CONFIG_FS_LOADER=y # CONFIG_SPL_USE_TINY_PRINTF is not set CONFIG_CMD_DHRYSTONE=y CONFIG_RSA_VERIFY_WITH_PKEY=y
configs/sandbox_vpl_defconfig +1 -0
@@ -234,6 +234,7 @@ CONFIG_OSD=y CONFIG_SANDBOX_OSD=y CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y +CONFIG_FS_LOADER=y # CONFIG_SPL_USE_TINY_PRINTF is not set CONFIG_CMD_DHRYSTONE=y CONFIG_RSA_VERIFY_WITH_PKEY=y
test/boot/bootdev.c +22 -12
@@ -34,8 +34,10 @@ static int bootdev_test_cmd_list(struct unit_test_state *uts) "mmc", "mmc1.bootdev");ut_assert_nextline ("%3x [ %c ] %6s %-8s %s" ,2 , probe_ch,"OK" ,"mmc" ,"mmc0.bootdev" ); +ut_assert_nextline ("%3x [ %c ] %6s %-8s %s" ,3 , probe_ch,"OK" , +"mmc" ,"mmc11.bootdev" );ut_assert_nextlinen ("---" ); -ut_assert_nextline ("(3 bootdevs)" ); +ut_assert_nextline ("(4 bootdevs)" );ut_assert_console_end (); }
@@ -240,10 +242,11 @@ static int bootdev_test_order(struct unit_test_state *uts)/* Now scan past mmc1 and make sure that only mmc0 shows up */ ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow)); -ut_asserteq (3 , iter.num_devs); +ut_asserteq (4 , iter.num_devs);ut_asserteq_str ("mmc2.bootdev" , iter.dev_used[0 ]->name);ut_asserteq_str ("mmc1.bootdev" , iter.dev_used[1 ]->name);ut_asserteq_str ("mmc0.bootdev" , iter.dev_used[2 ]->name); +ut_asserteq_str ("mmc11.bootdev" , iter.dev_used[3 ]->name);bootflow_iter_uninit (&iter);/* Try a single uclass with boot_targets */
@@ -253,10 +256,11 @@ static int bootdev_test_order(struct unit_test_state *uts)/* Now scan past mmc1 and make sure that only mmc0 shows up */ ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow)); -ut_asserteq (3 , iter.num_devs); +ut_asserteq (4 , iter.num_devs);ut_asserteq_str ("mmc2.bootdev" , iter.dev_used[0 ]->name);ut_asserteq_str ("mmc1.bootdev" , iter.dev_used[1 ]->name);ut_asserteq_str ("mmc0.bootdev" , iter.dev_used[2 ]->name); +ut_asserteq_str ("mmc11.bootdev" , iter.dev_used[3 ]->name);bootflow_iter_uninit (&iter);/* Try a single uclass with boot_targets */
@@ -270,12 +274,13 @@ static int bootdev_test_order(struct unit_test_state *uts)*/ ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow)); -ut_asserteq (6 , iter.num_devs); +ut_asserteq (7 , iter.num_devs);ut_asserteq_str ("mmc2.bootdev" , iter.dev_used[0 ]->name);ut_asserteq_str ("mmc1.bootdev" , iter.dev_used[1 ]->name);ut_asserteq_str ("mmc0.bootdev" , iter.dev_used[2 ]->name); +ut_asserteq_str ("mmc11.bootdev" , iter.dev_used[3 ]->name);ut_asserteq_str ("usb_mass_storage.lun0.bootdev" , - iter.dev_used[3 ]->name); + iter.dev_used[4 ]->name);bootflow_iter_uninit (&iter);return 0 ;
@@ -301,8 +306,9 @@ static int bootdev_test_order_default(struct unit_test_state *uts)ut_asserteq_str ("mmc1.bootdev" , iter.dev_used[1 ]->name);ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow)); -ut_asserteq (3 , iter.num_devs); +ut_asserteq (4 , iter.num_devs);ut_asserteq_str ("mmc0.bootdev" , iter.dev_used[2 ]->name); +ut_asserteq_str ("mmc11.bootdev" , iter.dev_used[3 ]->name);bootflow_iter_uninit (&iter);return 0 ;
@@ -328,23 +334,23 @@ static int bootdev_test_prio(struct unit_test_state *uts)ut_assertok (bootstd_test_drop_bootdev_order (uts)); -/* 3 MMC and 3 USB bootdevs: MMC should come before USB */ +/* 4 MMC and 3 USB bootdevs: MMC should come before USB */ ut_assertok (bootflow_scan_first (NULL ,NULL , &iter,0 , &bflow));/* get the usb device which has a backing file (flash1.img) */ ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow)); -ut_asserteq (6 , iter.num_devs); +ut_asserteq (7 , iter.num_devs);ut_asserteq_str ("mmc2.bootdev" , iter.dev_used[0 ]->name);ut_asserteq_str ("usb_mass_storage.lun0.bootdev" , - iter.dev_used[3 ]->name); + iter.dev_used[4 ]->name); -ut_assertok (bootdev_get_sibling_blk (iter.dev_used[3 ], &blk)); +ut_assertok (bootdev_get_sibling_blk (iter.dev_used[4 ], &blk));ut_asserteq_str ("usb_mass_storage.lun0" , blk->name);/* adjust the priority of the first USB bootdev to the highest */ - ucp =dev_get_uclass_plat (iter.dev_used[3 ]); + ucp =dev_get_uclass_plat (iter.dev_used[4 ]); ucp->prio =BOOTDEVP_1_PRE_SCAN ;/* try again but enable hunting, which brings in SCSI */
@@ -356,7 +362,7 @@ static int bootdev_test_prio(struct unit_test_state *uts)ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow)); -ut_asserteq (7 , iter.num_devs); +ut_asserteq (8 , iter.num_devs);ut_asserteq_str ("usb_mass_storage.lun0.bootdev" , iter.dev_used[0 ]->name);ut_asserteq_str ("mmc2.bootdev" , iter.dev_used[1 ]->name);
@@ -732,6 +738,10 @@ static int bootdev_test_next_prio(struct unit_test_state *uts)ut_asserteq_str ("mmc0.bootdev" , dev->name);ut_assert_console_end (); +ut_assertok (bootdev_next_prio (&iter, &dev)); +ut_asserteq_str ("mmc11.bootdev" , dev->name); +ut_assert_console_end (); +ut_assertok (bootdev_next_prio (&iter, &dev));ut_asserteq_str ("[email protected]" , dev->name);ut_assert_skip_to_line ("Hunting with: spi_flash" );
test/boot/bootflow.c +10 -2
@@ -123,6 +123,7 @@ static int bootflow_cmd_label(struct unit_test_state *uts)* 8 [ ] OK mmc mmc2.bootdev * 9 [ + ] OK mmc mmc1.bootdev * a [ ] OK mmc mmc0.bootdev +* a [ ] OK mmc mmc11.bootdev * * However with CONFIG_DSA_SANDBOX=n we have two fewer (dsa-test@0 and * dsa-test@1).
@@ -159,6 +160,7 @@ static int bootflow_cmd_glob(struct unit_test_state *uts)ut_assert_nextline ("Scanning bootdev 'mmc1.bootdev':" );ut_assert_nextline (" 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf" );ut_assert_nextline ("Scanning bootdev 'mmc0.bootdev':" ); +ut_assert_nextline ("Scanning bootdev 'mmc11.bootdev':" );ut_assert_nextline ("No more bootdevs" );ut_assert_nextlinen ("---" );ut_assert_nextline ("(1 bootflow, 1 valid)" );
@@ -206,9 +208,13 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)ut_assert_skip_to_line (" 3f efi media mmc 0 mmc0.bootdev.whole " );ut_assert_nextline (" ** No partition found, err=-93: Protocol not supported" ); +ut_assert_skip_to_line ("Scanning bootdev 'mmc11.bootdev':" ); +ut_assert_skip_to_line ( +" 7b efi media mmc 1d mmc11.bootdev.part_1d " ); +ut_assert_nextline (" ** No partition found, err=-2: No such file or directory" );ut_assert_nextline ("No more bootdevs" );ut_assert_nextlinen ("---" ); -ut_assert_nextline ("(64 bootflows, 1 valid)" ); +ut_assert_nextline ("(124 bootflows, 1 valid)" );ut_assert_console_end ();ut_assertok (run_command ("bootflow list" ,0 ));
@@ -220,8 +226,9 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)ut_assert_skip_to_line (" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf" );ut_assert_skip_to_line (" 3f efi media mmc 0 mmc0.bootdev.whole " ); +ut_assert_skip_to_line (" 7b efi media mmc 1d mmc11.bootdev.part_1d " );ut_assert_nextlinen ("---" ); -ut_assert_nextline ("(64 bootflows, 1 valid)" ); +ut_assert_nextline ("(124 bootflows, 1 valid)" );ut_assert_console_end ();return 0 ;
@@ -549,6 +556,7 @@ static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)ut_assert_nextline ("Scanning bootdev 'mmc2.bootdev':" );ut_assert_nextline ("Scanning bootdev 'mmc1.bootdev':" );ut_assert_nextline ("Scanning bootdev 'mmc0.bootdev':" ); +ut_assert_nextline ("Scanning bootdev 'mmc11.bootdev':" );ut_assert_nextline ("No more bootdevs" );ut_assert_nextlinen ("---" );ut_assert_nextline ("(0 bootflows, 0 valid)" );
test/dm/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_EXTCON) += extcon.o ifneq ($(CONFIG_EFI_PARTITION),) obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o endif +obj-$(CONFIG_FW_LOADER_UCLASS) += fw_loader.o obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_FPGA) += fpga.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata.o
test/dm/blk.c +27 -14
106 lines not on this page · raw message
test/dm/fw_loader.c new file +112 -0
112 lines not on this page · raw message
test/py/tests/test_ut.py +18 -0
@@ -557,6 +557,23 @@ def test_ut_dm_init(ubman): with open(fn, 'wb') as fh: fh.write(data) +def setup_fw_loader_image(ubman): + """Create a 2MB disk image with a dummy firmware on it""" + mmc_dev = 11 + fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0xc, img_size=2) + + fw = os.path.join(mnt, 'firmware.bin') + data = b'\xaa' * 256 + with open(fw, 'wb') as fh: + fh.write(data) + + fsfile = 'vfat1M.img' + utils.run_and_log(ubman, f'fallocate -l 1M {fsfile}') + utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') + utils.run_and_log(ubman, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) + copy_partition(ubman, fsfile, fname) + utils.run_and_log(ubman, f'rm -rf {mnt}') + utils.run_and_log(ubman, f'rm -f {fsfile}') def setup_efi_image(ubman): """Create a 20MB disk image with an EFI app on it"""
@@ -624,6 +641,7 @@ def test_ut_dm_init_bootstd(ubman): setup_cedit_file(ubman) setup_cros_image(ubman) setup_android_image(ubman) + setup_fw_loader_image(ubman) setup_efi_image(ubman) setup_rauc_image(ubman)
Signature · 1 line
2.53.0
Re: [PATCH v7 7/7] test: dm: Add test for FW Loader feature
Hi Christian,
Quoted 27 lines · Christian Marangi
test: dm: Add test for FW Loader feature
Add basic test for FW Loader feature for the Filesystem way.
An additional MMC testing image is added that loads a dummy firmware.bin in a fat partition. Update all the affected test for this additional eMMC node.
Signed-off-by Christian Marangi <[email protected]>
arch/sandbox/dts/test.dts| 20 +++++++configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_noinst_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + configs/sandbox_vpl_defconfig | 1 + test/boot/bootdev.c | 34 +++++++---- test/boot/bootflow.c | 12 +++- test/dm/Makefile | 1 + test/dm/blk.c | 41 +++++++++----- test/dm/fw_loader.c | 112 +++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 18 ++++++ 13 files changed, 216 insertions(+), 28 deletions(-)
test/boot/bootflow.c static int bootflow_cmd_label(struct unit_test_state *uts) · line 127
Quoted 5 lines
test/boot/bootflow.c +1
-0@@ -123,6 +123,7 @@ static int bootflow_cmd_label(struct unit_test_state *uts)* 8 [ ] OK mmc mmc2.bootdev * 9 [ + ] OK mmc mmc1.bootdev * a [ ] OK mmc mmc0.bootdev +* a [ ] OK mmc mmc11.bootdev *
The label here should be b for the new bootdev, not a second a.
Quoted 10 lines
test/dm/fw_loader.c +8
-0@@ -0,0 +1,112 @@ +static int dm_test_fw_loader_get_fw_size (struct unit_test_state *uts) +{ +struct udevice *mdio_dev, *fw_loader_dev =NULL ; +ofnode mdio_node, phy_node; +int ret; + +ut_assertok (uclass_get_device_by_name (UCLASS_MDIO ,'mdio-test' , + &mdio_dev));
test/dm/fw_loader.c line 18
Quoted 10 lines
test/dm/fw_loader.c +10
-0+ + mdio_node =dev_ofnode (mdio_dev); +ut_assert (ofnode_valid (mdio_node)); + + phy_node =ofnode_find_subnode (mdio_node,'ethernet-phy@2' ); +ut_assert (ofnode_valid (phy_node)); + + ret =get_fw_loader_from_node (phy_node, &fw_loader_dev); +ut_assertok (ret); +ut_assertnonnull (fw_loader_dev);
All three tests repeat the same six-line dance to look up the mdio device, walk to ethernet-phy@2 and resolve the loader. Please factor this into a helper (or per-suite fixture).
test/dm/fw_loader.c line 7
Quoted 9 lines
test/dm/fw_loader.c +7
-0@@ -0,0 +1,112 @@ + ret =request_firmware_into_buf (fw_loader_dev,'firmware.bin' , + buf, firmware_size, firmware_size); +ut_asserteq (0 , ret); + + ret =request_firmware_into_buf (fw_loader_dev,'firmware.bin' , + buf, firmware_size,0 ); +ut_asserteq (firmware_size, ret);
Please also exercise the past-the-end case (offset > firmware_size) and a missing-file case (does-not-exist.bin). Also free(buf) before returning.
test/dm/fw_loader.c line 1
Quoted 3 lines
test/dm/fw_loader.c +1
-0@@ -0,0 +1,112 @@ +DM_TEST (dm_test_fw_loader_get_fw_in_buf,UTF_SCAN_FDT );
The FIP loader is the headline feature of the series but has no coverage here - only the FS loader path is exercised. Given that the FIP parser does UUID lookups, header validation and offset accounting, please add at least one test (a small canned FIP blob in an image, or a sandbox helper to fabricate one). Otherwise regressions in fip_loader.c will go unnoticed.
test/dm/blk.c static int dm_test_blk_iter(struct unit_test_state *uts) · line 216
Quoted 9 lines
test/dm/blk.c +3
-2@@ -208,14 +212,15 @@ static int dm_test_blk_iter(struct unit_test_state *uts) i =0 ; blk_foreach_probe(BLKF_REMOVABLE, dev) -ut_asserteq_str (i++ ?'mmc0.blk' :'mmc1.blk' , dev->name); -ut_asserteq (2 , i); +ut_asserteq_str ((++i ==1 ?'mmc1.blk' : i ==2 ? +'mmc0.blk' :'mmc11.blk' ), dev->name); +ut_asserteq (3 , i);
The nested ternary is hard to read; with three entries a small const char *expected[] = { ... } indexed by i would be clearer, matching the BLKF_BOTH case below.
Regards,
Simon