From patchwork Wed Sep 4 14:16:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 272630 X-Patchwork-Delegate: scottwood@freescale.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 80D1D2C00CA for ; Thu, 5 Sep 2013 00:19:33 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E21034A09F; Wed, 4 Sep 2013 16:19:17 +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 BIEIBukIjqLO; Wed, 4 Sep 2013 16:19:17 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3D5694A0B5; Wed, 4 Sep 2013 16:19:01 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C953A4A07F for ; Wed, 4 Sep 2013 16:18:51 +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 8FpBTxdgB7ui for ; Wed, 4 Sep 2013 16:18:51 +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 multi.imgtec.com (multi.imgtec.com [194.200.65.239]) by theia.denx.de (Postfix) with ESMTPS id 21A8B4A081 for ; Wed, 4 Sep 2013 16:18:39 +0200 (CEST) From: Paul Burton To: Date: Wed, 4 Sep 2013 15:16:59 +0100 Message-ID: <1378304219-11229-5-git-send-email-paul.burton@imgtec.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1378304219-11229-1-git-send-email-paul.burton@imgtec.com> References: <1378304219-11229-1-git-send-email-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [192.168.152.22] X-SEF-Processed: 7_3_0_01192__2013_09_04_15_18_31 Cc: scottwood@freescale.com, kmpark@infradead.org Subject: [U-Boot] [PATCH v2 4/4] cmd_ubi: add write.part command, to write a volume in multiple parts 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 This allows you to write data to an UBI volume when the amount of memory available to write that data from is less than the total size of the data. For example, you may split a root filesystem UBIFS image into parts, provide the total size of the image to the first write.part command and then use multiple write.part commands to write the subsequent parts of the volume. This results in a sequence of commands akin to: ext4load mmc 0:1 0x80000000 rootfs.ubifs.0 ubi write.part 0x80000000 root 0x08000000 0x18000000 ext4load mmc 0:1 0x80000000 rootfs.ubifs.1 ubi write.part 0x80000000 root 0x08000000 ext4load mmc 0:1 0x80000000 rootfs.ubifs.2 ubi write.part 0x80000000 root 0x08000000 This would write 384MiB of data to the UBI volume 'root' whilst only requiring 128MiB of said data to be held in memory at a time. Signed-off-by: Paul Burton --- Changes from v1: - Style fixes (braces) to address Stefan Roese's comments. --- common/cmd_ubi.c | 63 ++++++++++++++++++++++++++++++++++++++++++-------------- doc/README.ubi | 3 +++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c index f11cb61..122ba7e 100644 --- a/common/cmd_ubi.c +++ b/common/cmd_ubi.c @@ -266,28 +266,15 @@ out_err: return err; } -int ubi_volume_write(char *volume, void *buf, size_t size) +int ubi_volume_continue_write(char *volume, void *buf, size_t size) { int err = 1; - int rsvd_bytes = 0; struct ubi_volume *vol; vol = ubi_find_volume(volume); if (vol == NULL) return ENODEV; - rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad); - if (size < 0 || size > rsvd_bytes) { - printf("size > volume size! Aborting!\n"); - return EINVAL; - } - - err = ubi_start_update(ubi, vol, size); - if (err < 0) { - printf("Cannot start volume update\n"); - return -err; - } - err = ubi_more_update_data(ubi, vol, buf, size); if (err < 0) { printf("Couldnt or partially wrote data\n"); @@ -314,6 +301,37 @@ int ubi_volume_write(char *volume, void *buf, size_t size) return 0; } +int ubi_volume_begin_write(char *volume, void *buf, size_t size, + size_t full_size) +{ + int err = 1; + int rsvd_bytes = 0; + struct ubi_volume *vol; + + vol = ubi_find_volume(volume); + if (vol == NULL) + return ENODEV; + + rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad); + if (size < 0 || size > rsvd_bytes) { + printf("size > volume size! Aborting!\n"); + return EINVAL; + } + + err = ubi_start_update(ubi, vol, full_size); + if (err < 0) { + printf("Cannot start volume update\n"); + return -err; + } + + return ubi_volume_continue_write(volume, buf, size); +} + +int ubi_volume_write(char *volume, void *buf, size_t size) +{ + return ubi_volume_begin_write(volume, buf, size, size); +} + int ubi_volume_read(char *volume, char *buf, size_t size) { int err, lnum, off, len, tbuf_size; @@ -588,7 +606,20 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr = simple_strtoul(argv[2], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); - ret = ubi_volume_write(argv[3], (void *)addr, size); + if (strlen(argv[1]) == 10 && + strncmp(argv[1] + 5, ".part", 5) == 0) { + if (argc < 6) { + ret = ubi_volume_continue_write(argv[3], + (void *)addr, size); + } else { + size_t full_size; + full_size = simple_strtoul(argv[5], NULL, 16); + ret = ubi_volume_begin_write(argv[3], + (void *)addr, size, full_size); + } + } else { + ret = ubi_volume_write(argv[3], (void *)addr, size); + } if (!ret) { printf("%lld bytes written to volume %s\n", size, argv[3]); @@ -636,6 +667,8 @@ U_BOOT_CMD( " - create volume name with size\n" "ubi write[vol] address volume size" " - Write volume from address with size\n" + "ubi write.part address volume size [fullsize]\n" + " - Write part of a volume from address\n" "ubi read[vol] address volume [size]" " - Read volume to address with size\n" "ubi remove[vol] volume" diff --git a/doc/README.ubi b/doc/README.ubi index 3cf4ef2..d82c75c 100644 --- a/doc/README.ubi +++ b/doc/README.ubi @@ -14,6 +14,8 @@ ubi part [part] [offset] ubi info [l[ayout]] - Display volume and ubi layout information ubi create[vol] volume [size] [type] - create volume name with size ubi write[vol] address volume size - Write volume from address with size +ubi write.part address volume size [fullsize] + - Write part of a volume from address ubi read[vol] address volume [size] - Read volume to address with size ubi remove[vol] volume - Remove volume [Legends] @@ -77,6 +79,7 @@ ubi createvol Create UBI volume on UBI device ubi removevol Remove UBI volume from UBI device ubi read Read data from UBI volume to memory ubi write Write data from memory to UBI volume +ubi write.part Write data from memory to UBI volume, in parts Here a few examples on the usage: