Generic firmware loader
v7 cover Generic firmware loader
From: Tien Fong Chee <[email protected]>
This patchset contains generic firmware loader which is very close to Linux firmware loader but for U-Boot framework. Generic firmware loader can be used load whatever into target location, and then consumer driver would use it to program whatever, ie. the FPGA. This version mainly resolved comments from Tom Rini, Marek Vasut and Simon Goldschmidt in [v6].
This series is working on top of u-boot.git -
http://git.denx.de/u-boot.git .
[v6]: https://www.mail-archive.com/u-boot at lists.denx.de/msg273961.html
v6 -> v7 changes:
-----------------
- Fixed minor issues from checkpatch.pl.
- Ensure <asm/spl.h> is included when running generic firmware loader.
- Created new Kconfig option for generic firmware loader.
- Changed all printf to debug.
- Changed sprintf to snprintf.
- Call ubifs function directly instead of involving whoe command machinery.
- Follow kerneldoc format.
- Declare __weak to init_mmc, so user can override it.
- Some nitpicks fixed.
Patchset history
----------------
[v1]: https://www.mail-archive.com/u-boot at lists.denx.de/msg271905.html [v2]: https://www.mail-archive.com/u-boot at lists.denx.de/msg271979.html [v3]: https://www.mail-archive.com/u-boot at lists.denx.de/msg272039.html [v4]: https://www.mail-archive.com/u-boot at lists.denx.de/msg272432.html [v5]: https://www.mail-archive.com/u-boot at lists.denx.de/msg272771.html
Tien Fong Chee (3):
spl: Remove static declaration on spl_mmc_find_device function
cmd: ubifs: Move ubifs_initialized checking into cmd_ubifs_umount()
common: Generic firmware loader for file system
cmd/ubifs.c | 20 +-- common/Kconfig | 9 ++ common/Makefile | 1 + common/fs_loader.c | 326 +++++++++++++++++++++++++++++++++++++++++++++ common/spl/spl_mmc.c | 2 +- doc/README.firmware_loader | 76 +++++++++++ include/fs_loader.h | 28 ++++ include/spl.h | 2 + include/ubi_uboot.h | 1 + 9 files changed, 456 insertions(+), 9 deletions(-) create mode 100644 common/fs_loader.c create mode 100644 doc/README.firmware_loader create mode 100644 include/fs_loader.h
Signature · 1 line
2.2.0
PATCH v7 1/3 spl: Remove static declaration on spl_mmc_find_device function
From: Tien Fong Chee <[email protected]>
This patch removes the static declation on spl_mmc_find_device_function so this function is accessible by the caller from other file. This patch is required for later patch.
--- common/spl/spl_mmc.c | 2 +- include/spl.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
common/spl/spl_mmc.c +1 -1
@@ -114,7 +114,7 @@ static int spl_mmc_get_device_index(u32 boot_device)return -ENODEV ; } -static int spl_mmc_find_device (struct mmc **mmcp,u32 boot_device) +int spl_mmc_find_device (struct mmc **mmcp,u32 boot_device) {#if CONFIG_IS_ENABLED (DM_MMC )struct udevice *dev;
include/spl.h +2 -0
@@ -12,6 +12,7 @@/* Platform-specific defines */ #include <linux/compiler.h> #include <asm/spl.h> +#include <mmc.h> /* Value in r0 indicates we booted from U-Boot */ #define UBOOT_NOT_LOADED_FROM_SPL 0x13578642
@@ -83,6 +84,7 @@ void preloader_console_init(void);u32 spl_boot_device (void );u32 spl_boot_mode (const u32 boot_device);void spl_set_bd (void ); +int spl_mmc_find_device (struct mmc **mmcp,u32 boot_device);/** * spl_set_header_raw_uboot() - Set up a standard SPL image structure
Signature · 1 line
2.2.0
PATCH v7 2/3 cmd: ubifs: Move ubifs_initialized checking into cmd_ubifs_umount()
In reply to tien.fong.chee at intel.comFrom: Tien Fong Chee <[email protected]>
cmd_ubifs_umount() function would be called directly instead of involving whole command machinery in generic firmware loader, so checking on ubifs_initialized status need to be done in cmd_ubifs_umount() without breaking original functionality design.
--- cmd/ubifs.c | 20 ++++++++++++-------- include/ubi_uboot.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-)
cmd/ubifs.c +12 -8
@@ -51,27 +51,31 @@ int ubifs_is_mounted(void)return ubifs_mounted; } -void cmd_ubifs_umount (void ) +int cmd_ubifs_umount (void ) { +if (ubifs_initialized ==0 ) { +printf ("No UBIFS volume mounted!\n" ); +return -1 ; + } +uboot_ubifs_umount (); ubifs_mounted =0 ; ubifs_initialized =0 ; + +return 0 ; }static int do_ubifs_umount (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { +int ret; +if (argc !=1 )return CMD_RET_USAGE ; -if (ubifs_initialized ==0 ) { -printf ("No UBIFS volume mounted!\n" ); -return -1 ; - } - -cmd_ubifs_umount (); + ret =cmd_ubifs_umount (); -return 0 ; +return ret; } static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
include/ubi_uboot.h +1 -0
@@ -75,5 +75,6 @@ extern int ubi_volume_write(char *volume, void *buf, size_t size);extern int ubi_volume_read (char *volume,char *buf,size_t size);extern struct ubi_device *ubi_devices[]; +int cmd_ubifs_umount (void );#endif
Signature · 1 line
2.2.0
PATCH v7 2/3 cmd: ubifs: Move ubifs_initialized checking into cmd_ubifs_umount()
Quoted 41 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
cmd_ubifs_umount()function would be called directly instead of involving whole command machinery in generic firmware loader, so checking onubifs_initializedstatus need to be done incmd_ubifs_umount()without breaking original functionality design.--- cmd/ubifs.c | 20 ++++++++++++-------- include/ubi_uboot.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-)cmd/ubifs.c +10
-1@@ -51,27 +51,31 @@ int ubifs_is_mounted(void)return ubifs_mounted; } -void cmd_ubifs_umount (void ) +int cmd_ubifs_umount (void ) { +if (ubifs_initialized ==0 ) { +printf ("No UBIFS volume mounted!\n" ); +return -1 ; + } +uboot_ubifs_umount (); ubifs_mounted =0 ; ubifs_initialized =0 ; + +return 0 ; }static int do_ubifs_umount (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { +int ret; +
cmd/ubifs.c int ubifs_is_mounted(void) · line 76
Quoted 10 lines
cmd/ubifs.c +1
-6if (argc !=1 )return CMD_RET_USAGE ; -if (ubifs_initialized ==0 ) { -printf ("No UBIFS volume mounted!\n" ); -return -1 ; - } - -cmd_ubifs_umount (); + ret =cmd_ubifs_umount ();
return cmd_ubifs_umount() directly ?
Quoted 17 lines
cmd/ubifs.c +1
-1-return 0 ; +return ret; } static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,include/ubi_uboot.h +1
-0@@ -75,5 +75,6 @@ extern int ubi_volume_write(char *volume, void *buf, size_t size);extern int ubi_volume_read (char *volume,char *buf,size_t size);extern struct ubi_device *ubi_devices[]; +int cmd_ubifs_umount (void );#endif
Signature · 2 lines
Best regards, Marek Vasut
Chee
PATCH v7 2/3 cmd: ubifs: Move ubifs_initialized checking into cmd_ubifs_umount()
Quoted 49 lines · Marek Vasut
Quoted 48 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
cmd_ubifs_umount()function would be called directly instead of involving
whole command machinery in generic firmware loader, so checking onubifs_initializedstatus need to be done incmd_ubifs_umount()without
breaking original functionality design.Signed-off-by Tien Fong Chee <[email protected]>64db5518baa
2ea1a8a0e81cc485d760b850c7052
---
cmd/ubifs.c | 20 ++++++++++++--------
include/ubi_uboot.h | 1 +2 files changed, 13 insertions(+), 8 deletions(-)cmd/ubifs.c +0
-0@@ -51,27 +51,31 @@ int ubifs_is_mounted(void) return ubifs_mounted; }cmd/ubifs.c +1
-1-void cmd_ubifs_umount (void ) +int cmd_ubifs_umount (void ){
cmd/ubifs.c +5
-0+if (ubifs_initialized ==0 ) { +printf ("No UBIFS volume mounted!\n" ); +return -1 ; + } +
uboot_ubifs_umount();
ubifs_mounted= 0;
ubifs_initialized= 0;cmd/ubifs.c +2
-0+ +return 0 ;}
static intdo_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{cmd/ubifs.c +2
-0+int ret; +if (argc != 1)
returnCMD_RET_USAGE;
Quoted 9 lines
cmd/ubifs.c int ubifs_is_mounted(void) · line 76
Quoted 7 lines
cmd/ubifs.c +1
-6-if (ubifs_initialized ==0 ) { -printf ("No UBIFS volume mounted!\n" ); -return -1 ; - } - -cmd_ubifs_umount (); + ret =cmd_ubifs_umount ();return
cmd_ubifs_umount()directly ?
Okay.
Quoted 20 lines
Quoted 19 lines
cmd/ubifs.c +1
-1-return 0 ; +return ret;}
static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,include/ubi_uboot.h +0
-0@@ -75,5 +75,6 @@ extern int ubi_volume_write(char *volume, void *buf, size_t size); extern int ubi_volume_read(char *volume, char *buf, size_t size);
extern structubi_device*ubi_devices[];
+intcmd_ubifs_umount(void);
#endif
PATCH v7 3/3 common: Generic firmware loader for file system
In reply to tien.fong.chee at intel.comFrom: Tien Fong Chee <[email protected]>
This is file system generic loader which can be used to load the file image from the storage into target such as memory. The consumer driver would then use this loader to program whatever, ie. the FPGA device.
--- common/Kconfig | 9 ++ common/Makefile | 1 + common/fs_loader.c | 326 +++++++++++++++++++++++++++++++++++++++++++++ doc/README.firmware_loader | 76 +++++++++++ include/fs_loader.h | 28 ++++ 5 files changed, 440 insertions(+) create mode 100644 common/fs_loader.c create mode 100644 doc/README.firmware_loader create mode 100644 include/fs_loader.h
common/Kconfig +9 -0
@@ -547,6 +547,15 @@ config DISPLAY_BOARDINFO when U-Boot starts up. The board function checkboard() is called to do this. +config GENERIC_FIRMWARE_LOADER + bool "Enable generic firmware loader driver for file system" + help + This is file system generic loader which can be used to load + the file image from the storage into target such as memory. + + The consumer driver would then use this loader to program whatever, + ie. the FPGA device. + menu "Start-up hooks" config ARCH_EARLY_INIT_R
common/Makefile +1 -0
@@ -134,3 +134,4 @@ obj-$(CONFIG_$(SPL_)LOG) += log.o obj-$(CONFIG_$(SPL_)LOG_CONSOLE) += log_console.o obj-y += s_record.o obj-y += xyzModem.o +obj-$(CONFIG_GENERIC_FIRMWARE_LOADER) += fs_loader.o
common/fs_loader.c new file +326 -0
326 lines not on this page · raw message
doc/README.firmware_loader new file +76 -0
76 lines not on this page · raw message
include/fs_loader.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 2018 Intel Corporation <www.intel.com> +* +* SPDX-License-Identifier: GPL-2.0 +*/ +#ifndef _FS_LOADER_H_ +#define _FS_LOADER_H_ + +#include <linux/types.h> + +struct firmware { +size_t size;/* Size of a file */ +const u8 *data;/* Buffer for file */ +void *priv;/* Firmware loader private fields */ +}; + +struct device_location { +char *name;/* Such as mmc, usb,and sata. */ +char *devpart;/* Use the load command dev:part conventions */ +char *mtdpart;/* MTD partition for ubi part */ +char *ubivol;/* UBI volume-name for ubifsmount */ +}; + +int request_firmware_into_buf (struct firmware **firmware_p, +const char *name, +struct device_location *location, +void *buf,size_t size,u32 offset); +#endif
Signature · 1 line
2.2.0
PATCH v7 3/3 common: Generic firmware loader for file system
Quoted 19 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
This is file system generic loader which can be used to load the file image from the storage into target such as memory. The consumer driver would then use this loader to program whatever, ie. the FPGA device.
Signed-off-by Tien Fong Chee <[email protected]>Reviewed-by Lothar Waßmann <[email protected]>--- common/Kconfig | 9 ++ common/Makefile | 1 + common/fs_loader.c | 326 +++++++++++++++++++++++++++++++++++++++++++++ doc/README.firmware_loader | 76 +++++++++++ include/fs_loader.h | 28 ++++ 5 files changed, 440 insertions(+) create mode 100644 common/fs_loader.c create mode 100644 doc/README.firmware_loader create mode 100644 include/fs_loader.h
[...]
common/fs_loader.c line 94
Quoted 10 lines
common/fs_loader.c new file +10
-0+#ifdef CONFIG_CMD_UBIFS +static int mount_ubifs (struct device_location *location) +{ +int ret; +char cmd[32 ]; + +snprintf (cmd,sizeof (location->mtdpart),"ubi part %s" , + location->mtdpart); + + ret =run_command (cmd,0 );
Can you call the UBI functions directly instead of invoking the U-Boot command parser ?
common/fs_loader.c line 101
Quoted 7 lines
common/fs_loader.c new file +7
-0+if (ret) +return ret; + +snprintf (cmd,sizeof (location->ubivol),"ubifsmount %s" , + location->ubivol); + + ret =run_command (cmd,0 );
DTTO here ...
Quoted 14 lines
common/fs_loader.c new file +14
-0+ return ret; +} + +static int umount_ubifs (void ) +{ +return cmd_ubifs_umount (); +} +#else +static int mount_ubifs (struct device_location *location) +{ +debug ("Error: Cannot load image: no UBIFS support\n" ); +return -ENOSYS ; +} +#endif
[...]
Signature · 2 lines
Best regards, Marek Vasut
Chee
PATCH v7 3/3 common: Generic firmware loader for file system
Quoted 25 lines · Marek Vasut
Quoted 21 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
This is file system generic loader which can be used to load the file image from the storage into target such as memory. The consumer driver would then use this loader to program whatever, ie. the FPGA device.
Signed-off-by Tien Fong Chee <[email protected]>Reviewed-by Lothar Waßmann <[email protected]>---
common/Kconfig | 9 ++
common/Makefile | 1 +
common/fs_loader.c | 326
+++++++++++++++++++++++++++++++++++++++++++++
doc/README.firmware_loader | 76 +++++++++++
include/fs_loader.h | 28 ++++5 files changed, 440 insertions(+)create mode 100644
common/fs_loader.c
create mode 100644 doc/README.firmware_loader
create mode 100644include/fs_loader.h[...]
Quoted 1 line
Quoted 14 lines
common/fs_loader.c line 94
Quoted 10 lines
common/fs_loader.c new file +10
-0+#ifdef CONFIG_CMD_UBIFS +static int mount_ubifs (struct device_location *location) +{ +int ret; +char cmd[32 ]; + +snprintf (cmd,sizeof (location->mtdpart),"ubi part %s" , + location->mtdpart); + + ret =run_command (cmd,0 );Can you call the UBI functions directly instead of invoking the U- Boot
command parser ?
Okay.
Quoted 10 lines
common/fs_loader.c line 101
Quoted 8 lines
common/fs_loader.c new file +7
-0+if (ret) +return ret; + +snprintf (cmd,sizeof (location->ubivol),"ubifsmount %s" , + location->ubivol); + + ret =run_command (cmd,0 );DTTO here ...
Okay.
Could i submit the next version immediately for this minor change?
Quoted 16 lines
Quoted 15 lines
common/fs_loader.c new file +14
-0+ return ret; +} + +static int umount_ubifs (void ) +{ +return cmd_ubifs_umount (); +} +#else +static int mount_ubifs (struct device_location *location) +{ +debug ("Error: Cannot load image: no UBIFS support\n" ); +return -ENOSYS ; +} +#endif [...]
PATCH v7 3/3 common: Generic firmware loader for file system
Quoted 51 lines · Tien Fong
Quoted 25 lines · Marek Vasut
Quoted 21 lines · tien.fong.chee at intel.com
From: Tien Fong Chee <[email protected]>
This is file system generic loader which can be used to load the file image from the storage into target such as memory. The consumer driver would then use this loader to program whatever, ie. the FPGA device.
Signed-off-by Tien Fong Chee <[email protected]>Reviewed-by Lothar Waßmann <[email protected]>---
common/Kconfig | 9 ++
common/Makefile | 1 +
common/fs_loader.c | 326
+++++++++++++++++++++++++++++++++++++++++++++
doc/README.firmware_loader | 76 +++++++++++
include/fs_loader.h | 28 ++++5 files changed, 440 insertions(+)create mode 100644
common/fs_loader.c
create mode 100644 doc/README.firmware_loader
create mode 100644include/fs_loader.h[...]
Quoted 1 line
Quoted 14 lines
common/fs_loader.c line 94
Quoted 10 lines
common/fs_loader.c new file +10
-0+#ifdef CONFIG_CMD_UBIFS +static int mount_ubifs (struct device_location *location) +{ +int ret; +char cmd[32 ]; + +snprintf (cmd,sizeof (location->mtdpart),"ubi part %s" , + location->mtdpart); + + ret =run_command (cmd,0 );Can you call the UBI functions directly instead of invoking the U- Boot
command parser ?Okay.
Quoted 10 lines
common/fs_loader.c line 101
Quoted 8 lines
common/fs_loader.c new file +7
-0+if (ret) +return ret; + +snprintf (cmd,sizeof (location->ubivol),"ubifsmount %s" , + location->ubivol); + + ret =run_command (cmd,0 );DTTO here ...
Quoted 3 lines
Okay.
Could i submit the next version immediately for this minor change?
Wait a bit for some further feedback. Also make sure to go through the patchset one more time and see if there aren't any similar mistakes.
Signature · 2 lines
Best regards, Marek Vasut