]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
gpt: support random UUIDs without setting environment variables
authorRob Herring <robh@kernel.org>
Mon, 26 Jan 2015 15:44:18 +0000 (09:44 -0600)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 1 Sep 2015 12:18:43 +0000 (14:18 +0200)
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>
common/cmd_gpt.c
doc/README.gpt

index dad0973f3ca3108985e44ddc7209538d676baed3..1feb41d93c75d8ffc92a4a2197570391c32ab0ae 100644 (file)
@@ -155,23 +155,28 @@ 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) {
-               errno = -2;
-               goto free_str;
-       }
-       if (extract_env(val, &p) == 0)
-               guid_str = strdup(p);
-       else
-               guid_str = strdup(val);
-
-       free(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 {
+               char *v = val;
 
-       if (strlen(s) == 0) {
-               errno = -3;
-               goto free_guid;
+               v = strsep(&v, ";");
+               if (extract_env(v, &p))
+                       p = v;
+               *str_disk_guid = strdup(p);
+               free(val);
+               /* Move s to first partition */
+               strsep(&s, ";");
        }
+       if (strlen(s) == 0)
+               return -3;
 
        i = strlen(s) - 1;
        if (s[i] == ';')
@@ -197,20 +202,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 */
index ec0156d8aa9b8073555bbe00f5836f4e0883fe1c..59fdeebfe89ccedbf6dc41e7d70c6449bb505c23 100644 (file)
@@ -157,11 +157,13 @@ To restore GUID partition table one needs to:
      "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
        size=${uboot_size},uuid=${uboot_uuid};"
 
-   Fields 'name', 'size' and 'uuid' are mandatory for every partition.
+   The fields 'name' and 'size' are mandatory for every partition.
    The field 'start' is optional.
 
-   option: CONFIG_RANDOM_UUID
-   If any partition "UUID" no exists then it is randomly generated.
+   The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
+   enabled. A random uuid will be used if omitted or they point to an empty/
+   non-existent environment variable. The environment variable will be set to
+   the generated UUID.
 
 2. Define 'CONFIG_EFI_PARTITION' and 'CONFIG_CMD_GPT'