From: Ladislav Michl <ladis@linux-mips.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes
Date: Sun, 17 Jan 2016 04:13:58 +0100 [thread overview]
Message-ID: <20160117031358.GE28493@localhost.localdomain> (raw)
In-Reply-To: <20160117030929.GA28493@localhost.localdomain>
Add support for loading from UBI volumes on the top of NAND.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
common/spl/Makefile | 3 +++
common/spl/spl.c | 4 ++++
common/spl/spl_ubi.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/spl.h | 4 ++++
4 files changed, 79 insertions(+)
create mode 100644 common/spl/spl_ubi.c
diff --git a/common/spl/Makefile b/common/spl/Makefile
index 10a4589..36e5338 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -12,8 +12,11 @@ ifdef CONFIG_SPL_BUILD
obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
obj-$(CONFIG_SPL_NOR_SUPPORT) += spl_nor.o
obj-$(CONFIG_SPL_YMODEM_SUPPORT) += spl_ymodem.o
+ifndef CONFIG_SPL_UBI
obj-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
+endif
obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o
+obj-$(CONFIG_SPL_UBI) += spl_ubi.o
obj-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o
obj-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o
obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o
diff --git a/common/spl/spl.c b/common/spl/spl.c
index e5167bf..b945a48 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -288,8 +288,12 @@ static int spl_load_image(u32 boot_device)
#endif
#ifdef CONFIG_SPL_NAND_SUPPORT
case BOOT_DEVICE_NAND:
+#ifdef CONFIG_SPL_UBI
+ return spl_ubi_load_image(boot_device);
+#else
return spl_nand_load_image();
#endif
+#endif
#ifdef CONFIG_SPL_ONENAND_SUPPORT
case BOOT_DEVICE_ONENAND:
return spl_onenand_load_image();
diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c
new file mode 100644
index 0000000..dd8ce36
--- /dev/null
+++ b/common/spl/spl_ubi.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016
+ * Ladislav Michl <ladis@linux-mips.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <config.h>
+#include <nand.h>
+#include <ubispl.h>
+#include <spl.h>
+
+int spl_ubi_load_image(u32 boot_device)
+{
+ int ret;
+ struct image_header *header;
+ struct ubispl_info info;
+ struct ubispl_load volumes[2];
+
+#ifdef CONFIG_SPL_NAND_SUPPORT
+ if (boot_device == BOOT_DEVICE_NAND)
+ nand_init();
+#endif
+ info.ubi = (struct ubi_scan_info *) CONFIG_SPL_UBI_INFO_ADDR;
+ info.fastmap = 1;
+ info.read = nand_spl_read_block;
+
+ info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET;
+ info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
+ info.vid_offset = CONFIG_SPL_UBI_VID_OFFSET;
+ info.leb_start = CONFIG_SPL_UBI_LEB_START;
+ info.peb_count = CONFIG_SPL_UBI_MAX_PEBS - info.peb_offset;
+
+#ifdef CONFIG_SPL_OS_BOOT
+ if (!spl_start_uboot()) {
+ volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_KERNEL_ID;
+ volumes[0].load_addr = (void *)CONFIG_SYS_LOAD_ADDR;
+ volumes[1].vol_id = CONFIG_SPL_UBI_LOAD_ARGS_ID;
+ volumes[1].load_addr = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
+
+ ret = ubispl_load_volumes(&info, volumes, 2);
+ if (!ret) {
+ header = (struct image_header *) volumes[0].load_addr;
+ spl_parse_image_header(header);
+ puts("Linux loaded.\n");
+ goto out;
+ }
+ puts("Loading Linux failed, falling back to U-Boot.\n");
+ }
+#endif
+ header = (struct image_header *)
+ (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
+ volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
+ volumes[0].load_addr = (void *)header;
+
+ ret = ubispl_load_volumes(&info, volumes, 1);
+ if (!ret)
+ spl_parse_image_header(header);
+#ifdef CONFIG_SPL_OS_BOOT
+out:
+#endif
+#ifdef CONFIG_SPL_NAND_SUPPORT
+ if (boot_device == BOOT_DEVICE_NAND)
+ nand_deselect();
+#endif
+ return ret;
+}
diff --git a/include/spl.h b/include/spl.h
index 92cdc04..1ab9295 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -40,6 +40,7 @@ u32 spl_boot_mode(void);
void spl_set_header_raw_uboot(void);
void spl_parse_image_header(const struct image_header *header);
void spl_board_prepare_for_linux(void);
+int spl_board_ubi_load_image(u32 boot_device);
void __noreturn jump_to_image_linux(void *arg);
int spl_start_uboot(void);
void spl_display_print(void);
@@ -53,6 +54,9 @@ int spl_onenand_load_image(void);
/* NOR SPL functions */
int spl_nor_load_image(void);
+/* UBI SPL functions */
+int spl_ubi_load_image(u32 boot_device);
+
/* MMC SPL functions */
int spl_mmc_load_image(u32 boot_device);
--
2.1.4
next prev parent reply other threads:[~2016-01-17 3:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-17 3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-17 3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
2016-01-21 6:04 ` Heiko Schocher
2016-01-17 3:12 ` [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function Ladislav Michl
2016-01-21 6:05 ` Heiko Schocher
2016-01-17 3:13 ` [U-Boot] [PATCHv4 3/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-17 3:13 ` Ladislav Michl [this message]
2016-01-21 6:06 ` [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes Heiko Schocher
2016-01-17 3:15 ` [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode Ladislav Michl
2016-01-21 6:07 ` Heiko Schocher
2016-01-17 3:16 ` [U-Boot] [PATCHv7 6/7] igep00x0: UBIize Ladislav Michl
2016-01-21 6:07 ` Heiko Schocher
2016-01-22 22:35 ` Enric Balletbo Serra
2016-01-24 13:44 ` Ladislav Michl
2016-01-25 6:39 ` Heiko Schocher
2016-01-25 7:26 ` Enric Balletbo Serra
2016-01-25 8:13 ` Heiko Schocher
2016-01-25 15:56 ` Ladislav Michl
2016-01-25 16:56 ` Enric Balletbo Serra
2016-04-13 5:19 ` Heiko Schocher
2016-04-13 11:39 ` Enric Balletbo Serra
2016-04-19 10:15 ` Enric Balletbo Serra
2016-06-04 20:48 ` [U-Boot] [RFC] runtime mtdparts_default; was: " Ladislav Michl
2016-01-25 15:13 ` [U-Boot] [PATCHv7 6/7] " Tom Rini
2016-01-25 15:35 ` Heiko Schocher
2016-01-17 3:16 ` [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode Ladislav Michl
2016-01-21 6:08 ` Heiko Schocher
2016-01-22 22:38 ` Enric Balletbo Serra
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=20160117031358.GE28493@localhost.localdomain \
--to=ladis@linux-mips.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox