summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2026-02-15 13:28:32 -0600
committerTom Rini <[email protected]>2026-02-15 13:28:32 -0600
commited6e970569b45c02a354f443502ed7616e0b0adf (patch)
treedef3e781dc1ef06f641997f3adbf3eaa000ccde7
parent136faf7b0cc92af1d38b0db1bfaa5405e884ee2d (diff)
parente54fbb2f901e897b2a2fb2a718a1ef1607b20ce5 (diff)
Merge tag 'efi-next-2026-02-15' of https://source.denx.de/u-boot/custodians/u-boot-efi into next
Pull request efi-next-2026-02-15 CI: https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/1380382 UEFI: * Add MBR support to EFI_PARTITION_INFO_PROTOCOL * 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 * Prepare for supporting more stores (e.g. SPI-flash) for EFI variables. * efi_var: Unify read/write access helper function * efi_loader: Setup default location for UEFI Variables storing * efi_var_file: refactor to move buffer functions
-rw-r--r--disk/part_dos.c89
-rw-r--r--disk/part_efi.c4
-rw-r--r--include/efi_variable.h18
-rw-r--r--include/part.h14
-rw-r--r--include/part_dos.h (renamed from disk/part_dos.h)6
-rw-r--r--include/part_efi.h19
-rw-r--r--lib/efi_loader/Kconfig3
-rw-r--r--lib/efi_loader/Makefile2
-rw-r--r--lib/efi_loader/efi_disk.c9
-rw-r--r--lib/efi_loader/efi_var_common.c42
-rw-r--r--lib/efi_loader/efi_var_file.c65
-rw-r--r--lib/efi_loader/efi_variable.c19
-rw-r--r--lib/efi_selftest/efi_selftest_block_device.c26
13 files changed, 183 insertions, 133 deletions
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 18dd35c9b98..4e1d01b2f21 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -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
@@ -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 :
@@ -196,12 +196,26 @@ 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 partition information (optional)
+ * @mbr: Returns MBR partition entry (optional)
+ * @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,
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 };
@@ -232,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);
@@ -247,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->start4));
- info->size = (lbaint_t)get_unaligned_le32(pt->size4);
- 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];
+ 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);
+ 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;
}
@@ -281,11 +301,12 @@ 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,
- part_num, which_part, info, disksig);
+ part_num, which_part, info,
+ mbr, disksig);
}
}
@@ -317,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)
@@ -356,8 +383,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,
diff --git a/disk/part_efi.c b/disk/part_efi.c
index fb1ed534f86..d8b17ec2e91 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -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) {
diff --git a/include/efi_variable.h b/include/efi_variable.h
index 4065cf45eca..fc1184e5ca1 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -137,13 +137,11 @@ struct efi_var_file {
};
/**
- * efi_var_to_file() - save non-volatile variables as file
- *
- * File ubootefi.var is created on the EFI system partion.
+ * efi_var_to_storage() - save non-volatile variables
*
* Return: status code
*/
-efi_status_t efi_var_to_file(void);
+efi_status_t efi_var_to_storage(void);
/**
* efi_var_collect() - collect variables in buffer
@@ -161,6 +159,11 @@ efi_status_t efi_var_to_file(void);
efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *lenp,
u32 check_attr_mask);
+/* GUID used by Shim to store the MOK database */
+#define SHIM_LOCK_GUID \
+ EFI_GUID(0x605dab50, 0xe046, 0x4300, \
+ 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
+
/**
* efi_var_restore() - restore EFI variables from buffer
*
@@ -173,17 +176,14 @@ efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *
efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe);
/**
- * efi_var_from_file() - read variables from file
- *
- * File ubootefi.var is read from the EFI system partitions and the variables
- * stored in the file are created.
+ * efi_var_from_storage() - read variables
*
* In case the file does not exist yet or a variable cannot be set EFI_SUCCESS
* is returned.
*
* Return: status code
*/
-efi_status_t efi_var_from_file(void);
+efi_status_t efi_var_from_storage(void);
/**
* efi_var_mem_init() - set-up variable list
diff --git a/include/part.h b/include/part.h
index daebbbc2e68..aed089d00f6 100644
--- a/include/part.h
+++ b/include/part.h
@@ -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)
diff --git a/disk/part_dos.h b/include/part_dos.h
index 50558224228..92956d53063 100644
--- a/disk/part_dos.h
+++ b/include/part_dos.h
@@ -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 */
diff --git a/include/part_efi.h b/include/part_efi.h
index fb402df6f13..2cea5088046 100644
--- a/include/part_efi.h
+++ b/include/part_efi.h
@@ -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;
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 13e44be1d06..579eed65880 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -112,7 +112,8 @@ menu "UEFI Variables"
choice
prompt "Store for non-volatile UEFI variables"
- default EFI_VARIABLE_FILE_STORE
+ default EFI_VARIABLE_FILE_STORE if FAT_WRITE
+ default EFI_VARIABLE_NO_STORE
help
Select where non-volatile UEFI variables shall be stored.
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index f490081f654..ca1775eb03b 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -53,7 +53,7 @@ ifeq ($(CONFIG_EFI_MM_COMM_TEE),y)
obj-y += efi_variable_tee.o
else
obj-y += efi_variable.o
-obj-y += efi_var_file.o
+obj-$(CONFIG_EFI_VARIABLE_FILE_STORE) += efi_var_file.o
obj-$(CONFIG_EFI_VARIABLES_PRESEED) += efi_var_seed.o
endif
obj-y += efi_watchdog.o
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 130c4db9606..f8a57539ec6 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -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:
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
index 4b34a58b4cf..5ea1688dca3 100644
--- a/lib/efi_loader/efi_var_common.c
+++ b/lib/efi_loader/efi_var_common.c
@@ -41,6 +41,7 @@ static const struct efi_auth_var_name_type name_type[] = {
static bool efi_secure_boot;
static enum efi_secure_mode efi_secure_mode;
+static const efi_guid_t shim_lock_guid = SHIM_LOCK_GUID;
/**
* efi_efi_get_variable() - retrieve value of a UEFI variable
@@ -488,3 +489,44 @@ efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *
return EFI_SUCCESS;
}
+
+efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
+{
+ struct efi_var_entry *var, *last_var;
+ u16 *data;
+ efi_status_t ret;
+
+ if (buf->reserved || buf->magic != EFI_VAR_FILE_MAGIC ||
+ buf->crc32 != crc32(0, (u8 *)buf->var,
+ buf->length - sizeof(struct efi_var_file))) {
+ log_err("Invalid EFI variables file\n");
+ return EFI_INVALID_PARAMETER;
+ }
+
+ last_var = (struct efi_var_entry *)((u8 *)buf + buf->length);
+ for (var = buf->var; var < last_var;
+ var = (struct efi_var_entry *)ALIGN((uintptr_t)data + var->length, 8)) {
+ data = var->name + u16_strlen(var->name) + 1;
+
+ /*
+ * Secure boot related and volatile variables shall only be
+ * restored from U-Boot's preseed.
+ */
+ if (!safe &&
+ (efi_auth_var_get_type(var->name, &var->guid) !=
+ EFI_AUTH_VAR_NONE ||
+ !guidcmp(&var->guid, &shim_lock_guid) ||
+ !(var->attr & EFI_VARIABLE_NON_VOLATILE)))
+ continue;
+ if (!var->length)
+ continue;
+ if (efi_var_mem_find(&var->guid, var->name, NULL))
+ continue;
+ ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
+ var->length, data, 0, NULL,
+ var->time);
+ if (ret != EFI_SUCCESS)
+ log_err("Failed to set EFI variable %ls\n", var->name);
+ }
+ return EFI_SUCCESS;
+}
diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c
index f23a964a418..9cda38f319e 100644
--- a/lib/efi_loader/efi_var_file.c
+++ b/lib/efi_loader/efi_var_file.c
@@ -14,17 +14,9 @@
#include <mapmem.h>
#include <efi_loader.h>
#include <efi_variable.h>
-#include <u-boot/crc.h>
#define PART_STR_LEN 10
-/* GUID used by Shim to store the MOK database */
-#define SHIM_LOCK_GUID \
- EFI_GUID(0x605dab50, 0xe046, 0x4300, \
- 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
-
-static const efi_guid_t shim_lock_guid = SHIM_LOCK_GUID;
-
/**
* efi_set_blk_dev_to_system_partition() - select EFI system partition
*
@@ -51,15 +43,14 @@ static efi_status_t __maybe_unused efi_set_blk_dev_to_system_partition(void)
}
/**
- * efi_var_to_file() - save non-volatile variables as file
+ * efi_var_to_storage() - save non-volatile variables as file
*
* File ubootefi.var is created on the EFI system partion.
*
* Return: status code
*/
-efi_status_t efi_var_to_file(void)
+efi_status_t efi_var_to_storage(void)
{
-#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
efi_status_t ret;
struct efi_var_file *buf;
loff_t len;
@@ -91,56 +82,10 @@ error:
out:
free(buf);
return ret;
-#else
- return EFI_SUCCESS;
-#endif
-}
-
-efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
-{
- struct efi_var_entry *var, *last_var;
- u16 *data;
- efi_status_t ret;
-
- if (buf->reserved || buf->magic != EFI_VAR_FILE_MAGIC ||
- buf->crc32 != crc32(0, (u8 *)buf->var,
- buf->length - sizeof(struct efi_var_file))) {
- log_err("Invalid EFI variables file\n");
- return EFI_INVALID_PARAMETER;
- }
-
- last_var = (struct efi_var_entry *)((u8 *)buf + buf->length);
- for (var = buf->var; var < last_var;
- var = (struct efi_var_entry *)
- ALIGN((uintptr_t)data + var->length, 8)) {
-
- data = var->name + u16_strlen(var->name) + 1;
-
- /*
- * Secure boot related and volatile variables shall only be
- * restored from U-Boot's preseed.
- */
- if (!safe &&
- (efi_auth_var_get_type(var->name, &var->guid) !=
- EFI_AUTH_VAR_NONE ||
- !guidcmp(&var->guid, &shim_lock_guid) ||
- !(var->attr & EFI_VARIABLE_NON_VOLATILE)))
- continue;
- if (!var->length)
- continue;
- if (efi_var_mem_find(&var->guid, var->name, NULL))
- continue;
- ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
- var->length, data, 0, NULL,
- var->time);
- if (ret != EFI_SUCCESS)
- log_err("Failed to set EFI variable %ls\n", var->name);
- }
- return EFI_SUCCESS;
}
/**
- * efi_var_from_file() - read variables from file
+ * efi_var_from_storage() - read variables from file
*
* File ubootefi.var is read from the EFI system partitions and the variables
* stored in the file are created.
@@ -153,9 +98,8 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
*
* Return: status code
*/
-efi_status_t efi_var_from_file(void)
+efi_status_t efi_var_from_storage(void)
{
-#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
struct efi_var_file *buf;
loff_t len;
efi_status_t ret;
@@ -180,6 +124,5 @@ efi_status_t efi_var_from_file(void)
log_err("Invalid EFI variables file\n");
error:
free(buf);
-#endif
return EFI_SUCCESS;
}
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index f3533f4def3..8512bc20f11 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -397,11 +397,15 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
ret = EFI_SUCCESS;
/*
- * Write non-volatile EFI variables to file
+ * Write non-volatile EFI variables
* TODO: check if a value change has occured to avoid superfluous writes
*/
- if (attributes & EFI_VARIABLE_NON_VOLATILE)
- efi_var_to_file();
+ if (attributes & EFI_VARIABLE_NON_VOLATILE) {
+ if (IS_ENABLED(CONFIG_EFI_VARIABLE_NO_STORE))
+ return EFI_SUCCESS;
+
+ efi_var_to_storage();
+ }
return EFI_SUCCESS;
}
@@ -594,9 +598,12 @@ efi_status_t efi_init_variables(void)
if (ret != EFI_SUCCESS)
return ret;
- ret = efi_var_from_file();
- if (ret != EFI_SUCCESS)
- return ret;
+ if (!IS_ENABLED(CONFIG_EFI_VARIABLE_NO_STORE)) {
+ ret = efi_var_from_storage();
+ if (ret != EFI_SUCCESS)
+ return ret;
+ }
+
if (IS_ENABLED(CONFIG_EFI_VARIABLES_PRESEED)) {
ret = efi_var_restore((struct efi_var_file *)
__efi_var_file_begin, true);
diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c
index f145e58a267..9c4be834eeb 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),
+ };
+
/* 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,