All of lore.kernel.org
 help / color / mirror / Atom feed
From: tien.fong.chee at intel.com <tien.fong.chee@intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 06/20] common: Generic firmware loader for file system
Date: Fri, 13 Oct 2017 16:08:43 +0800	[thread overview]
Message-ID: <1507882137-27841-7-git-send-email-tien.fong.chee@intel.com> (raw)
In-Reply-To: <1507882137-27841-1-git-send-email-tien.fong.chee@intel.com>

From: Tien Fong Chee <tien.fong.chee@intel.com>

Generic firmware loader framework contains some common functionality
which is reusable by any specific file system firmware loader.

Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
---
 common/Makefile   |   2 +
 common/load_fs.c  | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/load_fs.h |  40 ++++++++++++++
 3 files changed, 205 insertions(+)
 create mode 100644 common/load_fs.c
 create mode 100644 include/load_fs.h

diff --git a/common/Makefile b/common/Makefile
index 801ea31..0e591c0 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -130,3 +130,5 @@ obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-y += command.o
 obj-y += s_record.o
 obj-y += xyzModem.o
+
+obj-y += load_fs.o
diff --git a/common/load_fs.c b/common/load_fs.c
new file mode 100644
index 0000000..9f9ca88
--- /dev/null
+++ b/common/load_fs.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2017 Intel Corporation <www.intel.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <fs.h>
+#include <fdt_support.h>
+#include <load_fs.h>
+#include <nand.h>
+#include <sata.h>
+#include <spi.h>
+#include <spi_flash.h>
+#include <usb.h>
+
+int flash_select_fs_dev(struct flash_location *location)
+{
+	int res;
+
+	switch (location->storage) {
+	case FLASH_STORAGE_MMC:
+		res = fs_set_blk_dev("mmc", location->devpart, FS_TYPE_ANY);
+		break;
+	case FLASH_STORAGE_USB:
+		res = fs_set_blk_dev("usb", location->devpart, FS_TYPE_ANY);
+		break;
+	case FLASH_STORAGE_SATA:
+		res = fs_set_blk_dev("sata", location->devpart, FS_TYPE_ANY);
+		break;
+	case FLASH_STORAGE_NAND:
+		if (location->ubivol != NULL)
+			res = fs_set_blk_dev("ubi", NULL, FS_TYPE_UBIFS);
+		else
+			res = -ENODEV;
+		break;
+	default:
+		printf("Error: unsupported location storage.\n");
+		return -ENODEV;
+	}
+
+	if (res)
+		printf("Error: could not access storage.\n");
+
+	return res;
+}
+#ifndef CONFIG_SPL_BUILD
+#ifdef CONFIG_USB_STORAGE
+static int flash_init_usb(void)
+{
+	int err;
+
+	err = usb_init();
+	if (err)
+		return err;
+
+#ifndef CONFIG_DM_USB
+	err = usb_stor_scan(1) < 0 ? -ENODEV : 0;
+#endif
+
+	return err;
+}
+#else
+static inline int flash_init_usb(void)
+{
+	printf("Cannot load flash image: no USB support\n");
+	return -ENOSYS;
+}
+#endif
+#endif
+
+#ifdef CONFIG_SATA
+static int flash_init_sata(void)
+{
+	return sata_probe(0);
+}
+#else
+static inline int flash_init_sata(void)
+{
+	printf("Cannot load flash image: no SATA support\n");
+	return -ENOSYS;
+}
+#endif
+
+#ifdef CONFIG_CMD_UBIFS
+static int flash_mount_ubifs(struct flash_location *location)
+{
+	int res;
+	char cmd[32];
+
+	sprintf(cmd, "ubi part %s", location->mtdpart);
+	res = run_command(cmd, 0);
+	if (res)
+		return res;
+
+	sprintf(cmd, "ubifsmount %s", location->ubivol);
+	res = run_command(cmd, 0);
+
+	return res;
+}
+
+static inline int flash_umount_ubifs(void)
+{
+	return run_command("ubifsumount", 0);
+}
+#else
+static inline int flash_mount_ubifs(struct flash_location *location)
+{
+	printf("Cannot load flash image: no UBIFS support\n");
+	return -ENOSYS;
+}
+
+static inline int flash_umount_ubifs(void)
+{
+	printf("Cannot unmount UBIFS: no UBIFS support\n");
+	return -ENOSYS;
+}
+#endif
+
+__weak char *get_file(void *file_info)
+{
+	return NULL;
+}
+
+__weak int fs_loading(void *file_info, const void *load_addr, size_t bsize)
+{
+	return 0;
+}
+
+int load_fs(struct flash_location *location, void *file_info,
+		const void *load_addr, size_t bsize)
+{
+	int res = 0;
+	char *flash_file;
+
+	flash_file = get_file(file_info);
+	if (!flash_file) {
+		printf("no filename specified.\n");
+		return -EINVAL;
+	}
+
+#ifndef CONFIG_SPL_BUILD
+	if (location->storage == FLASH_STORAGE_USB)
+		res = flash_init_usb();
+#endif
+
+	if (location->storage == FLASH_STORAGE_SATA)
+		res = flash_init_sata();
+
+	if (location->ubivol != NULL)
+		res = flash_mount_ubifs(location);
+
+	if (res)
+		return res;
+
+	res = fs_loading(file_info, load_addr, bsize);
+
+	if (location->ubivol != NULL)
+		flash_umount_ubifs();
+
+	return res;
+}
diff --git a/include/load_fs.h b/include/load_fs.h
new file mode 100644
index 0000000..a26d630
--- /dev/null
+++ b/include/load_fs.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 Intel Corporation <www.intel.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+
+#ifndef _LOAD_FS_H_
+#define _LOAD_FS_H_
+
+#include <errno.h>
+
+enum flash_storage {
+	FLASH_STORAGE_NAND,
+	FLASH_STORAGE_SF,
+	FLASH_STORAGE_MMC,
+	FLASH_STORAGE_USB,
+	FLASH_STORAGE_SATA,
+};
+
+enum flash_flags {
+	FLASH_STORAGE_RAW, /* Stored in raw memory */
+	FLASH_STORAGE_FS,  /* Stored within a file system */
+	FLASH_STORAGE_FIT, /* Stored inside a FIT image */
+};
+
+struct flash_location {
+	char *name;
+	enum flash_storage storage;
+	enum flash_flags flags;
+	u32 offset;	/* offset from start of storage */
+	char *devpart;  /* Use the load command dev:part conventions */
+	char *mtdpart;	/* MTD partition for ubi part */
+	char *ubivol;	/* UBI volume-name for ubifsmount */
+};
+
+int load_fs(struct flash_location *location, void *file_info,
+				const void *load_addr, size_t bsize);
+int flash_select_fs_dev(struct flash_location *location);
+#endif
-- 
2.2.0

  parent reply	other threads:[~2017-10-13  8:08 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13  8:08 [U-Boot] [PATCH v3 00/20] Add FPGA, SDRAM, SPL loadfs U-boot & booting to console tien.fong.chee at intel.com
2017-10-13  8:08 ` [U-Boot] [PATCH v3 01/20] ARM: socfpga: Description on FPGA RBF properties at Arria 10 FPGA manager tien.fong.chee at intel.com
2017-10-13  8:08 ` [U-Boot] [PATCH v3 02/20] dts: Add FPGA bitstream properties to Arria 10 DTS tien.fong.chee at intel.com
2017-10-13  8:08 ` [U-Boot] [PATCH v3 03/20] arm: socfpga: Add Arria 10 SoCFPGA programming interface tien.fong.chee at intel.com
2017-10-16 12:39   ` Dinh Nguyen
2017-10-23  6:46     ` Chee, Tien Fong
2017-10-23  7:04   ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 04/20] dts: Enable fpga-mgr node build for Arria 10 SPL tien.fong.chee at intel.com
2017-10-13  8:08 ` [U-Boot] [PATCH v3 05/20] fs: Enable generic filesystems interface support in SPL tien.fong.chee at intel.com
2017-10-13  8:08 ` tien.fong.chee at intel.com [this message]
2017-10-16 14:08   ` [U-Boot] [PATCH v3 06/20] common: Generic firmware loader for file system Dinh Nguyen
2017-10-16 14:41     ` Marek Vasut
2017-10-23  6:37       ` Chee, Tien Fong
2017-10-26 12:51         ` Lukasz Majewski
2017-10-27  9:23           ` Chee, Tien Fong
2017-10-27 10:35             ` Lukasz Majewski
2017-10-28 11:32               ` Marek Vasut
2017-10-28 21:43                 ` Lukasz Majewski
2017-10-29  9:35                   ` Marek Vasut
2017-10-29 22:57                     ` Lukasz Majewski
2017-10-29 22:59                       ` Marek Vasut
2017-10-13  8:08 ` [U-Boot] [PATCH v3 07/20] arm: socfpga: Fix with the correct polling status bit tien.fong.chee at intel.com
2017-10-16 15:29   ` Dinh Nguyen
2017-10-23  6:49     ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 08/20] arm: socfpga: Add drivers for programing FPGA from flash tien.fong.chee at intel.com
2017-10-16 15:33   ` Dinh Nguyen
2017-10-24  5:52     ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 09/20] arm: socfpga: Rename the gen5 sdram driver to more specific name tien.fong.chee at intel.com
2017-10-13  8:08 ` [U-Boot] [PATCH v3 10/20] arm: socfpga: Add DRAM bank size initialization function tien.fong.chee at intel.com
2017-10-13  8:08 ` [U-Boot] [PATCH v3 11/20] arm: socfpga: Add DDR driver for Arria 10 tien.fong.chee at intel.com
2017-10-17  3:08   ` Dinh Nguyen
2017-10-23  7:45     ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 12/20] configs: Add DDR Kconfig support " tien.fong.chee at intel.com
2017-10-17  3:21   ` Dinh Nguyen
2017-10-13  8:08 ` [U-Boot] [PATCH v3 13/20] arm: socfpga: Enable SPL memory allocation tien.fong.chee at intel.com
2017-10-17  3:44   ` Dinh Nguyen
2017-10-13  8:08 ` [U-Boot] [PATCH v3 14/20] arm: socfpga: Improve comments for Intel SoCFPGA program header tien.fong.chee at intel.com
2017-10-20 14:18   ` Dinh Nguyen
2017-10-13  8:08 ` [U-Boot] [PATCH v3 15/20] arm: socfpga: Enhance Intel SoCFPGA program header to support Arria 10 tien.fong.chee at intel.com
2017-10-20 14:19   ` Dinh Nguyen
2017-10-13  8:08 ` [U-Boot] [PATCH v3 16/20] arm: socfpga: Adding clock frequency info for U-boot tien.fong.chee at intel.com
2017-10-20 14:29   ` Dinh Nguyen
2017-10-23  8:02     ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 17/20] arm: socfpga: Adding SoCFPGA info for both SPL and U-boot tien.fong.chee at intel.com
2017-10-20 14:33   ` Dinh Nguyen
2017-10-23  8:13     ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 18/20] arm: socfpga: Enable function visible to other file tien.fong.chee at intel.com
2017-10-20 14:39   ` Dinh Nguyen
2017-10-23  8:19     ` Chee, Tien Fong
2017-10-23 14:24       ` Dinh Nguyen
2017-10-24  5:11         ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 19/20] arm: socfpga: Enable DDR working tien.fong.chee at intel.com
2017-10-20 15:11   ` Dinh Nguyen
2017-10-24  5:34     ` Chee, Tien Fong
2017-10-13  8:08 ` [U-Boot] [PATCH v3 20/20] arm: socfpga: Enable SPL booting U-boot tien.fong.chee at intel.com
2017-10-20 15:21   ` Dinh Nguyen
2017-10-24  5:37     ` Chee, Tien Fong

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=1507882137-27841-7-git-send-email-tien.fong.chee@intel.com \
    --to=tien.fong.chee@intel.com \
    --cc=u-boot@lists.denx.de \
    /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.