1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * efi_selftest_fdt
4  *
5  * Copyright (c) 2022 Heinrich Schuchardt <xypron.glpk@gmx.de>
6  *
7  * Check the EFI_CONFORMANCE_PROFILE_TABLE
8  */
9 
10 #include <efi_selftest.h>
11 
12 static const efi_guid_t guid_ecpt = EFI_CONFORMANCE_PROFILES_TABLE_GUID;
13 static const efi_guid_t guid_ebbr_2_1 = EFI_CONFORMANCE_PROFILE_EBBR_2_1_GUID;
14 
15 /*
16  * ecpt_find_guid() - find GUID in EFI Conformance Profile Table
17  *
18  * @ecpt:	EFI Conformance Profile Table
19  * @guid:	GUID to find
20  * Return:	EFI_ST_SUCCESS for success
21  */
ecpt_find_guid(struct efi_conformance_profiles_table * ecpt,const efi_guid_t * guid)22 static int ecpt_find_guid(struct efi_conformance_profiles_table *ecpt,
23 			  const efi_guid_t *guid) {
24 	int i;
25 
26 	for (i = 0; i < ecpt->number_of_profiles; ++i) {
27 		if (!memcmp(&ecpt->conformance_profiles[i], guid, 16))
28 			return EFI_ST_SUCCESS;
29 	}
30 	efi_st_error("GUID %pU not found\n", guid);
31 	return EFI_ST_FAILURE;
32 }
33 
34 /*
35  * Execute unit test.
36  *
37  * Return:	EFI_ST_SUCCESS for success
38  */
execute(void)39 static int execute(void)
40 {
41 	struct efi_conformance_profiles_table *ecpt;
42 	int expected_entries = 0;
43 
44 	ecpt = efi_st_get_config_table(&guid_ecpt);
45 
46 	if (!ecpt) {
47 		efi_st_error("Missing EFI Conformance Profile Table\n");
48 		return EFI_ST_FAILURE;
49 	}
50 
51 	if (ecpt->version != EFI_CONFORMANCE_PROFILES_TABLE_VERSION) {
52 		efi_st_error("Wrong table version\n");
53 		return EFI_ST_FAILURE;
54 	}
55 
56 	if (CONFIG_IS_ENABLED(EFI_EBBR_2_1_CONFORMANCE)) {
57 		++expected_entries;
58 		if (ecpt_find_guid(ecpt, &guid_ebbr_2_1))
59 			return EFI_ST_FAILURE;
60 	}
61 
62 	if (ecpt->number_of_profiles != expected_entries) {
63 		efi_st_error("Expected %d entries, found %d\n",
64 			     expected_entries, ecpt->number_of_profiles);
65 		return EFI_ST_FAILURE;
66 	}
67 
68 	return EFI_ST_SUCCESS;
69 }
70 
71 EFI_UNIT_TEST(ecpt) = {
72 	.name = "conformance profile table",
73 	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
74 	.execute = execute,
75 };
76