From patchwork Mon Jun 15 19:35:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 484514 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 B133C14010F for ; Tue, 16 Jun 2015 05:35:29 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CB3C24B652; Mon, 15 Jun 2015 21:35:27 +0200 (CEST) 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 4A-buADXHRxe; Mon, 15 Jun 2015 21:35:27 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F1E6E4B61D; Mon, 15 Jun 2015 21:35:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 954D04B617 for ; Mon, 15 Jun 2015 21:35:18 +0200 (CEST) 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 9b8lk0CC6LtZ for ; Mon, 15 Jun 2015 21:35:18 +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 gagarine.paulk.fr (gagarine.paulk.fr [109.190.93.129]) by theia.denx.de (Postfix) with ESMTPS id 210404B615 for ; Mon, 15 Jun 2015 21:35:16 +0200 (CEST) Received: by gagarine.paulk.fr (Postfix, from userid 65534) id BFC681FE7C; Mon, 15 Jun 2015 21:35:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on gagarine.paulk.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=RDNS_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from localhost.localdomain (unknown [192.168.1.22]) by gagarine.paulk.fr (Postfix) with ESMTP id 6C22B1FE75; Mon, 15 Jun 2015 21:35:10 +0200 (CEST) From: Paul Kocialkowski To: u-boot@lists.denx.de Date: Mon, 15 Jun 2015 21:35:05 +0200 Message-Id: <1434396905-6086-2-git-send-email-contact@paulk.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434396905-6086-1-git-send-email-contact@paulk.fr> References: <1434396905-6086-1-git-send-email-contact@paulk.fr> Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH v3 2/2] common: cmd_part: start and size sub-commands introduction X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This introduces the part start and part size sub-commands. The purpose of these is to store the start block and size of a partition in a variable, given the device and partition number. This allows reading raw data that fits a single partition more easily. For instance, this could be used to figure out the start block and size of a kernel partition when a partition table is present, given the partition number. Signed-off-by: Paul Kocialkowski Acked-by: Stephen Warren --- common/cmd_part.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/common/cmd_part.c b/common/cmd_part.c index 4bdbf90..8085d26 100644 --- a/common/cmd_part.c +++ b/common/cmd_part.c @@ -112,6 +112,74 @@ static int do_part_list(int argc, char * const argv[]) return 0; } +static int do_part_start(int argc, char * const argv[]) +{ + block_dev_desc_t *desc; + disk_partition_t info; + char buf[512] = { 0 }; + int part; + int err; + int ret; + + if (argc < 3) + return CMD_RET_USAGE; + if (argc > 4) + return CMD_RET_USAGE; + + part = simple_strtoul(argv[2], NULL, 0); + + ret = get_device(argv[0], argv[1], &desc); + if (ret < 0) + return 1; + + err = get_partition_info(desc, part, &info); + if (err) + return 1; + + snprintf(buf, sizeof(buf), "%lx", info.start); + + if (argc > 3) + setenv(argv[3], buf); + else + printf("%s\n", buf); + + return 0; +} + +static int do_part_size(int argc, char * const argv[]) +{ + block_dev_desc_t *desc; + disk_partition_t info; + char buf[512] = { 0 }; + int part; + int err; + int ret; + + if (argc < 3) + return CMD_RET_USAGE; + if (argc > 4) + return CMD_RET_USAGE; + + part = simple_strtoul(argv[2], NULL, 0); + + ret = get_device(argv[0], argv[1], &desc); + if (ret < 0) + return 1; + + err = get_partition_info(desc, part, &info); + if (err) + return 1; + + snprintf(buf, sizeof(buf), "%lx", info.size); + + if (argc > 3) + setenv(argv[3], buf); + else + printf("%s\n", buf); + + return 0; +} + static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) @@ -121,6 +189,10 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return do_part_uuid(argc - 2, argv + 2); else if (!strcmp(argv[1], "list")) return do_part_list(argc - 2, argv + 2); + else if (!strcmp(argv[1], "start")) + return do_part_start(argc - 2, argv + 2); + else if (!strcmp(argv[1], "size")) + return do_part_size(argc - 2, argv + 2); return CMD_RET_USAGE; } @@ -136,5 +208,9 @@ U_BOOT_CMD( " - print a device's partition table\n" "part list [flags] \n" " - set environment variable to the list of partitions\n" - " flags can be -bootable (list only bootable partitions)" + " flags can be -bootable (list only bootable partitions)\n" + "part start \n" + " - set environment variable to the start of the partition (in blocks)\n" + "part size \n" + " - set environment variable to the size of the partition (in blocks)" );