From patchwork Thu May 11 07:51:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 760965 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wNlgv3jKTz9sDF for ; Thu, 11 May 2017 17:52:27 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 35C4CC21C79; Thu, 11 May 2017 07:52:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5CA28C21C75; Thu, 11 May 2017 07:52:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A2752C21C75; Thu, 11 May 2017 07:52:17 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by lists.denx.de (Postfix) with ESMTPS id 5FFC1C21C3C for ; Thu, 11 May 2017 07:52:17 +0000 (UTC) Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v4B7cj5F003944; Thu, 11 May 2017 09:52:16 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 2abjadrvxv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 11 May 2017 09:52:16 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id CD27A3F; Thu, 11 May 2017 07:52:15 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B76011110; Thu, 11 May 2017 07:52:15 +0000 (GMT) Received: from localhost (10.201.23.85) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Thu, 11 May 2017 09:52:15 +0200 From: Patrick Delaunay To: Date: Thu, 11 May 2017 09:51:51 +0200 Message-ID: <1494489128-24806-2-git-send-email-patrick.delaunay@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1494489128-24806-1-git-send-email-patrick.delaunay@st.com> References: <1494489128-24806-1-git-send-email-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.85] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-11_05:, , signatures=0 Cc: Franck Albesa , Christophe Kerello , Gerald Baeza , Patrick Delaunay Subject: [U-Boot] [PATCH v6 01/18] uuid: add a function for GUID string parsing X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- Changes in v6: - rebase of the top of the latest v2017.05 Changes in v5: - rebase of the top of latest u-boot master Changes in v4: - change RFC to PATCH - update cover letter - rebase on v2017.03 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