uuid.c (4e4815feae4d37032a7afce18a4c26074c51f159) uuid.c (89c8230dec063d894aec1a7b5c58f1dcadced738)
1/*
2 * Copyright 2011 Calxeda, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
1/*
2 * Copyright 2011 Calxeda, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
7#include <linux/ctype.h>
8#include <errno.h>
9#include <common.h>
10#include <asm/io.h>
11#include <part_efi.h>
12#include <malloc.h>
13
14/*

--- 151 unchanged lines hidden (view full) ---

166
167/*
168 * gen_rand_uuid() - this function generates a random binary UUID version 4.
169 * In this version all fields beside 4 bits of version and
170 * 2 bits of variant are randomly generated.
171 *
172 * @param uuid_bin - pointer to allocated array [16B]. Output is in big endian.
173*/
8#include <linux/ctype.h>
9#include <errno.h>
10#include <common.h>
11#include <asm/io.h>
12#include <part_efi.h>
13#include <malloc.h>
14
15/*

--- 151 unchanged lines hidden (view full) ---

167
168/*
169 * gen_rand_uuid() - this function generates a random binary UUID version 4.
170 * In this version all fields beside 4 bits of version and
171 * 2 bits of variant are randomly generated.
172 *
173 * @param uuid_bin - pointer to allocated array [16B]. Output is in big endian.
174*/
174#ifdef CONFIG_RANDOM_UUID
175#if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
175void gen_rand_uuid(unsigned char *uuid_bin)
176{
177 struct uuid uuid;
178 unsigned int *ptr = (unsigned int *)&uuid;
179 int i;
180
181 /* Set all fields randomly */
182 for (i = 0; i < sizeof(struct uuid) / sizeof(*ptr); i++)

--- 22 unchanged lines hidden (view full) ---

205 unsigned char uuid_bin[UUID_BIN_LEN];
206
207 /* Generate UUID (big endian) */
208 gen_rand_uuid(uuid_bin);
209
210 /* Convert UUID bin to UUID or GUID formated STRING */
211 uuid_bin_to_str(uuid_bin, uuid_str, str_format);
212}
176void gen_rand_uuid(unsigned char *uuid_bin)
177{
178 struct uuid uuid;
179 unsigned int *ptr = (unsigned int *)&uuid;
180 int i;
181
182 /* Set all fields randomly */
183 for (i = 0; i < sizeof(struct uuid) / sizeof(*ptr); i++)

--- 22 unchanged lines hidden (view full) ---

206 unsigned char uuid_bin[UUID_BIN_LEN];
207
208 /* Generate UUID (big endian) */
209 gen_rand_uuid(uuid_bin);
210
211 /* Convert UUID bin to UUID or GUID formated STRING */
212 uuid_bin_to_str(uuid_bin, uuid_str, str_format);
213}
214
215#ifdef CONFIG_CMD_UUID
216int do_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
217{
218 char uuid[UUID_STR_LEN + 1];
219 int str_format;
220
221 if (!strcmp(argv[0], "uuid"))
222 str_format = UUID_STR_FORMAT_STD;
223 else
224 str_format = UUID_STR_FORMAT_GUID;
225
226 if (argc > 2)
227 return CMD_RET_USAGE;
228
229 gen_rand_uuid_str(uuid, str_format);
230
231 if (argc == 1)
232 printf("%s\n", uuid);
233 else
234 setenv(argv[1], uuid);
235
236 return CMD_RET_SUCCESS;
237}
238
239U_BOOT_CMD(uuid, CONFIG_SYS_MAXARGS, 1, do_uuid,
240 "UUID - generate random Universally Unique Identifier",
241 "[<varname>]\n"
242 "Argument:\n"
243 "varname: for set result in a environment variable\n"
244 "e.g. uuid uuid_env"
245);
246
247U_BOOT_CMD(guid, CONFIG_SYS_MAXARGS, 1, do_uuid,
248 "GUID - generate Globally Unique Identifier based on random UUID",
249 "[<varname>]\n"
250 "Argument:\n"
251 "varname: for set result in a environment variable\n"
252 "e.g. guid guid_env"
253);
213#endif
254#endif
255#endif