Skip to content

Commit

Permalink
[app][uefi] Add configuration table
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxp1998 committed Nov 5, 2024
1 parent 7df58fa commit 8fb4dbb
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 10 deletions.
31 changes: 31 additions & 0 deletions lib/uefi/configuration_table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "configuration_table.h"
#include "boot_service_provider.h"
#include "system_table.h"
#include <string.h>

void setup_configuration_table(EfiSystemTable *table) {
auto &rng = table->configuration_table[0];
rng.vendor_guid = LINUX_EFI_RANDOM_SEED_TABLE_GUID;
rng.vendor_table = alloc_page(PAGE_SIZE);
auto rng_seed = reinterpret_cast<linux_efi_random_seed *>(rng.vendor_table);
rng_seed->size = 512;
memset(&rng_seed->bits, 0, rng_seed->size);
table->number_of_table_entries = 1;
}
37 changes: 37 additions & 0 deletions lib/uefi/configuration_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef __CONFIGURATION_TABLE_
#define __CONFIGURATION_TABLE_

#include "system_table.h"
#include "types.h"

struct linux_efi_random_seed {
uint32_t size;
uint8_t bits[];
};

static constexpr auto LINUX_EFI_RANDOM_SEED_TABLE_GUID =
EfiGuid{0x1ce1e5bc,
0x7ceb,
0x42f2,
{0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b}};

void setup_configuration_table(EfiSystemTable *table);

#endif
17 changes: 17 additions & 0 deletions lib/uefi/defer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef __DEFER_HEADER_
#define __DEFER_HEADER_

Expand Down
12 changes: 6 additions & 6 deletions lib/uefi/include/system_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#include "protocols/simple_text_output_protocol.h"
#include "runtime_service.h"

typedef struct {
struct EfiConfigurationTable {
EfiGuid vendor_guid;
const void* vendor_table;
} EfiConfigurationTable;
void *vendor_table;
};

typedef struct EfiSystemTable {
struct EfiSystemTable {
EfiTableHeader header;
char16_t* firmware_vendor;
uint32_t firmware_revision;
Expand All @@ -43,7 +43,7 @@ typedef struct EfiSystemTable {
EfiRuntimeService *runtime_service;
EfiBootService* boot_services;
size_t number_of_table_entries;
const EfiConfigurationTable* configuration_table;
} EfiSystemTable;
EfiConfigurationTable *configuration_table;
};

#endif // __SYSTEM_TABLE_H__
1 change: 1 addition & 0 deletions lib/uefi/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ MODULE_SRCS += \
$(LOCAL_DIR)/boot_service_provider.cpp \
$(LOCAL_DIR)/runtime_service_provider.cpp \
$(LOCAL_DIR)/switch_stack.S \
$(LOCAL_DIR)/configuration_table.cpp \

include make/module.mk
31 changes: 27 additions & 4 deletions lib/uefi/uefi.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "arch/mmu.h"
#include "boot_service.h"
#include "boot_service_provider.h"
Expand All @@ -11,11 +28,13 @@
#include <lk/debug.h>
#include <lk/err.h>
#include <lk/trace.h>
#include <math.h>
#include <platform.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#include "configuration_table.h"
#include "protocols/simple_text_output_protocol.h"
#include "runtime_service.h"
#include "runtime_service_provider.h"
Expand Down Expand Up @@ -53,7 +72,7 @@ static constexpr size_t BIT10 = 1 << 10;
@return Immediate address encoded in the instruction
**/
uint16_t ThumbMovtImmediateAddress(uint16_t *Instruction) {
uint16_t ThumbMovtImmediateAddress(const uint16_t *Instruction) {
uint32_t Movt;
uint16_t Address;

Expand Down Expand Up @@ -262,7 +281,7 @@ int load_sections_and_execute(bdev_t *dev,
image_base + optional_header->AddressOfEntryPoint);
printf("Entry function located at %p\n", entry);

EfiSystemTable table{};
EfiSystemTable &table = *static_cast<EfiSystemTable *>(alloc_page(PAGE_SIZE));
EfiBootService boot_service{};
EfiRuntimeService runtime_service{};
fill(&runtime_service, 0);
Expand All @@ -274,8 +293,12 @@ int load_sections_and_execute(bdev_t *dev,
table.header.signature = EFI_SYSTEM_TABLE_SIGNATURE;
EfiSimpleTextOutputProtocol console_out = get_text_output_protocol();
table.con_out = &console_out;
constexpr size_t kStackSize = 1024ul * 1024;
auto stack = reinterpret_cast<char *>(alloc_page(kStackSize, PAGE_SIZE));
table.configuration_table =
reinterpret_cast<EfiConfigurationTable *>(alloc_page(PAGE_SIZE));
setup_configuration_table(&table);

constexpr size_t kStackSize = 8 * 1024ul * 1024;
auto stack = reinterpret_cast<char *>(alloc_page(kStackSize, 23));
memset(stack, 0, kStackSize);
return call_with_stack(stack + kStackSize, entry, image_base, &table);
}
Expand Down

0 comments on commit 8fb4dbb

Please sign in to comment.