Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011 Calxeda, Inc. |
Abdellatif El Khlifi | dc3cb5d | 2023-08-04 14:33:38 +0100 | [diff] [blame] | 4 | * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 5 | * |
| 6 | * Authors: |
| 7 | * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 10 | #ifndef USE_HOSTCC |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 11 | #include <command.h> |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 12 | #include <efi_api.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <rand.h> |
Simon Glass | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 15 | #include <time.h> |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <part_efi.h> |
| 18 | #include <malloc.h> |
Matthias Brugger | d03560b | 2020-12-18 10:28:03 +0100 | [diff] [blame] | 19 | #include <dm/uclass.h> |
| 20 | #include <rng.h> |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 21 | #include <linux/ctype.h> |
| 22 | #include <hexdump.h> |
| 23 | #else |
| 24 | #include <stdarg.h> |
| 25 | #include <stdint.h> |
| 26 | #include <eficapsule.h> |
| 27 | #include <ctype.h> |
| 28 | #endif |
| 29 | #include <linux/types.h> |
| 30 | #include <errno.h> |
| 31 | #include <linux/kconfig.h> |
Caleb Connolly | 29cab7c | 2024-08-30 13:34:37 +0100 | [diff] [blame] | 32 | #include <u-boot/uuid.h> |
Caleb Connolly | 2f4f0be | 2024-08-30 13:34:32 +0100 | [diff] [blame] | 33 | #include <u-boot/sha1.h> |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 34 | |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 35 | #ifdef USE_HOSTCC |
| 36 | /* polyfill hextoul to avoid pulling in strto.c */ |
| 37 | #define hextoul(cp, endp) strtoul(cp, endp, 16) |
Heinrich Schuchardt | 80e81d8 | 2024-11-03 23:42:21 +0100 | [diff] [blame] | 38 | #define hextoull(cp, endp) strtoull(cp, endp, 16) |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 39 | #endif |
| 40 | |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 41 | int uuid_str_valid(const char *uuid) |
| 42 | { |
| 43 | int i, valid; |
| 44 | |
| 45 | if (uuid == NULL) |
| 46 | return 0; |
| 47 | |
| 48 | for (i = 0, valid = 1; uuid[i] && valid; i++) { |
| 49 | switch (i) { |
| 50 | case 8: case 13: case 18: case 23: |
| 51 | valid = (uuid[i] == '-'); |
| 52 | break; |
| 53 | default: |
| 54 | valid = isxdigit(uuid[i]); |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 59 | if (i != UUID_STR_LEN || !valid) |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 60 | return 0; |
| 61 | |
| 62 | return 1; |
| 63 | } |
| 64 | |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 65 | /* |
| 66 | * Array of string (short and long) for known GUID of GPT partition type |
| 67 | * at least one string must be present, @type or @description |
| 68 | * |
| 69 | * @type : short name for the parameter 'type' of gpt command (max size UUID_STR_LEN = 36, |
| 70 | * no space), also used as fallback description when the next field is absent |
| 71 | * @description : long description associated to type GUID, used for %pUs |
| 72 | * @guid : known type GUID value |
| 73 | */ |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 74 | static const struct { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 75 | const char *type; |
| 76 | const char *description; |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 77 | efi_guid_t guid; |
| 78 | } list_guid[] = { |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 79 | #ifndef USE_HOSTCC |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 80 | #if CONFIG_IS_ENABLED(EFI_PARTITION) |
| 81 | {"mbr", NULL, LEGACY_MBR_PARTITION_GUID}, |
| 82 | {"msft", NULL, PARTITION_MSFT_RESERVED_GUID}, |
| 83 | {"data", NULL, PARTITION_BASIC_DATA_GUID}, |
| 84 | {"linux", NULL, PARTITION_LINUX_FILE_SYSTEM_DATA_GUID}, |
| 85 | {"raid", NULL, PARTITION_LINUX_RAID_GUID}, |
| 86 | {"swap", NULL, PARTITION_LINUX_SWAP_GUID}, |
| 87 | {"lvm", NULL, PARTITION_LINUX_LVM_GUID}, |
| 88 | {"u-boot-env", NULL, PARTITION_U_BOOT_ENVIRONMENT}, |
| 89 | {"cros-kern", NULL, PARTITION_CROS_KERNEL}, |
| 90 | {"cros-root", NULL, PARTITION_CROS_ROOT}, |
| 91 | {"cros-fw", NULL, PARTITION_CROS_FIRMWARE}, |
| 92 | {"cros-rsrv", NULL, PARTITION_CROS_RESERVED}, |
| 93 | { |
| 94 | "system", "EFI System Partition", |
| 95 | PARTITION_SYSTEM_GUID, |
| 96 | }, |
Simon Glass | f7f5578 | 2023-03-20 08:30:12 +1300 | [diff] [blame] | 97 | #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI) |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 98 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 99 | NULL, "Device Path", |
| 100 | PARTITION_SYSTEM_GUID, |
| 101 | }, |
| 102 | { |
| 103 | NULL, "Device Path", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 104 | EFI_DEVICE_PATH_PROTOCOL_GUID, |
| 105 | }, |
| 106 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 107 | NULL, "Device Path To Text", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 108 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, |
| 109 | }, |
| 110 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 111 | NULL, "Device Path Utilities", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 112 | EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, |
| 113 | }, |
| 114 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 115 | NULL, "Unicode Collation 2", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 116 | EFI_UNICODE_COLLATION_PROTOCOL2_GUID, |
| 117 | }, |
| 118 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 119 | NULL, "Driver Binding", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 120 | EFI_DRIVER_BINDING_PROTOCOL_GUID, |
| 121 | }, |
| 122 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 123 | NULL, "Simple Text Input", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 124 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, |
| 125 | }, |
| 126 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 127 | NULL, "Simple Text Input Ex", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 128 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, |
| 129 | }, |
| 130 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 131 | NULL, "Simple Text Output", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 132 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, |
| 133 | }, |
| 134 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 135 | NULL, "Block IO", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 136 | EFI_BLOCK_IO_PROTOCOL_GUID, |
| 137 | }, |
| 138 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 139 | NULL, "Disk IO", |
Vincent Stehlé | e3cdedc | 2025-01-17 18:13:26 +0100 | [diff] [blame] | 140 | EFI_DISK_IO_PROTOCOL_GUID, |
| 141 | }, |
| 142 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 143 | NULL, "Simple File System", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 144 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, |
| 145 | }, |
| 146 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 147 | NULL, "Loaded Image", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 148 | EFI_LOADED_IMAGE_PROTOCOL_GUID, |
| 149 | }, |
| 150 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 151 | NULL, "Loaded Image Device Path", |
Vincent Stehlé | e3cdedc | 2025-01-17 18:13:26 +0100 | [diff] [blame] | 152 | EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID, |
| 153 | }, |
| 154 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 155 | NULL, "Graphics Output", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 156 | EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, |
| 157 | }, |
| 158 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 159 | NULL, "HII String", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 160 | EFI_HII_STRING_PROTOCOL_GUID, |
| 161 | }, |
| 162 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 163 | NULL, "HII Database", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 164 | EFI_HII_DATABASE_PROTOCOL_GUID, |
| 165 | }, |
| 166 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 167 | NULL, "HII Config Access", |
Vincent Stehlé | e3cdedc | 2025-01-17 18:13:26 +0100 | [diff] [blame] | 168 | EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID, |
| 169 | }, |
| 170 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 171 | NULL, "HII Config Routing", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 172 | EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, |
| 173 | }, |
| 174 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 175 | NULL, "Load File", |
Vincent Stehlé | e3cdedc | 2025-01-17 18:13:26 +0100 | [diff] [blame] | 176 | EFI_LOAD_FILE_PROTOCOL_GUID, |
| 177 | }, |
| 178 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 179 | NULL, "Load File2", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 180 | EFI_LOAD_FILE2_PROTOCOL_GUID, |
| 181 | }, |
| 182 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 183 | NULL, "Random Number Generator", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 184 | EFI_RNG_PROTOCOL_GUID, |
| 185 | }, |
| 186 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 187 | NULL, "Simple Network", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 188 | EFI_SIMPLE_NETWORK_PROTOCOL_GUID, |
| 189 | }, |
| 190 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 191 | NULL, "PXE Base Code", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 192 | EFI_PXE_BASE_CODE_PROTOCOL_GUID, |
| 193 | }, |
| 194 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 195 | NULL, "Device-Tree Fixup", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 196 | EFI_DT_FIXUP_PROTOCOL_GUID, |
| 197 | }, |
| 198 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 199 | NULL, "TCG2", |
Heinrich Schuchardt | d2a7d12 | 2022-01-16 17:46:38 +0100 | [diff] [blame] | 200 | EFI_TCG2_PROTOCOL_GUID, |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 201 | }, |
| 202 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 203 | NULL, "Firmware Management", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 204 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID |
| 205 | }, |
Heinrich Schuchardt | 06649fe | 2024-12-04 00:05:27 -0300 | [diff] [blame] | 206 | #if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL) |
| 207 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 208 | NULL, "HTTP", |
Heinrich Schuchardt | 06649fe | 2024-12-04 00:05:27 -0300 | [diff] [blame] | 209 | EFI_HTTP_PROTOCOL_GUID, |
| 210 | }, |
| 211 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 212 | NULL, "HTTP Service Binding", |
Heinrich Schuchardt | 06649fe | 2024-12-04 00:05:27 -0300 | [diff] [blame] | 213 | EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID, |
| 214 | }, |
| 215 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 216 | NULL, "IPv4 Config2", |
Heinrich Schuchardt | 06649fe | 2024-12-04 00:05:27 -0300 | [diff] [blame] | 217 | EFI_IP4_CONFIG2_PROTOCOL_GUID, |
| 218 | }, |
| 219 | #endif |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 220 | /* Configuration table GUIDs */ |
| 221 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 222 | NULL, "ACPI table", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 223 | EFI_ACPI_TABLE_GUID, |
| 224 | }, |
| 225 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 226 | NULL, "EFI System Resource Table", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 227 | EFI_SYSTEM_RESOURCE_TABLE_GUID, |
| 228 | }, |
| 229 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 230 | NULL, "device tree", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 231 | EFI_FDT_GUID, |
| 232 | }, |
| 233 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 234 | NULL, "SMBIOS table", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 235 | SMBIOS_TABLE_GUID, |
| 236 | }, |
| 237 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 238 | NULL, "SMBIOS3 table", |
Heinrich Schuchardt | b36c9a0 | 2024-01-22 14:04:35 +0100 | [diff] [blame] | 239 | SMBIOS3_TABLE_GUID, |
| 240 | }, |
| 241 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 242 | NULL, "Runtime properties", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 243 | EFI_RT_PROPERTIES_TABLE_GUID, |
| 244 | }, |
| 245 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 246 | NULL, "TCG2 Final Events Table", |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 247 | EFI_TCG2_FINAL_EVENTS_TABLE_GUID, |
| 248 | }, |
Jose Marinho | ff72cb3 | 2021-12-23 14:51:07 +0000 | [diff] [blame] | 249 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 250 | NULL, "EFI Conformance Profiles Table", |
Jose Marinho | ff72cb3 | 2021-12-23 14:51:07 +0000 | [diff] [blame] | 251 | EFI_CONFORMANCE_PROFILES_TABLE_GUID, |
| 252 | }, |
Heinrich Schuchardt | f4c5bcb | 2022-01-28 19:29:47 +0100 | [diff] [blame] | 253 | #ifdef CONFIG_EFI_RISCV_BOOT_PROTOCOL |
| 254 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 255 | NULL, "RISC-V Boot", |
Heinrich Schuchardt | f4c5bcb | 2022-01-28 19:29:47 +0100 | [diff] [blame] | 256 | RISCV_EFI_BOOT_PROTOCOL_GUID, |
| 257 | }, |
Heinrich Schuchardt | a4628b4 | 2022-01-16 14:10:23 +0100 | [diff] [blame] | 258 | #endif |
Heinrich Schuchardt | f4c5bcb | 2022-01-28 19:29:47 +0100 | [diff] [blame] | 259 | #endif /* CONFIG_CMD_EFIDEBUG */ |
Heinrich Schuchardt | 1bebcb6 | 2022-01-16 14:53:37 +0100 | [diff] [blame] | 260 | #ifdef CONFIG_CMD_NVEDIT_EFI |
| 261 | /* signature database */ |
| 262 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 263 | "EFI_GLOBAL_VARIABLE_GUID", NULL, |
Heinrich Schuchardt | 1bebcb6 | 2022-01-16 14:53:37 +0100 | [diff] [blame] | 264 | EFI_GLOBAL_VARIABLE_GUID, |
| 265 | }, |
| 266 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 267 | "EFI_IMAGE_SECURITY_DATABASE_GUID", NULL, |
Heinrich Schuchardt | 1bebcb6 | 2022-01-16 14:53:37 +0100 | [diff] [blame] | 268 | EFI_IMAGE_SECURITY_DATABASE_GUID, |
| 269 | }, |
| 270 | /* certificate types */ |
| 271 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 272 | "EFI_CERT_SHA256_GUID", NULL, |
Heinrich Schuchardt | 1bebcb6 | 2022-01-16 14:53:37 +0100 | [diff] [blame] | 273 | EFI_CERT_SHA256_GUID, |
| 274 | }, |
| 275 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 276 | "EFI_CERT_X509_GUID", NULL, |
Heinrich Schuchardt | 1bebcb6 | 2022-01-16 14:53:37 +0100 | [diff] [blame] | 277 | EFI_CERT_X509_GUID, |
| 278 | }, |
| 279 | { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 280 | "EFI_CERT_TYPE_PKCS7_GUID", NULL, |
Heinrich Schuchardt | 1bebcb6 | 2022-01-16 14:53:37 +0100 | [diff] [blame] | 281 | EFI_CERT_TYPE_PKCS7_GUID, |
| 282 | }, |
| 283 | #endif |
Simon Glass | 54d26e7 | 2023-07-15 21:38:51 -0600 | [diff] [blame] | 284 | #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI) |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 285 | { "EFI_LZMA_COMPRESSED", NULL, EFI_LZMA_COMPRESSED }, |
| 286 | { "EFI_DXE_SERVICES", NULL, EFI_DXE_SERVICES }, |
| 287 | { "EFI_HOB_LIST", NULL, EFI_HOB_LIST }, |
| 288 | { "EFI_MEMORY_TYPE", NULL, EFI_MEMORY_TYPE }, |
| 289 | { "EFI_MEM_STATUS_CODE_REC", NULL, EFI_MEM_STATUS_CODE_REC }, |
| 290 | { "EFI_GUID_EFI_ACPI1", NULL, EFI_GUID_EFI_ACPI1 }, |
Simon Glass | d134ad5 | 2023-03-20 08:30:11 +1300 | [diff] [blame] | 291 | #endif |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 292 | #endif /* EFI_PARTITION */ |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 293 | #endif /* !USE_HOSTCC */ |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 294 | }; |
| 295 | |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 296 | int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin) |
| 297 | { |
| 298 | int i; |
| 299 | |
| 300 | for (i = 0; i < ARRAY_SIZE(list_guid); i++) { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 301 | if (list_guid[i].type && |
| 302 | !strcmp(list_guid[i].type, guid_str)) { |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 303 | memcpy(guid_bin, &list_guid[i].guid, 16); |
| 304 | return 0; |
| 305 | } |
| 306 | } |
| 307 | return -ENODEV; |
| 308 | } |
| 309 | |
Rasmus Villemoes | 7b70bdc | 2020-11-20 11:45:35 +0100 | [diff] [blame] | 310 | const char *uuid_guid_get_str(const unsigned char *guid_bin) |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 311 | { |
| 312 | int i; |
| 313 | |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 314 | for (i = 0; i < ARRAY_SIZE(list_guid); i++) { |
| 315 | if (!memcmp(list_guid[i].guid.b, guid_bin, 16)) { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 316 | if (list_guid[i].description) |
| 317 | return list_guid[i].description; |
| 318 | return list_guid[i].type; |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 319 | } |
| 320 | } |
Rasmus Villemoes | 7b70bdc | 2020-11-20 11:45:35 +0100 | [diff] [blame] | 321 | return NULL; |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 322 | } |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 323 | |
Simon Glass | 4acd4f0 | 2020-04-08 08:32:58 -0600 | [diff] [blame] | 324 | int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, |
| 325 | int str_format) |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 326 | { |
| 327 | uint16_t tmp16; |
| 328 | uint32_t tmp32; |
| 329 | uint64_t tmp64; |
| 330 | |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 331 | if (!uuid_str_valid(uuid_str)) { |
Patrick Delaunay | 5d2451d | 2025-06-16 13:27:47 +0200 | [diff] [blame^] | 332 | if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) && |
| 333 | !uuid_guid_get_bin(uuid_str, uuid_bin)) |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 334 | return 0; |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 335 | return -EINVAL; |
Patrick Delaunay | 65f94ed | 2015-10-27 11:00:28 +0100 | [diff] [blame] | 336 | } |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 337 | |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 338 | if (str_format == UUID_STR_FORMAT_STD) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 339 | tmp32 = cpu_to_be32(hextoul(uuid_str, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 340 | memcpy(uuid_bin, &tmp32, 4); |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 341 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 342 | tmp16 = cpu_to_be16(hextoul(uuid_str + 9, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 343 | memcpy(uuid_bin + 4, &tmp16, 2); |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 344 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 345 | tmp16 = cpu_to_be16(hextoul(uuid_str + 14, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 346 | memcpy(uuid_bin + 6, &tmp16, 2); |
| 347 | } else { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 348 | tmp32 = cpu_to_le32(hextoul(uuid_str, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 349 | memcpy(uuid_bin, &tmp32, 4); |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 350 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 351 | tmp16 = cpu_to_le16(hextoul(uuid_str + 9, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 352 | memcpy(uuid_bin + 4, &tmp16, 2); |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 353 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 354 | tmp16 = cpu_to_le16(hextoul(uuid_str + 14, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 355 | memcpy(uuid_bin + 6, &tmp16, 2); |
| 356 | } |
| 357 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 358 | tmp16 = cpu_to_be16(hextoul(uuid_str + 19, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 359 | memcpy(uuid_bin + 8, &tmp16, 2); |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 360 | |
Heinrich Schuchardt | 5833b05 | 2024-11-03 23:42:22 +0100 | [diff] [blame] | 361 | tmp64 = cpu_to_be64(hextoull(uuid_str + 24, NULL)); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 362 | memcpy(uuid_bin + 10, (char *)&tmp64 + 2, 6); |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Abdellatif El Khlifi | dc3cb5d | 2023-08-04 14:33:38 +0100 | [diff] [blame] | 367 | int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin) |
| 368 | { |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 369 | uint16_t tmp16; |
| 370 | uint32_t tmp32; |
| 371 | uint64_t tmp64; |
Abdellatif El Khlifi | dc3cb5d | 2023-08-04 14:33:38 +0100 | [diff] [blame] | 372 | |
| 373 | if (!uuid_str_valid(uuid_str) || !uuid_bin) |
| 374 | return -EINVAL; |
| 375 | |
| 376 | tmp32 = cpu_to_le32(hextoul(uuid_str, NULL)); |
| 377 | memcpy(uuid_bin, &tmp32, 4); |
| 378 | |
| 379 | tmp16 = cpu_to_le16(hextoul(uuid_str + 9, NULL)); |
| 380 | memcpy(uuid_bin + 4, &tmp16, 2); |
| 381 | |
| 382 | tmp16 = cpu_to_le16(hextoul(uuid_str + 14, NULL)); |
| 383 | memcpy(uuid_bin + 6, &tmp16, 2); |
| 384 | |
| 385 | tmp16 = cpu_to_le16(hextoul(uuid_str + 19, NULL)); |
| 386 | memcpy(uuid_bin + 8, &tmp16, 2); |
| 387 | |
Heinrich Schuchardt | 80e81d8 | 2024-11-03 23:42:21 +0100 | [diff] [blame] | 388 | tmp64 = cpu_to_le64(hextoull(uuid_str + 24, NULL)); |
Abdellatif El Khlifi | dc3cb5d | 2023-08-04 14:33:38 +0100 | [diff] [blame] | 389 | memcpy(uuid_bin + 10, &tmp64, 6); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Simon Glass | 4acd4f0 | 2020-04-08 08:32:58 -0600 | [diff] [blame] | 394 | void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, |
| 395 | int str_format) |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 396 | { |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 397 | const uint8_t uuid_char_order[UUID_BIN_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 398 | 9, 10, 11, 12, 13, 14, 15}; |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 399 | const uint8_t guid_char_order[UUID_BIN_LEN] = {3, 2, 1, 0, 5, 4, 7, 6, 8, |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 400 | 9, 10, 11, 12, 13, 14, 15}; |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 401 | const uint8_t *char_order; |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 402 | const char *format; |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 403 | int i; |
| 404 | |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 405 | /* |
| 406 | * UUID and GUID bin data - always in big endian: |
| 407 | * 4B-2B-2B-2B-6B |
| 408 | * be be be be be |
| 409 | */ |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 410 | if (str_format & UUID_STR_FORMAT_GUID) |
| 411 | char_order = guid_char_order; |
| 412 | else |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 413 | char_order = uuid_char_order; |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 414 | if (str_format & UUID_STR_UPPER_CASE) |
| 415 | format = "%02X"; |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 416 | else |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 417 | format = "%02x"; |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 418 | |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 419 | for (i = 0; i < 16; i++) { |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 420 | sprintf(uuid_str, format, uuid_bin[char_order[i]]); |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 421 | uuid_str += 2; |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 422 | switch (i) { |
| 423 | case 3: |
| 424 | case 5: |
| 425 | case 7: |
| 426 | case 9: |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 427 | *uuid_str++ = '-'; |
Przemyslaw Marczak | fa90734 | 2014-04-02 10:20:02 +0200 | [diff] [blame] | 428 | break; |
| 429 | } |
| 430 | } |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 431 | } |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 432 | |
Caleb Connolly | 2f4f0be | 2024-08-30 13:34:32 +0100 | [diff] [blame] | 433 | static void configure_uuid(struct uuid *uuid, unsigned char version) |
| 434 | { |
| 435 | uint16_t tmp; |
| 436 | |
| 437 | /* Configure variant/version bits */ |
| 438 | tmp = be16_to_cpu(uuid->time_hi_and_version); |
| 439 | tmp = (tmp & ~UUID_VERSION_MASK) | (version << UUID_VERSION_SHIFT); |
| 440 | uuid->time_hi_and_version = cpu_to_be16(tmp); |
| 441 | |
| 442 | uuid->clock_seq_hi_and_reserved &= ~UUID_VARIANT_MASK; |
| 443 | uuid->clock_seq_hi_and_reserved |= (UUID_VARIANT << UUID_VARIANT_SHIFT); |
| 444 | } |
| 445 | |
| 446 | void gen_v5_guid(const struct uuid *namespace, struct efi_guid *guid, ...) |
| 447 | { |
| 448 | sha1_context ctx; |
| 449 | va_list args; |
| 450 | const uint8_t *data; |
| 451 | uint32_t *tmp32; |
| 452 | uint16_t *tmp16; |
| 453 | uint8_t hash[SHA1_SUM_LEN]; |
| 454 | |
| 455 | sha1_starts(&ctx); |
| 456 | /* Hash the namespace UUID as salt */ |
| 457 | sha1_update(&ctx, (unsigned char *)namespace, UUID_BIN_LEN); |
| 458 | va_start(args, guid); |
| 459 | |
| 460 | while ((data = va_arg(args, const uint8_t *))) { |
| 461 | unsigned int len = va_arg(args, size_t); |
| 462 | |
| 463 | sha1_update(&ctx, data, len); |
| 464 | } |
| 465 | |
| 466 | va_end(args); |
| 467 | sha1_finish(&ctx, hash); |
| 468 | |
| 469 | /* Truncate the hash into output UUID, it is already big endian */ |
| 470 | memcpy(guid, hash, sizeof(*guid)); |
| 471 | |
| 472 | configure_uuid((struct uuid *)guid, 5); |
| 473 | |
| 474 | /* Make little endian */ |
| 475 | tmp32 = (uint32_t *)&guid->b[0]; |
| 476 | *tmp32 = cpu_to_le32(be32_to_cpu(*tmp32)); |
| 477 | tmp16 = (uint16_t *)&guid->b[4]; |
| 478 | *tmp16 = cpu_to_le16(be16_to_cpu(*tmp16)); |
| 479 | tmp16 = (uint16_t *)&guid->b[6]; |
| 480 | *tmp16 = cpu_to_le16(be16_to_cpu(*tmp16)); |
| 481 | } |
| 482 | |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 483 | #ifndef USE_HOSTCC |
Przemyslaw Marczak | 2eb40ee | 2014-04-02 10:20:05 +0200 | [diff] [blame] | 484 | #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID) |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 485 | void gen_rand_uuid(unsigned char *uuid_bin) |
| 486 | { |
Heinrich Schuchardt | 1c126e2 | 2019-07-14 23:31:50 +0200 | [diff] [blame] | 487 | u32 ptr[4]; |
| 488 | struct uuid *uuid = (struct uuid *)ptr; |
Matthias Brugger | d03560b | 2020-12-18 10:28:03 +0100 | [diff] [blame] | 489 | int i, ret; |
| 490 | struct udevice *devp; |
| 491 | u32 randv = 0; |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 492 | |
Marek Vasut | 0d871e7 | 2024-04-26 01:02:07 +0200 | [diff] [blame] | 493 | if (CONFIG_IS_ENABLED(DM_RNG)) { |
Matthias Brugger | d03560b | 2020-12-18 10:28:03 +0100 | [diff] [blame] | 494 | ret = uclass_get_device(UCLASS_RNG, 0, &devp); |
Patrick Delaunay | a6064f7 | 2021-10-22 17:05:47 +0200 | [diff] [blame] | 495 | if (!ret) { |
Matthias Brugger | d03560b | 2020-12-18 10:28:03 +0100 | [diff] [blame] | 496 | ret = dm_rng_read(devp, &randv, sizeof(randv)); |
| 497 | if (ret < 0) |
| 498 | randv = 0; |
| 499 | } |
| 500 | } |
| 501 | if (randv) |
| 502 | srand(randv); |
| 503 | else |
| 504 | srand(get_ticks() + rand()); |
Eugeniu Rosca | 9d74ba6 | 2019-05-02 14:27:06 +0200 | [diff] [blame] | 505 | |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 506 | /* Set all fields randomly */ |
Heinrich Schuchardt | 1c126e2 | 2019-07-14 23:31:50 +0200 | [diff] [blame] | 507 | for (i = 0; i < 4; i++) |
| 508 | ptr[i] = rand(); |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 509 | |
Caleb Connolly | 2f4f0be | 2024-08-30 13:34:32 +0100 | [diff] [blame] | 510 | configure_uuid(uuid, UUID_VERSION); |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 511 | |
Heinrich Schuchardt | 1c126e2 | 2019-07-14 23:31:50 +0200 | [diff] [blame] | 512 | memcpy(uuid_bin, uuid, 16); |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Przemyslaw Marczak | b428514 | 2014-04-02 10:20:04 +0200 | [diff] [blame] | 515 | void gen_rand_uuid_str(char *uuid_str, int str_format) |
| 516 | { |
| 517 | unsigned char uuid_bin[UUID_BIN_LEN]; |
| 518 | |
| 519 | /* Generate UUID (big endian) */ |
| 520 | gen_rand_uuid(uuid_bin); |
| 521 | |
| 522 | /* Convert UUID bin to UUID or GUID formated STRING */ |
| 523 | uuid_bin_to_str(uuid_bin, uuid_str, str_format); |
| 524 | } |
Przemyslaw Marczak | 2eb40ee | 2014-04-02 10:20:05 +0200 | [diff] [blame] | 525 | |
Simon Glass | 0e84d96 | 2024-09-29 19:49:50 -0600 | [diff] [blame] | 526 | #if !defined(CONFIG_XPL_BUILD) && defined(CONFIG_CMD_UUID) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 527 | int do_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Przemyslaw Marczak | 2eb40ee | 2014-04-02 10:20:05 +0200 | [diff] [blame] | 528 | { |
| 529 | char uuid[UUID_STR_LEN + 1]; |
| 530 | int str_format; |
| 531 | |
| 532 | if (!strcmp(argv[0], "uuid")) |
| 533 | str_format = UUID_STR_FORMAT_STD; |
| 534 | else |
| 535 | str_format = UUID_STR_FORMAT_GUID; |
| 536 | |
| 537 | if (argc > 2) |
| 538 | return CMD_RET_USAGE; |
| 539 | |
| 540 | gen_rand_uuid_str(uuid, str_format); |
| 541 | |
| 542 | if (argc == 1) |
| 543 | printf("%s\n", uuid); |
| 544 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 545 | env_set(argv[1], uuid); |
Przemyslaw Marczak | 2eb40ee | 2014-04-02 10:20:05 +0200 | [diff] [blame] | 546 | |
| 547 | return CMD_RET_SUCCESS; |
| 548 | } |
| 549 | |
| 550 | U_BOOT_CMD(uuid, CONFIG_SYS_MAXARGS, 1, do_uuid, |
| 551 | "UUID - generate random Universally Unique Identifier", |
| 552 | "[<varname>]\n" |
| 553 | "Argument:\n" |
| 554 | "varname: for set result in a environment variable\n" |
| 555 | "e.g. uuid uuid_env" |
| 556 | ); |
| 557 | |
| 558 | U_BOOT_CMD(guid, CONFIG_SYS_MAXARGS, 1, do_uuid, |
| 559 | "GUID - generate Globally Unique Identifier based on random UUID", |
| 560 | "[<varname>]\n" |
| 561 | "Argument:\n" |
| 562 | "varname: for set result in a environment variable\n" |
| 563 | "e.g. guid guid_env" |
| 564 | ); |
Przemyslaw Marczak | 5ec2ed2 | 2014-04-02 10:20:06 +0200 | [diff] [blame] | 565 | #endif /* CONFIG_CMD_UUID */ |
| 566 | #endif /* CONFIG_RANDOM_UUID || CONFIG_CMD_UUID */ |
Caleb Connolly | fb9e948 | 2024-08-30 13:34:36 +0100 | [diff] [blame] | 567 | #endif /* !USE_HOSTCC */ |