1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include "configuration_table.h"
19 
20 #include <libfdt.h>
21 #include <string.h>
22 #include <uefi/system_table.h>
23 
24 #include "debug_support.h"
25 #include "platform.h"
26 #include "uefi_platform.h"
27 
setup_configuration_table(EfiSystemTable * table)28 void setup_configuration_table(EfiSystemTable *table) {
29   auto &rng = table->configuration_table[table->number_of_table_entries++];
30   rng.vendor_guid = LINUX_EFI_RANDOM_SEED_TABLE_GUID;
31   rng.vendor_table = alloc_page(PAGE_SIZE);
32   auto rng_seed = reinterpret_cast<linux_efi_random_seed *>(rng.vendor_table);
33   rng_seed->size = 512;
34   memset(&rng_seed->bits, 0, rng_seed->size);
35 
36   const void *fdt = get_fdt();
37   if (fdt != nullptr) {
38     auto &dtb = table->configuration_table[table->number_of_table_entries++];
39     dtb.vendor_guid = DEVICE_TREE_GUID;
40     const auto fdt_size = fdt_totalsize(fdt);
41     dtb.vendor_table = alloc_page(fdt_size);
42     memcpy(dtb.vendor_table, fdt, fdt_size);
43   }
44 
45   auto &debug_image_info_table =
46       table->configuration_table[table->number_of_table_entries++];
47   debug_image_info_table.vendor_guid = EFI_DEBUG_IMAGE_INFO_TABLE_GUID;
48   debug_image_info_table.vendor_table = &efi_m_debug_info_table_header;
49 }
50