Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 2 | /* |
| 3 | * cmd_gpt.c -- GPT (GUID Partition Table) handling command |
| 4 | * |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 5 | * Copyright (C) 2015 |
| 6 | * Lukasz Majewski <l.majewski@majess.pl> |
| 7 | * |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 8 | * Copyright (C) 2012 Samsung Electronics |
| 9 | * author: Lukasz Majewski <l.majewski@samsung.com> |
| 10 | * author: Piotr Wilczek <p.wilczek@samsung.com> |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 14 | #include <blk.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 15 | #include <env.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 17 | #include <malloc.h> |
| 18 | #include <command.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 19 | #include <part.h> |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 20 | #include <part_efi.h> |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 21 | #include <part.h> |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 22 | #include <exports.h> |
Simon Glass | 6f04498 | 2020-05-10 11:39:52 -0600 | [diff] [blame] | 23 | #include <uuid.h> |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 24 | #include <linux/ctype.h> |
Piotr Wilczek | 36c06b1 | 2013-01-27 22:59:25 +0000 | [diff] [blame] | 25 | #include <div64.h> |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 26 | #include <memalign.h> |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 27 | #include <linux/compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 28 | #include <linux/err.h> |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 29 | #include <linux/sizes.h> |
| 30 | #include <stdlib.h> |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 31 | |
| 32 | static LIST_HEAD(disk_partitions); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 33 | |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 34 | /** |
| 35 | * extract_env(): Expand env name from string format '&{env_name}' |
| 36 | * and return pointer to the env (if the env is set) |
| 37 | * |
| 38 | * @param str - pointer to string |
| 39 | * @param env - pointer to pointer to extracted env |
| 40 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 41 | * Return: - zero on successful expand and env is set |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 42 | */ |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 43 | static int extract_env(const char *str, char **env) |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 44 | { |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 45 | int ret = -1; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 46 | char *e, *s; |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_RANDOM_UUID |
| 48 | char uuid_str[UUID_STR_LEN + 1]; |
| 49 | #endif |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 50 | |
| 51 | if (!str || strlen(str) < 4) |
| 52 | return -1; |
| 53 | |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 54 | if (!((strncmp(str, "${", 2) == 0) && (str[strlen(str) - 1] == '}'))) |
| 55 | return -1; |
| 56 | |
| 57 | s = strdup(str); |
| 58 | if (s == NULL) |
| 59 | return -1; |
| 60 | |
| 61 | memset(s + strlen(s) - 1, '\0', 1); |
| 62 | memmove(s, s + 2, strlen(s) - 1); |
| 63 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 64 | e = env_get(s); |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 65 | if (e == NULL) { |
| 66 | #ifdef CONFIG_RANDOM_UUID |
| 67 | debug("%s unset. ", str); |
Vincent Tinelli | bdfacea | 2017-02-27 16:11:15 +0200 | [diff] [blame] | 68 | gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_GUID); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 69 | env_set(s, uuid_str); |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 70 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 71 | e = env_get(s); |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 72 | if (e) { |
| 73 | debug("Set to random.\n"); |
| 74 | ret = 0; |
| 75 | } else { |
| 76 | debug("Can't get random UUID.\n"); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 77 | } |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 78 | #else |
| 79 | debug("%s unset.\n", str); |
| 80 | #endif |
| 81 | } else { |
| 82 | debug("%s get from environment.\n", str); |
| 83 | ret = 0; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 86 | *env = e; |
| 87 | free(s); |
| 88 | |
| 89 | return ret; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * extract_val(): Extract value from a key=value pair list (comma separated). |
| 94 | * Only value for the given key is returend. |
| 95 | * Function allocates memory for the value, remember to free! |
| 96 | * |
| 97 | * @param str - pointer to string with key=values pairs |
| 98 | * @param key - pointer to the key to search for |
| 99 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 100 | * Return: - pointer to allocated string with the value |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 101 | */ |
| 102 | static char *extract_val(const char *str, const char *key) |
| 103 | { |
| 104 | char *v, *k; |
| 105 | char *s, *strcopy; |
| 106 | char *new = NULL; |
| 107 | |
| 108 | strcopy = strdup(str); |
| 109 | if (strcopy == NULL) |
| 110 | return NULL; |
| 111 | |
| 112 | s = strcopy; |
| 113 | while (s) { |
| 114 | v = strsep(&s, ","); |
| 115 | if (!v) |
| 116 | break; |
| 117 | k = strsep(&v, "="); |
| 118 | if (!k) |
| 119 | break; |
| 120 | if (strcmp(k, key) == 0) { |
| 121 | new = strdup(v); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | free(strcopy); |
| 127 | |
| 128 | return new; |
| 129 | } |
| 130 | |
| 131 | /** |
Patrick Delaunay | 7840c4a | 2015-11-17 11:36:52 +0100 | [diff] [blame] | 132 | * found_key(): Found key without value in parameter list (comma separated). |
| 133 | * |
| 134 | * @param str - pointer to string with key |
| 135 | * @param key - pointer to the key to search for |
| 136 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 137 | * Return: - true on found key |
Patrick Delaunay | 7840c4a | 2015-11-17 11:36:52 +0100 | [diff] [blame] | 138 | */ |
| 139 | static bool found_key(const char *str, const char *key) |
| 140 | { |
| 141 | char *k; |
| 142 | char *s, *strcopy; |
| 143 | bool result = false; |
| 144 | |
| 145 | strcopy = strdup(str); |
| 146 | if (!strcopy) |
| 147 | return NULL; |
| 148 | |
| 149 | s = strcopy; |
| 150 | while (s) { |
| 151 | k = strsep(&s, ","); |
| 152 | if (!k) |
| 153 | break; |
| 154 | if (strcmp(k, key) == 0) { |
| 155 | result = true; |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | free(strcopy); |
| 161 | |
| 162 | return result; |
| 163 | } |
| 164 | |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 165 | static int calc_parts_list_len(int numparts) |
| 166 | { |
| 167 | int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk="); |
| 168 | /* for the comma */ |
| 169 | partlistlen++; |
| 170 | |
| 171 | /* per-partition additions; numparts starts at 1, so this should be correct */ |
| 172 | partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1); |
| 173 | /* see part.h for definition of struct disk_partition */ |
| 174 | partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1); |
| 175 | partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1); |
| 176 | partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1); |
| 177 | /* for the terminating null */ |
| 178 | partlistlen++; |
| 179 | debug("Length of partitions_list is %d for %d partitions\n", partlistlen, |
| 180 | numparts); |
| 181 | return partlistlen; |
| 182 | } |
| 183 | |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 184 | #ifdef CONFIG_CMD_GPT_RENAME |
| 185 | static void del_gpt_info(void) |
| 186 | { |
| 187 | struct list_head *pos = &disk_partitions; |
| 188 | struct disk_part *curr; |
| 189 | while (!list_empty(pos)) { |
| 190 | curr = list_entry(pos->next, struct disk_part, list); |
| 191 | list_del(pos->next); |
| 192 | free(curr); |
| 193 | } |
| 194 | } |
| 195 | |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 196 | static struct disk_part *allocate_disk_part(struct disk_partition *info, |
| 197 | int partnum) |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 198 | { |
| 199 | struct disk_part *newpart; |
Heinrich Schuchardt | 30725f5 | 2017-09-21 19:03:06 +0200 | [diff] [blame] | 200 | newpart = calloc(1, sizeof(struct disk_part)); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 201 | if (!newpart) |
| 202 | return ERR_PTR(-ENOMEM); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 203 | |
| 204 | newpart->gpt_part_info.start = info->start; |
| 205 | newpart->gpt_part_info.size = info->size; |
| 206 | newpart->gpt_part_info.blksz = info->blksz; |
| 207 | strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name, |
| 208 | PART_NAME_LEN); |
| 209 | newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0'; |
| 210 | strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type, |
| 211 | PART_TYPE_LEN); |
| 212 | newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0'; |
| 213 | newpart->gpt_part_info.bootable = info->bootable; |
Simon Glass | 23e3453 | 2023-08-24 13:55:31 -0600 | [diff] [blame] | 214 | if (IS_ENABLED(CONFIG_PARTITION_UUIDS)) { |
| 215 | strlcpy(newpart->gpt_part_info.uuid, disk_partition_uuid(info), |
| 216 | UUID_STR_LEN + 1); |
| 217 | } |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 218 | newpart->partnum = partnum; |
| 219 | |
| 220 | return newpart; |
| 221 | } |
| 222 | |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 223 | static void prettyprint_part_size(char *sizestr, lbaint_t partsize, |
| 224 | lbaint_t blksize) |
| 225 | { |
| 226 | unsigned long long partbytes, partmegabytes; |
| 227 | |
| 228 | partbytes = partsize * blksize; |
| 229 | partmegabytes = lldiv(partbytes, SZ_1M); |
| 230 | snprintf(sizestr, 16, "%lluMiB", partmegabytes); |
| 231 | } |
| 232 | |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 233 | static void print_gpt_info(void) |
| 234 | { |
| 235 | struct list_head *pos; |
| 236 | struct disk_part *curr; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 237 | char partstartstr[16]; |
| 238 | char partsizestr[16]; |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 239 | |
| 240 | list_for_each(pos, &disk_partitions) { |
| 241 | curr = list_entry(pos, struct disk_part, list); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 242 | prettyprint_part_size(partstartstr, curr->gpt_part_info.start, |
| 243 | curr->gpt_part_info.blksz); |
| 244 | prettyprint_part_size(partsizestr, curr->gpt_part_info.size, |
| 245 | curr->gpt_part_info.blksz); |
| 246 | |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 247 | printf("Partition %d:\n", curr->partnum); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 248 | printf("Start %s, size %s\n", partstartstr, partsizestr); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 249 | printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz, |
| 250 | curr->gpt_part_info.name); |
| 251 | printf("Type %s, bootable %d\n", curr->gpt_part_info.type, |
Heinrich Schuchardt | 59a860d | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 252 | curr->gpt_part_info.bootable & PART_BOOTABLE); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 253 | #ifdef CONFIG_PARTITION_UUIDS |
| 254 | printf("UUID %s\n", curr->gpt_part_info.uuid); |
| 255 | #endif |
| 256 | printf("\n"); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /* |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 261 | * create the string that upstream 'gpt write' command will accept as an |
| 262 | * argument |
| 263 | * |
| 264 | * From doc/README.gpt, Format of partitions layout: |
| 265 | * "uuid_disk=...;name=u-boot,size=60MiB,uuid=...; |
| 266 | * name=kernel,size=60MiB,uuid=...;" |
| 267 | * The fields 'name' and 'size' are mandatory for every partition. |
| 268 | * The field 'start' is optional. The fields 'uuid' and 'uuid_disk' |
| 269 | * are optional if CONFIG_RANDOM_UUID is enabled. |
| 270 | */ |
| 271 | static int create_gpt_partitions_list(int numparts, const char *guid, |
| 272 | char *partitions_list) |
| 273 | { |
| 274 | struct list_head *pos; |
| 275 | struct disk_part *curr; |
| 276 | char partstr[PART_NAME_LEN + 1]; |
| 277 | |
| 278 | if (!partitions_list) |
| 279 | return -EINVAL; |
| 280 | |
| 281 | strcpy(partitions_list, "uuid_disk="); |
| 282 | strncat(partitions_list, guid, UUID_STR_LEN + 1); |
| 283 | strcat(partitions_list, ";"); |
| 284 | |
| 285 | list_for_each(pos, &disk_partitions) { |
| 286 | curr = list_entry(pos, struct disk_part, list); |
| 287 | strcat(partitions_list, "name="); |
| 288 | strncat(partitions_list, (const char *)curr->gpt_part_info.name, |
| 289 | PART_NAME_LEN + 1); |
Patrick Delaunay | 309a6fa | 2017-10-18 15:11:08 +0200 | [diff] [blame] | 290 | sprintf(partstr, ",start=0x%llx", |
| 291 | (unsigned long long)curr->gpt_part_info.start * |
| 292 | curr->gpt_part_info.blksz); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 293 | /* one extra byte for NULL */ |
| 294 | strncat(partitions_list, partstr, PART_NAME_LEN + 1); |
Patrick Delaunay | 309a6fa | 2017-10-18 15:11:08 +0200 | [diff] [blame] | 295 | sprintf(partstr, ",size=0x%llx", |
| 296 | (unsigned long long)curr->gpt_part_info.size * |
| 297 | curr->gpt_part_info.blksz); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 298 | strncat(partitions_list, partstr, PART_NAME_LEN + 1); |
| 299 | |
| 300 | strcat(partitions_list, ",uuid="); |
| 301 | strncat(partitions_list, curr->gpt_part_info.uuid, |
| 302 | UUID_STR_LEN + 1); |
| 303 | strcat(partitions_list, ";"); |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | /* |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 309 | * read partition info into disk_partitions list where |
| 310 | * it can be printed or modified |
| 311 | */ |
| 312 | static int get_gpt_info(struct blk_desc *dev_desc) |
| 313 | { |
| 314 | /* start partition numbering at 1, as U-Boot does */ |
| 315 | int valid_parts = 0, p, ret; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 316 | struct disk_partition info; |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 317 | struct disk_part *new_disk_part; |
| 318 | |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 319 | /* |
| 320 | * Always re-read partition info from device, in case |
| 321 | * it has changed |
| 322 | */ |
| 323 | INIT_LIST_HEAD(&disk_partitions); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 324 | |
| 325 | for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { |
| 326 | ret = part_get_info(dev_desc, p, &info); |
| 327 | if (ret) |
| 328 | continue; |
| 329 | |
| 330 | /* Add 1 here because counter is zero-based but p1 is |
| 331 | the first partition */ |
| 332 | new_disk_part = allocate_disk_part(&info, valid_parts+1); |
| 333 | if (IS_ERR(new_disk_part)) |
| 334 | goto out; |
| 335 | |
| 336 | list_add_tail(&new_disk_part->list, &disk_partitions); |
| 337 | valid_parts++; |
| 338 | } |
| 339 | if (valid_parts == 0) { |
| 340 | printf("** No valid partitions found **\n"); |
| 341 | goto out; |
| 342 | } |
| 343 | return valid_parts; |
| 344 | out: |
| 345 | if (valid_parts >= 1) |
| 346 | del_gpt_info(); |
| 347 | return -ENODEV; |
| 348 | } |
| 349 | |
| 350 | /* a wrapper to test get_gpt_info */ |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 351 | static int do_get_gpt_info(struct blk_desc *dev_desc, char * const namestr) |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 352 | { |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 353 | int numparts; |
| 354 | |
| 355 | numparts = get_gpt_info(dev_desc); |
| 356 | |
| 357 | if (numparts > 0) { |
| 358 | if (namestr) { |
| 359 | char disk_guid[UUID_STR_LEN + 1]; |
| 360 | char *partitions_list; |
| 361 | int partlistlen; |
| 362 | int ret = -1; |
| 363 | |
| 364 | ret = get_disk_guid(dev_desc, disk_guid); |
| 365 | if (ret < 0) |
| 366 | return ret; |
| 367 | |
| 368 | partlistlen = calc_parts_list_len(numparts); |
| 369 | partitions_list = malloc(partlistlen); |
| 370 | if (!partitions_list) { |
| 371 | del_gpt_info(); |
| 372 | return -ENOMEM; |
| 373 | } |
| 374 | memset(partitions_list, '\0', partlistlen); |
| 375 | |
| 376 | ret = create_gpt_partitions_list(numparts, disk_guid, |
| 377 | partitions_list); |
| 378 | if (ret < 0) |
| 379 | printf("Error: Could not create partition list string!\n"); |
| 380 | else |
| 381 | env_set(namestr, partitions_list); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 382 | |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 383 | free(partitions_list); |
| 384 | } else { |
| 385 | print_gpt_info(); |
| 386 | } |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 387 | del_gpt_info(); |
| 388 | return 0; |
| 389 | } |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 390 | return numparts; |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 391 | } |
| 392 | #endif |
| 393 | |
Patrick Delaunay | 7840c4a | 2015-11-17 11:36:52 +0100 | [diff] [blame] | 394 | /** |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 395 | * set_gpt_info(): Fill partition information from string |
| 396 | * function allocates memory, remember to free! |
| 397 | * |
| 398 | * @param dev_desc - pointer block device descriptor |
| 399 | * @param str_part - pointer to string with partition information |
| 400 | * @param str_disk_guid - pointer to pointer to allocated string with disk guid |
| 401 | * @param partitions - pointer to pointer to allocated partitions array |
| 402 | * @param parts_count - number of partitions |
| 403 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 404 | * Return: - zero on success, otherwise error |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 405 | * |
| 406 | */ |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 407 | static int set_gpt_info(struct blk_desc *dev_desc, |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 408 | const char *str_part, |
| 409 | char **str_disk_guid, |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 410 | struct disk_partition **partitions, |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 411 | u8 *parts_count) |
| 412 | { |
| 413 | char *tok, *str, *s; |
| 414 | int i; |
| 415 | char *val, *p; |
| 416 | int p_count; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 417 | struct disk_partition *parts; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 418 | int errno = 0; |
Piotr Wilczek | 36c06b1 | 2013-01-27 22:59:25 +0000 | [diff] [blame] | 419 | uint64_t size_ll, start_ll; |
Michael Trimarchi | 853445f | 2016-06-08 10:18:16 +0200 | [diff] [blame] | 420 | lbaint_t offset = 0; |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 421 | int max_str_part = calc_parts_list_len(MAX_SEARCH_PARTITIONS); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 422 | |
Egbert Eich | bfd4a71 | 2013-10-04 18:53:04 +0200 | [diff] [blame] | 423 | debug("%s: lba num: 0x%x %d\n", __func__, |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 424 | (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba); |
| 425 | |
| 426 | if (str_part == NULL) |
| 427 | return -1; |
| 428 | |
| 429 | str = strdup(str_part); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 430 | if (str == NULL) |
| 431 | return -ENOMEM; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 432 | |
| 433 | /* extract disk guid */ |
| 434 | s = str; |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 435 | val = extract_val(str, "uuid_disk"); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 436 | if (!val) { |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 437 | #ifdef CONFIG_RANDOM_UUID |
| 438 | *str_disk_guid = malloc(UUID_STR_LEN + 1); |
Tom Rini | a29829e | 2017-10-07 11:27:59 -0400 | [diff] [blame] | 439 | if (*str_disk_guid == NULL) |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 440 | return -ENOMEM; |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 441 | gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD); |
| 442 | #else |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 443 | free(str); |
| 444 | return -2; |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 445 | #endif |
| 446 | } else { |
| 447 | val = strsep(&val, ";"); |
| 448 | if (extract_env(val, &p)) |
| 449 | p = val; |
| 450 | *str_disk_guid = strdup(p); |
| 451 | free(val); |
| 452 | /* Move s to first partition */ |
| 453 | strsep(&s, ";"); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 454 | } |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 455 | if (s == NULL) { |
| 456 | printf("Error: is the partitions string NULL-terminated?\n"); |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | if (strnlen(s, max_str_part) == 0) |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 460 | return -3; |
| 461 | |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 462 | i = strnlen(s, max_str_part) - 1; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 463 | if (s[i] == ';') |
| 464 | s[i] = '\0'; |
| 465 | |
| 466 | /* calculate expected number of partitions */ |
| 467 | p_count = 1; |
| 468 | p = s; |
| 469 | while (*p) { |
| 470 | if (*p++ == ';') |
| 471 | p_count++; |
| 472 | } |
| 473 | |
| 474 | /* allocate memory for partitions */ |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 475 | parts = calloc(sizeof(struct disk_partition), p_count); |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 476 | if (parts == NULL) |
| 477 | return -ENOMEM; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 478 | |
Robert P. J. Day | e3f2c2e | 2013-08-21 11:39:19 -0400 | [diff] [blame] | 479 | /* retrieve partitions data from string */ |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 480 | for (i = 0; i < p_count; i++) { |
| 481 | tok = strsep(&s, ";"); |
| 482 | |
| 483 | if (tok == NULL) |
| 484 | break; |
| 485 | |
| 486 | /* uuid */ |
| 487 | val = extract_val(tok, "uuid"); |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 488 | if (!val) { |
| 489 | /* 'uuid' is optional if random uuid's are enabled */ |
| 490 | #ifdef CONFIG_RANDOM_UUID |
| 491 | gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD); |
| 492 | #else |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 493 | errno = -4; |
| 494 | goto err; |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 495 | #endif |
| 496 | } else { |
| 497 | if (extract_env(val, &p)) |
| 498 | p = val; |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 499 | if (strnlen(p, max_str_part) >= sizeof(parts[i].uuid)) { |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 500 | printf("Wrong uuid format for partition %d\n", i); |
| 501 | errno = -4; |
| 502 | goto err; |
| 503 | } |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 504 | strncpy((char *)parts[i].uuid, p, max_str_part); |
Rob Herring | d976197 | 2015-01-26 09:44:18 -0600 | [diff] [blame] | 505 | free(val); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 506 | } |
Patrick Delaunay | 8248c8d | 2015-10-27 11:00:27 +0100 | [diff] [blame] | 507 | #ifdef CONFIG_PARTITION_TYPE_GUID |
| 508 | /* guid */ |
| 509 | val = extract_val(tok, "type"); |
| 510 | if (val) { |
| 511 | /* 'type' is optional */ |
| 512 | if (extract_env(val, &p)) |
| 513 | p = val; |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 514 | if (strnlen(p, max_str_part) >= sizeof(parts[i].type_guid)) { |
Patrick Delaunay | 8248c8d | 2015-10-27 11:00:27 +0100 | [diff] [blame] | 515 | printf("Wrong type guid format for partition %d\n", |
| 516 | i); |
| 517 | errno = -4; |
| 518 | goto err; |
| 519 | } |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 520 | strncpy((char *)parts[i].type_guid, p, max_str_part); |
Patrick Delaunay | 8248c8d | 2015-10-27 11:00:27 +0100 | [diff] [blame] | 521 | free(val); |
| 522 | } |
| 523 | #endif |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 524 | /* name */ |
| 525 | val = extract_val(tok, "name"); |
| 526 | if (!val) { /* name is mandatory */ |
| 527 | errno = -4; |
| 528 | goto err; |
| 529 | } |
| 530 | if (extract_env(val, &p)) |
| 531 | p = val; |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 532 | if (strnlen(p, max_str_part) >= sizeof(parts[i].name)) { |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 533 | errno = -4; |
| 534 | goto err; |
| 535 | } |
Alison Chaiken | 8dcee7c | 2017-07-04 11:19:46 -0700 | [diff] [blame] | 536 | strncpy((char *)parts[i].name, p, max_str_part); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 537 | free(val); |
| 538 | |
| 539 | /* size */ |
| 540 | val = extract_val(tok, "size"); |
| 541 | if (!val) { /* 'size' is mandatory */ |
| 542 | errno = -4; |
| 543 | goto err; |
| 544 | } |
| 545 | if (extract_env(val, &p)) |
| 546 | p = val; |
Michael Trimarchi | 853445f | 2016-06-08 10:18:16 +0200 | [diff] [blame] | 547 | if ((strcmp(p, "-") == 0)) { |
Kever Yang | f1d070d | 2016-07-29 11:12:18 +0800 | [diff] [blame] | 548 | /* Let part efi module to auto extend the size */ |
| 549 | parts[i].size = 0; |
Michael Trimarchi | 853445f | 2016-06-08 10:18:16 +0200 | [diff] [blame] | 550 | } else { |
| 551 | size_ll = ustrtoull(p, &p, 0); |
| 552 | parts[i].size = lldiv(size_ll, dev_desc->blksz); |
| 553 | } |
| 554 | |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 555 | free(val); |
| 556 | |
| 557 | /* start address */ |
| 558 | val = extract_val(tok, "start"); |
| 559 | if (val) { /* start address is optional */ |
| 560 | if (extract_env(val, &p)) |
| 561 | p = val; |
Piotr Wilczek | 36c06b1 | 2013-01-27 22:59:25 +0000 | [diff] [blame] | 562 | start_ll = ustrtoull(p, &p, 0); |
| 563 | parts[i].start = lldiv(start_ll, dev_desc->blksz); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 564 | free(val); |
| 565 | } |
Patrick Delaunay | 7840c4a | 2015-11-17 11:36:52 +0100 | [diff] [blame] | 566 | |
Michael Trimarchi | 853445f | 2016-06-08 10:18:16 +0200 | [diff] [blame] | 567 | offset += parts[i].size + parts[i].start; |
| 568 | |
Patrick Delaunay | 7840c4a | 2015-11-17 11:36:52 +0100 | [diff] [blame] | 569 | /* bootable */ |
| 570 | if (found_key(tok, "bootable")) |
Heinrich Schuchardt | 59a860d | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 571 | parts[i].bootable = PART_BOOTABLE; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | *parts_count = p_count; |
| 575 | *partitions = parts; |
| 576 | free(str); |
| 577 | |
| 578 | return 0; |
| 579 | err: |
| 580 | free(str); |
| 581 | free(*str_disk_guid); |
| 582 | free(parts); |
| 583 | |
| 584 | return errno; |
| 585 | } |
| 586 | |
Philippe Reynes | 5121529 | 2022-04-22 17:46:49 +0200 | [diff] [blame] | 587 | static int gpt_repair(struct blk_desc *blk_dev_desc) |
| 588 | { |
| 589 | int ret = 0; |
| 590 | |
| 591 | ret = gpt_repair_headers(blk_dev_desc); |
| 592 | |
| 593 | return ret; |
| 594 | } |
| 595 | |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 596 | static int gpt_default(struct blk_desc *blk_dev_desc, const char *str_part) |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 597 | { |
| 598 | int ret; |
| 599 | char *str_disk_guid; |
| 600 | u8 part_count = 0; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 601 | struct disk_partition *partitions = NULL; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 602 | |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 603 | /* fill partitions */ |
Egbert Eich | bfd4a71 | 2013-10-04 18:53:04 +0200 | [diff] [blame] | 604 | ret = set_gpt_info(blk_dev_desc, str_part, |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 605 | &str_disk_guid, &partitions, &part_count); |
| 606 | if (ret) { |
| 607 | if (ret == -1) |
| 608 | printf("No partition list provided\n"); |
| 609 | if (ret == -2) |
| 610 | printf("Missing disk guid\n"); |
| 611 | if ((ret == -3) || (ret == -4)) |
| 612 | printf("Partition list incomplete\n"); |
| 613 | return -1; |
| 614 | } |
| 615 | |
| 616 | /* save partitions layout to disk */ |
Rob Herring | 008ab49 | 2015-01-26 09:43:15 -0600 | [diff] [blame] | 617 | ret = gpt_restore(blk_dev_desc, str_disk_guid, partitions, part_count); |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 618 | free(str_disk_guid); |
| 619 | free(partitions); |
| 620 | |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 621 | return ret; |
| 622 | } |
| 623 | |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 624 | static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part) |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 625 | { |
| 626 | ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, |
| 627 | blk_dev_desc->blksz); |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 628 | struct disk_partition *partitions = NULL; |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 629 | gpt_entry *gpt_pte = NULL; |
| 630 | char *str_disk_guid; |
| 631 | u8 part_count = 0; |
| 632 | int ret = 0; |
| 633 | |
| 634 | /* fill partitions */ |
| 635 | ret = set_gpt_info(blk_dev_desc, str_part, |
| 636 | &str_disk_guid, &partitions, &part_count); |
| 637 | if (ret) { |
| 638 | if (ret == -1) { |
| 639 | printf("No partition list provided - only basic check\n"); |
| 640 | ret = gpt_verify_headers(blk_dev_desc, gpt_head, |
| 641 | &gpt_pte); |
| 642 | goto out; |
| 643 | } |
| 644 | if (ret == -2) |
| 645 | printf("Missing disk guid\n"); |
| 646 | if ((ret == -3) || (ret == -4)) |
| 647 | printf("Partition list incomplete\n"); |
| 648 | return -1; |
| 649 | } |
| 650 | |
| 651 | /* Check partition layout with provided pattern */ |
| 652 | ret = gpt_verify_partitions(blk_dev_desc, partitions, part_count, |
| 653 | gpt_head, &gpt_pte); |
| 654 | free(str_disk_guid); |
| 655 | free(partitions); |
| 656 | out: |
| 657 | free(gpt_pte); |
Rob Herring | 008ab49 | 2015-01-26 09:43:15 -0600 | [diff] [blame] | 658 | return ret; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 659 | } |
| 660 | |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 661 | /** |
| 662 | * gpt_enumerate() - Enumerate partition names into environment variable. |
| 663 | * |
| 664 | * Enumerate partition names. Partition names are stored in gpt_partition_list |
| 665 | * environment variable. Each partition name is delimited by space. |
| 666 | * |
| 667 | * @desc: block device descriptor |
| 668 | * |
| 669 | * @Return: '0' on success and -ve error on failure |
| 670 | */ |
| 671 | static int gpt_enumerate(struct blk_desc *desc) |
| 672 | { |
| 673 | struct part_driver *first_drv, *part_drv; |
| 674 | int str_len = 0, tmp_len; |
| 675 | char part_list[2048]; |
| 676 | int n_drvs; |
| 677 | char *ptr; |
| 678 | |
| 679 | part_list[0] = 0; |
| 680 | n_drvs = part_driver_get_count(); |
| 681 | if (!n_drvs) { |
| 682 | printf("Failed to get partition driver count\n"); |
| 683 | return -ENOENT; |
| 684 | } |
| 685 | |
| 686 | first_drv = part_driver_get_first(); |
| 687 | for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) { |
| 688 | struct disk_partition pinfo; |
| 689 | int ret; |
| 690 | int i; |
| 691 | |
Heinrich Schuchardt | 16e48de | 2023-08-26 03:53:42 +0200 | [diff] [blame] | 692 | if (part_drv->test(desc)) |
| 693 | continue; |
| 694 | |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 695 | for (i = 1; i < part_drv->max_entries; i++) { |
| 696 | ret = part_drv->get_info(desc, i, &pinfo); |
Heinrich Schuchardt | 16e48de | 2023-08-26 03:53:42 +0200 | [diff] [blame] | 697 | if (ret) |
| 698 | continue; |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 699 | |
| 700 | ptr = &part_list[str_len]; |
| 701 | tmp_len = strlen((const char *)pinfo.name); |
| 702 | str_len += tmp_len; |
| 703 | /* +1 for space */ |
| 704 | str_len++; |
| 705 | if (str_len > sizeof(part_list)) { |
| 706 | printf("Error insufficient memory\n"); |
| 707 | return -ENOMEM; |
| 708 | } |
| 709 | strcpy(ptr, (const char *)pinfo.name); |
| 710 | /* One byte for space(" ") delimiter */ |
| 711 | ptr[tmp_len] = ' '; |
| 712 | } |
Heinrich Schuchardt | 16e48de | 2023-08-26 03:53:42 +0200 | [diff] [blame] | 713 | if (*part_list) |
| 714 | part_list[strlen(part_list) - 1] = 0; |
| 715 | break; |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 716 | } |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 717 | debug("setenv gpt_partition_list %s\n", part_list); |
| 718 | |
| 719 | return env_set("gpt_partition_list", part_list); |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * gpt_setenv_part_variables() - setup partition environmental variables |
| 724 | * |
| 725 | * Setup the gpt_partition_name, gpt_partition_entry, gpt_partition_addr |
Joshua Watt | fd1134e | 2023-08-31 10:51:37 -0600 | [diff] [blame^] | 726 | * and gpt_partition_size, gpt_partition_bootable environment variables. |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 727 | * |
| 728 | * @pinfo: pointer to disk partition |
| 729 | * @i: partition entry |
| 730 | * |
| 731 | * @Return: '0' on success and -ENOENT on failure |
| 732 | */ |
| 733 | static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i) |
| 734 | { |
| 735 | int ret; |
| 736 | |
| 737 | ret = env_set_hex("gpt_partition_addr", pinfo->start); |
| 738 | if (ret) |
| 739 | goto fail; |
| 740 | |
| 741 | ret = env_set_hex("gpt_partition_size", pinfo->size); |
| 742 | if (ret) |
| 743 | goto fail; |
| 744 | |
Heinrich Schuchardt | 7e879da | 2023-08-26 03:53:43 +0200 | [diff] [blame] | 745 | ret = env_set_hex("gpt_partition_entry", i); |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 746 | if (ret) |
| 747 | goto fail; |
| 748 | |
| 749 | ret = env_set("gpt_partition_name", (const char *)pinfo->name); |
| 750 | if (ret) |
| 751 | goto fail; |
| 752 | |
Joshua Watt | fd1134e | 2023-08-31 10:51:37 -0600 | [diff] [blame^] | 753 | ret = env_set_ulong("gpt_partition_bootable", !!(pinfo->bootable & PART_BOOTABLE)); |
| 754 | if (ret) |
| 755 | goto fail; |
| 756 | |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 757 | return 0; |
| 758 | |
| 759 | fail: |
| 760 | return -ENOENT; |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * gpt_setenv() - Dynamically setup environment variables. |
| 765 | * |
| 766 | * Dynamically setup environment variables for name, index, offset and size |
| 767 | * for partition in GPT table after running "gpt setenv" for a partition name. |
| 768 | * |
| 769 | * @desc: block device descriptor |
| 770 | * @name: partition name |
| 771 | * |
| 772 | * @Return: '0' on success and -ve err on failure |
| 773 | */ |
| 774 | static int gpt_setenv(struct blk_desc *desc, const char *name) |
| 775 | { |
| 776 | struct part_driver *first_drv, *part_drv; |
| 777 | int n_drvs; |
| 778 | int ret = -1; |
| 779 | |
| 780 | n_drvs = part_driver_get_count(); |
| 781 | if (!n_drvs) { |
| 782 | printf("Failed to get partition driver count\n"); |
| 783 | goto fail; |
| 784 | } |
| 785 | |
| 786 | first_drv = part_driver_get_first(); |
| 787 | for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) { |
| 788 | struct disk_partition pinfo; |
| 789 | int i; |
| 790 | |
| 791 | for (i = 1; i < part_drv->max_entries; i++) { |
| 792 | ret = part_drv->get_info(desc, i, &pinfo); |
Heinrich Schuchardt | 441dc54 | 2023-08-26 03:53:41 +0200 | [diff] [blame] | 793 | if (ret) |
| 794 | continue; |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 795 | |
| 796 | if (!strcmp(name, (const char *)pinfo.name)) { |
| 797 | /* match found, setup environment variables */ |
| 798 | ret = gpt_setenv_part_variables(&pinfo, i); |
| 799 | if (ret) |
| 800 | goto fail; |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | fail: |
| 808 | return ret; |
| 809 | } |
| 810 | |
Alison Chaiken | e422258 | 2017-06-25 16:43:23 -0700 | [diff] [blame] | 811 | static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr) |
| 812 | { |
| 813 | int ret; |
| 814 | char disk_guid[UUID_STR_LEN + 1]; |
| 815 | |
| 816 | ret = get_disk_guid(dev_desc, disk_guid); |
| 817 | if (ret < 0) |
| 818 | return CMD_RET_FAILURE; |
| 819 | |
| 820 | if (namestr) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 821 | env_set(namestr, disk_guid); |
Alison Chaiken | e422258 | 2017-06-25 16:43:23 -0700 | [diff] [blame] | 822 | else |
| 823 | printf("%s\n", disk_guid); |
| 824 | |
| 825 | return ret; |
| 826 | } |
| 827 | |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 828 | #ifdef CONFIG_CMD_GPT_RENAME |
| 829 | static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, |
| 830 | char *name1, char *name2) |
| 831 | { |
| 832 | struct list_head *pos; |
| 833 | struct disk_part *curr; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 834 | struct disk_partition *new_partitions = NULL; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 835 | char disk_guid[UUID_STR_LEN + 1]; |
Tom Rini | b0d3c0b | 2020-01-21 11:53:38 -0500 | [diff] [blame] | 836 | char *partitions_list, *str_disk_guid = NULL; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 837 | u8 part_count = 0; |
| 838 | int partlistlen, ret, numparts = 0, partnum, i = 1, ctr1 = 0, ctr2 = 0; |
| 839 | |
| 840 | if ((subcomm == NULL) || (name1 == NULL) || (name2 == NULL) || |
| 841 | (strcmp(subcomm, "swap") && (strcmp(subcomm, "rename")))) |
| 842 | return -EINVAL; |
| 843 | |
| 844 | ret = get_disk_guid(dev_desc, disk_guid); |
| 845 | if (ret < 0) |
| 846 | return ret; |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 847 | /* |
| 848 | * Allocates disk_partitions, requiring matching call to del_gpt_info() |
| 849 | * if successful. |
| 850 | */ |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 851 | numparts = get_gpt_info(dev_desc); |
| 852 | if (numparts <= 0) |
| 853 | return numparts ? numparts : -ENODEV; |
| 854 | |
| 855 | partlistlen = calc_parts_list_len(numparts); |
| 856 | partitions_list = malloc(partlistlen); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 857 | if (!partitions_list) { |
| 858 | del_gpt_info(); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 859 | return -ENOMEM; |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 860 | } |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 861 | memset(partitions_list, '\0', partlistlen); |
| 862 | |
| 863 | ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 864 | if (ret < 0) { |
| 865 | free(partitions_list); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 866 | return ret; |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 867 | } |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 868 | /* |
| 869 | * Uncomment the following line to print a string that 'gpt write' |
| 870 | * or 'gpt verify' will accept as input. |
| 871 | */ |
| 872 | debug("OLD partitions_list is %s with %u chars\n", partitions_list, |
| 873 | (unsigned)strlen(partitions_list)); |
| 874 | |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 875 | /* set_gpt_info allocates new_partitions and str_disk_guid */ |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 876 | ret = set_gpt_info(dev_desc, partitions_list, &str_disk_guid, |
| 877 | &new_partitions, &part_count); |
Tom Rini | b0d3c0b | 2020-01-21 11:53:38 -0500 | [diff] [blame] | 878 | if (ret < 0) |
| 879 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 880 | |
| 881 | if (!strcmp(subcomm, "swap")) { |
| 882 | if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > PART_NAME_LEN)) { |
| 883 | printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 884 | ret = -EINVAL; |
| 885 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 886 | } |
| 887 | list_for_each(pos, &disk_partitions) { |
| 888 | curr = list_entry(pos, struct disk_part, list); |
| 889 | if (!strcmp((char *)curr->gpt_part_info.name, name1)) { |
| 890 | strcpy((char *)curr->gpt_part_info.name, name2); |
| 891 | ctr1++; |
| 892 | } else if (!strcmp((char *)curr->gpt_part_info.name, name2)) { |
| 893 | strcpy((char *)curr->gpt_part_info.name, name1); |
| 894 | ctr2++; |
| 895 | } |
| 896 | } |
| 897 | if ((ctr1 + ctr2 < 2) || (ctr1 != ctr2)) { |
| 898 | printf("Cannot swap partition names except in pairs.\n"); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 899 | ret = -EINVAL; |
| 900 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 901 | } |
| 902 | } else { /* rename */ |
| 903 | if (strlen(name2) > PART_NAME_LEN) { |
| 904 | printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 905 | ret = -EINVAL; |
| 906 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 907 | } |
| 908 | partnum = (int)simple_strtol(name1, NULL, 10); |
| 909 | if ((partnum < 0) || (partnum > numparts)) { |
| 910 | printf("Illegal partition number %s\n", name1); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 911 | ret = -EINVAL; |
| 912 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 913 | } |
| 914 | ret = part_get_info(dev_desc, partnum, new_partitions); |
| 915 | if (ret < 0) |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 916 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 917 | |
| 918 | /* U-Boot partition numbering starts at 1 */ |
| 919 | list_for_each(pos, &disk_partitions) { |
| 920 | curr = list_entry(pos, struct disk_part, list); |
| 921 | if (i == partnum) { |
| 922 | strcpy((char *)curr->gpt_part_info.name, name2); |
| 923 | break; |
| 924 | } |
| 925 | i++; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list); |
| 930 | if (ret < 0) |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 931 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 932 | debug("NEW partitions_list is %s with %u chars\n", partitions_list, |
| 933 | (unsigned)strlen(partitions_list)); |
| 934 | |
| 935 | ret = set_gpt_info(dev_desc, partitions_list, &str_disk_guid, |
| 936 | &new_partitions, &part_count); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 937 | /* |
| 938 | * Even though valid pointers are here passed into set_gpt_info(), |
| 939 | * it mallocs again, and there's no way to tell which failed. |
| 940 | */ |
Tom Rini | b0d3c0b | 2020-01-21 11:53:38 -0500 | [diff] [blame] | 941 | if (ret < 0) |
| 942 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 943 | |
| 944 | debug("Writing new partition table\n"); |
| 945 | ret = gpt_restore(dev_desc, disk_guid, new_partitions, numparts); |
| 946 | if (ret < 0) { |
| 947 | printf("Writing new partition table failed\n"); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 948 | goto out; |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | debug("Reading back new partition table\n"); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 952 | /* |
| 953 | * Empty the existing disk_partitions list, as otherwise the memory in |
| 954 | * the original list is unreachable. |
| 955 | */ |
| 956 | del_gpt_info(); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 957 | numparts = get_gpt_info(dev_desc); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 958 | if (numparts <= 0) { |
| 959 | ret = numparts ? numparts : -ENODEV; |
| 960 | goto out; |
| 961 | } |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 962 | printf("new partition table with %d partitions is:\n", numparts); |
| 963 | print_gpt_info(); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 964 | out: |
Tom Rini | b0d3c0b | 2020-01-21 11:53:38 -0500 | [diff] [blame] | 965 | del_gpt_info(); |
| 966 | #ifdef CONFIG_RANDOM_UUID |
Heinrich Schuchardt | 443806d | 2020-04-28 21:40:13 +0200 | [diff] [blame] | 967 | free(str_disk_guid); |
Tom Rini | b0d3c0b | 2020-01-21 11:53:38 -0500 | [diff] [blame] | 968 | #endif |
Heinrich Schuchardt | 443806d | 2020-04-28 21:40:13 +0200 | [diff] [blame] | 969 | free(new_partitions); |
Alison Chaiken | 7e805c0 | 2017-09-26 07:42:28 -0700 | [diff] [blame] | 970 | free(partitions_list); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 971 | return ret; |
| 972 | } |
| 973 | #endif |
| 974 | |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 975 | /** |
| 976 | * do_gpt(): Perform GPT operations |
| 977 | * |
| 978 | * @param cmdtp - command name |
| 979 | * @param flag |
| 980 | * @param argc |
| 981 | * @param argv |
| 982 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 983 | * Return: zero on success; otherwise error |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 984 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 985 | static int do_gpt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 986 | { |
| 987 | int ret = CMD_RET_SUCCESS; |
| 988 | int dev = 0; |
Egbert Eich | bfd4a71 | 2013-10-04 18:53:04 +0200 | [diff] [blame] | 989 | char *ep; |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 990 | struct blk_desc *blk_dev_desc = NULL; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 991 | |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 992 | #ifndef CONFIG_CMD_GPT_RENAME |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 993 | if (argc < 4 || argc > 5) |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 994 | #else |
| 995 | if (argc < 4 || argc > 6) |
| 996 | #endif |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 997 | return CMD_RET_USAGE; |
| 998 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 999 | dev = (int)dectoul(argv[3], &ep); |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 1000 | if (!ep || ep[0] != '\0') { |
| 1001 | printf("'%s' is not a number\n", argv[3]); |
| 1002 | return CMD_RET_USAGE; |
| 1003 | } |
Simon Glass | be1e9bb | 2016-02-29 15:25:42 -0700 | [diff] [blame] | 1004 | blk_dev_desc = blk_get_dev(argv[2], dev); |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 1005 | if (!blk_dev_desc) { |
| 1006 | printf("%s: %s dev %d NOT available\n", |
| 1007 | __func__, argv[2], dev); |
| 1008 | return CMD_RET_FAILURE; |
| 1009 | } |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 1010 | |
Philippe Reynes | 5121529 | 2022-04-22 17:46:49 +0200 | [diff] [blame] | 1011 | if (strcmp(argv[1], "repair") == 0) { |
| 1012 | printf("Repairing GPT: "); |
| 1013 | ret = gpt_repair(blk_dev_desc); |
| 1014 | } else if ((strcmp(argv[1], "write") == 0) && (argc == 5)) { |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 1015 | printf("Writing GPT: "); |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 1016 | ret = gpt_default(blk_dev_desc, argv[4]); |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 1017 | } else if ((strcmp(argv[1], "verify") == 0)) { |
| 1018 | ret = gpt_verify(blk_dev_desc, argv[4]); |
| 1019 | printf("Verify GPT: "); |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 1020 | } else if ((strcmp(argv[1], "setenv") == 0)) { |
| 1021 | ret = gpt_setenv(blk_dev_desc, argv[4]); |
| 1022 | } else if ((strcmp(argv[1], "enumerate") == 0)) { |
| 1023 | ret = gpt_enumerate(blk_dev_desc); |
Alison Chaiken | e422258 | 2017-06-25 16:43:23 -0700 | [diff] [blame] | 1024 | } else if (strcmp(argv[1], "guid") == 0) { |
| 1025 | ret = do_disk_guid(blk_dev_desc, argv[4]); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 1026 | #ifdef CONFIG_CMD_GPT_RENAME |
| 1027 | } else if (strcmp(argv[1], "read") == 0) { |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 1028 | ret = do_get_gpt_info(blk_dev_desc, (argc == 5) ? argv[4] : NULL); |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 1029 | } else if ((strcmp(argv[1], "swap") == 0) || |
| 1030 | (strcmp(argv[1], "rename") == 0)) { |
| 1031 | ret = do_rename_gpt_parts(blk_dev_desc, argv[1], argv[4], argv[5]); |
Alison Chaiken | f04d4b5 | 2017-07-04 11:18:50 -0700 | [diff] [blame] | 1032 | #endif |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 1033 | } else { |
| 1034 | return CMD_RET_USAGE; |
| 1035 | } |
Lukasz Majewski | 309691b | 2015-11-20 08:06:17 +0100 | [diff] [blame] | 1036 | |
| 1037 | if (ret) { |
| 1038 | printf("error!\n"); |
| 1039 | return CMD_RET_FAILURE; |
| 1040 | } |
| 1041 | |
| 1042 | printf("success!\n"); |
| 1043 | return CMD_RET_SUCCESS; |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt, |
| 1047 | "GUID Partition Table", |
Robert P. J. Day | e3f2c2e | 2013-08-21 11:39:19 -0400 | [diff] [blame] | 1048 | "<command> <interface> <dev> <partitions_list>\n" |
Lukasz Majewski | cc5f3d7 | 2015-11-13 07:42:10 +0100 | [diff] [blame] | 1049 | " - GUID partition table restoration and validity check\n" |
| 1050 | " Restore or verify GPT information on a device connected\n" |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 1051 | " to interface\n" |
Lukasz Majewski | cc5f3d7 | 2015-11-13 07:42:10 +0100 | [diff] [blame] | 1052 | " Example usage:\n" |
Philippe Reynes | 5121529 | 2022-04-22 17:46:49 +0200 | [diff] [blame] | 1053 | " gpt repair mmc 0\n" |
| 1054 | " - repair the GPT on the device\n" |
Lukasz Majewski | cc5f3d7 | 2015-11-13 07:42:10 +0100 | [diff] [blame] | 1055 | " gpt write mmc 0 $partitions\n" |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 1056 | " - write the GPT to device\n" |
Lukasz Majewski | cc5f3d7 | 2015-11-13 07:42:10 +0100 | [diff] [blame] | 1057 | " gpt verify mmc 0 $partitions\n" |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 1058 | " - verify the GPT on device against $partitions\n" |
| 1059 | " gpt setenv mmc 0 $name\n" |
| 1060 | " - setup environment variables for partition $name:\n" |
| 1061 | " gpt_partition_addr, gpt_partition_size,\n" |
Joshua Watt | fd1134e | 2023-08-31 10:51:37 -0600 | [diff] [blame^] | 1062 | " gpt_partition_name, gpt_partition_entry,\n" |
| 1063 | " gpt_partition_bootable\n" |
Corneliu Doban | 0c6776c | 2020-11-09 11:49:16 +0530 | [diff] [blame] | 1064 | " gpt enumerate mmc 0\n" |
| 1065 | " - store list of partitions to gpt_partition_list environment variable\n" |
Eugeniu Rosca | fa8acbc | 2019-04-30 04:53:46 +0200 | [diff] [blame] | 1066 | " gpt guid <interface> <dev>\n" |
Alison Chaiken | e422258 | 2017-06-25 16:43:23 -0700 | [diff] [blame] | 1067 | " - print disk GUID\n" |
Eugeniu Rosca | fa8acbc | 2019-04-30 04:53:46 +0200 | [diff] [blame] | 1068 | " gpt guid <interface> <dev> <varname>\n" |
Alison Chaiken | e422258 | 2017-06-25 16:43:23 -0700 | [diff] [blame] | 1069 | " - set environment variable to disk GUID\n" |
| 1070 | " Example usage:\n" |
| 1071 | " gpt guid mmc 0\n" |
| 1072 | " gpt guid mmc 0 varname\n" |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 1073 | #ifdef CONFIG_CMD_GPT_RENAME |
| 1074 | "gpt partition renaming commands:\n" |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 1075 | " gpt read <interface> <dev> [<varname>]\n" |
Eugeniu Rosca | fa8acbc | 2019-04-30 04:53:46 +0200 | [diff] [blame] | 1076 | " - read GPT into a data structure for manipulation\n" |
Farhan Ali | 078d022 | 2021-02-26 10:17:33 -0800 | [diff] [blame] | 1077 | " - read GPT partitions into environment variable\n" |
Eugeniu Rosca | fa8acbc | 2019-04-30 04:53:46 +0200 | [diff] [blame] | 1078 | " gpt swap <interface> <dev> <name1> <name2>\n" |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 1079 | " - change all partitions named name1 to name2\n" |
| 1080 | " and vice-versa\n" |
Eugeniu Rosca | fa8acbc | 2019-04-30 04:53:46 +0200 | [diff] [blame] | 1081 | " gpt rename <interface> <dev> <part> <name>\n" |
Alison Chaiken | 8b3397f | 2017-07-04 11:19:18 -0700 | [diff] [blame] | 1082 | " - rename the specified partition\n" |
| 1083 | " Example usage:\n" |
| 1084 | " gpt swap mmc 0 foo bar\n" |
| 1085 | " gpt rename mmc 0 3 foo\n" |
| 1086 | #endif |
Piotr Wilczek | cc00ea8 | 2012-12-11 11:09:47 +0100 | [diff] [blame] | 1087 | ); |