From patchwork Fri Feb 8 20:07:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 219292 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 270902C0086 for ; Sat, 9 Feb 2013 07:08:56 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 850314A151; Fri, 8 Feb 2013 21:08:43 +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 Ji1zHrVdnKxK; Fri, 8 Feb 2013 21:08:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7F1A14A15B; Fri, 8 Feb 2013 21:08:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0CF6C4A12F for ; Fri, 8 Feb 2013 21:08:19 +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 hwKkPL0aTaPo for ; Fri, 8 Feb 2013 21:08:17 +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 spamkiller06.natinst.com (mailserver6.natinst.com [130.164.80.6]) by theia.denx.de (Postfix) with ESMTP id C1D734A12E for ; Fri, 8 Feb 2013 21:08:14 +0100 (CET) Received: from mailserv59-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller06.natinst.com (8.14.5/8.14.5) with ESMTP id r18K895a006268; Fri, 8 Feb 2013 14:08:09 -0600 Received: from linux-xvxi.natinst.com ([130.164.14.197]) by mailserv59-us.natinst.com (Lotus Domino Release 8.5.3FP2 HF169) with ESMTP id 2013020814080929-196534 ; Fri, 8 Feb 2013 14:08:09 -0600 From: Joe Hershberger To: u-boot@lists.denx.de Date: Fri, 8 Feb 2013 14:07:22 -0600 Message-Id: <1360354046-32392-2-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1360354046-32392-1-git-send-email-joe.hershberger@ni.com> References: <1360354046-32392-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ59-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 02/08/2013 02:08:09 PM, Serialize by Router on MailServ59-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 02/08/2013 02:08:09 PM, Serialize complete at 02/08/2013 02:08:09 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327, 1.0.431, 0.0.0000 definitions=2013-02-08_07:2013-02-08, 2013-02-08, 1970-01-01 signatures=0 Cc: Tom Rini , Joe Hershberger Subject: [U-Boot] [PATCH 1/5] ubi: Expose a few simple functions from the cmd_ubi 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 Part, Read, and Write functionality that will be used by env_ubi. Signed-off-by: Joe Hershberger --- common/cmd_ubi.c | 146 ++++++++++++++++++++++++++++------------------------ include/ubi_uboot.h | 3 ++ 2 files changed, 83 insertions(+), 66 deletions(-) diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c index 35b1d31..01335dd 100644 --- a/common/cmd_ubi.c +++ b/common/cmd_ubi.c @@ -263,7 +263,7 @@ out_err: return err; } -static int ubi_volume_write(char *volume, void *buf, size_t size) +int ubi_volume_write(char *volume, void *buf, size_t size) { int err = 1; int rsvd_bytes = 0; @@ -308,12 +308,10 @@ static int ubi_volume_write(char *volume, void *buf, size_t size) ubi_gluebi_updated(vol); } - printf("%d bytes written to volume %s\n", size, volume); - return 0; } -static int ubi_volume_read(char *volume, char *buf, size_t size) +int ubi_volume_read(char *volume, char *buf, size_t size) { int err, lnum, off, len, tbuf_size; void *tbuf; @@ -325,8 +323,6 @@ static int ubi_volume_read(char *volume, char *buf, size_t size) if (vol == NULL) return ENODEV; - printf("Read %d bytes from volume %s to %p\n", size, volume, buf); - if (vol->updating) { printf("updating"); return EBUSY; @@ -431,26 +427,82 @@ static int ubi_dev_scan(struct mtd_info *info, char *ubidev, return 0; } -static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) +int ubi_part(char *part_name, const char *vid_header_offset) { - size_t size = 0; - ulong addr = 0; int err = 0; - - if (argc < 2) - return CMD_RET_USAGE; + char mtd_dev[16]; + struct mtd_device *dev; + struct part_info *part; + u8 pnum; if (mtdparts_init() != 0) { printf("Error initializing mtdparts!\n"); return 1; } +#ifdef CONFIG_CMD_UBIFS + /* + * Automatically unmount UBIFS partition when user + * changes the UBI device. Otherwise the following + * UBIFS commands will crash. + */ + if (ubifs_is_mounted()) + cmd_ubifs_umount(); +#endif + + /* todo: get dev number for NAND... */ + ubi_dev.nr = 0; + + /* + * Call ubi_exit() before re-initializing the UBI subsystem + */ + if (ubi_initialized) { + ubi_exit(); + del_mtd_partitions(ubi_dev.mtd_info); + } + + /* + * Search the mtd device number where this partition + * is located + */ + if (find_dev_and_part(part_name, &dev, &pnum, &part)) { + printf("Partition %s not found!\n", part_name); + return 1; + } + sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(dev->id->type), dev->id->num); + ubi_dev.mtd_info = get_mtd_device_nm(mtd_dev); + if (IS_ERR(ubi_dev.mtd_info)) { + printf("Partition %s not found on device %s!\n", part_name, + mtd_dev); + return 1; + } + + ubi_dev.selected = 1; + + strcpy(ubi_dev.part_name, part_name); + err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name, + vid_header_offset); + if (err) { + printf("UBI init error %d\n", err); + ubi_dev.selected = 0; + return err; + } + + ubi = ubi_devices[0]; + + return 0; +} + +static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + size_t size = 0; + ulong addr = 0; + + if (argc < 2) + return CMD_RET_USAGE; + if (strcmp(argv[1], "part") == 0) { - char mtd_dev[16]; - struct mtd_device *dev; - struct part_info *part; const char *vid_header_offset = NULL; - u8 pnum; /* Print current partition */ if (argc == 2) { @@ -467,58 +519,10 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) if (argc < 3) return CMD_RET_USAGE; -#ifdef CONFIG_CMD_UBIFS - /* - * Automatically unmount UBIFS partition when user - * changes the UBI device. Otherwise the following - * UBIFS commands will crash. - */ - if (ubifs_is_mounted()) - cmd_ubifs_umount(); -#endif - - /* todo: get dev number for NAND... */ - ubi_dev.nr = 0; - - /* - * Call ubi_exit() before re-initializing the UBI subsystem - */ - if (ubi_initialized) { - ubi_exit(); - del_mtd_partitions(ubi_dev.mtd_info); - } - - /* - * Search the mtd device number where this partition - * is located - */ - if (find_dev_and_part(argv[2], &dev, &pnum, &part)) { - printf("Partition %s not found!\n", argv[2]); - return 1; - } - sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(dev->id->type), dev->id->num); - ubi_dev.mtd_info = get_mtd_device_nm(mtd_dev); - if (IS_ERR(ubi_dev.mtd_info)) { - printf("Partition %s not found on device %s!\n", argv[2], mtd_dev); - return 1; - } - - ubi_dev.selected = 1; - if (argc > 3) vid_header_offset = argv[3]; - strcpy(ubi_dev.part_name, argv[2]); - err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name, - vid_header_offset); - if (err) { - printf("UBI init error %d\n", err); - ubi_dev.selected = 0; - return err; - } - ubi = ubi_devices[0]; - - return 0; + return ubi_part(argv[2], vid_header_offset); } if ((strcmp(argv[1], "part") != 0) && (!ubi_dev.selected)) { @@ -571,6 +575,8 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) } if (strncmp(argv[1], "write", 5) == 0) { + int ret; + if (argc < 5) { printf("Please see usage\n"); return 1; @@ -579,7 +585,12 @@ 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); - return ubi_volume_write(argv[3], (void *)addr, size); + ret = ubi_volume_write(argv[3], (void *)addr, size); + if (!ret) + printf("%d bytes written to volume %s\n", size, + argv[3]); + + return ret; } if (strncmp(argv[1], "read", 4) == 0) { @@ -598,6 +609,9 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) } if (argc == 3) + printf("Read %d bytes from volume %s to %lx\n", size, + argv[3], addr); + return ubi_volume_read(argv[3], (char *)addr, size); } diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h index 69006e2..1207895 100644 --- a/include/ubi_uboot.h +++ b/include/ubi_uboot.h @@ -214,6 +214,9 @@ static inline long IS_ERR(const void *ptr) extern int ubi_mtd_param_parse(const char *val, struct kernel_param *kp); extern int ubi_init(void); extern void ubi_exit(void); +int ubi_part(char *part_name, const char *vid_header_offset); +extern int ubi_volume_write(char *volume, void *buf, size_t size); +extern int ubi_volume_read(char *volume, char *buf, size_t size); extern struct ubi_device *ubi_devices[];