mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-09 16:56:58 +02:00
lib: uuid: supporting building as part of host tools
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@linaro.org> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
This commit is contained in:
parent
2bf0a87ae3
commit
22c48a92cd
@ -70,8 +70,8 @@ struct uuid {
|
|||||||
|
|
||||||
/* Bits of a bitmask specifying the output format for GUIDs */
|
/* Bits of a bitmask specifying the output format for GUIDs */
|
||||||
#define UUID_STR_FORMAT_STD 0
|
#define UUID_STR_FORMAT_STD 0
|
||||||
#define UUID_STR_FORMAT_GUID BIT(0)
|
#define UUID_STR_FORMAT_GUID 0x1
|
||||||
#define UUID_STR_UPPER_CASE BIT(1)
|
#define UUID_STR_UPPER_CASE 0x2
|
||||||
|
|
||||||
/* Use UUID_STR_LEN + 1 for string space */
|
/* Use UUID_STR_LEN + 1 for string space */
|
||||||
#define UUID_STR_LEN 36
|
#define UUID_STR_LEN 36
|
||||||
|
44
lib/uuid.c
44
lib/uuid.c
@ -7,23 +7,36 @@
|
|||||||
* Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
|
* Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_CATEGOT LOGC_CORE
|
#ifndef USE_HOSTCC
|
||||||
|
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <efi_api.h>
|
#include <efi_api.h>
|
||||||
#include <env.h>
|
#include <env.h>
|
||||||
#include <rand.h>
|
#include <rand.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <uuid.h>
|
|
||||||
#include <linux/ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <part_efi.h>
|
#include <part_efi.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <dm/uclass.h>
|
#include <dm/uclass.h>
|
||||||
#include <rng.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>
|
#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 uuid_str_valid(const char *uuid)
|
||||||
{
|
{
|
||||||
int i, valid;
|
int i, valid;
|
||||||
@ -52,6 +65,7 @@ static const struct {
|
|||||||
const char *string;
|
const char *string;
|
||||||
efi_guid_t guid;
|
efi_guid_t guid;
|
||||||
} list_guid[] = {
|
} list_guid[] = {
|
||||||
|
#ifndef USE_HOSTCC
|
||||||
#ifdef CONFIG_PARTITION_TYPE_GUID
|
#ifdef CONFIG_PARTITION_TYPE_GUID
|
||||||
{"system", PARTITION_SYSTEM_GUID},
|
{"system", PARTITION_SYSTEM_GUID},
|
||||||
{"mbr", LEGACY_MBR_PARTITION_GUID},
|
{"mbr", LEGACY_MBR_PARTITION_GUID},
|
||||||
@ -232,6 +246,7 @@ static const struct {
|
|||||||
{ "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
|
{ "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
|
||||||
{ "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
|
{ "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* !USE_HOSTCC */
|
||||||
};
|
};
|
||||||
|
|
||||||
int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin)
|
int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin)
|
||||||
@ -267,7 +282,6 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
|
|||||||
uint64_t tmp64;
|
uint64_t tmp64;
|
||||||
|
|
||||||
if (!uuid_str_valid(uuid_str)) {
|
if (!uuid_str_valid(uuid_str)) {
|
||||||
log_debug("not valid\n");
|
|
||||||
#ifdef CONFIG_PARTITION_TYPE_GUID
|
#ifdef CONFIG_PARTITION_TYPE_GUID
|
||||||
if (!uuid_guid_get_bin(uuid_str, uuid_bin))
|
if (!uuid_guid_get_bin(uuid_str, uuid_bin))
|
||||||
return 0;
|
return 0;
|
||||||
@ -298,7 +312,7 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
|
|||||||
tmp16 = cpu_to_be16(hextoul(uuid_str + 19, NULL));
|
tmp16 = cpu_to_be16(hextoul(uuid_str + 19, NULL));
|
||||||
memcpy(uuid_bin + 8, &tmp16, 2);
|
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);
|
memcpy(uuid_bin + 10, (char *)&tmp64 + 2, 6);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -306,9 +320,9 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
|
|||||||
|
|
||||||
int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
|
int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
|
||||||
{
|
{
|
||||||
u16 tmp16;
|
uint16_t tmp16;
|
||||||
u32 tmp32;
|
uint32_t tmp32;
|
||||||
u64 tmp64;
|
uint64_t tmp64;
|
||||||
|
|
||||||
if (!uuid_str_valid(uuid_str) || !uuid_bin)
|
if (!uuid_str_valid(uuid_str) || !uuid_bin)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -325,7 +339,7 @@ int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
|
|||||||
tmp16 = cpu_to_le16(hextoul(uuid_str + 19, NULL));
|
tmp16 = cpu_to_le16(hextoul(uuid_str + 19, NULL));
|
||||||
memcpy(uuid_bin + 8, &tmp16, 2);
|
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));
|
||||||
memcpy(uuid_bin + 10, &tmp64, 6);
|
memcpy(uuid_bin + 10, &tmp64, 6);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -334,11 +348,11 @@ int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
|
|||||||
void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
|
void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
|
||||||
int str_format)
|
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};
|
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};
|
9, 10, 11, 12, 13, 14, 15};
|
||||||
const u8 *char_order;
|
const uint8_t *char_order;
|
||||||
const char *format;
|
const char *format;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -420,6 +434,7 @@ void gen_v5_guid(const struct uuid *namespace, struct efi_guid *guid, ...)
|
|||||||
*tmp16 = cpu_to_le16(be16_to_cpu(*tmp16));
|
*tmp16 = cpu_to_le16(be16_to_cpu(*tmp16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_HOSTCC
|
||||||
#if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
|
#if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
|
||||||
void gen_rand_uuid(unsigned char *uuid_bin)
|
void gen_rand_uuid(unsigned char *uuid_bin)
|
||||||
{
|
{
|
||||||
@ -503,3 +518,4 @@ U_BOOT_CMD(guid, CONFIG_SYS_MAXARGS, 1, do_uuid,
|
|||||||
);
|
);
|
||||||
#endif /* CONFIG_CMD_UUID */
|
#endif /* CONFIG_CMD_UUID */
|
||||||
#endif /* CONFIG_RANDOM_UUID || CONFIG_CMD_UUID */
|
#endif /* CONFIG_RANDOM_UUID || CONFIG_CMD_UUID */
|
||||||
|
#endif /* !USE_HOSTCC */
|
||||||
|
Loading…
Reference in New Issue
Block a user