[U-Boot] [RFC PATCH v3 01/16] uuid: add a function for GUID string parsing

Patrick Delaunay patrick.delaunay at st.com
Mon Feb 6 09:06:41 UTC 2017


uuid_guid_parse_str parses a string provided in commands line
to found a valid GUID as valid uuid string or as shortcut
(under CONFIG_PARTITION_TYPE_GUID).

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
Reviewed-by: Christophe KERELLO <christophe.kerello at st.com>
---

Changes in v3:
- solve issue in compute partition_entry_lba update :
  missing / lba_size
- rework and split patches for unrelated change after review
  from Cristophe Kerello and Simon Glass
- rebase on v2017.03-rc1

Changes in v2:
- split serie to reduce patches size
  (separate disk part and cmd impact and add precursor patch)
- split large function

 include/uuid.h |  1 +
 lib/uuid.c     | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/uuid.h b/include/uuid.h
index c3f423f..f444095 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -40,6 +40,7 @@ void uuid_bin_to_str(unsigned char *uuid_bin, char *uuid_str, int str_format);
 int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
 int uuid_guid_get_str(unsigned char *guid_bin, char *guid_str);
 #endif
+int uuid_guid_parse_str(const char *str, char *guid_str);
 void gen_rand_uuid(unsigned char *uuid_bin);
 void gen_rand_uuid_str(char *uuid_str, int str_format);
 #endif
diff --git a/lib/uuid.c b/lib/uuid.c
index c8584ed..7ce822c 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -136,6 +136,41 @@ int uuid_guid_get_str(unsigned char *guid_bin, char *guid_str)
 #endif
 
 /*
+ * uuid_guid_parse_str() - this function parses string to found a valid GUID.
+ *
+ * @param guid_str - pointer to string with partition type guid [37B]
+ *                   or GUID shorcut defined in list_guid[]
+ * @param guid_str - pointer to allocated partition type string [37B]
+ * @return 0 if OK, else -ENODEV
+ */
+int uuid_guid_parse_str(const char *str, char *guid_str)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+	int i;
+#endif
+
+	if (guid_str == NULL)
+		return -ENODEV;
+
+	if (uuid_str_valid(str)) {
+		memcpy(guid_str, str, UUID_STR_LEN + 1);
+		return 0;
+	}
+
+#ifdef CONFIG_PARTITION_TYPE_GUID
+	for (i = 0; i < ARRAY_SIZE(list_guid); i++) {
+		if (!strcmp(list_guid[i].string, str)) {
+			uuid_bin_to_str((unsigned char *)list_guid[i].guid.b,
+					guid_str, UUID_STR_FORMAT_GUID);
+			return 0;
+		}
+	}
+#endif
+
+	return -ENODEV;
+}
+
+/*
  * uuid_str_to_bin() - convert string UUID or GUID to big endian binary data.
  *
  * @param uuid_str - pointer to UUID or GUID string [37B] or GUID shorcut
-- 
1.9.1



More information about the U-Boot mailing list