From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CCC8C38A2D for ; Mon, 24 Oct 2022 12:07:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BCD80806F0; Mon, 24 Oct 2022 14:07:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="fBH3iKgG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 52A9A806ED; Mon, 24 Oct 2022 14:07:43 +0200 (CEST) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6C268806ED for ; Mon, 24 Oct 2022 14:07:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x534.google.com with SMTP id i21so9306768edj.10 for ; Mon, 24 Oct 2022 05:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x21a4LcadwDU8azeYd/10yx8VzV6jbu1UDS6BNEOHyY=; b=fBH3iKgGjSWJ+L9t0CyPXDEf3bmzQ+YV9gT84pIn/465i8i0116BJuYFLh08Sdvq3k 36+wVQtMEak8M/kjFqpPsnFPrp9tbRA05JYsGkh1I7Omqk5AX5abND/FXKB+qWnqTFR8 ZTr0ricCVbGOHFTJenFhWPbxU0FQbkiUc8G5omuUwCCMGIxvIZ/F3sf3o5r/8vOfP0i+ vkKsceg+M04GIot9lxSJqdZHp1n0Enf+gln9T8iTosXX9cAFzwnwnmX/XG0S4UvLjdJ0 HUoDhpREFhd/dTy2qxnXZCWSWojCHkLMha+0uKAKVB4YFfGXw64N0xTKkj0tMfM0Da90 yYXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=x21a4LcadwDU8azeYd/10yx8VzV6jbu1UDS6BNEOHyY=; b=qipq6a3YeuB//LgQJzPSUipO+e2de6HTOJJ1xWtePvWHjQLmFev+frQTrpdUDfwAMO rNZrQu8mglEn2GZXDsEH4W98k30ICTVRsKRA8JMHG39jbHtCdBWRODWAtoPcfm7Z2qBu rBOIyF77GxAmxgOtv5hgALsTl9uAVTJFmcTy6G8BQf+aNuNW/qaVeAGkY1Fyy3Ky2iHq rt9ySO7YeRODcRyfrJVKuEBlt9qJ8pnxgKL6WbLwPqFUPUGfvZTyFA6X8IXor9vdPpKS ZVzkSDyEdIoXnK42lA6hGl8MWT03i6Sh2HQs8aT4+hS6E3lklAu4VaQwW8HmXXzmTinN CWLg== X-Gm-Message-State: ACrzQf0rLHbVonEUwKT5Svq/iJxvRE0zvEWz4KRcU2/PwKldRILi3mh4 zM14NMja+79hfosQwHSd2Oebbw== X-Google-Smtp-Source: AMsMyM4hMeR3CReTTcOMVlm4pcnT1sh+wvE4S3w/dAFD8i7uTaalwmpHPlgkmxI3DEEAh0lcmmIvJw== X-Received: by 2002:a17:907:d04:b0:76e:e208:27ba with SMTP id gn4-20020a1709070d0400b0076ee20827bamr28289881ejc.652.1666613259014; Mon, 24 Oct 2022 05:07:39 -0700 (PDT) Received: from hera (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id b19-20020a17090630d300b0073c0b87ba34sm15458348ejb.198.2022.10.24.05.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 05:07:38 -0700 (PDT) Date: Mon, 24 Oct 2022 15:07:35 +0300 From: Ilias Apalodimas To: Abdellatif El Khlifi Cc: achin.gupta@arm.com, jens.wiklander@linaro.org, nd@arm.com, sjg@chromium.org, trini@konsulko.com, u-boot@lists.denx.de, vishnu.banavath@arm.com, xueliang.zhong@arm.com, Drew.Reed@arm.com Subject: Re: [PATCH v6 02/10] lib: uuid: introduce be_uuid_str_to_le_bin function Message-ID: References: <20220926140827.15125-1-abdellatif.elkhlifi@arm.com> <20221013103857.614-1-abdellatif.elkhlifi@arm.com> <20221013103857.614-3-abdellatif.elkhlifi@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221013103857.614-3-abdellatif.elkhlifi@arm.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Hi Abdellatif, On Thu, Oct 13, 2022 at 11:38:49AM +0100, Abdellatif El Khlifi wrote: > convert big endian UUID string to little endian buffer You don't really need the be_ suffix on the declaration, endianness doesn't apply to strings. Can't we do something similar to uuid_str_to_bin() and just convert to LE? Thanks /Ilias > > Signed-off-by: Abdellatif El Khlifi > Cc: Tom Rini > Cc: Simon Glass > Cc: Ilias Apalodimas > Cc: Jens Wiklander > > --- > > Changelog: > =============== > > v4: > > * rename ffa_uuid_str_to_bin to be_uuid_str_to_le_bin and put in > a standalone commit (the current) > > v3: > > * introduce ffa_uuid_str_to_bin (provided by > arm_ffa: introduce Arm FF-A low-level driver) > > include/uuid.h | 8 +++++++ > lib/uuid.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 72 insertions(+) > > diff --git a/include/uuid.h b/include/uuid.h > index 4a4883d3b5..ad3af350f9 100644 > --- a/include/uuid.h > +++ b/include/uuid.h > @@ -2,6 +2,8 @@ > /* > * Copyright (C) 2014 Samsung Electronics > * Przemyslaw Marczak > + * (C) Copyright 2022 ARM Limited > + * Abdellatif El Khlifi > */ > #ifndef __UUID_H__ > #define __UUID_H__ > @@ -44,4 +46,10 @@ int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin); > const char *uuid_guid_get_str(const unsigned char *guid_bin); > void gen_rand_uuid(unsigned char *uuid_bin); > void gen_rand_uuid_str(char *uuid_str, int str_format); > + > +/** > + * be_uuid_str_to_le_bin - Converts a big endian UUID string to a little endian buffer > + */ > +int be_uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin); > + > #endif > diff --git a/lib/uuid.c b/lib/uuid.c > index 465e1ac38f..15a9ab49d5 100644 > --- a/lib/uuid.c > +++ b/lib/uuid.c > @@ -1,6 +1,8 @@ > // SPDX-License-Identifier: GPL-2.0+ > /* > * Copyright 2011 Calxeda, Inc. > + * (C) Copyright 2022 ARM Limited > + * Abdellatif El Khlifi > */ > > #include > @@ -346,6 +348,68 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, > return 0; > } > > +/** > + * be_uuid_str_to_le_bin - Converts a big endian UUID string to a little endian buffer > + * @uuid_str: UUID string in big endian format (36 bytes wide + '/0') > + * @uuid_bin: preallocated 16 bytes UUID buffer in little endian format > + * > + * UUID string is 36 characters (36 bytes): > + * > + * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx > + * be be be be be > + * > + * where x is a hexadecimal character. Fields are separated by '-'s. > + * When converting to a binary UUID, these endianness rules apply: > + * be: means the field in the string is considered a big endian hex number > + * and should be converted to little endian binary format > + * > + * Return: > + * > + * uuid_bin filled with little endian UUID data > + * On success 0 is returned. Otherwise, failure code. > + */ > +int be_uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin) > +{ > + u16 tmp16 = 0; > + u32 tmp32 = 0; > + u64 tmp64 = 0; > + > + if (!uuid_str_valid(uuid_str) || !uuid_bin) > + return -EINVAL; > + > + /* > + * reverse bytes from big to little endian > + */ > + tmp32 = simple_strtoul(uuid_str, NULL, 16); > + memcpy(uuid_bin, &tmp32, 4); > + > + /* > + * reverse bytes from big to little endian > + */ > + tmp16 = simple_strtoul(uuid_str + 9, NULL, 16); > + memcpy(uuid_bin + 4, &tmp16, 2); > + > + /* > + * reverse bytes from big to little endian > + */ > + tmp16 = simple_strtoul(uuid_str + 14, NULL, 16); > + memcpy(uuid_bin + 6, &tmp16, 2); > + > + /* > + * reverse bytes from big to little endian > + */ > + tmp16 = simple_strtoul(uuid_str + 19, NULL, 16); > + memcpy(uuid_bin + 8, &tmp16, 2); > + > + /* > + * reverse bytes from big to little endian > + */ > + tmp64 = simple_strtoull(uuid_str + 24, NULL, 16); > + memcpy(uuid_bin + 10, (char *)&tmp64, 6); > + > + return 0; > +} > + > /* > * uuid_bin_to_str() - convert big endian binary data to string UUID or GUID. > * > -- > 2.17.1 >