public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Farhan Ali <farhan.ali@broadcom.com>
To: u-boot@lists.denx.de
Subject: [PATCH] cmd: gpt: Add option to write GPT partitions to environment variable
Date: Thu, 25 Feb 2021 10:56:36 -0800	[thread overview]
Message-ID: <20210225185636.14148-1-farhan.ali@broadcom.com> (raw)

This change would enhance the existing 'gpt read' command to allow
(optionally) writing of the read GPT partitions to an environment
variable. This would allow users to easily change the partition
settings and then simply reuse the variable in the 'gpt write' and
'gpt verify' commands.

Signed-off-by: Farhan Ali <farhan.ali@broadcom.com>
---
Cc: Simon Glass <sjg@chromium.org>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Corneliu Doban <cdoban@broadcom.com>
Cc: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>

 cmd/gpt.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 76a95ad..12d0551 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -350,17 +350,46 @@ static int get_gpt_info(struct blk_desc *dev_desc)
 }
 
 /* a wrapper to test get_gpt_info */
-static int do_get_gpt_info(struct blk_desc *dev_desc)
+static int do_get_gpt_info(struct blk_desc *dev_desc, char * const namestr)
 {
-	int ret;
+	int numparts;
+
+	numparts = get_gpt_info(dev_desc);
+
+	if (numparts > 0) {
+		if (namestr) {
+			char disk_guid[UUID_STR_LEN + 1];
+			char *partitions_list;
+			int partlistlen;
+			int ret = -1;
+
+			ret = get_disk_guid(dev_desc, disk_guid);
+			if (ret < 0)
+				return ret;
+
+			partlistlen = calc_parts_list_len(numparts);
+			partitions_list = malloc(partlistlen);
+			if (!partitions_list) {
+				del_gpt_info();
+				return -ENOMEM;
+			}
+			memset(partitions_list, '\0', partlistlen);
+
+			ret = create_gpt_partitions_list(numparts, disk_guid,
+							 partitions_list);
+			if (ret < 0)
+				printf("Error: Could not create partition list string!\n");
+			else
+				env_set(namestr, partitions_list);
 
-	ret = get_gpt_info(dev_desc);
-	if (ret > 0) {
-		print_gpt_info();
+			free(partitions_list);
+		} else {
+			print_gpt_info();
+		}
 		del_gpt_info();
 		return 0;
 	}
-	return ret;
+	return numparts;
 }
 #endif
 
@@ -982,7 +1011,7 @@ static int do_gpt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		ret = do_disk_guid(blk_dev_desc, argv[4]);
 #ifdef CONFIG_CMD_GPT_RENAME
 	} else if (strcmp(argv[1], "read") == 0) {
-		ret = do_get_gpt_info(blk_dev_desc);
+		ret = do_get_gpt_info(blk_dev_desc, argv[4]);
 	} else if ((strcmp(argv[1], "swap") == 0) ||
 		   (strcmp(argv[1], "rename") == 0)) {
 		ret = do_rename_gpt_parts(blk_dev_desc, argv[1], argv[4], argv[5]);
@@ -1028,8 +1057,9 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
 	" gpt guid mmc 0 varname\n"
 #ifdef CONFIG_CMD_GPT_RENAME
 	"gpt partition renaming commands:\n"
-	" gpt read <interface> <dev>\n"
+	" gpt read <interface> <dev> [<varname>]\n"
 	"    - read GPT into a data structure for manipulation\n"
+	"    - read GPT partitions into environment variable\n"
 	" gpt swap <interface> <dev> <name1> <name2>\n"
 	"    - change all partitions named name1 to name2\n"
 	"      and vice-versa\n"
-- 
1.8.3.1

             reply	other threads:[~2021-02-25 18:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25 18:56 Farhan Ali [this message]
2021-02-25 20:03 ` [PATCH] cmd: gpt: Add option to write GPT partitions to environment variable Heinrich Schuchardt
2021-02-25 22:25   ` Farhan Ali

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210225185636.14148-1-farhan.ali@broadcom.com \
    --to=farhan.ali@broadcom.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox