1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2020 Linaro Limited
4  */
5 
6 #include <common.h>
7 #include <efi_api.h>
8 #include <efi_loader.h>
9 #include <env.h>
10 #include <fdtdec.h>
11 #include <asm/global_data.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
efi_get_public_key_data(void ** pkey,efi_uintn_t * pkey_len)15 int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
16 {
17 	const void *fdt_blob = gd->fdt_blob;
18 	const void *blob;
19 	const char *cnode_name = "capsule-key";
20 	const char *snode_name = "signature";
21 	int sig_node;
22 	int len;
23 
24 	sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name);
25 	if (sig_node < 0) {
26 		EFI_PRINT("Unable to get signature node offset\n");
27 		return -FDT_ERR_NOTFOUND;
28 	}
29 
30 	blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len);
31 
32 	if (!blob || len < 0) {
33 		EFI_PRINT("Unable to get capsule-key value\n");
34 		*pkey = NULL;
35 		*pkey_len = 0;
36 		return -FDT_ERR_NOTFOUND;
37 	}
38 
39 	*pkey = (void *)blob;
40 	*pkey_len = len;
41 
42 	return 0;
43 }
44 
efi_capsule_auth_enabled(void)45 bool efi_capsule_auth_enabled(void)
46 {
47 	return env_get("capsule_authentication_enabled") != NULL ?
48 		true : false;
49 }
50