From patchwork Tue Mar 26 08:01:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: egbert.eich@googlemail.com X-Patchwork-Id: 231117 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 B840E2C00E3 for ; Tue, 26 Mar 2013 20:13:41 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9FB914A09C; Tue, 26 Mar 2013 10:13:39 +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 p8-4Fi34c7kh; Tue, 26 Mar 2013 10:13:36 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 07F984A049; Tue, 26 Mar 2013 10:13:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0C3364A049 for ; Tue, 26 Mar 2013 10:03:41 +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 q3exnD7LcoHI for ; Tue, 26 Mar 2013 10:03:40 +0100 (CET) X-Greylist: delayed 441 seconds by postgrey-1.27 at theia; Tue, 26 Mar 2013 10:03:38 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-ea0-f179.google.com (mail-ea0-f179.google.com [209.85.215.179]) by theia.denx.de (Postfix) with ESMTPS id 1C0FC4A048 for ; Tue, 26 Mar 2013 10:03:38 +0100 (CET) Received: by mail-ea0-f179.google.com with SMTP id f15so2699990eak.38 for ; Tue, 26 Mar 2013 02:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=u4/Swhee6I8A3hK9rWM3Gt8Z3J/xGglrj+5PL0c7ZCU=; b=EQnknfjo0D7bm9MQWEkao3P6bZDh40+74IVU3Y5EugDBLrqHJX0xgJANzqIZoACT4a +hL/JvyjXFmagHRxK1rUnl5Yz1drK/0umlck5jvhha7JsBHKJWbPVTH7lGNJAceHpmTu PpRq1OQfSxK6r7d0rXYJD8uotUTFdH4Je0W9HZS89N7V6n909Fuxp2pD3FF1wtFTrfK1 LJhrUFFOIOoJMJZFjFl5TOKq837KniEUm+EJ06TccapMJM5dCtsKgYBmQYMXFRFppuYJ cRGZqhO0176eAQYkv0HVpDoWws5rpN0ceug3BYnxph9mlMSBDrPmvJTWaNsYMnmGJcFp daxA== X-Received: by 10.15.35.193 with SMTP id g41mr31864076eev.45.1364288174163; Tue, 26 Mar 2013 01:56:14 -0700 (PDT) Received: from debian (p5DCF07C5.dip0.t-ipconnect.de. [93.207.7.197]) by mx.google.com with ESMTPS id u44sm23685714eel.7.2013.03.26.01.56.12 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Mar 2013 01:56:12 -0700 (PDT) Received: from sles11.fritz.box (sles11.fritz.box [192.168.178.22]) by debian (Postfix) with ESMTP id B999F13C76; Tue, 26 Mar 2013 09:56:10 +0100 (CET) From: egbert.eich@googlemail.com To: u-boot@lists.denx.de Date: Tue, 26 Mar 2013 04:01:53 -0400 Message-Id: <1364284913-2277-1-git-send-email-egbert.eich@gmail.com> X-Mailer: git-send-email 1.7.7 X-Mailman-Approved-At: Tue, 26 Mar 2013 10:13:35 +0100 Cc: Egbert Eich Subject: [U-Boot] [PATCH] cmd/gpt: Support gpt command for all devices. 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 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 --- common/cmd_gpt.c | 43 ++++++++++++++++++------------------------- 1 files changed, 18 insertions(+), 25 deletions(-) diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c index efd7934..1a72e8e 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); free(str_disk_guid); free(partitions); @@ -306,20 +298,21 @@ 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) { + 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; } else { return CMD_RET_USAGE; }