[PATCH v8 06/11] lib: uuid: supporting building as part of host tools

Patrick DELAUNAY patrick.delaunay at foss.st.com
Mon Oct 28 15:14:11 CET 2024


Hi,


This patch seens cause problemes for STM32MP1 platforms, AARCH32

For FIP UUID configuration.


On 8/30/24 14:34, Caleb Connolly wrote:
> Adjust the UUID library code so that it can be compiled as part of a
> host tool.
>
> This removes the one redundant log_debug() call, as well as the
> incorrectly defined LOG_CATEGORY.
>
> In general this is a fairly trivial change, just adjusting includes and
> disabling list_guid.
>
> This will be used by a new genguid tool to generate v5 GUIDs that match
> those generated by U-Boot at runtime.
>
> Acked-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> Signed-off-by: Caleb Connolly <caleb.connolly at linaro.org>
> ---
>   include/uuid.h |  4 ++--
>   lib/uuid.c     | 44 ++++++++++++++++++++++++++++++--------------
>   2 files changed, 32 insertions(+), 16 deletions(-)
>
> diff --git a/include/uuid.h b/include/uuid.h
> index 1f4fa103b5e9..7f8414dc906c 100644
> --- a/include/uuid.h
> +++ b/include/uuid.h
> @@ -69,10 +69,10 @@ struct uuid {
>   } __packed;
>   
>   /* Bits of a bitmask specifying the output format for GUIDs */
>   #define UUID_STR_FORMAT_STD	0
> -#define UUID_STR_FORMAT_GUID	BIT(0)
> -#define UUID_STR_UPPER_CASE	BIT(1)
> +#define UUID_STR_FORMAT_GUID	0x1
> +#define UUID_STR_UPPER_CASE	0x2
>   
>   /* Use UUID_STR_LEN + 1 for string space */
>   #define UUID_STR_LEN		36
>   #define UUID_BIN_LEN		sizeof(struct uuid)
> diff --git a/lib/uuid.c b/lib/uuid.c
> index c9dfdf007a18..6fdae7997702 100644
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> @@ -6,25 +6,38 @@
>    * Authors:
>    *   Abdellatif El Khlifi <abdellatif.elkhlifi at arm.com>
>    */
>   
> -#define LOG_CATEGOT LOGC_CORE
> -
> +#ifndef USE_HOSTCC
>   #include <command.h>
>   #include <efi_api.h>
>   #include <env.h>
>   #include <rand.h>
>   #include <time.h>
> -#include <uuid.h>
> -#include <linux/ctype.h>
> -#include <errno.h>
>   #include <asm/io.h>
>   #include <part_efi.h>
>   #include <malloc.h>
>   #include <dm/uclass.h>
>   #include <rng.h>
> +#include <linux/ctype.h>
> +#include <hexdump.h>
> +#else
> +#include <stdarg.h>
> +#include <stdint.h>
> +#include <eficapsule.h>
> +#include <ctype.h>
> +#endif
> +#include <linux/types.h>
> +#include <errno.h>
> +#include <linux/kconfig.h>
> +#include <uuid.h>
>   #include <u-boot/sha1.h>
>   
> +#ifdef USE_HOSTCC
> +/* polyfill hextoul to avoid pulling in strto.c */
> +#define hextoul(cp, endp) strtoul(cp, endp, 16)
> +#endif
> +
>   int uuid_str_valid(const char *uuid)
>   {
>   	int i, valid;
>   
> @@ -51,8 +64,9 @@ int uuid_str_valid(const char *uuid)
>   static const struct {
>   	const char *string;
>   	efi_guid_t guid;
>   } list_guid[] = {
> +#ifndef USE_HOSTCC
>   #ifdef CONFIG_PARTITION_TYPE_GUID
>   	{"system",	PARTITION_SYSTEM_GUID},
>   	{"mbr",		LEGACY_MBR_PARTITION_GUID},
>   	{"msft",	PARTITION_MSFT_RESERVED_GUID},
> @@ -231,8 +245,9 @@ static const struct {
>   	{ "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE },
>   	{ "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
>   	{ "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
>   #endif
> +#endif /* !USE_HOSTCC */
>   };
>   
>   int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin)
>   {
> @@ -266,9 +281,8 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
>   	uint32_t tmp32;
>   	uint64_t tmp64;
>   
>   	if (!uuid_str_valid(uuid_str)) {
> -		log_debug("not valid\n");
>   #ifdef CONFIG_PARTITION_TYPE_GUID
>   		if (!uuid_guid_get_bin(uuid_str, uuid_bin))
>   			return 0;
>   #endif
> @@ -297,19 +311,19 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
>   
>   	tmp16 = cpu_to_be16(hextoul(uuid_str + 19, NULL));
>   	memcpy(uuid_bin + 8, &tmp16, 2);
>   
> -	tmp64 = cpu_to_be64(simple_strtoull(uuid_str + 24, NULL, 16));
> +	tmp64 = cpu_to_be64(hextoul(uuid_str + 24, NULL));
>   	memcpy(uuid_bin + 10, (char *)&tmp64 + 2, 6);
>   
>   	return 0;
>   }
>   
>   int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
>   {
> -	u16 tmp16;
> -	u32 tmp32;
> -	u64 tmp64;
> +	uint16_t tmp16;
> +	uint32_t tmp32;
> +	uint64_t tmp64;
>   
>   	if (!uuid_str_valid(uuid_str) || !uuid_bin)
>   		return -EINVAL;
>   
> @@ -324,22 +338,22 @@ int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
>   
>   	tmp16 = cpu_to_le16(hextoul(uuid_str + 19, NULL));
>   	memcpy(uuid_bin + 8, &tmp16, 2);
>   
> -	tmp64 = cpu_to_le64(simple_strtoull(uuid_str + 24, NULL, 16));
> +	tmp64 = cpu_to_le64(hextoul(uuid_str + 24, NULL));

Here you change

simple_strtoull  => return unsigned long long

to

hextoul => return unsigned long

for 32bits system that can the cause of issue I think

with UUID defined in stm32prog command, with use a gpt
create command with UUID define in

./arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c

/* FIP type partition UUID used by TF-A*/
#define FIP_TYPE_UUID "19D5DF83-11B0-457B-BE2C-7559C13142A5"

/* unique partition guid (uuid) for FIP partitions A/B */
#define FIP_A_UUID \
	EFI_GUID(0x4FD84C93, 0x54EF, 0x463F, \
		 0xA7, 0xEF, 0xAE, 0x25, 0xFF, 0x88, 0x70, 0x87)


with the patch the GPT partition is create with incorrect UUID (type and partion)
with "0000" in last field.


$> BAD
Partition GUID code: 19D5DF83-11B0-457B-BE2C-0000C13142A5
Partition unique GUID: 4FD84C93-54EF-463F-A7EF-0000FF887087

before the patch

$> OK
Partition GUID code: 19D5DF83-11B0-457B-BE2C-7559C13142A5
Partition unique GUID: 4FD84C93-54EF-463F-A7EF-AE25FF887087

for 32bits platform, we must use simple_strtoull and not

ulong hextoul(const char *cp, char **endp)
{
	return simple_strtoul(cp, endp, 16);
}

for define hextoull()


what do you thin, of this issue ?

>   	memcpy(uuid_bin + 10, &tmp64, 6);
>   
>   	return 0;
>   }
>   
>   void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
>   		     int str_format)
>   {
> -	const u8 uuid_char_order[UUID_BIN_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8,
> +	const uint8_t uuid_char_order[UUID_BIN_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8,
>   						  9, 10, 11, 12, 13, 14, 15};
> -	const u8 guid_char_order[UUID_BIN_LEN] = {3, 2, 1, 0, 5, 4, 7, 6, 8,
> +	const uint8_t guid_char_order[UUID_BIN_LEN] = {3, 2, 1, 0, 5, 4, 7, 6, 8,
>   						  9, 10, 11, 12, 13, 14, 15};
> -	const u8 *char_order;
> +	const uint8_t *char_order;
>   	const char *format;
>   	int i;
>   
>   	/*
> @@ -419,8 +433,9 @@ void gen_v5_guid(const struct uuid *namespace, struct efi_guid *guid, ...)
>   	tmp16 = (uint16_t *)&guid->b[6];
>   	*tmp16 = cpu_to_le16(be16_to_cpu(*tmp16));
>   }
>   
> +#ifndef USE_HOSTCC
>   #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
>   void gen_rand_uuid(unsigned char *uuid_bin)
>   {
>   	u32 ptr[4];
> @@ -502,4 +517,5 @@ U_BOOT_CMD(guid, CONFIG_SYS_MAXARGS, 1, do_uuid,
>   	   "e.g. guid guid_env"
>   );
>   #endif /* CONFIG_CMD_UUID */
>   #endif /* CONFIG_RANDOM_UUID || CONFIG_CMD_UUID */
> +#endif /* !USE_HOSTCC */
>


More information about the U-Boot mailing list