From mboxrd@z Thu Jan 1 00:00:00 1970 From: Piotr Wilczek Date: Wed, 10 Apr 2013 15:44:19 +0200 Subject: [U-Boot] [Patch v2] cmd/gpt: Support gpt command for all devices In-Reply-To: <1365520317-30116-1-git-send-email-egbert.eich@gmail.com> References: <1364288746-2597-1-git-send-email-egbert.eich@gmail.com> <1365520317-30116-1-git-send-email-egbert.eich@gmail.com> Message-ID: <000101ce35f1$81520670$83f61350$%wilczek@samsung.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Egbert Eich, > -----Original Message----- > From: Egbert Eich [mailto:egbert.eich at gmail.com] > Sent: Tuesday, April 09, 2013 5:12 PM > To: u-boot at lists.denx.de > Cc: Piotr Wilczek; Egbert Eich > Subject: [Patch v2] cmd/gpt: Support gpt command for all devices > > From: Egbert Eich > > The gpt command was only implemented for mmc devices. There is no > reason why this command should not be generalized and be applied all > other storage device classes. > This change both simplifies the implementation and eliminates a build > failure for systems that don't support mmcs. > > Signed-off-by: Egbert Eich > --- > Changes for v2: > - Coding style cleanup. > > common/cmd_gpt.c | 44 +++++++++++++++++++------------------------- > 1 file changed, 19 insertions(+), 25 deletions(-) > > diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c index efd7934..3594dca > 100644 > --- a/common/cmd_gpt.c > +++ b/common/cmd_gpt.c > @@ -23,7 +23,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -134,7 +133,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc, > int errno = 0; > uint64_t size_ll, start_ll; > > - debug("%s: MMC lba num: 0x%x %d\n", __func__, > + debug("%s: lba num: 0x%x %d\n", __func__, > (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba); > > if (str_part == NULL) > @@ -247,25 +246,18 @@ err: > return errno; > } > > -static int gpt_mmc_default(int dev, const char *str_part) > +static int gpt_default(block_dev_desc_t *blk_dev_desc, const char > +*str_part) > { > int ret; > char *str_disk_guid; > u8 part_count = 0; > disk_partition_t *partitions = NULL; > > - struct mmc *mmc = find_mmc_device(dev); > - > - if (mmc == NULL) { > - printf("%s: mmc dev %d NOT available\n", __func__, dev); > - return CMD_RET_FAILURE; > - } > - > if (!str_part) > return -1; > > /* fill partitions */ > - ret = set_gpt_info(&mmc->block_dev, str_part, > + ret = set_gpt_info(blk_dev_desc, str_part, > &str_disk_guid, &partitions, &part_count); > if (ret) { > if (ret == -1) > @@ -278,7 +270,7 @@ static int gpt_mmc_default(int dev, const char > *str_part) > } > > /* save partitions layout to disk */ > - gpt_restore(&mmc->block_dev, str_disk_guid, partitions, > part_count); > + gpt_restore(&blk_dev_desc, str_disk_guid, partitions, > part_count); 'blk_dev_desc' is a pointer, no need to take its address > free(str_disk_guid); > free(partitions); > > @@ -306,20 +298,22 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int > argc, char * const argv[]) > > /* command: 'write' */ > if ((strcmp(argv[1], "write") == 0) && (argc == 5)) { > - /* device: 'mmc' */ > - if (strcmp(argv[2], "mmc") == 0) { > - /* check if 'dev' is a number */ > - for (pstr = argv[3]; *pstr != '\0'; pstr++) > - if (!isdigit(*pstr)) { > - printf("'%s' is not a number\n", > - argv[3]); > - return CMD_RET_USAGE; > - } > - dev = (int)simple_strtoul(argv[3], NULL, 10); > - /* write to mmc */ > - if (gpt_mmc_default(dev, argv[4])) > - return CMD_RET_FAILURE; > + char *ep; > + block_dev_desc_t *blk_dev_desc; > + dev = (int)simple_strtoul(argv[3], NULL, 10); > + if (*ep) { warning: 'ep' may be used uninitialized in this function shouldn't the address of 'ep' be passed to 'simple_strtoul' and then compared with argv[3]? > + printf("'%s' is not a number\n", argv[3]); > + return CMD_RET_USAGE; > } > + blk_dev_desc = get_dev(argv[2], dev); > + if (!blk_dev_desc) { > + printf("%s: %s dev %d NOT available\n", > + __func__, argv[2], dev); > + return CMD_RET_FAILURE; > + } > + > + if (gpt_default(blk_dev_desc, argv[4])) > + return CMD_RET_FAILURE; unused 'pstr' variable can be removed > } else { > return CMD_RET_USAGE; > } > -- > 1.8.1.4 Best ragards, Piotr Wilczek