From: "Vincent Stehlé" <vincent.stehle@arm.com>
To: u-boot@lists.u-boot-project.org
Cc: "Heinrich Schuchardt" <xypron.glpk@gmx.de>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Tom Rini" <trini@konsulko.com>,
"Sughosh Ganu" <sughosh.ganu@arm.com>,
"Udit Kumar" <u-kumar1@ti.com>,
"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
"Vincent Stehlé" <vincent.stehle@arm.com>
Subject: [PATCH 2/2] efi_selftest: add minimal fmp test
Date: Tue, 22 Sep 2026 16:58:41 +0200 [thread overview]
Message-ID: <20260922-authi-v1-2-e943530349bb@arm.com> (raw)
In-Reply-To: <20260922-authi-v1-0-e943530349bb@arm.com>
Add a minimal test for the UEFI Firmware Management Protocol.
At this point the test only does the following:
- Get current firmware images info.
- For each image, verify consistency of the authentication flags.
This can be tested on the sandbox with the following command:
./u-boot -T -c "setenv efi_selftest firmware management protocol; \
bootefi selftest"
Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
lib/efi_selftest/Makefile | 2 +
lib/efi_selftest/efi_selftest_fmp.c | 135 ++++++++++++++++++++++++++++++++++++
2 files changed, 137 insertions(+)
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
index 67102648703..9882d9f2748 100644
--- a/lib/efi_selftest/Makefile
+++ b/lib/efi_selftest/Makefile
@@ -80,6 +80,8 @@ obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o
obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_selftest_debug_support.o
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_selftest_fmp.o
+
targets += \
efi_miniapp_file_image_exception.h \
efi_miniapp_file_image_exit.h \
diff --git a/lib/efi_selftest/efi_selftest_fmp.c b/lib/efi_selftest/efi_selftest_fmp.c
new file mode 100644
index 00000000000..c17cf59a237
--- /dev/null
+++ b/lib/efi_selftest/efi_selftest_fmp.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Test Firmware Management Protocol support.
+ *
+ * Copyright (C) 2026 Arm Ltd.
+ */
+#include <efi_selftest.h>
+
+static const efi_guid_t firmware_management_protocol_guid =
+ EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID;
+
+static struct efi_boot_services *boottime;
+static struct efi_firmware_management_protocol *fmp;
+
+/**
+ * setup() - Setup unit test.
+ * @handle: handle of the loaded image
+ * @systable: system table
+ *
+ * Keep Boot Services and locate firmware management protocol.
+ *
+ * Return: EFI_ST_SUCCESS for success, EFI_ST_FAILURE in case of error.
+ */
+static int setup(const efi_handle_t handle,
+ const struct efi_system_table *systable)
+{
+ efi_status_t ret;
+
+ boottime = systable->boottime;
+
+ ret = boottime->locate_protocol(&firmware_management_protocol_guid,
+ NULL, (void **)&fmp);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("Firmware management protocol not available.\n");
+ return EFI_ST_FAILURE;
+ }
+
+ return EFI_ST_SUCCESS;
+}
+
+/**
+ * execute() - Perform the test.
+ *
+ * Call GetImageInfo() to retrieve current firmware images descriptors.
+ * For each descriptor, verify image authentication consistency.
+ *
+ * Return: EFI_ST_SUCCESS for success, EFI_ST_FAILURE in case of error.
+ */
+static int execute(void)
+{
+ efi_status_t ret;
+ efi_uintn_t img_info_size, desc_size;
+ struct efi_firmware_image_descriptor *img_info = NULL;
+ u32 desc_ver, pkg_ver;
+ u8 desc_cnt;
+ u16 *pkg_ver_name;
+ int i, result = EFI_ST_FAILURE;
+
+ /* Determine buffer size */
+ img_info_size = 0;
+ ret = fmp->get_image_info(fmp, &img_info_size, NULL, NULL, NULL, NULL,
+ NULL, NULL);
+ if (ret != EFI_BUFFER_TOO_SMALL) {
+ efi_st_error("GetImageInfo returned %u\n", (unsigned int)ret);
+ goto out;
+ }
+
+ /* Allocate enough memory for image info */
+ ret = boottime->allocate_pool(EFI_LOADER_DATA, img_info_size,
+ (void **)&img_info);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("AllocatePool returned %u\n", (unsigned int)ret);
+ goto out;
+ }
+
+ ret = fmp->get_image_info(fmp, &img_info_size, img_info, &desc_ver,
+ &desc_cnt, &desc_size, &pkg_ver,
+ &pkg_ver_name);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("GetImageInfo returned %u\n", (unsigned int)ret);
+ goto out;
+ }
+
+ if (desc_ver != EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) {
+ efi_st_error("Bad DescriptorVersion %u\n", desc_ver);
+ goto out;
+ }
+
+ /* Verify each image info */
+ for (i = 0; i < desc_cnt; i++) {
+ const struct efi_firmware_image_descriptor *inf = &img_info[i];
+ u64 attr_supp = inf->attributes_supported,
+ attr_set = inf->attributes_setting;
+
+ efi_st_printf(" image %u: %ps\n", inf->image_index, inf->image_id_name);
+
+ /* Verify authentication */
+ if (CONFIG_IS_ENABLED(EFI_CAPSULE_AUTHENTICATE) &&
+ (attr_supp & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+ !(attr_supp & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {
+ efi_st_error("Bad AttributesSupported %u\n",
+ (unsigned int)attr_supp);
+ goto out;
+ }
+
+ if (CONFIG_IS_ENABLED(EFI_CAPSULE_AUTHENTICATE) &&
+ (attr_set & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+ !(attr_set & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {
+ efi_st_error("Bad AttributesSetting %u\n",
+ (unsigned int)attr_set);
+ goto out;
+ }
+ }
+
+ result = EFI_ST_SUCCESS;
+
+out:
+ if (img_info) {
+ ret = boottime->free_pool(img_info);
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("FreePool returned %u\n",
+ (unsigned int)ret);
+ result = EFI_ST_FAILURE;
+ }
+ }
+
+ return result;
+}
+
+EFI_UNIT_TEST(fmp) = {
+ .name = "firmware management protocol",
+ .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
+ .setup = setup,
+ .execute = execute,
+};
--
2.53.0
next prev parent reply other threads:[~2026-09-22 14:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 14:58 [PATCH 0/2] efi: fix and test FMP image info authentication attribute Vincent Stehlé
2026-09-22 14:58 ` [PATCH 1/2] efi_loader: fix " Vincent Stehlé
2026-10-01 1:31 ` Simon Glass
2026-10-01 12:37 ` Ilias Apalodimas
2026-09-22 14:58 ` Vincent Stehlé [this message]
2026-10-01 1:31 ` [PATCH 2/2] efi_selftest: add minimal fmp test Simon Glass
2026-10-01 15:46 ` Vincent Stehlé
2026-10-01 13:55 ` Heinrich Schuchardt
2026-10-02 9:26 ` Vincent Stehlé
2026-10-02 14:39 ` Heinrich Schuchardt
2026-10-02 8:37 ` [PATCH v2 0/2] efi: fix and test FMP image info authentication attribute Vincent Stehlé
2026-10-02 8:37 ` [PATCH v2 1/2] efi_loader: fix " Vincent Stehlé
2026-10-03 5:39 ` Simon Glass
2026-10-08 10:33 ` Ilias Apalodimas
2026-10-02 8:37 ` [PATCH v2 2/2] efi_selftest: add minimal fmp test Vincent Stehlé
2026-10-03 5:40 ` Simon Glass
2026-10-03 15:23 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260922-authi-v1-2-e943530349bb@arm.com \
--to=vincent.stehle@arm.com \
--cc=ilias.apalodimas@linaro.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=sughosh.ganu@arm.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=u-kumar1@ti.com \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox