]> 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 e38422d792eec2784102bccadea93b5b522c8666..f401209f7ffcfa30c87be97527458cd8ae2b5869 100644 (file)
@@ -154,17 +154,26 @@ 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;
-       }
-       if (extract_env(val, &p))
-               p = val;
-       *str_disk_guid = strdup(p);
-       free(val);
+#endif
+       } else {
+               char *v = val;
 
+               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;
 
@@ -192,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,11 +263,15 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
        free(str);
 
        return 0;
+
 err:
-       free(str);
        free(*str_disk_guid);
        free(parts);
+       free(str);
 
+       *str_disk_guid = NULL;
+       *parts_count = 0;
+       *partitions = NULL;
        return errno;
 }
 
@@ -281,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;
 }
 
 /**