Skip to contentSkip to conversation

Generic firmware loader

PATCH Superseded tien.fong.chee at intel.com 4 participants 7 messages Dec 11, 2017 – Dec 12, 2017

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

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 series is working on top of u-boot-socfpga.git -
http://git.denx.de/u-boot-socfpga.git .

Tien Fong Chee (2):
arm: socfpga: Remove static declaration on spl_mmc_find_device
function
common: Generic firmware loader for file system

 common/Makefile      |   1 +
 common/fs_loader.c   | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/spl/spl_mmc.c |   2 +-
 include/fs_loader.h  |  30 ++++++
 include/spl.h        |   2 +
 5 files changed, 333 insertions(+), 1 deletion(-)
 create mode 100644 common/fs_loader.c
 create mode 100644 include/fs_loader.h
Signature · 1 line
2.2.0
#1 lore raw

PATCH 1/2 arm: socfpga: 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
index b57e0b0..183d05a 100644
@@ -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
index 308ce7b..912983a 100644
@@ -10,6 +10,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
@@ -72,6 +73,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
#2 lore raw

PATCH 1/2 arm: socfpga: Remove static declaration on spl_mmc_find_device function

Quoted 1 line · tien.fong.chee at intel.com

From: Tien Fong Chee <[email protected]>

So the tags would imply this has a lot to do with SoCFPGA, but this is not touching any file in the SoCFPGA. The tags are thus completely bogus.

Quoted 44 lines

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
index b57e0b0..183d05a 100644
@@ -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
index 308ce7b..912983a 100644
@@ -10,6 +10,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
@@ -72,6 +73,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 · 2 lines
Best regards,
Marek Vasut
#3 lore raw

PATCH 1/2 arm: socfpga: Remove static declaration on spl_mmc_find_device function

Quoted 8 lines · Marek Vasut
Quoted 2 lines · tien.fong.chee at intel.com

From: Tien Fong Chee <[email protected]>

So the tags would imply this has a lot to do with SoCFPGA, but this is
not touching any file in the SoCFPGA. The tags are thus completely bogus.

Opps...sorry, i forgot to remove the socfpga tag. I would fix it.

Quoted 50 lines
Quoted 49 lines

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 +0 -0
index b57e0b0..183d05a 100644
@@ -114,7 +114,7 @@ static int spl_mmc_get_device_index(u32
 boot_device)
  	return -ENODEV;
  }

common/spl/spl_mmc.c +1 -1
-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 +1 -0
index 308ce7b..912983a 100644
@@ -10,6 +10,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

include/spl.h +1 -0
@@ -72,6 +73,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

#4 lore raw

PATCH 2/2 common: Generic firmware loader for file system

In reply to 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.

---
 common/Makefile     |   1 +
 common/fs_loader.c  | 299 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fs_loader.h |  30 ++++++
 3 files changed, 330 insertions(+)
 create mode 100644 common/fs_loader.c
 create mode 100644 include/fs_loader.h
common/Makefile +1 -0
index cec506f..2934221 100644
@@ -130,3 +130,4 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-y += command.o
 obj-y += s_record.o
 obj-y += xyzModem.o
+obj-y += fs_loader.o
common/fs_loader.c new file +299 -0

299 lines not on this page · raw message

include/fs_loader.h new file +30 -0
new file mode 100644
index 0000000..dacc1f3
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017 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 */
+	const char *name;	/* Filename */
+	u32 offset;		/* Offset of reading a 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
#5 lore raw

PATCH 2/2 common: Generic firmware loader for file system

Hi,

Quoted 2 lines · On Mon, 11 Dec 2017 18:53:46 +0800 tien.fong.chee at intel.com wrote:

From: Tien Fong Chee <[email protected]>

[...}

common/fs_loader.c line 203

Quoted 13 lines
common/fs_loader.c new file +12 -0
+/*
+ * Prepare firmware struct;
+ * return -ve if fail.
+ */
+static int _request_firmware_prepare(struct firmware **firmware_p,
+				     const char *name, void *dbuf,
+				     size_t size, u32 offset)
+{
+	struct firmware *firmware = NULL;
+	int ret = 0;
+
+	*firmware_p = NULL;

Sigh. This is useless...

common/fs_loader.c line 207

Quoted 3 lines
common/fs_loader.c new file +3 -0
+	if (!name || name[0] == '\0')
+		ret = -EINVAL;
+

unless you do a 'return -EINVAL' here!

Quoted 5 lines
common/fs_loader.c new file +5 -0
+	*firmware_p = firmware = calloc(1, sizeof(*firmware));
+
+	if (!firmware) {
+		printf("%s: calloc(struct firmware) failed\n", __func__);
+		return -ENOMEM;

common/fs_loader.c line 222

Quoted 10 lines
common/fs_loader.c new file +10 -0
+	}
+
+	firmware->name = name;
+	firmware->data = dbuf;
+	firmware->size = size;
+	firmware->offset = offset;
+
+	return ret;
+}
+

Lothar Waßmann

#6 lore raw

PATCH 2/2 common: Generic firmware loader for file system

Quoted 23 lines · Lothar Waßmann

Hi,

Quoted 3 lines · On Mon, 11 Dec 2017 18:53:46 +0800 tien.fong.chee at intel.com wrote:

From: Tien Fong Chee <[email protected]>

[...}

Quoted 4 lines
common/fs_loader.c new file +2 -0
+/*
+ * Prepare firmware struct;

common/fs_loader.c line 203

Quoted 10 lines
common/fs_loader.c new file +10 -0
+ * return -ve if fail.
+ */
+static int _request_firmware_prepare(struct firmware **firmware_p,
+				     const char *name, void *dbuf,
+				     size_t size, u32 offset)
+{
+	struct firmware *firmware = NULL;
+	int ret = 0;
+
+	*firmware_p = NULL;

Sigh. This is useless...

Quoted 1 line
Quoted 5 lines

common/fs_loader.c line 207

Quoted 3 lines
common/fs_loader.c new file +3 -0
+	if (!name || name[0] == '\0')
+		ret = -EINVAL;
+

unless you do a 'return -EINVAL' here!

You are right, i missed to change this to return. I would fix it.

Quoted 19 lines
Quoted 7 lines
common/fs_loader.c new file +4 -0
+	*firmware_p = firmware = calloc(1, sizeof(*firmware));
+
+	if (!firmware) {
+		printf("%s: calloc(struct firmware) failed\n",

__func__);

common/fs_loader.c new file +1 -0
+		return -ENOMEM;

common/fs_loader.c line 222

Quoted 10 lines
common/fs_loader.c new file +10 -0
+	}
+
+	firmware->name = name;
+	firmware->data = dbuf;
+	firmware->size = size;
+	firmware->offset = offset;
+
+	return ret;
+}
+

Lothar Waßmann