new commands: uuid and guid - generate random unique identifier
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Wed, 2 Apr 2014 08:20:05 +0000 (10:20 +0200)
committerChanho Park <chanho61.park@samsung.com>
Fri, 24 Jul 2015 07:29:48 +0000 (16:29 +0900)
Those commands basis on implementation of random UUID generator version 4
which is described in RFC4122. The same algorithm is used for generation
both ids but string representation is different as below.

char:  0        9    14   19   24         36
       xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
UUID:     be     be   be   be       be
GUID:     le     le   le   be       be

Commands usage:
- uuid [<varname>]
- guid [<varname>]

The result is saved in environment as a "varname" variable if argument is given,
if not then it is printed.

New config:
- CONFIG_CMD_UUID

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: trini@ti.com
Conflicts:
README
include/config_fallbacks.h

README
include/config_fallbacks.h
lib/uuid.c

diff --git a/README b/README
index cb08485292c4e07135e42cd894c3ecfedee888bc..784114bd9a55bb312f094cba5859dece3bc35b88 100644 (file)
--- a/README
+++ b/README
@@ -836,7 +836,7 @@ The following options need to be configured:
                CONFIG_CMD_USB          * USB support
                CONFIG_CMD_CDP          * Cisco Discover Protocol support
                CONFIG_CMD_MFSL         * Microblaze FSL support
-
+               CONFIG_CMD_UUID         * Generate random UUID or GUID string
 
                EXAMPLE: If you want all functions except of network
                support you can write:
index 945e274e4d5d6767d632957b768944046ec8f69d..5fa5f603a74f108f14500912074bd1e13dc0b0b2 100644 (file)
 #endif
 
 #if (defined(CONFIG_PARTITION_UUIDS) || \
-       defined(CONFIG_EFI_PARTITION) || \
-       defined(CONFIG_RANDOM_UUID) || \
-       defined(CONFIG_BOOTP_PXE)) && \
-       !defined(CONFIG_LIB_UUID)
+       defined(CONFIG_EFI_PARTITION) || \
+       defined(CONFIG_RANDOM_UUID) || \
+       defined(CONFIG_CMD_UUID) || \
+       defined(CONFIG_BOOTP_PXE)) && \
+       !defined(CONFIG_LIB_UUID)
 #define CONFIG_LIB_UUID
 #endif
 
-#if defined(CONFIG_RANDOM_UUID) && \
-       !defined(CONFIG_LIB_RAND) && \
-       !defined(CONFIG_LIB_HW_RAND)
+#if (defined(CONFIG_RANDOM_UUID) || \
+       defined(CONFIG_CMD_UUID)) && \
+       (!defined(CONFIG_LIB_RAND) && \
+       !defined(CONFIG_LIB_HW_RAND))
 #define CONFIG_LIB_RAND
 #endif
 
index d19d9f50b9fad8d354268942f6497b50f341af26..d4418bd42bfe42ba05866f0608b36221131008f0 100644 (file)
@@ -20,6 +20,7 @@
  * MA 02111-1307 USA
  */
 
+#include <common.h>
 #include <linux/ctype.h>
 #include <errno.h>
 #include <common.h>
@@ -187,7 +188,7 @@ void uuid_bin_to_str(unsigned char *uuid_bin, char *uuid_str, int str_format)
  *
  * @param uuid_bin - pointer to allocated array [16B]. Output is in big endian.
 */
-#ifdef CONFIG_RANDOM_UUID
+#if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
 void gen_rand_uuid(unsigned char *uuid_bin)
 {
        struct uuid uuid;
@@ -226,4 +227,45 @@ void gen_rand_uuid_str(char *uuid_str, int str_format)
        /* Convert UUID bin to UUID or GUID formated STRING  */
        uuid_bin_to_str(uuid_bin, uuid_str, str_format);
 }
+
+#ifdef CONFIG_CMD_UUID
+int do_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       char uuid[UUID_STR_LEN + 1];
+       int str_format;
+
+       if (!strcmp(argv[0], "uuid"))
+               str_format = UUID_STR_FORMAT_STD;
+       else
+               str_format = UUID_STR_FORMAT_GUID;
+
+       if (argc > 2)
+               return CMD_RET_USAGE;
+
+       gen_rand_uuid_str(uuid, str_format);
+
+       if (argc == 1)
+               printf("%s\n", uuid);
+       else
+               setenv(argv[1], uuid);
+
+       return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(uuid, CONFIG_SYS_MAXARGS, 1, do_uuid,
+          "UUID - generate random Universally Unique Identifier",
+          "[<varname>]\n"
+          "Argument:\n"
+          "varname: for set result in a environment variable\n"
+          "e.g. uuid uuid_env"
+);
+
+U_BOOT_CMD(guid, CONFIG_SYS_MAXARGS, 1, do_uuid,
+          "GUID - generate Globally Unique Identifier based on random UUID",
+          "[<varname>]\n"
+          "Argument:\n"
+          "varname: for set result in a environment variable\n"
+          "e.g. guid guid_env"
+);
+#endif
 #endif