Skip to contentSkip to conversation

efi_loader: disk: Add EFI_PARTITION_INFO_PROTOCOL support for MBR

PATCH In review Javier Martinez Canillas 4 participants 19 messages Feb 12 – Feb 15

lore
Share & tools
lore
#0 lore raw

v2 cover efi_loader: disk: Add EFI_PARTITION_INFO_PROTOCOL support for MBR

This patch series extends the EFI_PARTITION_INFO_PROTOCOL implementation to also support MBR partition tables schemes.

When EFI_PARTITION_INFO_PROTOCOL was implented, only GPT support was added but this can cause compatibility issues with platforms whose boot ROM only supports MBR. This series add support for MBR partition tables to the protocol, making U-Boot compatible with systems that require a legacy MBR table.

This is a second version of the patches that addresses issues pointed out by Heinrich Schuchardt (thanks!). The first version can be found here:

https://lists.denx.de/pipermail/u-boot/2025-June/592644.html

Patches #1 to #3 are preparatory changes to remove duplicated definitions of data structures to store the MBR records.

Patch #4 just documents the part_get_info_extended() helper function and patch #5 refactors this function to also optionally return the MBR record data.

Patch #6 adds the MBR support to the EFI_PARTITION_INFO_PROTOCOL implementation and patch #7 enhances the protocol selftest, to check that the partition record data is correctly filled.

Changes in v2:
- Add Tom Rini Rini's Reviewed-by tags to patches 1-3.
- Document part_get_info_extended() helper function.
- Split partition library and EFI changes in separate patches.
- Add static MBR data in EFI block device test and compare the queried data.

Javier Martinez Canillas (7):
disk: part_dos: Move header to the main include directory
disk: part_dos: Align dos_partition_t with struct partition
disk: part_efi: Remove redundant struct partition definition
disk: part_dos: Document part_get_info_extended() helper function
disk: part_dos: Refactor to allow retrieving raw MBR partition data
efi_loader: disk: Extend EFI_PARTITION_INFO_PROTOCOL to support MBR
efi_selftest: Enhance MBR test for PARTITION_INFO_PROTOCOL

 disk/part_dos.c                              | 91 +++++++++++++-------
 disk/part_efi.c                              |  4 +-
 include/part.h                               | 14 +++
 {disk => include}/part_dos.h                 |  6 +-
 include/part_efi.h                           | 19 +---
 lib/efi_loader/efi_disk.c                    |  9 +-
 lib/efi_selftest/efi_selftest_block_device.c | 26 ++++++
 7 files changed, 113 insertions(+), 56 deletions(-)
 rename {disk => include}/part_dos.h (87%)
Signature · 4 lines
2.53.0

base-commit: f9ffeec4bdcf1da655a0ffea482062adde78fee8
branch: add-mbr-efi-part-info-proto-v2
#1 lore raw

PATCH v2 1/7 disk: part_dos: Move header to the main include directory

There are two different struct definitions for MBR partition table
entries: one in part_dos.h and a nearly identical one in part_efi.h.

To enable future consolidation of these two structures, move part_dos.h to the main include directory. This makes it accessible from other parts of the codebase, such as part_efi.h, and is the first step toward removing the redundant definition.

---

(no changes since v1)

 disk/part_dos.c              | 2 +-
 {disk => include}/part_dos.h | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename {disk => include}/part_dos.h (100%)
disk/part_dos.c +1 -1
index 18dd35c9b98e..2545cc6bf5d2 100644
@@ -19,7 +19,7 @@
 #include <vsprintf.h>
 #include <asm/unaligned.h>
 #include <linux/compiler.h>
-#include "part_dos.h"
+#include <part_dos.h>
 #include <part.h>
 
 #define DOS_PART_DEFAULT_SECTOR 512
include/part_dos.h renamed from disk/part_dos.h +0 -0
similarity index 100%
rename from disk/part_dos.h
rename to include/part_dos.h
Signature · 1 line
2.53.0
Reviewed-by on v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] disk: part_dos: Move header to the main include directory

Quoted 4 lines · Javier Martinez Canillas

There are two different struct definitions for MBR partition table
entries: one in part_dos.h and a nearly identical one in part_efi.h.

Quoted 8 lines

To enable future consolidation of these two structures, move part_dos.h to the main include directory. This makes it accessible from other parts of the codebase, such as part_efi.h, and is the first step toward removing the redundant definition.

---

Quoted 28 lines

(no changes since v1)

 disk/part_dos.c              | 2 +-
 {disk => include}/part_dos.h | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename {disk => include}/part_dos.h (100%)
disk/part_dos.c +1 -1
index 18dd35c9b98e..2545cc6bf5d2 100644
@@ -19,7 +19,7 @@
 #include <vsprintf.h>
 #include <asm/unaligned.h>
 #include <linux/compiler.h>
-#include "part_dos.h"
+#include <part_dos.h>
 #include <part.h>
 
 #define DOS_PART_DEFAULT_SECTOR 512
include/part_dos.h renamed from disk/part_dos.h +0 -1
similarity index 100%
rename from disk/part_dos.h
rename to include/part_dos.h
--

2.53.0

#3 lore raw

PATCH v2 2/7 disk: part_dos: Align dos_partition_t with struct partition

In reply to Javier Martinez Canillas

The dos_partition_t struct defined in part_dos.h is nearly identical to the struct partition defined in part_efi.h. They differ primarily in how define their starting sector and number of sectors fields.

The former uses unsigned char arrays while the latter uses __le32 types. Using __le32 is preferable, as it removes the ambiguity and potential misuse of a raw byte array. This also aligns the structure with how the Linux kernel defines it nowadays, which is the original source of it.

To prepare for future consolidation where one of the data structures can be removed, this change aligns both definitions and updates all accessors for dos_partition_t.

---

(no changes since v1)

 disk/part_dos.c    | 16 ++++++++--------
 include/part_dos.h |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)
disk/part_dos.c +8 -8
index 2545cc6bf5d2..60c3d6773696 100644
@@ -49,8 +49,8 @@ static int get_bootable(dos_partition_t *p)
 static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
 			   int part_num, unsigned int disksig)
 {
-	lbaint_t lba_start = ext_part_sector + get_unaligned_le32(p->start4);
-	lbaint_t lba_size  = get_unaligned_le32(p->size4);
+	lbaint_t lba_start = ext_part_sector + get_unaligned_le32(&p->start_sect);
+	lbaint_t lba_size  = get_unaligned_le32(&p->nr_sects);
 
 	printf("%3d\t%-10" LBAFlength "u\t%-10" LBAFlength
 		"u\t%08x-%02x\t%02x%s%s\n",
@@ -185,7 +185,7 @@ static void print_partition_extended(struct blk_desc *desc,
 	for (i = 0; i < 4; i++, pt++) {
 		if (is_extended (pt->sys_ind)) {
 			lbaint_t lba_start
-				= get_unaligned_le32 (pt->start4) + relative;
+				= get_unaligned_le32 (&pt->start_sect) + relative;
 
 			print_partition_extended(desc, lba_start,
 						 !ext_part_sector ? lba_start :
@@ -252,8 +252,8 @@ static int part_get_info_extended(struct blk_desc *desc,
 			else
 				info->blksz = DOS_PART_DEFAULT_SECTOR;
 			info->start = (lbaint_t)(ext_part_sector +
-					get_unaligned_le32(pt->start4));
-			info->size  = (lbaint_t)get_unaligned_le32(pt->size4);
+					get_unaligned_le32(&pt->start_sect));
+			info->size  = (lbaint_t)get_unaligned_le32(&pt->nr_sects);
 			part_set_generic_name(desc, part_num,
 					      (char *)info->name);
 			/* sprintf(info->type, "%d, pt->sys_ind); */
@@ -281,7 +281,7 @@ static int part_get_info_extended(struct blk_desc *desc,
 	for (i = 0; i < 4; i++, pt++) {
 		if (is_extended (pt->sys_ind)) {
 			lbaint_t lba_start
-				= get_unaligned_le32 (pt->start4) + relative;
+				= get_unaligned_le32 (&pt->start_sect) + relative;
 
 			return part_get_info_extended(desc, lba_start,
 				 ext_part_sector == 0 ? lba_start : relative,
@@ -356,8 +356,8 @@ static void mbr_fill_pt_entry(dos_partition_t *pt, lbaint_t start,
 	pt->sys_ind = sys_ind;
 	lba_to_chs(start, &pt->cyl, &pt->head, &pt->sector);
 	lba_to_chs(start + size - 1, &pt->end_cyl, &pt->end_head, &pt->end_sector);
-	put_unaligned_le32(relative, &pt->start4);
-	put_unaligned_le32(size, &pt->size4);
+	put_unaligned_le32(relative, &pt->start_sect);
+	put_unaligned_le32(size, &pt->nr_sects);
 }
 
 int write_mbr_partitions(struct blk_desc *dev,
include/part_dos.h +3 -3
index 505582242281..92956d530637 100644
@@ -30,8 +30,8 @@ typedef struct dos_partition {
 	unsigned char end_head;		/* end head				*/
 	unsigned char end_sector;	/* end sector				*/
 	unsigned char end_cyl;		/* end cylinder				*/
-	unsigned char start4[4];	/* starting sector counting from 0	*/
-	unsigned char size4[4];		/* nr of sectors in partition		*/
-} dos_partition_t;
+	__le32 start_sect;		/* starting sector counting from 0	*/
+	__le32 nr_sects;		/* nr of sectors in partition		*/
+} __packed dos_partition_t;
 
 #endif	/* _DISK_PART_DOS_H */
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH v2 2/7] disk: part_dos: Align dos_partition_t with struct partition

Hi Javier

[...]

include/part_dos.h typedef struct dos_partition { · line 35

Quoted 9 lines
        unsigned char end_head;         /* end head                             */
        unsigned char end_sector;       /* end sector                           */
        unsigned char end_cyl;          /* end cylinder                         */
include/part_dos.h +3 -3
-       unsigned char start4[4];        /* starting sector counting from 0      */
-       unsigned char size4[4];         /* nr of sectors in partition           */
-} dos_partition_t;
+       __le32 start_sect;              /* starting sector counting from 0      */
+       __le32 nr_sects;                /* nr of sectors in partition           */
+} __packed dos_partition_t;

This always has to be packed and the part_dos.h definition had this wrong all along?

Quoted 5 lines

#endif /* _DISK_PART_DOS_H */
--
2.53.0

#5 lore raw

Re: [PATCH v2 2/7] disk: part_dos: Align dos_partition_t with struct partition

Ilias Apalodimas <[email protected]> writes:

Hello Ilias,

Quoted 4 lines

Hi Javier

[...]

Quoted 13 lines

include/part_dos.h typedef struct dos_partition { · line 35

Quoted 9 lines
        unsigned char end_head;         /* end head                             */
        unsigned char end_sector;       /* end sector                           */
        unsigned char end_cyl;          /* end cylinder                         */
include/part_dos.h +3 -3
-       unsigned char start4[4];        /* starting sector counting from 0      */
-       unsigned char size4[4];         /* nr of sectors in partition           */
-} dos_partition_t;
+       __le32 start_sect;              /* starting sector counting from 0      */
+       __le32 nr_sects;                /* nr of sectors in partition           */
+} __packed dos_partition_t;

This always has to be packed and the part_dos.h definition had this wrong all along?

I wondered exactly the same when working on these patches and did a bit of code archaeology, so I'm glad that you asked!

It wasn't wrong because it was using unsigned char arrays for the start and number of sectors struct fields, instead of __le32 types.

Given the alignment of a char array is 1-byte (and all the other fields are unsigned chars), the structure was naturally aligned.

But I agree that using __le32 and __packed is preferred, and in fact is how Linux defines this data structure in include/linux/msdos_partition.h:

struct msdos_partition {

        u8 boot_ind;            /* 0x80 - active */
        u8 head;                /* starting head */
        u8 sector;              /* starting sector */
        u8 cyl;                 /* starting cylinder */
        u8 sys_ind;             /* What partition type */
        u8 end_head;            /* end head */
        u8 end_sector;          /* end sector */
        u8 end_cyl;             /* end cylinder */
        __le32 start_sect;      /* starting sector counting from 0 */
        __le32 nr_sects;        /* nr of sectors in partition */

} __packed;

The struct_partition in disk/part_efi.c is said to be taken from Linux's linux/include/genhd.h, which was the old location before commit 1442f76d4317b ("1442f76d4317 block: move struct partition out of genhd.h").

My guess is that the old data structure defined in part_dos.h was copied from Linux, and that at the time of the copy it was using unsigned char arrays too.

But the struct definition has been like this since the original Linux git import, so I couldn't check if my guess was correct.

In any case, now this single data structure definition is aligned with how both the Linux kernel and edk2 define it.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Reviewed-by
#6 lore raw

Re: [PATCH v2 2/7] disk: part_dos: Align dos_partition_t with struct partition

Quoted 46 lines · Javier Martinez Canillas

Ilias Apalodimas <[email protected]> writes:

Hello Ilias,

Quoted 4 lines

Hi Javier

[...]

Quoted 13 lines

include/part_dos.h typedef struct dos_partition { · line 35

Quoted 9 lines
        unsigned char end_head;         /* end head                             */
        unsigned char end_sector;       /* end sector                           */
        unsigned char end_cyl;          /* end cylinder                         */
include/part_dos.h +3 -3
-       unsigned char start4[4];        /* starting sector counting from 0      */
-       unsigned char size4[4];         /* nr of sectors in partition           */
-} dos_partition_t;
+       __le32 start_sect;              /* starting sector counting from 0      */
+       __le32 nr_sects;                /* nr of sectors in partition           */
+} __packed dos_partition_t;

This always has to be packed and the part_dos.h definition had this wrong all along?

I wondered exactly the same when working on these patches and did a bit of code archaeology, so I'm glad that you asked!

It wasn't wrong because it was using unsigned char arrays for the start and number of sectors struct fields, instead of __le32 types.

Given the alignment of a char array is 1-byte (and all the other fields are unsigned chars), the structure was naturally aligned.

But I agree that using __le32 and __packed is preferred, and in fact is how Linux defines this data structure in include/linux/msdos_partition.h:

struct msdos_partition {

        u8 boot_ind;            /* 0x80 - active */
        u8 head;                /* starting head */
        u8 sector;              /* starting sector */
        u8 cyl;                 /* starting cylinder */
        u8 sys_ind;             /* What partition type */
        u8 end_head;            /* end head */
        u8 end_sector;          /* end sector */
        u8 end_cyl;             /* end cylinder */
        __le32 start_sect;      /* starting sector counting from 0 */
        __le32 nr_sects;        /* nr of sectors in partition */
Quoted 8 lines

} __packed;

The struct_partition in disk/part_efi.c is said to be taken from Linux's linux/include/genhd.h, which was the old location before commit 1442f76d4317b ("1442f76d4317 block: move struct partition out of genhd.h").

My guess is that the old data structure defined in part_dos.h was copied from Linux, and that at the time of the copy it was using unsigned char arrays too.

Ok that makes sense and yes, the alignment is not affected by le32 or a a 4b char.

Quoted 14 lines

But the struct definition has been like this since the original Linux git import, so I couldn't check if my guess was correct.

In any case, now this single data structure definition is aligned with how both the Linux kernel and edk2 define it.

--
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat

#7 lore raw

Re: [PATCH v2 2/7] disk: part_dos: Align dos_partition_t with struct partition

In reply to Ilias Apalodimas
Quoted 4 lines · Ilias Apalodimas

Hi Javier

[...]

Quoted 12 lines

include/part_dos.h typedef struct dos_partition { · line 35

Quoted 9 lines
        unsigned char end_head;         /* end head                             */
        unsigned char end_sector;       /* end sector                           */
        unsigned char end_cyl;          /* end cylinder                         */
include/part_dos.h +3 -3
-       unsigned char start4[4];        /* starting sector counting from 0      */
-       unsigned char size4[4];         /* nr of sectors in partition           */
-} dos_partition_t;
+       __le32 start_sect;              /* starting sector counting from 0      */
+       __le32 nr_sects;                /* nr of sectors in partition           */
+} __packed dos_partition_t;

This always has to be packed and the part_dos.h definition had this wrong all along?

I believe that's what we found as part of v1, yes. Or at least the linux kernel has always packed it?

Signature · 1 line
Tom
#8 lore raw

PATCH v2 3/7 disk: part_efi: Remove redundant struct partition definition

In reply to Javier Martinez Canillas

Now that dos_partition_t and struct partition are identical, the duplicated data structure definition in the part_efi.h header can just be removed.

This results in a single, shared definition for MBR partition table entries, instead of having the same definition in two different places.

---

(no changes since v1)

 disk/part_efi.c    |  4 ++--
 include/part_efi.h | 19 +++----------------
 2 files changed, 5 insertions(+), 18 deletions(-)
disk/part_efi.c +2 -2
index fb1ed534f861..d8b17ec2e91a 100644
@@ -51,7 +51,7 @@ static inline u32 efi_crc32(const void *buf, u32 len)
  * Private function prototypes
  */
 
-static int pmbr_part_valid(struct partition *part);
+static int pmbr_part_valid(dos_partition_t *part);
 static int is_pmbr_valid(legacy_mbr * mbr);
 static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head,
 			gpt_entry **pgpt_pte);
@@ -990,7 +990,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *desc, void *buf)
  *
  * Returns: 1 if EFI GPT partition type is found.
  */
-static int pmbr_part_valid(struct partition *part)
+static int pmbr_part_valid(dos_partition_t *part)
 {
 	if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT &&
 		get_unaligned_le32(&part->start_sect) == 1UL) {
include/part_efi.h +3 -16
index fb402df6f13e..2cea50880465 100644
@@ -18,6 +18,7 @@
 #define _DISK_PART_EFI_H
 
 #include <efi.h>
+#include <part_dos.h>
 
 #define MSDOS_MBR_SIGNATURE 0xAA55
 #define MSDOS_MBR_BOOT_CODE_SIZE 440
@@ -77,20 +78,6 @@
 /* linux/include/efi.h */
 typedef u16 efi_char16_t;
 
-/* based on linux/include/genhd.h */
-struct partition {
-	u8 boot_ind;		/* 0x80 - active */
-	u8 head;		/* starting head */
-	u8 sector;		/* starting sector */
-	u8 cyl;			/* starting cylinder */
-	u8 sys_ind;		/* What partition type */
-	u8 end_head;		/* end head */
-	u8 end_sector;		/* end sector */
-	u8 end_cyl;		/* end cylinder */
-	__le32 start_sect;	/* starting sector counting from 0 */
-	__le32 nr_sects;	/* nr of sectors in partition */
-} __packed;
-
 /* based on linux/fs/partitions/efi.h */
 typedef struct _gpt_header {
 	__le64 signature;
@@ -134,7 +121,7 @@ typedef struct _legacy_mbr {
 	u8 boot_code[MSDOS_MBR_BOOT_CODE_SIZE];
 	__le32 unique_mbr_signature;
 	__le16 unknown;
-	struct partition partition_record[4];
+	dos_partition_t partition_record[4];
 	__le16 signature;
 } __packed legacy_mbr;
 
@@ -153,7 +140,7 @@ struct efi_partition_info {
 	u8 system;
 	u8 reserved[7];
 	union {
-		struct partition mbr;
+		dos_partition_t mbr;
 		gpt_entry gpt;
 	} info;
 } __packed;
Signature · 1 line
2.53.0
Reviewed-by on v2 3/7
#9 lore raw

Re: [PATCH v2 3/7] disk: part_efi: Remove redundant struct partition definition

Quoted 11 lines · Javier Martinez Canillas

Now that dos_partition_t and struct partition are identical, the duplicated data structure definition in the part_efi.h header can just be removed.

This results in a single, shared definition for MBR partition table entries, instead of having the same definition in two different places.

---

Quoted 82 lines

(no changes since v1)

 disk/part_efi.c    |  4 ++--
 include/part_efi.h | 19 +++----------------
 2 files changed, 5 insertions(+), 18 deletions(-)
disk/part_efi.c +2 -2
index fb1ed534f861..d8b17ec2e91a 100644
@@ -51,7 +51,7 @@ static inline u32 efi_crc32(const void *buf, u32 len)
  * Private function prototypes
  */
 
-static int pmbr_part_valid(struct partition *part);
+static int pmbr_part_valid(dos_partition_t *part);
 static int is_pmbr_valid(legacy_mbr * mbr);
 static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head,
                        gpt_entry **pgpt_pte);
@@ -990,7 +990,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *desc, void *buf)
  *
  * Returns: 1 if EFI GPT partition type is found.
  */
-static int pmbr_part_valid(struct partition *part)
+static int pmbr_part_valid(dos_partition_t *part)
 {
        if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT &&
                get_unaligned_le32(&part->start_sect) == 1UL) {
include/part_efi.h +3 -17
index fb402df6f13e..2cea50880465 100644
@@ -18,6 +18,7 @@
 #define _DISK_PART_EFI_H
 
 #include <efi.h>
+#include <part_dos.h>
 
 #define MSDOS_MBR_SIGNATURE 0xAA55
 #define MSDOS_MBR_BOOT_CODE_SIZE 440
@@ -77,20 +78,6 @@
 /* linux/include/efi.h */
 typedef u16 efi_char16_t;
 
-/* based on linux/include/genhd.h */
-struct partition {
-       u8 boot_ind;            /* 0x80 - active */
-       u8 head;                /* starting head */
-       u8 sector;              /* starting sector */
-       u8 cyl;                 /* starting cylinder */
-       u8 sys_ind;             /* What partition type */
-       u8 end_head;            /* end head */
-       u8 end_sector;          /* end sector */
-       u8 end_cyl;             /* end cylinder */
-       __le32 start_sect;      /* starting sector counting from 0 */
-       __le32 nr_sects;        /* nr of sectors in partition */
-} __packed;
-
 /* based on linux/fs/partitions/efi.h */
 typedef struct _gpt_header {
        __le64 signature;
@@ -134,7 +121,7 @@ typedef struct _legacy_mbr {
        u8 boot_code[MSDOS_MBR_BOOT_CODE_SIZE];
        __le32 unique_mbr_signature;
        __le16 unknown;
-       struct partition partition_record[4];
+       dos_partition_t partition_record[4];
        __le16 signature;
 } __packed legacy_mbr;
 
@@ -153,7 +140,7 @@ struct efi_partition_info {
        u8 system;
        u8 reserved[7];
        union {
-               struct partition mbr;
+               dos_partition_t mbr;
                gpt_entry gpt;
        } info;
 } __packed;
--

2.53.0

#10 lore raw

PATCH v2 4/7 disk: part_dos: Document part_get_info_extended() helper function

In reply to Javier Martinez Canillas

The function receives many parameters but these are not documented. Add a description for these to make it easier to follow what it does.

---

(no changes since v1)

 disk/part_dos.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
disk/part_dos.c +12 -1
index 60c3d6773696..a69ad8962106 100644
@@ -196,7 +196,18 @@ static void print_partition_extended(struct blk_desc *desc,
 	return;
 }
 
-/*  Print a partition that is relative to its Extended partition table
+/**
+ * part_get_info_extended() - get partition info for a DOS partition
+ *
+ * @desc:		Block device descriptor
+ * @ext_part_sector:	Partition table sector
+ * @relative:		Relative offset for the partition
+ * @part_num:		Current partition number
+ * @which_part:		Target partition number
+ * @info:		Returns a pointer to the partition info
+ * @disksig:		Disk signature
+ *
+ * Return:		0 on success, negative on error
  */
 static int part_get_info_extended(struct blk_desc *desc,
 				  lbaint_t ext_part_sector, lbaint_t relative,
Signature · 1 line
2.53.0
Reviewed-by on v2 4/7
#11 lore raw

Re: [PATCH v2 4/7] disk: part_dos: Document part_get_info_extended() helper function

Quoted 7 lines · Javier Martinez Canillas

The function receives many parameters but these are not documented. Add a description for these to make it easier to follow what it does.

---

Quoted 33 lines

(no changes since v1)

 disk/part_dos.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
disk/part_dos.c +12 -2
index 60c3d6773696..a69ad8962106 100644
@@ -196,7 +196,18 @@ static void print_partition_extended(struct blk_desc *desc,
        return;
 }
 
-/*  Print a partition that is relative to its Extended partition table
+/**
+ * part_get_info_extended() - get partition info for a DOS partition
+ *
+ * @desc:              Block device descriptor
+ * @ext_part_sector:   Partition table sector
+ * @relative:          Relative offset for the partition
+ * @part_num:          Current partition number
+ * @which_part:                Target partition number
+ * @info:              Returns a pointer to the partition info
+ * @disksig:           Disk signature
+ *
+ * Return:             0 on success, negative on error
  */
 static int part_get_info_extended(struct blk_desc *desc,
                                  lbaint_t ext_part_sector, lbaint_t relative,
--

2.53.0

#12 lore raw

PATCH v2 5/7 disk: part_dos: Refactor to allow retrieving raw MBR partition data

In reply to Javier Martinez Canillas

Refactor the part_get_info_extended() helper function (which already recursively traverses DOS partitions) to optionally return the raw MBR partition structure (dos_partition_t).

This allows other subsystems, such as EFI, to retrieve the partition details in the legacy MBR format.

---

(no changes since v1)

 disk/part_dos.c | 66 ++++++++++++++++++++++++++++++-------------------
 include/part.h  | 14 +++++++++++
 2 files changed, 55 insertions(+), 25 deletions(-)
disk/part_dos.c +41 -25
index a69ad8962106..4e1d01b2f21e 100644
@@ -204,7 +204,8 @@ static void print_partition_extended(struct blk_desc *desc,
  * @relative:		Relative offset for the partition
  * @part_num:		Current partition number
  * @which_part:		Target partition number
- * @info:		Returns a pointer to the partition info
+ * @info:		Returns partition information (optional)
+ * @mbr:		Returns MBR partition entry (optional)
  * @disksig:		Disk signature
  *
  * Return:		0 on success, negative on error
@@ -212,7 +213,9 @@ static void print_partition_extended(struct blk_desc *desc,
 static int part_get_info_extended(struct blk_desc *desc,
 				  lbaint_t ext_part_sector, lbaint_t relative,
 				  int part_num, int which_part,
-				  struct disk_partition *info, uint disksig)
+				  struct disk_partition *info,
+				  dos_partition_t *mbr,
+				  uint disksig)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);
 	struct disk_partition wdinfo = { 0 };
@@ -243,9 +246,11 @@ static int part_get_info_extended(struct blk_desc *desc,
 	if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector)
 		disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 
-	ret = part_get_info_whole_disk(desc, &wdinfo);
-	if (ret)
-		return ret;
+	if (info) {
+		ret = part_get_info_whole_disk(desc, &wdinfo);
+		if (ret)
+			return ret;
+	}
 
 	/* Print all primary/logical partitions */
 	pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
@@ -258,25 +263,29 @@ static int part_get_info_extended(struct blk_desc *desc,
 		    (pt->sys_ind != 0) &&
 		    (part_num == which_part) &&
 		    (ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
-			if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
-				info->blksz = wdinfo.blksz;
-			else
-				info->blksz = DOS_PART_DEFAULT_SECTOR;
-			info->start = (lbaint_t)(ext_part_sector +
-					get_unaligned_le32(&pt->start_sect));
-			info->size  = (lbaint_t)get_unaligned_le32(&pt->nr_sects);
-			part_set_generic_name(desc, part_num,
-					      (char *)info->name);
-			/* sprintf(info->type, "%d, pt->sys_ind); */
-			strcpy((char *)info->type, "U-Boot");
-			info->bootable = get_bootable(pt);
-			if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
-				char str[12];
-
-				sprintf(str, "%08x-%02x", disksig, part_num);
-				disk_partition_set_uuid(info, str);
+			if (info) {
+				if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
+					info->blksz = wdinfo.blksz;
+				else
+					info->blksz = DOS_PART_DEFAULT_SECTOR;
+				info->start = (lbaint_t)(ext_part_sector +
+							 get_unaligned_le32(&pt->start_sect));
+				info->size  = (lbaint_t)get_unaligned_le32(&pt->nr_sects);
+				part_set_generic_name(desc, part_num,
+						      (char *)info->name);
+				/* sprintf(info->type, "%d, pt->sys_ind); */
+				strcpy((char *)info->type, "U-Boot");
+				info->bootable = get_bootable(pt);
+				if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+					char str[12];
+
+					sprintf(str, "%08x-%02x", disksig, part_num);
+					disk_partition_set_uuid(info, str);
+				}
+				info->sys_ind = pt->sys_ind;
 			}
-			info->sys_ind = pt->sys_ind;
+			if (mbr)
+				memcpy(mbr, pt, sizeof(*mbr));
 			return 0;
 		}
 
@@ -296,7 +305,8 @@ static int part_get_info_extended(struct blk_desc *desc,
 
 			return part_get_info_extended(desc, lba_start,
 				 ext_part_sector == 0 ? lba_start : relative,
-				 part_num, which_part, info, disksig);
+						      part_num, which_part, info,
+						      mbr, disksig);
 		}
 	}
 
@@ -328,7 +338,13 @@ static void __maybe_unused part_print_dos(struct blk_desc *desc)
 static int __maybe_unused part_get_info_dos(struct blk_desc *desc, int part,
 					    struct disk_partition *info)
 {
-	return part_get_info_extended(desc, 0, 0, 1, part, info, 0);
+	return part_get_info_extended(desc, 0, 0, 1, part, info, NULL, 0);
+}
+
+int __maybe_unused part_get_mbr(struct blk_desc *desc, int part,
+				dos_partition_t *mbr)
+{
+	return part_get_info_extended(desc, 0, 0, 1, part, NULL, mbr, 0);
 }
 
 int is_valid_dos_buf(void *buf)
include/part.h +14 -0
index daebbbc2e68f..aed089d00f64 100644
@@ -704,6 +704,20 @@ int write_mbr_partitions(struct blk_desc *dev,
 int layout_mbr_partitions(struct disk_partition *p, int count,
 			  lbaint_t total_sectors);
 
+/**
+ * part_get_mbr() - get the MBR partition record of a partition
+ *
+ * This function reads the MBR partition record for a given block
+ * device and partition number.
+ *
+ * @desc:	block device descriptor
+ * @part:	partition number for which to return the partition record
+ * @mbr:	MBR partition record
+ *
+ * Return:	0 on success, otherwise error
+ */
+int part_get_mbr(struct blk_desc *desc, int part, dos_partition_t *mbr);
+
 #endif
 
 #if CONFIG_IS_ENABLED(PARTITIONS)
Signature · 1 line
2.53.0
Reviewed-by on v2 5/7
#13 lore raw

Re: [PATCH v2 5/7] disk: part_dos: Refactor to allow retrieving raw MBR partition data

Quoted 10 lines · Javier Martinez Canillas

Refactor the part_get_info_extended() helper function (which already recursively traverses DOS partitions) to optionally return the raw MBR partition structure (dos_partition_t).

This allows other subsystems, such as EFI, to retrieve the partition details in the legacy MBR format.

---

Quoted 148 lines

(no changes since v1)

 disk/part_dos.c | 66 ++++++++++++++++++++++++++++++-------------------
 include/part.h  | 14 +++++++++++
 2 files changed, 55 insertions(+), 25 deletions(-)
disk/part_dos.c +41 -25
index a69ad8962106..4e1d01b2f21e 100644
@@ -204,7 +204,8 @@ static void print_partition_extended(struct blk_desc *desc,
  * @relative:          Relative offset for the partition
  * @part_num:          Current partition number
  * @which_part:                Target partition number
- * @info:              Returns a pointer to the partition info
+ * @info:              Returns partition information (optional)
+ * @mbr:               Returns MBR partition entry (optional)
  * @disksig:           Disk signature
  *
  * Return:             0 on success, negative on error
@@ -212,7 +213,9 @@ static void print_partition_extended(struct blk_desc *desc,
 static int part_get_info_extended(struct blk_desc *desc,
                                  lbaint_t ext_part_sector, lbaint_t relative,
                                  int part_num, int which_part,
-                                 struct disk_partition *info, uint disksig)
+                                 struct disk_partition *info,
+                                 dos_partition_t *mbr,
+                                 uint disksig)
 {
        ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);
        struct disk_partition wdinfo = { 0 };
@@ -243,9 +246,11 @@ static int part_get_info_extended(struct blk_desc *desc,
        if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector)
                disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 
-       ret = part_get_info_whole_disk(desc, &wdinfo);
-       if (ret)
-               return ret;
+       if (info) {
+               ret = part_get_info_whole_disk(desc, &wdinfo);
+               if (ret)
+                       return ret;
+       }
 
        /* Print all primary/logical partitions */
        pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
@@ -258,25 +263,29 @@ static int part_get_info_extended(struct blk_desc *desc,
                    (pt->sys_ind != 0) &&
                    (part_num == which_part) &&
                    (ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
-                       if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
-                               info->blksz = wdinfo.blksz;
-                       else
-                               info->blksz = DOS_PART_DEFAULT_SECTOR;
-                       info->start = (lbaint_t)(ext_part_sector +
-                                       get_unaligned_le32(&pt->start_sect));
-                       info->size  = (lbaint_t)get_unaligned_le32(&pt->nr_sects);
-                       part_set_generic_name(desc, part_num,
-                                             (char *)info->name);
-                       /* sprintf(info->type, "%d, pt->sys_ind); */
-                       strcpy((char *)info->type, "U-Boot");
-                       info->bootable = get_bootable(pt);
-                       if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
-                               char str[12];
-
-                               sprintf(str, "%08x-%02x", disksig, part_num);
-                               disk_partition_set_uuid(info, str);
+                       if (info) {
+                               if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
+                                       info->blksz = wdinfo.blksz;
+                               else
+                                       info->blksz = DOS_PART_DEFAULT_SECTOR;
+                               info->start = (lbaint_t)(ext_part_sector +
+                                                        get_unaligned_le32(&pt->start_sect));
+                               info->size  = (lbaint_t)get_unaligned_le32(&pt->nr_sects);
+                               part_set_generic_name(desc, part_num,
+                                                     (char *)info->name);
+                               /* sprintf(info->type, "%d, pt->sys_ind); */
+                               strcpy((char *)info->type, "U-Boot");
+                               info->bootable = get_bootable(pt);
+                               if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+                                       char str[12];
+
+                                       sprintf(str, "%08x-%02x", disksig, part_num);
+                                       disk_partition_set_uuid(info, str);
+                               }
+                               info->sys_ind = pt->sys_ind;
                        }
-                       info->sys_ind = pt->sys_ind;
+                       if (mbr)
+                               memcpy(mbr, pt, sizeof(*mbr));
                        return 0;
                }
 
@@ -296,7 +305,8 @@ static int part_get_info_extended(struct blk_desc *desc,
 
                        return part_get_info_extended(desc, lba_start,
                                 ext_part_sector == 0 ? lba_start : relative,
-                                part_num, which_part, info, disksig);
+                                                     part_num, which_part, info,
+                                                     mbr, disksig);
                }
        }
 
@@ -328,7 +338,13 @@ static void __maybe_unused part_print_dos(struct blk_desc *desc)
 static int __maybe_unused part_get_info_dos(struct blk_desc *desc, int part,
                                            struct disk_partition *info)
 {
-       return part_get_info_extended(desc, 0, 0, 1, part, info, 0);
+       return part_get_info_extended(desc, 0, 0, 1, part, info, NULL, 0);
+}
+
+int __maybe_unused part_get_mbr(struct blk_desc *desc, int part,
+                               dos_partition_t *mbr)
+{
+       return part_get_info_extended(desc, 0, 0, 1, part, NULL, mbr, 0);
 }
 
 int is_valid_dos_buf(void *buf)
include/part.h +14 -1
index daebbbc2e68f..aed089d00f64 100644
@@ -704,6 +704,20 @@ int write_mbr_partitions(struct blk_desc *dev,
 int layout_mbr_partitions(struct disk_partition *p, int count,
                          lbaint_t total_sectors);
 
+/**
+ * part_get_mbr() - get the MBR partition record of a partition
+ *
+ * This function reads the MBR partition record for a given block
+ * device and partition number.
+ *
+ * @desc:      block device descriptor
+ * @part:      partition number for which to return the partition record
+ * @mbr:       MBR partition record
+ *
+ * Return:     0 on success, otherwise error
+ */
+int part_get_mbr(struct blk_desc *desc, int part, dos_partition_t *mbr);
+
 #endif
 
 #if CONFIG_IS_ENABLED(PARTITIONS)
--

2.53.0

#14 lore raw

PATCH v2 6/7 efi_loader: disk: Extend EFI_PARTITION_INFO_PROTOCOL to support MBR

In reply to Javier Martinez Canillas

The EFI_PARTITION_INFO_PROTOCOL provides detailed information about partitions. The UEFI specification mentions that both GPT and MBR partition schemes are supported, but the U-Boot implementation only supports the former.

This can cause compatibility issues for platforms whose boot ROM only supports MBR. This change adds support for MBR partition tables to the protocol, making U-Boot compatible with systems that require a legacy MBR table.

---

(no changes since v1)

 lib/efi_loader/efi_disk.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/efi_loader/efi_disk.c +6 -3
index 130c4db9606f..f8a57539ec61 100644
@@ -475,9 +475,12 @@ static efi_status_t efi_disk_add_dev(
 #if CONFIG_IS_ENABLED(DOS_PARTITION)
 		case PART_TYPE_DOS:
 			info->type = PARTITION_TYPE_MBR;
-
-			/* TODO: implement support for MBR partition types */
-			log_debug("EFI_PARTITION_INFO_PROTOCOL doesn't support MBR\n");
+			ret = part_get_mbr(desc, part, &info->info.mbr);
+			if (ret) {
+				log_debug("get MBR for part %d failed %ld\n",
+					  part, ret);
+				goto error;
+			}
 			break;
 #endif
 		default:
Signature · 1 line
2.53.0
Reviewed-by on v2 6/7
#15 lore raw

Re: [PATCH v2 6/7] efi_loader: disk: Extend EFI_PARTITION_INFO_PROTOCOL to support MBR

Quoted 6 lines · Javier Martinez Canillas

The EFI_PARTITION_INFO_PROTOCOL provides detailed information about partitions. The UEFI specification mentions that both GPT and MBR partition schemes are supported, but the U-Boot implementation only supports the former.

Quoted 7 lines

This can cause compatibility issues for platforms whose boot ROM only supports MBR. This change adds support for MBR partition tables to the protocol, making U-Boot compatible with systems that require a legacy MBR table.

---

Quoted 29 lines

(no changes since v1)

 lib/efi_loader/efi_disk.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/efi_loader/efi_disk.c +6 -4
index 130c4db9606f..f8a57539ec61 100644
@@ -475,9 +475,12 @@ static efi_status_t efi_disk_add_dev(
 #if CONFIG_IS_ENABLED(DOS_PARTITION)
                case PART_TYPE_DOS:
                        info->type = PARTITION_TYPE_MBR;
-
-                       /* TODO: implement support for MBR partition types */
-                       log_debug("EFI_PARTITION_INFO_PROTOCOL doesn't support MBR\n");
+                       ret = part_get_mbr(desc, part, &info->info.mbr);
+                       if (ret) {
+                               log_debug("get MBR for part %d failed %ld\n",
+                                         part, ret);
+                               goto error;
+                       }
                        break;
 #endif
                default:
--

2.53.0

#16 lore raw

PATCH v2 7/7 efi_selftest: Enhance MBR test for PARTITION_INFO_PROTOCOL

In reply to Javier Martinez Canillas

The EFI_PARTITION_INFO_PROTOCOL test was added before the protocol fully supported MBR partitions. As a result, it lacked specific checks for the content of the raw MBR partition record.

Now that MBR support has been implemented, enhance the selftest to provide coverage for the MBR entries too.

This verifies that the protocol correctly reads and exposes MBR partition records and prevents this functionality to regress due future changes.

---

(no changes since v1)

 lib/efi_selftest/efi_selftest_block_device.c | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +26 -0
index f145e58a267a..9c4be834eebb 100644
@@ -19,6 +19,7 @@
 #include "efi_selftest_disk_image.h"
 #include <asm/cache.h>
 #include <part_efi.h>
+#include <part.h>
 
 /* Block size of compressed disk image */
 #define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
@@ -319,6 +320,25 @@ static int execute(void)
 	u64 pos;
 	char block_io_aligned[1 << LB_BLOCK_SIZE] __aligned(1 << LB_BLOCK_SIZE);
 
+	/*
+	 * The test disk image is defined in efi_selftest_disk_image.h,
+	 * it contains a single FAT12 partition of 127 sectors size.
+	 */
+	static const dos_partition_t mbr_expected = {
+		.boot_ind = 0x00,
+		.head = 0x00,
+		.sector = 0x02,
+		.cyl = 0x00,
+		.sys_ind = 0x01, /* FAT12 */
+		.end_head = 0x02,
+		.end_sector = 0x02,
+		.end_cyl = 0x00,
+		/* LBA 1 */
+		.start_sect = cpu_to_le32(1),
+		/* Size 127 sectors (0x7f) */
+		.nr_sects = cpu_to_le32(127),
+	};
+
 	/* Connect controller to virtual disk */
 	ret = boottime->connect_controller(disk_handle, NULL, NULL, 1);
 	if (ret != EFI_SUCCESS) {
@@ -405,6 +425,12 @@ static int execute(void)
 		return EFI_ST_FAILURE;
 	}
 
+	/* Compare the obtained MBR with the expected one for the test partition */
+	if (memcmp(&part_info->info.mbr, &mbr_expected, sizeof(mbr_expected))) {
+		efi_st_error("MBR partition record mismatch\n");
+		return EFI_ST_FAILURE;
+	}
+
 	/* Open the simple file system protocol */
 	ret = boottime->open_protocol(handle_partition,
 				      &guid_simple_file_system_protocol,
Signature · 1 line
2.53.0
Acked-by on v2 7/7
#17 lore raw

Re: [PATCH v2 7/7] efi_selftest: Enhance MBR test for PARTITION_INFO_PROTOCOL

Quoted 5 lines · Javier Martinez Canillas

The EFI_PARTITION_INFO_PROTOCOL test was added before the protocol fully supported MBR partitions. As a result, it lacked specific checks for the content of the raw MBR partition record.

Quoted 8 lines

Now that MBR support has been implemented, enhance the selftest to provide coverage for the MBR entries too.

This verifies that the protocol correctly reads and exposes MBR partition records and prevents this functionality to regress due future changes.

---

Quoted 60 lines

(no changes since v1)

 lib/efi_selftest/efi_selftest_block_device.c | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +26 -1
index f145e58a267a..9c4be834eebb 100644
@@ -19,6 +19,7 @@
 #include "efi_selftest_disk_image.h"
 #include <asm/cache.h>
 #include <part_efi.h>
+#include <part.h>
 
 /* Block size of compressed disk image */
 #define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
@@ -319,6 +320,25 @@ static int execute(void)
        u64 pos;
        char block_io_aligned[1 << LB_BLOCK_SIZE] __aligned(1 << LB_BLOCK_SIZE);
 
+       /*
+        * The test disk image is defined in efi_selftest_disk_image.h,
+        * it contains a single FAT12 partition of 127 sectors size.
+        */
+       static const dos_partition_t mbr_expected = {
+               .boot_ind = 0x00,
+               .head = 0x00,
+               .sector = 0x02,
+               .cyl = 0x00,
+               .sys_ind = 0x01, /* FAT12 */
+               .end_head = 0x02,
+               .end_sector = 0x02,
+               .end_cyl = 0x00,
+               /* LBA 1 */
+               .start_sect = cpu_to_le32(1),
+               /* Size 127 sectors (0x7f) */
+               .nr_sects = cpu_to_le32(127),
+       };
+
        /* Connect controller to virtual disk */
        ret = boottime->connect_controller(disk_handle, NULL, NULL, 1);
        if (ret != EFI_SUCCESS) {
@@ -405,6 +425,12 @@ static int execute(void)
                return EFI_ST_FAILURE;
        }
 
+       /* Compare the obtained MBR with the expected one for the test partition */
+       if (memcmp(&part_info->info.mbr, &mbr_expected, sizeof(mbr_expected))) {
+               efi_st_error("MBR partition record mismatch\n");
+               return EFI_ST_FAILURE;
+       }
+
        /* Open the simple file system protocol */
        ret = boottime->open_protocol(handle_partition,
                                      &guid_simple_file_system_protocol,
--

2.53.0

Reviewed-by on v2 7/7
#18 lore raw

Re: [PATCH v2 7/7] efi_selftest: Enhance MBR test for PARTITION_INFO_PROTOCOL

In reply to Javier Martinez Canillas
Quoted 41 lines · Javier Martinez Canillas

The EFI_PARTITION_INFO_PROTOCOL test was added before the protocol fully supported MBR partitions. As a result, it lacked specific checks for the content of the raw MBR partition record.

Now that MBR support has been implemented, enhance the selftest to provide coverage for the MBR entries too.

This verifies that the protocol correctly reads and exposes MBR partition records and prevents this functionality to regress due future changes.

---

(no changes since v1)

  lib/efi_selftest/efi_selftest_block_device.c | 26 ++++++++++++++++++++
  1 file changed, 26 insertions(+)
lib/efi_selftest/efi_selftest_block_device.c +8 -0
index f145e58a267a..9c4be834eebb 100644
@@ -19,6 +19,7 @@
  #include "efi_selftest_disk_image.h"
  #include <asm/cache.h>
  #include <part_efi.h>
+#include <part.h>
 
  /* Block size of compressed disk image */
  #define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
@@ -319,6 +320,25 @@ static int execute(void)
  	u64 pos;
  	char block_io_aligned[1 << LB_BLOCK_SIZE] __aligned(1 << LB_BLOCK_SIZE);
 
+	/*
+	 * The test disk image is defined in efi_selftest_disk_image.h,
+	 * it contains a single FAT12 partition of 127 sectors size.
+	 */
+	static const dos_partition_t mbr_expected = {
+		.boot_ind = 0x00,
+		.head = 0x00,

lib/efi_selftest/efi_selftest_block_device.c static int execute(void) · line 339

Quoted 10 lines
lib/efi_selftest/efi_selftest_block_device.c +10 -0
+		.sector = 0x02,
+		.cyl = 0x00,
+		.sys_ind = 0x01, /* FAT12 */
+		.end_head = 0x02,
+		.end_sector = 0x02,
+		.end_cyl = 0x00,
+		/* LBA 1 */
+		.start_sect = cpu_to_le32(1),
+		/* Size 127 sectors (0x7f) */
+		.nr_sects = cpu_to_le32(127),

UEFI only exists on low endian systems. Field nr_sects is naturally aligned. cpu_to_le32() is superfluous here. But it is a nop anyway.

Quoted 18 lines
lib/efi_selftest/efi_selftest_block_device.c +8 -0
+	};
+
  	/* Connect controller to virtual disk */
  	ret = boottime->connect_controller(disk_handle, NULL, NULL, 1);
  	if (ret != EFI_SUCCESS) {
@@ -405,6 +425,12 @@ static int execute(void)
  		return EFI_ST_FAILURE;
  	}
 
+	/* Compare the obtained MBR with the expected one for the test partition */
+	if (memcmp(&part_info->info.mbr, &mbr_expected, sizeof(mbr_expected))) {
+		efi_st_error("MBR partition record mismatch\n");
+		return EFI_ST_FAILURE;
+	}
+
  	/* Open the simple file system protocol */
  	ret = boottime->open_protocol(handle_partition,
  				      &guid_simple_file_system_protocol,