From patchwork Sat Apr 20 18:42:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 238170 X-Patchwork-Delegate: sjg@chromium.org 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 3A0252C0082 for ; Sun, 21 Apr 2013 04:47:05 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6C3644A5CC; Sat, 20 Apr 2013 20:46:05 +0200 (CEST) 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 DbTGmsx6nz0x; Sat, 20 Apr 2013 20:46:05 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A1E014A47A; Sat, 20 Apr 2013 20:44:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E0F624A3F2 for ; Sat, 20 Apr 2013 20:43:57 +0200 (CEST) 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 ZJXDeXgkZ8IQ for ; Sat, 20 Apr 2013 20:43:56 +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 mail-vc0-f201.google.com (mail-vc0-f201.google.com [209.85.220.201]) by theia.denx.de (Postfix) with ESMTPS id 9C8264A3F8 for ; Sat, 20 Apr 2013 20:43:19 +0200 (CEST) Received: by mail-vc0-f201.google.com with SMTP id hz11so545603vcb.2 for ; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=3BZds1A7bI+KNpR//RYOEMa4OpQzha6lPWuw4wAyJ2Y=; b=dGA4uySx5Jo7D/caSvUsDEMRDYP+r6UGkJ8dSsdtWLbK3HOVzfu71mg28lIhCrIECL VjCn6Aj/nI6yMdv/7mO9tpNGUMxyk1q59Q5yavxxkXID9HRTJ38hCd+vAEz5y+YRHLYB vUFhX2QJ2YivY4+8399KSn4HSJTordEplWc+QKQ8VR/vToU6DJQ03trATkPtHLGcqP/U yBOy21dPjqaoQBQPaB3LWEoLc+RvxNM1pSbOmfWCbzxfhK0SqIS1/+MmC4ZbuNH50WEG 0uAqL9CEPGlu0vyxO2K3WsOQQsSY7pp2cr1YlUOBswT70xEn269ugRp82+wn+e2vX46i IoEA== X-Received: by 10.236.78.103 with SMTP id f67mr10059902yhe.52.1366483396337; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id q58si4433205yhe.4.2013.04.20.11.43.16 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 20 Apr 2013 11:43:16 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 10D7431C16A; Sat, 20 Apr 2013 11:43:16 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id E654C1606B6; Sat, 20 Apr 2013 11:43:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 20 Apr 2013 11:42:50 -0700 Message-Id: <1366483372-16523-16-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366483372-16523-1-git-send-email-sjg@chromium.org> References: <1366483372-16523-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQl80itreXDi2OEIiGh5ryHwc5Ch5Y39tvJm0miD4hjRMD+xXzmFaT2bbKZYnGqtre2S5AvfqgdsrNFMm8VtsaekiThrHNOMJoqxalVMizU2ynMlWr0KImY5auUT5m66wRpkZGyOv/bw3VcQI4vm8FQzBq1y3k54Eixrw/Nx7cK9u5F0ye7mVeBI4axtJsb8W1VpnRqK Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [PATCH v3 15/17] fs: Add support for saving data to filesystems 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 Add a new method for saving that filesystems can implement. This mirrors the existing load method. Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None fs/fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 2 ++ 2 files changed, 76 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 6f5063c..eee7e23 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -47,6 +47,12 @@ static inline int fs_read_unsupported(const char *filename, void *buf, return -1; } +static inline int fs_write_unsupported(const char *filename, void *buf, + int offset, int len) +{ + return -1; +} + static inline void fs_close_unsupported(void) { } @@ -57,6 +63,7 @@ struct fstype_info { disk_partition_t *fs_partition); int (*ls)(const char *dirname); int (*read)(const char *filename, void *buf, int offset, int len); + int (*write)(const char *filename, void *buf, int offset, int len); void (*close)(void); }; @@ -94,6 +101,7 @@ static struct fstype_info fstypes[] = { .close = fs_close_unsupported, .ls = fs_ls_unsupported, .read = fs_read_unsupported, + .write = fs_write_unsupported, }, }; @@ -125,6 +133,7 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) info->close += gd->reloc_off; info->ls += gd->reloc_off; info->read += gd->reloc_off; + info->write += gd->reloc_off; } relocated = 1; } @@ -196,6 +205,30 @@ int fs_read(const char *filename, ulong addr, int offset, int len) return ret; } +int fs_write(const char *filename, ulong addr, int offset, int len) +{ + struct fstype_info *info = fs_get_info(fs_type); + void *buf; + int ret; + + /* + * We don't actually know how many bytes are being read, since len==0 + * means read the whole file. + */ + buf = map_sysmem(addr, len); + ret = info->write(filename, buf, offset, len); + unmap_sysmem(buf); + + /* If we requested a specific number of bytes, check we got it */ + if (ret >= 0 && len && ret != len) { + printf("** Unable to write file %s **\n", filename); + ret = -1; + } + fs_close(); + + return ret; +} + int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype, int cmdline_base) { @@ -277,3 +310,44 @@ int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return 0; } + +int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype, int cmdline_base) +{ + unsigned long addr; + const char *filename; + unsigned long bytes; + unsigned long pos; + int len; + unsigned long time; + + if (argc < 6 || argc > 7) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + filename = argv[3]; + addr = simple_strtoul(argv[4], NULL, cmdline_base); + bytes = simple_strtoul(argv[5], NULL, cmdline_base); + if (argc >= 7) + pos = simple_strtoul(argv[6], NULL, cmdline_base); + else + pos = 0; + + time = get_timer(0); + len = fs_write(filename, addr, pos, bytes); + time = get_timer(time); + if (len <= 0) + return 1; + + printf("%d bytes written in %lu ms", len, time); + if (time > 0) { + puts(" ("); + print_size(len / time * 1000, "/s"); + puts(")"); + } + puts("\n"); + + return 0; +} diff --git a/include/fs.h b/include/fs.h index b6d69e5..c837bae 100644 --- a/include/fs.h +++ b/include/fs.h @@ -62,5 +62,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype, int cmdline_base); int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype); +int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype, int cmdline_base); #endif /* _FS_H */