diff mbox

[U-Boot,v0,11/20] efi_loader: add guidstr helper

Message ID 20170804193205.24669-12-robdclark@gmail.com
State Superseded
Delegated to: Alexander Graf
Headers show

Commit Message

Rob Clark Aug. 4, 2017, 7:31 p.m. UTC
There are a couple places where we'll need GUID -> string.  So add a
helper.

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 include/efi_loader.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Heinrich Schuchardt Aug. 5, 2017, 7:33 p.m. UTC | #1
On 08/04/2017 09:31 PM, Rob Clark wrote:
> There are a couple places where we'll need GUID -> string.  So add a
> helper.
> 
> Signed-off-by: Rob Clark <robdclark@gmail.com>
> ---
>  include/efi_loader.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/include/efi_loader.h b/include/efi_loader.h
> index 1028bfb75d..e6c46f713e 100644
> --- a/include/efi_loader.h
> +++ b/include/efi_loader.h
> @@ -239,6 +239,21 @@ static inline int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
>  	return memcmp(g1, g2, sizeof(efi_guid_t));
>  }
>  
> +static inline int guidstr(char *s, const efi_guid_t *g)
> +{
> +	/* unpacked-guid, otherwise we have to have to consider endianess */
> +	struct {
> +		uint32_t data1;
> +		uint16_t data2;
> +		uint16_t data3;
> +		uint8_t  data4[8];
> +	} *ug = (void *)g;
> +	return sprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
> +		       ug->data1, ug->data2, ug->data3, ug->data4[0],
> +		       ug->data4[1], ug->data4[2], ug->data4[3], ug->data4[4],
> +		       ug->data4[5], ug->data4[6], ug->data4[7]);
> +}
> +
>  /*
>   * Use these to indicate that your code / data should go into the EFI runtime
>   * section and thus still be available when the OS is running
> 


You may want to have a look at these:

include/uuid.h:40
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);

With a conversion to uchar* you should be able to use uuid_guid_get_str
for your purposes. So this patch could be eliminated from the series.

Regards

Heinrich
Rob Clark Aug. 5, 2017, 7:56 p.m. UTC | #2
On Sat, Aug 5, 2017 at 3:33 PM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> On 08/04/2017 09:31 PM, Rob Clark wrote:
>> There are a couple places where we'll need GUID -> string.  So add a
>> helper.
>>
>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>> ---
>>  include/efi_loader.h | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/include/efi_loader.h b/include/efi_loader.h
>> index 1028bfb75d..e6c46f713e 100644
>> --- a/include/efi_loader.h
>> +++ b/include/efi_loader.h
>> @@ -239,6 +239,21 @@ static inline int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
>>       return memcmp(g1, g2, sizeof(efi_guid_t));
>>  }
>>
>> +static inline int guidstr(char *s, const efi_guid_t *g)
>> +{
>> +     /* unpacked-guid, otherwise we have to have to consider endianess */
>> +     struct {
>> +             uint32_t data1;
>> +             uint16_t data2;
>> +             uint16_t data3;
>> +             uint8_t  data4[8];
>> +     } *ug = (void *)g;
>> +     return sprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
>> +                    ug->data1, ug->data2, ug->data3, ug->data4[0],
>> +                    ug->data4[1], ug->data4[2], ug->data4[3], ug->data4[4],
>> +                    ug->data4[5], ug->data4[6], ug->data4[7]);
>> +}
>> +
>>  /*
>>   * Use these to indicate that your code / data should go into the EFI runtime
>>   * section and thus still be available when the OS is running
>>
>
>
> You may want to have a look at these:
>
> include/uuid.h:40
> 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);
>
> With a conversion to uchar* you should be able to use uuid_guid_get_str
> for your purposes. So this patch could be eliminated from the series.
>

hmm, wow, those seem a bit over-engineered.  But I think we should add
this to vsprintf.c and drop both this patch plus your patch that adds
a macro to print GUIDs.  (And vsprintf.c should re-use
uuid_guid_get_str().. and I could re-use uuid_guid_get_bin() when I
get around to implementing efi_get_next_variable(), so thanks for
pointing that out.)

BR,
-R
Heinrich Schuchardt Aug. 5, 2017, 8:18 p.m. UTC | #3
On 08/05/2017 09:56 PM, Rob Clark wrote:
> On Sat, Aug 5, 2017 at 3:33 PM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>> On 08/04/2017 09:31 PM, Rob Clark wrote:
>>> There are a couple places where we'll need GUID -> string.  So add a
>>> helper.
>>>
>>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>>> ---
>>>  include/efi_loader.h | 15 +++++++++++++++
>>>  1 file changed, 15 insertions(+)
>>>
>>> diff --git a/include/efi_loader.h b/include/efi_loader.h
>>> index 1028bfb75d..e6c46f713e 100644
>>> --- a/include/efi_loader.h
>>> +++ b/include/efi_loader.h
>>> @@ -239,6 +239,21 @@ static inline int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
>>>       return memcmp(g1, g2, sizeof(efi_guid_t));
>>>  }
>>>
>>> +static inline int guidstr(char *s, const efi_guid_t *g)
>>> +{
>>> +     /* unpacked-guid, otherwise we have to have to consider endianess */
>>> +     struct {
>>> +             uint32_t data1;
>>> +             uint16_t data2;
>>> +             uint16_t data3;
>>> +             uint8_t  data4[8];
>>> +     } *ug = (void *)g;
>>> +     return sprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
>>> +                    ug->data1, ug->data2, ug->data3, ug->data4[0],
>>> +                    ug->data4[1], ug->data4[2], ug->data4[3], ug->data4[4],
>>> +                    ug->data4[5], ug->data4[6], ug->data4[7]);
>>> +}
>>> +
>>>  /*
>>>   * Use these to indicate that your code / data should go into the EFI runtime
>>>   * section and thus still be available when the OS is running
>>>
>>
>>
>> You may want to have a look at these:
>>
>> include/uuid.h:40
>> 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);
>>
>> With a conversion to uchar* you should be able to use uuid_guid_get_str
>> for your purposes. So this patch could be eliminated from the series.
>>
> 
> hmm, wow, those seem a bit over-engineered.  But I think we should add
> this to vsprintf.c and drop both this patch plus your patch that adds
> a macro to print GUIDs.  (And vsprintf.c should re-use
> uuid_guid_get_str().. and I could re-use uuid_guid_get_bin() when I
> get around to implementing efi_get_next_variable(), so thanks for
> pointing that out.)
> 
> BR,
> -R
> 

In the case of guidstr we are switching two functions where the existing
one has one constant extra parameter.

In EFI_PRINT_GUID we would replace a single
debug(format, guid)
by code that would have to check _DEBUG that only is used inside the
definition of debug, a variable declaration, a call to uuid_guid_get_str
and a printf.

I think we should not evaluate _DEBUG outside include/common.h.

Regards

Heinrich
diff mbox

Patch

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 1028bfb75d..e6c46f713e 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -239,6 +239,21 @@  static inline int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2)
 	return memcmp(g1, g2, sizeof(efi_guid_t));
 }
 
+static inline int guidstr(char *s, const efi_guid_t *g)
+{
+	/* unpacked-guid, otherwise we have to have to consider endianess */
+	struct {
+		uint32_t data1;
+		uint16_t data2;
+		uint16_t data3;
+		uint8_t  data4[8];
+	} *ug = (void *)g;
+	return sprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+		       ug->data1, ug->data2, ug->data3, ug->data4[0],
+		       ug->data4[1], ug->data4[2], ug->data4[3], ug->data4[4],
+		       ug->data4[5], ug->data4[6], ug->data4[7]);
+}
+
 /*
  * Use these to indicate that your code / data should go into the EFI runtime
  * section and thus still be available when the OS is running