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

Heinrich Schuchardt xypron.glpk at gmx.de
Sun Feb 15 08:58:47 CET 2026


On 2/12/26 21:45, Javier Martinez Canillas wrote:
> 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.
> 
> Signed-off-by: Javier Martinez Canillas <javierm at redhat.com>
> ---
> 
> (no changes since v1)
> 
>   lib/efi_selftest/efi_selftest_block_device.c | 26 ++++++++++++++++++++
>   1 file changed, 26 insertions(+)
> 
> diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c
> index f145e58a267a..9c4be834eebb 100644
> --- a/lib/efi_selftest/efi_selftest_block_device.c
> +++ b/lib/efi_selftest/efi_selftest_block_device.c
> @@ -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),

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.

Reviewed-by: Heinrich Schuchardt <xypron.glpk at gmx.de>

> +	};
> +
>   	/* 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,



More information about the U-Boot mailing list