]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_selftest: Enhance MBR test for PARTITION_INFO_PROTOCOL
authorJavier Martinez Canillas <javierm@redhat.com>
Thu, 12 Feb 2026 20:45:01 +0000 (21:45 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 15 Feb 2026 07:59:24 +0000 (08:59 +0100)
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@redhat.com>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_selftest/efi_selftest_block_device.c

index f145e58a267a747851beaf0c41a77151a384ef73..9c4be834eebb220cb465aa17a6e7c0c49248ffa0 100644 (file)
@@ -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,