From patchwork Thu Jan 10 14:58:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 211047 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 55F232C008D for ; Fri, 11 Jan 2013 02:01:47 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B92484A19E; Thu, 10 Jan 2013 16:01:03 +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 cjV6aFTQ0z2T; Thu, 10 Jan 2013 16:01:03 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5665A4A0EF; Thu, 10 Jan 2013 15:59:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A9C374A164 for ; Thu, 10 Jan 2013 15:59:17 +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 OgXh+IProEWx for ; Thu, 10 Jan 2013 15:59:15 +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 mail-vb0-f73.google.com (mail-vb0-f73.google.com [209.85.212.73]) by theia.denx.de (Postfix) with ESMTPS id AC9394A14C for ; Thu, 10 Jan 2013 15:58:58 +0100 (CET) Received: by mail-vb0-f73.google.com with SMTP id l1so69553vba.0 for ; Thu, 10 Jan 2013 06:58:56 -0800 (PST) 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=s9EdiFVTMlpKEH7ApNUKngW5LksRnNHBlRsOMu924nk=; b=IOiNF1xlHu5lYx56tVZosd7ajNvSs1bDf7VVhLjdXpIw76T/1k/7TFJpIJdVBByIL8 IJ2+8zb1FP0XuxPsSooUhA88/osfDTCyPTmn9IO8RYx3TBRZQA5WYVS0bt0t51xtp6kT ziXGd0othrHw+v63mPlBP6OH55x9AUh/74BcY9n9fhja3I1tYWc3djVDyCyJS8PFsoql PlIjYeJ05EntQe9SCClHx1dYpxI868CpU7K7rOSEOgrwr03VbtbwCzhZx83z34BrtDZJ yU/inqIRsvb/FDCgzKmvzl/13vpQq07igV8PTrHCneC0ImIlTKiJ9xFSNg54/2oWN7X5 5cvA== X-Received: by 10.101.136.25 with SMTP id o25mr10390891ann.21.1357829935451; Thu, 10 Jan 2013 06:58:55 -0800 (PST) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id a24si81959yhi.0.2013.01.10.06.58.55 (version=TLSv1 cipher=AES128-SHA bits=128/128); Thu, 10 Jan 2013 06:58:55 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id 2723C100047; Thu, 10 Jan 2013 06:58:55 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id CE3FB160C5E; Thu, 10 Jan 2013 06:58:54 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 10 Jan 2013 06:58:06 -0800 Message-Id: <1357829905-6579-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1357829905-6579-1-git-send-email-sjg@chromium.org> References: <1357829905-6579-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlOvOmpv8oY9dl/uGIx3ODF8mV6U2dRPplZCam/vFk5JxG8PCDCqlrHag9ve7wETv0faBRylJ84TajwWnooW7AJnyMNCqc9c8FqA9M7N6WoxVF9cunJQZGVRr8pKB+LBxdLty8DkYuRulmSJXkOMLrXVZBuw6SGaB82hovpGeZbgzUqHknU2Fv2vKOfFvsEY55WTlhL Cc: Joe Hershberger , Tom Rini , Vadim Bendebury Subject: [U-Boot] [RFC PATCH 03/22] 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 Reviewed-by: Marek Vasut --- fs/fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 2 + 2 files changed, 76 insertions(+), 0 deletions(-) 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 */