[PATCH 2/6] efi/arm: a helper to parse secure boot param in fdt params

From: Chester Lin
Date: Fri Sep 04 2020 - 03:30:06 EST


Add a helper to query the UEFI secureboot param from the chosen node in
FDT.

Signed-off-by: Chester Lin <clin@xxxxxxxx>
---
drivers/firmware/efi/fdtparams.c | 23 +++++++++++++++++++++++
include/linux/efi.h | 1 +
2 files changed, 24 insertions(+)

diff --git a/drivers/firmware/efi/fdtparams.c b/drivers/firmware/efi/fdtparams.c
index bb042ab7c2be..d58ec4119bcf 100644
--- a/drivers/firmware/efi/fdtparams.c
+++ b/drivers/firmware/efi/fdtparams.c
@@ -124,3 +124,26 @@ u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm)
pr_info("UEFI not found.\n");
return 0;
}
+
+bool __init efi_secureboot_enabled_in_fdt(void)
+{
+ const void *fdt = initial_boot_params;
+ int node;
+ u32 secboot;
+
+
+ node = fdt_path_offset(fdt, "/chosen");
+
+ if (node < 0) {
+ pr_err("chosen node not found.\n");
+ return false;
+ }
+
+ if (!efi_get_fdt_prop(fdt, node, "linux,uefi-secure-boot",
+ "SECURE BOOT", &secboot, sizeof(secboot))) {
+ if (secboot)
+ return true;
+ }
+
+ return false;
+}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 73db1ae04cef..315126b2f5e9 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -663,6 +663,7 @@ extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
extern void efi_initialize_iomem_resources(struct resource *code_resource,
struct resource *data_resource, struct resource *bss_resource);
extern u64 efi_get_fdt_params(struct efi_memory_map_data *data);
+extern bool __init efi_secureboot_enabled_in_fdt(void);
extern struct kobject *efi_kobj;

extern int efi_reboot_quirk_mode;
--
2.26.1