From patchwork Tue Dec 20 03:48:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donggeun Kim X-Patchwork-Id: 132345 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 A099EB6FD0 for ; Tue, 20 Dec 2011 14:48:32 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 36897282F0; Tue, 20 Dec 2011 04:48: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 h1A+ZhlU1p-n; Tue, 20 Dec 2011 04:48:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 81847282F4; Tue, 20 Dec 2011 04:48:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2B66D282F4 for ; Tue, 20 Dec 2011 04:48:24 +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 25Sc4FDHZugt for ; Tue, 20 Dec 2011 04:48:22 +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 mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by theia.denx.de (Postfix) with ESMTP id 9C8CA282F0 for ; Tue, 20 Dec 2011 04:48:19 +0100 (CET) Received: from epcpsbgm1.samsung.com (mailout2.samsung.com [203.254.224.25]) by mailout2.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LWH008U1H8FLTC0@mailout2.samsung.com> for u-boot@lists.denx.de; Tue, 20 Dec 2011 12:48:17 +0900 (KST) X-AuditID: cbfee61a-b7b89ae000001a15-5b-4ef0058164f4 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (MMPCPMTA) with SMTP id E6.DF.06677.18500FE4; Tue, 20 Dec 2011 12:48:17 +0900 (KST) Received: from localhost.localdomain ([165.213.219.89]) by mmp2.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTPA id <0LWH00KFNH8GJQ70@mmp2.samsung.com> for u-boot@lists.denx.de; Tue, 20 Dec 2011 12:48:17 +0900 (KST) From: Donggeun Kim To: u-boot@lists.denx.de Date: Tue, 20 Dec 2011 12:48:06 +0900 Message-id: <1324352886-12315-1-git-send-email-dg77.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: AAAAAA== Cc: kyungmin.park@samsung.com, dg77.kim@samsung.com Subject: [U-Boot] [PATCH v2] cmd_fat: add FAT write command 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Once CONFIG_FAT_WRITE is defined, users can invoke 'fatwrite' command that saves data in RAM as a FAT file. By removing variable of 'part_size' in fs/fat.c, compile error occurs when enabling FAT write feature. The variable should be declared only when CONFIG_FAT_WRITE is defined. This patch also removes compile error when FAT write is enabled and compile warning when FAT write is disabled. Signed-off-by: Donggeun Kim Signed-off-by: Kyungmin Park --- Changes for v2: - merge the patch that fixes compile error when enabling FAT write - change do_fat_fswrite to be static function common/cmd_fat.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/fat/fat.c | 7 ++++++ 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/common/cmd_fat.c b/common/cmd_fat.c index 0220494..9057e65 100644 --- a/common/cmd_fat.c +++ b/common/cmd_fat.c @@ -184,3 +184,63 @@ U_BOOT_CMD( " \n" " - print information about filesystem from 'dev' on 'interface'" ); + +#ifdef CONFIG_FAT_WRITE +static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + long size; + unsigned long addr; + unsigned long count; + block_dev_desc_t *dev_desc = NULL; + int dev = 0; + int part = 1; + char *ep; + + if (argc < 5) { + printf("usage: fatwrite " + " \n"); + return 1; + } + + dev = (int)simple_strtoul(argv[2], &ep, 16); + dev_desc = get_dev(argv[1], dev); + if (dev_desc == NULL) { + puts("\n** Invalid boot device **\n"); + return 1; + } + if (*ep) { + if (*ep != ':') { + puts("\n** Invalid boot device, use `dev[:part]' **\n"); + return 1; + } + part = (int)simple_strtoul(++ep, NULL, 16); + } + if (fat_register_device(dev_desc, part) != 0) { + printf("\n** Unable to use %s %d:%d for fatwrite **\n", + argv[1], dev, part); + return 1; + } + addr = simple_strtoul(argv[3], NULL, 16); + count = simple_strtoul(argv[5], NULL, 16); + + size = file_fat_write(argv[4], (void *)addr, count); + if (size == -1) { + printf("\n** Unable to write \"%s\" from %s %d:%d **\n", + argv[4], argv[1], dev, part); + return 1; + } + + printf("%ld bytes write\n", size); + + return 0; +} + +U_BOOT_CMD( + fatwrite, 6, 0, do_fat_fswrite, + "write file into a dos filesystem", + " \n" + " - write file 'filename' from the address 'addr' in RAM\n" + " to 'dev' on 'interface'" +); +#endif diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 9a29458..40c0538 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -47,6 +47,10 @@ static block_dev_desc_t *cur_dev = NULL; static unsigned long part_offset = 0; +#ifdef CONFIG_FAT_WRITE +static unsigned long part_size; +#endif + static int cur_part = 1; #define DOS_PART_TBL_OFFSET 0x1be @@ -101,6 +105,9 @@ int fat_register_device (block_dev_desc_t * dev_desc, int part_no) if (!get_partition_info(dev_desc, part_no, &info)) { part_offset = info.start; cur_part = part_no; +#ifdef CONFIG_FAT_WRITE + part_size = info.size; +#endif } else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) || (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET],