bootstd: cros: store partition type in an efi_guid_t
PATCH 1/1 bootstd: cros: store partition type in an efi_guid_t
The scan_part() function uses a struct uuid to store the little-endian partition type GUID, but this structure should be used only to contain a big-endian UUID. Use an efi_guid_t instead.
--- boot/bootmeth_cros.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
boot/bootmeth_cros.c +2 -2
@@ -148,7 +148,7 @@ static int scan_part(struct udevice *blk, int partnum, {struct blk_desc *desc =dev_get_uclass_plat (blk);struct vb2_keyblock *hdr; -struct uuid type; +efi_guid_t type;ulong num_blks;int ret;
@@ -161,7 +161,7 @@ static int scan_part(struct udevice *blk, int partnum,/* Check for kernel partition type */ log_debug ("part %x: type=%s\n" , partnum, info->type_guid); -if (uuid_str_to_bin (info->type_guid, (u8 *)&type,UUID_STR_FORMAT_GUID )) +if (uuid_str_to_bin (info->type_guid, type.b,UUID_STR_FORMAT_GUID ))return log_msg_ret ("typ" , -EINVAL );if (memcmp (&cros_kern_type, &type,sizeof (type)))
Signature · 1 line
2.43.0
Quoted 11 lines · Vincent Stehlé
The
scan_part()function uses a struct uuid to store the little-endian partition type GUID, but this structure should be used only to contain a big-endian UUID. Use anefi_guid_tinstead.Signed-off-by Vincent Stehlé <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>--- boot/bootmeth_cros.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Am 27. Juni 2024 19:06:29 MESZ schrieb "Vincent Stehlé" <[email protected]>:
Quoted 16 lines
The
scan_part()function uses a struct uuid to store the little-endian partition type GUID, but this structure should be used only to contain a big-endian UUID. Use anefi_guid_tinstead.Signed-off-by Vincent Stehlé <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>---
boot/bootmeth_cros.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)boot/bootmeth_cros.c +0
-0
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 151
Quoted 5 lines
boot/bootmeth_cros.c +1
-1@@ -148,7 +148,7 @@ static int scan_part(struct udevice *blk, int partnum, {struct blk_desc *desc =dev_get_uclass_plat (blk);struct vb2_keyblock *hdr; -struct uuid type; +efi_guid_t type;
Does Chrome OS only support GPT partitioning?
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 165
Quoted 10 lines
boot/bootmeth_cros.c +1
-1ulong num_blks;int ret;@@ -161,7 +161,7 @@ static int scan_part(struct udevice *blk, int partnum,/* Check for kernel partition type */ log_debug ("part %x: type=%s\n" , partnum, info->type_guid); -if (uuid_str_to_bin (info->type_guid, (u8 *)&type,UUID_STR_FORMAT_GUID )) +if (uuid_str_to_bin (info->type_guid, type.b,UUID_STR_FORMAT_GUID ))return log_msg_ret ("typ" , -EINVAL );
struct disk_partition containing a string which is only needed in the CLI instead of the 16 byte GUID was a bad idea to start with. Shouldn't we replace it or add least add a GUID field instead of first converting to string and than back to GUID?
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 167
Quoted 2 lines
boot/bootmeth_cros.c +0
-0if (memcmp (&cros_kern_type, &type,sizeof (type)))
You could use the guidcmp() macro here.
Best regards
Heinrich
Hi,
Quoted 15 lines · Heinrich Schuchardt
Am 27. Juni 2024 19:06:29 MESZ schrieb "Vincent Stehlé" <[email protected]>:
Quoted 11 lines
The
scan_part()function uses a struct uuid to store the little-endian partition type GUID, but this structure should be used only to contain a big-endian UUID. Use anefi_guid_tinstead.Signed-off-by Vincent Stehlé <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>---
boot/bootmeth_cros.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 151
Quoted 10 lines
boot/bootmeth_cros.c +1
-1@@ -148,7 +148,7 @@ static int scan_part(struct udevice *blk, int partnum, {struct blk_desc *desc =dev_get_uclass_plat (blk);struct vb2_keyblock *hdr; -struct uuid type; +efi_guid_t type;Does Chrome OS only support GPT partitioning?
Indeed.
Quoted 6 lines
Quoted 6 lines
boot/bootmeth_cros.c +0
-0ulong num_blks;int ret;@@ -161,7 +161,7 @@ static int scan_part(struct udevice *blk, int partnum,
Quoted 7 lines
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 165
Quoted 5 lines
boot/bootmeth_cros.c +1
-1/* Check for kernel partition type */ log_debug ("part %x: type=%s\n" , partnum, info->type_guid); -if (uuid_str_to_bin (info->type_guid, (u8 *)&type,UUID_STR_FORMAT_GUID )) +if (uuid_str_to_bin (info->type_guid, type.b,UUID_STR_FORMAT_GUID ))return log_msg_ret ("typ" , -EINVAL );struct
disk_partitioncontaining a string which is only needed in the CLI instead of the 16 byte GUID was a bad idea to start with. Shouldn't we replace it or add least add a GUID field instead of first converting to string and than back to GUID?
Yes I agree, it would be nice to fix that.
Quoted 5 lines
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 167
Quoted 3 lines
boot/bootmeth_cros.c +0
-0if (memcmp (&cros_kern_type, &type,sizeof (type)))You could use the
guidcmp()macro here.
Regards,
Simon
Quoted 1 line · Heinrich Schuchardt
Hi Heinrich,
Thanks for your review.
My comments below.
Best regards,
Vincent.
Quoted 31 lines
Am 27. Juni 2024 19:06:29 MESZ schrieb "Vincent Stehlé" <[email protected]>:
Quoted 16 lines
The
scan_part()function uses a struct uuid to store the little-endian partition type GUID, but this structure should be used only to contain a big-endian UUID. Use anefi_guid_tinstead.Signed-off-by Vincent Stehlé <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>---
boot/bootmeth_cros.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)boot/bootmeth_cros.c +0
-0boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 151
Quoted 5 lines
boot/bootmeth_cros.c +1
-1@@ -148,7 +148,7 @@ static int scan_part(struct udevice *blk, int partnum, {struct blk_desc *desc =dev_get_uclass_plat (blk);struct vb2_keyblock *hdr; -struct uuid type; +efi_guid_t type;Does Chrome OS only support GPT partitioning?
Quoted 5 lines
boot/bootmeth_cros.c +0
-0ulong num_blks;int ret;@@ -161,7 +161,7 @@ static int scan_part(struct udevice *blk, int partnum,
Quoted 7 lines
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 165
Quoted 5 lines
boot/bootmeth_cros.c +1
-1/* Check for kernel partition type */ log_debug ("part %x: type=%s\n" , partnum, info->type_guid); -if (uuid_str_to_bin (info->type_guid, (u8 *)&type,UUID_STR_FORMAT_GUID )) +if (uuid_str_to_bin (info->type_guid, type.b,UUID_STR_FORMAT_GUID ))return log_msg_ret ("typ" , -EINVAL );struct
disk_partitioncontaining a string which is only needed in the CLI instead of the 16 byte GUID was a bad idea to start with. Shouldn't we replace it or add least add a GUID field instead of first converting to string and than back to GUID?
I had a quick look and it seems that converting all those UUIDs from strings to binary would indeed impact many places; let's separate this longer-term effort from this change if you agree.
Quoted 5 lines
boot/bootmeth_cros.c static int scan_part(struct udevice *blk, int partnum, · line 167
Quoted 3 lines
boot/bootmeth_cros.c +0
-0if (memcmp (&cros_kern_type, &type,sizeof (type)))You could use the
guidcmp()macro here.
Thanks for the tip; I will send a v2 series.
Quoted 5 lines
Best regards
Heinrich
v2 cover Respin bootstd cros patch into a series of two
In reply to Vincent StehléHi,
This is a respin of this patch [1] after discussion [2]. Thanks to Simon and Heinrich for their reviews.
To use the guidcmp() function, as suggested by Heinrich, we need to make it available to bootmeth_cros.c and I think that the cleanest way to do that is (arguably) to move the guid helper functions to efi.h near the efi_guid_t definition; this is why the original patch has now become a series of two patches.
The alternative would be to include efi_loader.h from bootmeth_cros.c but I think this does not sound "right". If this is in fact the preferred approach just let me know and I will respin.
There is no difference in the sandbox binaries before/after this series on Arm and on PC, and all the tests I have run on the sandbox are unchanged.
Best regards,
Vincent.
[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lists.denx.de/pipermail/u-boot/2024-June/557588.html
Vincent Stehlé (2):
efi: move guid helper functions to efi.h
bootstd: cros: store partition type in an efi_guid_t
boot/bootmeth_cros.c | 6 +++--- include/efi.h | 10 ++++++++++ include/efi_loader.h | 10 ---------- 3 files changed, 13 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 efi: move guid helper functions to efi.h
Move the guidcmp() and guidcpy() functions to efi.h, near the definition of the efi_guid_t type those functions deal with.
--- include/efi.h | 10 ++++++++++ include/efi_loader.h | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-)
include/efi.h +10 -0
@@ -78,6 +78,16 @@ typedef struct {u8 b[16 ]; } efi_guid_t __attribute__((aligned(4))); +static inline int guidcmp (const void *g1,const void *g2) +{ +return memcmp (g1, g2,sizeof (efi_guid_t)); +} + +static inline void *guidcpy (void *dst,const void *src) +{ +return memcpy (dst, src,sizeof (efi_guid_t)); +} +#define EFI_BITS_PER_LONG (sizeof(long) * 8)/* Bit mask for EFI status code with error */
include/efi_loader.h +0 -10
@@ -21,16 +21,6 @@struct blk_desc ;struct jmp_buf_data ; -static inline int guidcmp (const void *g1,const void *g2) -{ -return memcmp (g1, g2,sizeof (efi_guid_t)); -} - -static inline void *guidcpy (void *dst,const void *src) -{ -return memcpy (dst, src,sizeof (efi_guid_t)); -} -#if CONFIG_IS_ENABLED (EFI_LOADER )/**
Signature · 1 line
2.43.0
PATCH v2 2/2 bootstd: cros: store partition type in an efi_guid_t
In reply to Vincent StehléThe scan_part() function uses a struct uuid to store the little-endian partition type GUID, but this structure should be used only to contain a big-endian UUID. Use an efi_guid_t instead and use guidcmp() for the comparison.
---
Changes for v2:
- Use guidcmp() for the comparison, as suggested by Heinrich.
boot/bootmeth_cros.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
boot/bootmeth_cros.c +3 -3
@@ -147,7 +147,7 @@ static int scan_part(struct udevice *blk, int partnum, {struct blk_desc *desc =dev_get_uclass_plat (blk);struct vb2_keyblock *hdr; -struct uuid type; +efi_guid_t type;ulong num_blks;int ret;
@@ -160,10 +160,10 @@ static int scan_part(struct udevice *blk, int partnum,/* Check for kernel partition type */ log_debug ("part %x: type=%s\n" , partnum, info->type_guid); -if (uuid_str_to_bin (info->type_guid, (u8 *)&type,UUID_STR_FORMAT_GUID )) +if (uuid_str_to_bin (info->type_guid, type.b,UUID_STR_FORMAT_GUID ))return log_msg_ret ("typ" , -EINVAL ); -if (memcmp (&cros_kern_type, &type,sizeof (type))) +if (guidcmp (&cros_kern_type, &type))return log_msg_ret ("typ" , -ENOEXEC );/* Make a buffer for the header information */
Signature · 1 line
2.43.0
Re: [PATCH v2 0/2] Respin bootstd cros patch into a series of two
In reply to Vincent StehléQuoted 10 lines · Vincent Stehlé
This is a respin of this patch [1] after discussion [2]. Thanks to Simon and Heinrich for their reviews.
To use the
guidcmp()function, as suggested by Heinrich, we need to make it available tobootmeth_cros.cand I think that the cleanest way to do that is (arguably) to move the guid helper functions toefi.hnear theefi_guid_tdefinition; this is why the original patch has now become a series of two patches.[...]
Applied to u-boot/master, thanks!
Signature · 1 line
Tom