From patchwork Mon Feb 26 21:17:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 129725 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp653535lja; Mon, 26 Feb 2018 13:18:56 -0800 (PST) X-Google-Smtp-Source: AG47ELuFXQEijrcnu+QfXYSF1fXXYNv8b7UkXQzfGBERoJ3u8lwvq5KtrZNOW+Hj+Oyvm/S82E/1 X-Received: by 10.80.222.77 with SMTP id a13mr12211454edl.176.1519679936302; Mon, 26 Feb 2018 13:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679936; cv=none; d=google.com; s=arc-20160816; b=tUHOpgSsVS5o/K2pgIA/8jlnRuJIDgXA4EljeOMnJ8BX7zzIt0VIo8ByP+53tsys/K tY9jMU5XPbjZOatjm3IuHCH4/1fkMOpg1Qlcv4NgJkVKLiWtwpIH/3uyoWAie5JWZRl3 jDULPYJe8AHYjzieLOzfBvYfBE7lRBsVFSYuUVFcrIwyv0G9iHpeJ+9Z70bEir0lvsCr uqpOPWhEcOMrAJ7mIK1U6cHn208O5PEU8n3+E2sr9gFT5r6c7WBt0DPYLPncdPfuXGFD PIhenx03fvPygHGxxy7HMEcdi5FcE7z6dypepBdYO6h4zFs6wq/jO3ik6IitwvMG22fs CclA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=RJfn8Y84zFokEWBAAaGkz17AksAqdb9bm/alZQWsdhE=; b=LYqHKeVXykXInLyrbra67OrxvR0Hb67ddYviuM+8wWikJDUH1bMh5oiCdcU/sSsrw6 qTj4GxduGA3tYxDMpxdbwzJ4gB8uEQsm2Kx6JIC35IsTLEjT4rpd9h3WVGQaZslVhJC5 05h0d5j7jlQ1hfv70UWDThtr9lQyzbRFOqddc1MT3eKNv++M+z6tirs74cbwuwic9Nrm dM+apM2hwajcKWwyIvsH8fy2WUdhcdxf++uHXjQPWyyNBrhs3FeuNFFfRuVQOBxC13Yh SjNuAhtKVeCAnJeCS2zj54omOd5knHiekq6jIBNZZvxdP9R0KOPHLZbNQ0+KC7IcVHnz ka/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Jwe9spnD; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id n2si763172edl.109.2018.02.26.13.18.56; Mon, 26 Feb 2018 13:18:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Jwe9spnD; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id D36A1C21F50; Mon, 26 Feb 2018 21:18:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 79823C2216B; Mon, 26 Feb 2018 21:18:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C5BB7C21E2F; Mon, 26 Feb 2018 21:18:09 +0000 (UTC) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by lists.denx.de (Postfix) with ESMTPS id 84ED3C21E5B for ; Mon, 26 Feb 2018 21:18:05 +0000 (UTC) Received: by mail-wr0-f196.google.com with SMTP id f14so22693725wre.8 for ; Mon, 26 Feb 2018 13:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DboOJj8cL/jJUi1FPmzsY98S4GJ66FuscNfiADcPWq4=; b=Jwe9spnDFDs0cTVYWE52S7/oZJPQ00bINq6/+/GE/3Opy+PRxcLRKXJApq5WkCqNfU FIvxXQ+Y0jWlQ/1f98TTWiM8h6qEacPxl0oHZi7C++1xFCOaqMas1fhv46xDa0S23PgT rXJl7sNVqHUlc9t3xm7C29Gd2KwssPSF+cnXQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DboOJj8cL/jJUi1FPmzsY98S4GJ66FuscNfiADcPWq4=; b=Z25VLWzGn7tqGfITp2nIZ3HH/p1EYCnKmCenFuZ2nHv3G9/2A6T6FD1xCBXzMOZedg sgF4br2WnINtcppQ1yhYay/GP0uWkeirQQ5H3ZOLH97Tt8dhrqQas9yZzu7+45+n1h+v 6iGw8f7En7dH9/J5gzFEJotEfdBasi8dG3Qq+yyP4mytSUM3e40HI+9HKxQrLIg+enJ2 DDqNywJ3xzPf4RU9XfSNsednm2xo8W64kgeggmdrDJ9ZFZU+J1mwHHEPK/UObWScjc2z k8sDaDQuA/8clYi9OVJmcefQE7XLlMimI0AOqEzMwREvsZW6evyDZG1uuv6q7Xj0MhBY s52Q== X-Gm-Message-State: APf1xPBtkwjehu1umzyipUwJFwXO7a9bafyOMgWFwiMZNcevOP6mkLOg Dp14Bls6LjNBQbqQXkFfqlQdFCj5oCk= X-Received: by 10.223.157.22 with SMTP id k22mr9935475wre.208.1519679884747; Mon, 26 Feb 2018 13:18:04 -0800 (PST) Received: from localhost ([195.238.92.76]) by smtp.gmail.com with ESMTPSA id l8sm8291483wmf.39.2018.02.26.13.18.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2018 13:18:03 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Date: Mon, 26 Feb 2018 23:17:59 +0200 Message-Id: <20180226211801.16060-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180226211801.16060-1-semen.protsenko@linaro.org> References: <20180226211801.16060-1-semen.protsenko@linaro.org> Cc: Tom Rini , igor.opaniuk@linaro.org, Praneeth Bajjuri , Neil Williams Subject: [U-Boot] [PATCH 1/3] cmd: part: Allow passing partition name to start and size X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Allow passing the partition name to "part start" and "part size" commands, so we can avoid magic numbers in the environment. Consider one real use-case: in include/environment/ti/boot.h we have commands like these: setenv boot_part 9 part start mmc ${mmcdev} ${boot_part} boot_start part size mmc ${mmcdev} ${boot_part} boot_size mmc read ${loadaddr} ${boot_start} ${boot_size} Now suppose that we have changed the partition table and boot_part now is 10. We will need to fix commands above. And anyone who relies on these boot commands, will need to change them accordingly, too (this was an actual case in our lab while testing Linux boot on Android environment). By providing the option to pass partition name instead, we fix mentioned issue, by eliminating the necessity to use magic numbers. Signed-off-by: Sam Protsenko Reviewed-by: Lukasz Majewski --- cmd/part.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/cmd/part.c b/cmd/part.c index 746bf40b2d..fd8825a7ec 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -113,6 +113,7 @@ static int do_part_start(int argc, char * const argv[]) struct blk_desc *desc; disk_partition_t info; char buf[512] = { 0 }; + char *endp; int part; int err; int ret; @@ -122,15 +123,20 @@ static int do_part_start(int argc, char * const argv[]) if (argc > 4) return CMD_RET_USAGE; - part = simple_strtoul(argv[2], NULL, 0); - ret = blk_get_device_by_str(argv[0], argv[1], &desc); if (ret < 0) return 1; - err = part_get_info(desc, part, &info); - if (err) - return 1; + part = simple_strtoul(argv[2], &endp, 0); + if (*endp == '\0') { + err = part_get_info(desc, part, &info); + if (err) + return 1; + } else { + part = part_get_info_by_name(desc, argv[2], &info); + if (part == -1) + return 1; + } snprintf(buf, sizeof(buf), LBAF, info.start); @@ -147,6 +153,7 @@ static int do_part_size(int argc, char * const argv[]) struct blk_desc *desc; disk_partition_t info; char buf[512] = { 0 }; + char *endp; int part; int err; int ret; @@ -156,15 +163,20 @@ static int do_part_size(int argc, char * const argv[]) if (argc > 4) return CMD_RET_USAGE; - part = simple_strtoul(argv[2], NULL, 0); - ret = blk_get_device_by_str(argv[0], argv[1], &desc); if (ret < 0) return 1; - err = part_get_info(desc, part, &info); - if (err) - return 1; + part = simple_strtoul(argv[2], &endp, 0); + if (*endp == '\0') { + err = part_get_info(desc, part, &info); + if (err) + return 1; + } else { + part = part_get_info_by_name(desc, argv[2], &info); + if (part == -1) + return 1; + } snprintf(buf, sizeof(buf), LBAF, info.size); @@ -207,6 +219,8 @@ U_BOOT_CMD( " 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 can be either partition number or partition name\n" "part size \n" - " - set environment variable to the size of the partition (in blocks)" + " - set environment variable to the size of the partition (in blocks)\n" + " part can be either partition number or partition name" );