From patchwork Tue Jul 12 18:28:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 647539 X-Patchwork-Delegate: trini@ti.com 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 3rpr932wfzz9s6r for ; Wed, 13 Jul 2016 04:29:42 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C9BD5A756D; Tue, 12 Jul 2016 20:29:24 +0200 (CEST) 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 lbuetbKUFHSr; Tue, 12 Jul 2016 20:29:24 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AE47BA757A; Tue, 12 Jul 2016 20:29:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BCDDAA7576 for ; Tue, 12 Jul 2016 20:29:03 +0200 (CEST) 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 fNnqFccZoiQ5 for ; Tue, 12 Jul 2016 20:29:03 +0200 (CEST) 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 363D2A74E0 for ; Tue, 12 Jul 2016 20:29:00 +0200 (CEST) Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992616AbcGLS3ABJvfj for ; Tue, 12 Jul 2016 20:29:00 +0200 From: Ladislav Michl To: u-boot@lists.denx.de Date: Tue, 12 Jul 2016 20:28:13 +0200 Message-Id: <1468348114-11442-6-git-send-email-ladis@linux-mips.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1468348114-11442-1-git-send-email-ladis@linux-mips.org> References: <1468348114-11442-1-git-send-email-ladis@linux-mips.org> Cc: Tom Rini , Richard Weinberger , Scott Wood , Enric Balletbo i Serra Subject: [U-Boot] [PATCH v5 05/26] 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add support for loading from UBI volumes on the top of NAND and OneNAND. Signed-off-by: Ladislav Michl Reviewed-by: Heiko Schocher --- Changes in v5: - dual license GPL/BSD Changes in v4: None Changes in v3: None Changes in v2: None common/spl/Makefile | 3 ++ common/spl/spl.c | 6 ++++ common/spl/spl_ubi.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/spl.h | 4 +++ 4 files changed, 91 insertions(+) create mode 100644 common/spl/spl_ubi.c diff --git a/common/spl/Makefile b/common/spl/Makefile index 2e0f695..b15f0f6 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -13,8 +13,11 @@ obj-$(CONFIG_SPL_FRAMEWORK) += spl.o obj-$(CONFIG_SPL_LOAD_FIT) += spl_fit.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 obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o +endif +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 840910a..ef113f6 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -330,6 +330,11 @@ static int spl_load_image(u32 boot_device) case BOOT_DEVICE_MMC2_2: return spl_mmc_load_image(boot_device); #endif +#ifdef CONFIG_SPL_UBI + case BOOT_DEVICE_NAND: + case BOOT_DEVICE_ONENAND: + return spl_ubi_load_image(boot_device); +#else #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND: return spl_nand_load_image(); @@ -338,6 +343,7 @@ static int spl_load_image(u32 boot_device) case BOOT_DEVICE_ONENAND: return spl_onenand_load_image(); #endif +#endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR: return spl_nor_load_image(); diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c new file mode 100644 index 0000000..f97e1ef --- /dev/null +++ b/common/spl/spl_ubi.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2016 + * Ladislav Michl + * + * SPDX-License-Identifier: GPL 2.0+ BSD-3-Clause + */ + +#include +#include +#include +#include +#include +#include + +int spl_ubi_load_image(u32 boot_device) +{ + struct image_header *header; + struct ubispl_info info; + struct ubispl_load volumes[2]; + int ret = 1; + + switch (boot_device) { +#ifdef CONFIG_SPL_NAND_SUPPORT + case BOOT_DEVICE_NAND: + nand_init(); + info.read = nand_spl_read_block; + info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE; + break; +#endif +#ifdef CONFIG_SPL_ONENAND_SUPPORT + case BOOT_DEVICE_ONENAND: + info.read = onenand_spl_read_block; + info.peb_size = CONFIG_SYS_ONENAND_BLOCK_SIZE; + break; +#endif + default: + goto out; + } + info.ubi = (struct ubi_scan_info *)CONFIG_SPL_UBI_INFO_ADDR; + info.fastmap = 1; + + info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET; + 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); +out: +#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 2360466..8afa085 100644 --- a/include/spl.h +++ b/include/spl.h @@ -71,6 +71,7 @@ void spl_set_header_raw_uboot(void); int spl_parse_image_header(const struct image_header *header); void spl_board_prepare_for_linux(void); void spl_board_prepare_for_boot(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); @@ -84,6 +85,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);