From patchwork Thu Jan 16 17:23:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 311796 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 1D6F12C0097 for ; Fri, 17 Jan 2014 04:24:41 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AC9714AB4B; Thu, 16 Jan 2014 18:24:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 8h5R-84K0xa5; Thu, 16 Jan 2014 18:24:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 49A554AB4E; Thu, 16 Jan 2014 18:24:16 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 012FE4AA5D for ; Thu, 16 Jan 2014 18:24:02 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 m8egy9V0O51t for ; Thu, 16 Jan 2014 18:23:54 +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 bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by theia.denx.de (Postfix) with ESMTPS id 49A514AA79 for ; Thu, 16 Jan 2014 18:23:42 +0100 (CET) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s0GHNeN8017508 for ; Thu, 16 Jan 2014 11:23:40 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0GHNe1J009687 for ; Thu, 16 Jan 2014 11:23:40 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Thu, 16 Jan 2014 11:23:40 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0GHNetJ030059; Thu, 16 Jan 2014 11:23:40 -0600 Received: from localhost (j-172-22-135-197.vpn.ti.com [172.22.135.197]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id s0GHNet25141; Thu, 16 Jan 2014 11:23:40 -0600 (CST) From: Dan Murphy To: , Date: Thu, 16 Jan 2014 11:23:29 -0600 Message-ID: <1389893011-1879-2-git-send-email-dmurphy@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389893011-1879-1-git-send-email-dmurphy@ti.com> References: <1389893011-1879-1-git-send-email-dmurphy@ti.com> MIME-Version: 1.0 Subject: [U-Boot] [uBoot] [Patch v2 2/4] spl: common: Move FAT funcs to a common file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Move the FAT functions to a common location for reuse. Signed-off-by: Dan Murphy --- v2 - No change just a rebase - http://patchwork.ozlabs.org/patch/309264/ common/spl/Makefile | 1 + common/spl/spl_fat.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ common/spl/spl_mmc.c | 68 ++++------------------------------- include/spl.h | 5 +++ 4 files changed, 108 insertions(+), 62 deletions(-) create mode 100644 common/spl/spl_fat.c diff --git a/common/spl/Makefile b/common/spl/Makefile index 5c0637b..c8d5963 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -16,4 +16,5 @@ obj-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o obj-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o obj-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o +obj-$(CONFIG_SPL_FAT_SUPPORT) += spl_fat.o endif diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c new file mode 100644 index 0000000..9b40584 --- /dev/null +++ b/common/spl/spl_fat.c @@ -0,0 +1,96 @@ +/* + * (C) Copyright 2014 + * Texas Instruments, + * + * Dan Murphy + * + * SPDX-License-Identifier: GPL-2.0+ + * + * FAT Image Functions copied from spl_mmc.c + */ + +#include +#include +#include +#include +#include + +static int fat_registered; + +#ifdef CONFIG_SPL_FAT_SUPPORT +static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) +{ + int err = 0; + + if (fat_registered) + return err; + + err = fat_register_device(block_dev, partition); + if (err) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("spl: fat register err - %d\n", err); +#endif + hang(); + } + + fat_registered = 1; + + return err; +} + +int spl_load_image_fat(block_dev_desc_t *block_dev, + int partition, + const char *filename) +{ + int err; + struct image_header *header; + + err = spl_register_fat_device(block_dev, partition); + if (err <= 0) + goto end; + + header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - + sizeof(struct image_header)); + + err = file_fat_read(filename, header, sizeof(struct image_header)); + if (err <= 0) + goto end; + + spl_parse_image_header(header); + + err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0); + +end: +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + if (err <= 0) + printf("spl: error reading image %s, err - %d\n", + filename, err); +#endif + + return (err <= 0); +} + +#ifdef CONFIG_SPL_OS_BOOT +int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition) +{ + int err; + + err = spl_register_fat_device(block_dev, partition); + if (err <= 0) + return -1; + + err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME, + (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); + if (err <= 0) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("spl: error reading image %s, err - %d\n", + CONFIG_SPL_FAT_LOAD_ARGS_NAME, err); +#endif + return -1; + } + + return spl_load_image_fat(block_dev, partition, + CONFIG_SPL_FAT_LOAD_KERNEL_NAME); +} +#endif +#endif diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index fc2f226..13fbff0 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -69,54 +68,6 @@ static int mmc_load_image_raw_os(struct mmc *mmc) } #endif -#ifdef CONFIG_SPL_FAT_SUPPORT -static int mmc_load_image_fat(struct mmc *mmc, const char *filename) -{ - int err; - struct image_header *header; - - header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - - sizeof(struct image_header)); - - err = file_fat_read(filename, header, sizeof(struct image_header)); - if (err <= 0) - goto end; - - spl_parse_image_header(header); - - err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0); - -end: -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT - if (err <= 0) - printf("spl: error reading image %s, err - %d\n", - filename, err); -#endif - - return (err <= 0); -} - -#ifdef CONFIG_SPL_OS_BOOT -static int mmc_load_image_fat_os(struct mmc *mmc) -{ - int err; - - err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME, - (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); - if (err <= 0) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT - printf("spl: error reading image %s, err - %d\n", - CONFIG_SPL_FAT_LOAD_ARGS_NAME, err); -#endif - return -1; - } - - return mmc_load_image_fat(mmc, CONFIG_SPL_FAT_LOAD_KERNEL_NAME); -} -#endif - -#endif - void spl_mmc_load_image(void) { struct mmc *mmc; @@ -148,24 +99,17 @@ void spl_mmc_load_image(void) if (spl_start_uboot() || mmc_load_image_raw_os(mmc)) #endif err = mmc_load_image_raw(mmc, - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); #ifdef CONFIG_SPL_FAT_SUPPORT } else if (boot_mode == MMCSD_MODE_FAT) { debug("boot mode - FAT\n"); - - err = fat_register_device(&mmc->block_dev, - CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION); - if (err) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT - printf("spl: fat register err - %d\n", err); -#endif - hang(); - } - #ifdef CONFIG_SPL_OS_BOOT - if (spl_start_uboot() || mmc_load_image_fat_os(mmc)) + if (spl_start_uboot() || spl_load_image_fat_os(&mmc->block_dev, + CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION)) #endif - err = mmc_load_image_fat(mmc, CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); + err = spl_load_image_fat(&mmc->block_dev, + CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION, + CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); #endif } else { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT diff --git a/include/spl.h b/include/spl.h index 2bd6e16..cd5cd26 100644 --- a/include/spl.h +++ b/include/spl.h @@ -11,6 +11,7 @@ #include #include + /* Boot type */ #define MMCSD_MODE_UNDEFINED 0 #define MMCSD_MODE_RAW 1 @@ -60,6 +61,10 @@ void spl_spi_load_image(void); /* Ethernet SPL functions */ void spl_net_load_image(const char *device); +/* SPL FAT image functions */ +int spl_load_image_fat(block_dev_desc_t *block_dev, int partition, const char *filename); +int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition); + #ifdef CONFIG_SPL_BOARD_INIT void spl_board_init(void); #endif