]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_gpt.c
cmd: gpt: remove bogus code leftover from merge conflict resolution
[karo-tx-uboot.git] / common / cmd_gpt.c
index 446da2c97009a8ab682ad5726204a7d785dfa846..f401209f7ffcfa30c87be97527458cd8ae2b5869 100644 (file)
@@ -141,7 +141,6 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
        char *val, *p;
        int p_count;
        disk_partition_t *parts;
-       char *guid_str;
        int errno = 0;
        uint64_t size_ll, start_ll;
 
@@ -155,23 +154,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 +201,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 */
@@ -249,7 +258,6 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
                }
        }
 
-       *str_disk_guid = guid_str;
        *parts_count = p_count;
        *partitions = parts;
        free(str);
@@ -257,10 +265,8 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
        return 0;
 
 err:
+       free(*str_disk_guid);
        free(parts);
-free_guid:
-       free(guid_str);
-free_str:
        free(str);
 
        *str_disk_guid = NULL;
@@ -293,11 +299,11 @@ static int gpt_default(block_dev_desc_t *blk_dev_desc, const char *str_part)
        }
 
        /* save partitions layout to disk */
-       gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
+       ret = gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count);
        free(str_disk_guid);
        free(partitions);
 
-       return 0;
+       return ret;
 }
 
 /**