From patchwork Sun Jan 17 03:13:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 569212 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 884D314032F for ; Sun, 17 Jan 2016 14:14:12 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0FD5BA77EE; Sun, 17 Jan 2016 04:14:11 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9WOiP7v1L6bg; Sun, 17 Jan 2016 04:14:10 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 74586A756B; Sun, 17 Jan 2016 04:14:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A9BF2A758E for ; Sun, 17 Jan 2016 04:14:07 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1FEYfJ5O3zh7 for ; Sun, 17 Jan 2016 04:14:07 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from cvs.linux-mips.org (eddie.linux-mips.org [148.251.95.138]) by theia.denx.de (Postfix) with ESMTP id 7A668A7553 for ; Sun, 17 Jan 2016 04:14:06 +0100 (CET) Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S27006150AbcAQDOGIU7uD (ORCPT ); Sun, 17 Jan 2016 04:14:06 +0100 Date: Sun, 17 Jan 2016 04:13:58 +0100 From: Ladislav Michl To: u-boot@lists.denx.de Message-ID: <20160117031358.GE28493@localhost.localdomain> References: <20160117030929.GA28493@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160117030929.GA28493@localhost.localdomain> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: Scott Wood , Tom Rini , Richard Weinberger Subject: [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add support for loading from UBI volumes on the top of NAND. Signed-off-by: Ladislav Michl Reviewed-by: Heiko Schocher --- 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 + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +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);