[U-Boot] [PATCH V2 3/3] cmd:gpt: randomly generate each partition uuid if undefined

Przemyslaw Marczak p.marczak at samsung.com
Wed Mar 5 17:45:22 CET 2014


Changes:
- randomly generate each partition uuid if undefined
- print info about generated uuid
- save environment on gpt write success
- update doc/README.gpt

Signed-off-by: Przemyslaw Marczak <p.marczak at samsung.com>
Acked-by: Lukasz Majewski <l.majewski at samsung.com>
cc: Piotr Wilczek <p.wilczek at samsung.com>
cc: Tom Rini <trini at ti.com>

---
Changes v2:
- cmd_gpt: extract_env: change return type from char to int
- add tmp array to generate uuid string
- store generated uuid in env and next get it from it - don't need to alloc
  and maintain allcoated memory outside extract_env()

---
 common/cmd_gpt.c |   33 ++++++++++++++++++++++++++-------
 doc/README.gpt   |    1 +
 include/common.h |    3 ++-
 lib/Makefile     |    1 +
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index 1f12e6d..cad402f 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -29,9 +29,11 @@
  *
  * @return - zero on successful expand and env is set
  */
-static char extract_env(const char *str, char **env)
+static int extract_env(const char *str, char **env)
 {
+	int ret = -1;
 	char *e, *s;
+	char uuid_str[37];
 
 	if (!str || strlen(str) < 4)
 		return -1;
@@ -43,16 +45,25 @@ static char extract_env(const char *str, char **env)
 		memset(s + strlen(s) - 1, '\0', 1);
 		memmove(s, s + 2, strlen(s) - 1);
 		e = getenv(s);
-		free(s);
 		if (e == NULL) {
-			printf("Environmental '%s' not set\n", str);
-			return -1; /* env not set */
+			printf("%s unset. ", str);
+			gen_rand_uuid_str(uuid_str);
+			setenv(s, uuid_str);
+
+			e = getenv(s);
+			if (e) {
+				puts("Setting to random.\n");
+				ret = 0;
+			}
+		} else {
+			ret = 0;
 		}
+
 		*env = e;
-		return 0;
+		free(s);
 	}
 
-	return -1;
+	return ret;
 }
 
 /**
@@ -299,8 +310,16 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			return CMD_RET_FAILURE;
 		}
 
-		if (gpt_default(blk_dev_desc, argv[4]))
+		puts("Writing GPT: ");
+
+		ret = gpt_default(blk_dev_desc, argv[4]);
+		if (!ret) {
+			puts("success!\n");
+			return CMD_RET_SUCCESS;
+		} else {
+			puts("error!\n");
 			return CMD_RET_FAILURE;
+		}
 	} else {
 		return CMD_RET_USAGE;
 	}
diff --git a/doc/README.gpt b/doc/README.gpt
index 5c133f3..afe2538 100644
--- a/doc/README.gpt
+++ b/doc/README.gpt
@@ -176,3 +176,4 @@ Please, pay attention at -l switch for parted.
 "uuid" program is recommended to generate UUID string. Moreover it can decode
 (-d switch) passed in UUID string. It can be used to generate partitions UUID
 passed to u-boot environment variables.
+If each partition "uuid" no exists then it will be randomly generated.
diff --git a/include/common.h b/include/common.h
index 20e9ae6..665c98f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -834,7 +834,8 @@ char *	strmhz(char *buf, unsigned long hz);
 #if defined(CONFIG_RANDOM_MACADDR) || \
 	defined(CONFIG_BOOTP_RANDOM_DELAY) || \
 	defined(CONFIG_CMD_LINK_LOCAL) || \
-	defined(CONFIG_RANDOM_UUID)
+	defined(CONFIG_RANDOM_UUID) || \
+	defined(CONFIG_PARTITION_UUIDS)
 #define RAND_MAX -1U
 void srand(unsigned int seed);
 unsigned int rand(void);
diff --git a/lib/Makefile b/lib/Makefile
index 64a430f..e989b18 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -65,6 +65,7 @@ obj-$(CONFIG_BOOTP_PXE) += uuid.o
 obj-$(CONFIG_PARTITION_UUIDS) += uuid.o
 obj-$(CONFIG_RANDOM_UUID) += uuid.o
 obj-$(CONFIG_RANDOM_UUID) += rand.o
+obj-$(CONFIG_PARTITION_UUIDS) += rand.o
 obj-$(CONFIG_RANDOM_MACADDR) += rand.o
 obj-$(CONFIG_BOOTP_RANDOM_DELAY) += rand.o
 obj-$(CONFIG_CMD_LINK_LOCAL) += rand.o
-- 
1.7.9.5



More information about the U-Boot mailing list