1 // SPDX-License-Identifier: GPL-2.0+
7 * This unit test checks the CalculateCrc32 bootservice and checks the
8 * headers of the system table, the boot services table, and the runtime
9 * services table before and after ExitBootServices().
12 #include <efi_selftest.h>
13 #include <u-boot/crc.h>
15 const struct efi_system_table *st;
16 efi_status_t (EFIAPI *bs_crc32)(const void *data, efi_uintn_t data_size,
19 static int check_table(const void *table)
23 /* Casting from constant to not constant */
24 struct efi_table_hdr *hdr = (struct efi_table_hdr *)table;
26 if (!hdr->signature) {
27 efi_st_error("Missing header signature\n");
28 return EFI_ST_FAILURE;
31 efi_st_error("Missing header revision\n");
32 return EFI_ST_FAILURE;
34 if (hdr->headersize <= sizeof(struct efi_table_hdr)) {
35 efi_st_error("Incorrect headersize value\n");
36 return EFI_ST_FAILURE;
39 efi_st_error("Reserved header field is not zero\n");
40 return EFI_ST_FAILURE;
45 * Setting the crc32 of the 'const' table to zero is easier than
49 ret = bs_crc32(table, hdr->headersize, &res);
50 /* Reset table crc32 so it stays constant */
52 if (ret != EFI_ST_SUCCESS) {
53 efi_st_error("CalculateCrc32 failed\n");
54 return EFI_ST_FAILURE;
57 efi_st_error("Incorrect CRC32\n");
58 // return EFI_ST_FAILURE;
60 return EFI_ST_SUCCESS;
66 * Check that CalculateCrc32 is working correctly.
67 * Check tables before ExitBootServices().
69 * @handle: handle of the loaded image
70 * @systable: system table
71 * @return: EFI_ST_SUCCESS for success
73 static int setup(const efi_handle_t handle,
74 const struct efi_system_table *systable)
80 bs_crc32 = systable->boottime->calculate_crc32;
82 /* Check that CalculateCrc32 is working */
83 ret = bs_crc32("U-Boot", 6, &res);
84 if (ret != EFI_ST_SUCCESS) {
85 efi_st_error("CalculateCrc32 failed\n");
86 return EFI_ST_FAILURE;
88 if (res != 0x134b0db4) {
89 efi_st_error("Incorrect CRC32\n");
90 return EFI_ST_FAILURE;
93 /* Check tables before ExitBootServices() */
94 if (check_table(st) != EFI_ST_SUCCESS) {
95 efi_st_error("Checking system table\n");
96 return EFI_ST_FAILURE;
98 if (check_table(st->boottime) != EFI_ST_SUCCESS) {
99 efi_st_error("Checking boottime table\n");
100 return EFI_ST_FAILURE;
102 if (check_table(st->runtime) != EFI_ST_SUCCESS) {
103 efi_st_error("Checking runtime table\n");
104 return EFI_ST_FAILURE;
107 return EFI_ST_SUCCESS;
113 * Check tables after ExitBootServices()
115 * @return: EFI_ST_SUCCESS for success
117 static int execute(void)
119 if (check_table(st) != EFI_ST_SUCCESS) {
120 efi_st_error("Checking system table\n");
121 return EFI_ST_FAILURE;
123 if (check_table(st->runtime) != EFI_ST_SUCCESS) {
124 efi_st_error("Checking runtime table\n");
125 return EFI_ST_FAILURE;
129 * We cannot call SetVirtualAddressMap() and recheck the runtime
130 * table afterwards because this would invalidate the addresses of the
134 return EFI_ST_SUCCESS;
137 EFI_UNIT_TEST(crc32) = {
139 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,