summaryrefslogtreecommitdiff
path: root/common/cmd_gpt.c
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2015-01-26 09:44:18 -0600
committerTom Rini <trini@konsulko.com>2015-03-05 11:17:53 -0500
commit0c7e8d1317daa86da7d1cfdea7733f8091a002c1 (patch)
tree6503395c25d6723b6e06128691d9689c2445a912 /common/cmd_gpt.c
parenta150e6c9df04f8c5eb4c7f550a109e3e34aafa81 (diff)
downloadu-boot-0c7e8d1317daa86da7d1cfdea7733f8091a002c1.tar.gz
u-boot-0c7e8d1317daa86da7d1cfdea7733f8091a002c1.tar.bz2
u-boot-0c7e8d1317daa86da7d1cfdea7733f8091a002c1.zip
gpt: support random UUIDs without setting environment variables
Currently, an environment variable must be used to store the randomly generated UUID for each partition. This is not necessary, so make storing the UUID optional. Now passing uuid_disk and uuid are optional when random UUIDs are enabled. Signed-off-by: Rob Herring <robh@kernel.org> Acked-by: Przemyslaw Marczak <p.marczak@samsung.com>
Diffstat (limited to 'common/cmd_gpt.c')
-rw-r--r--common/cmd_gpt.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c
index 75df3feca2..c56fe15d3b 100644
--- a/common/cmd_gpt.c
+++ b/common/cmd_gpt.c
@@ -154,17 +154,24 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
/* extract disk guid */
s = str;
- tok = strsep(&s, ";");
- val = extract_val(tok, "uuid_disk");
+ val = extract_val(str, "uuid_disk");
if (!val) {
+#ifdef CONFIG_RANDOM_UUID
+ *str_disk_guid = malloc(UUID_STR_LEN + 1);
+ gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD);
+#else
free(str);
return -2;
+#endif
+ } else {
+ val = strsep(&val, ";");
+ if (extract_env(val, &p))
+ p = val;
+ *str_disk_guid = strdup(p);
+ free(val);
+ /* Move s to first partition */
+ strsep(&s, ";");
}
- if (extract_env(val, &p))
- p = val;
- *str_disk_guid = strdup(p);
- free(val);
-
if (strlen(s) == 0)
return -3;
@@ -192,20 +199,25 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
/* uuid */
val = extract_val(tok, "uuid");
- if (!val) { /* 'uuid' is mandatory */
- errno = -4;
- goto err;
- }
- if (extract_env(val, &p))
- p = val;
- if (strlen(p) >= sizeof(parts[i].uuid)) {
- printf("Wrong uuid format for partition %d\n", i);
+ if (!val) {
+ /* 'uuid' is optional if random uuid's are enabled */
+#ifdef CONFIG_RANDOM_UUID
+ gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD);
+#else
errno = -4;
goto err;
+#endif
+ } else {
+ if (extract_env(val, &p))
+ p = val;
+ if (strlen(p) >= sizeof(parts[i].uuid)) {
+ printf("Wrong uuid format for partition %d\n", i);
+ errno = -4;
+ goto err;
+ }
+ strcpy((char *)parts[i].uuid, p);
+ free(val);
}
- strcpy((char *)parts[i].uuid, p);
- free(val);
-
/* name */
val = extract_val(tok, "name");
if (!val) { /* name is mandatory */