From fb99d8d36fd717c1df389d8c5683b14a42a1371b Mon Sep 17 00:00:00 2001 From: Jozef Nagy Date: Wed, 21 May 2025 02:32:30 +0200 Subject: [PATCH] Basic driver loading --- boot/common/init.c | 5 +++++ boot/include/driver.h | 39 +++++++++++++++++++++++++++++++++++++ boot/platform/uefi/driver.c | 37 ++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 boot/include/driver.h diff --git a/boot/common/init.c b/boot/common/init.c index ac35140..00f337f 100644 --- a/boot/common/init.c +++ b/boot/common/init.c @@ -36,6 +36,11 @@ void axboot_init() while (1); } +#ifdef AXBOOT_UEFI +#include + load_drivers(); +#endif + //config_init(); // boot straight away diff --git a/boot/include/driver.h b/boot/include/driver.h new file mode 100644 index 0000000..6c0a69a --- /dev/null +++ b/boot/include/driver.h @@ -0,0 +1,39 @@ +/*********************************************************************************/ +/* Module Name: driver.h */ +/* Project: AurixOS */ +/* */ +/* Copyright (c) 2024-2025 Jozef Nagy */ +/* */ +/* This source is subject to the MIT License. */ +/* See License.txt in the root of this repository. */ +/* All other rights reserved. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ +/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ +/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */ +/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */ +/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */ +/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ +/* SOFTWARE. */ +/*********************************************************************************/ + +#ifndef _DRIVER_H +#define _DRIVER_H + +#ifdef AXBOOT_UEFI + +#include +#include + +struct driver { + EFI_HANDLE handle; + char *binary; + size_t binsize; + EFI_MEMMAP_DEVICE_PATH devpath[2]; +}; + +#endif + +void load_drivers(); + +#endif /* _DRIVER_H */ \ No newline at end of file diff --git a/boot/platform/uefi/driver.c b/boot/platform/uefi/driver.c index 8c47927..6a9f7f5 100644 --- a/boot/platform/uefi/driver.c +++ b/boot/platform/uefi/driver.c @@ -17,8 +17,11 @@ /* SOFTWARE. */ /*********************************************************************************/ -// #include +#include #include +#include +#include +#include #include #include @@ -46,8 +49,40 @@ bool verify_secure_boot() void load_drivers() { + EFI_STATUS status; if (!verify_secure_boot()) { debug("load_drivers(): Secure boot is enabled! Won't load drivers...\n"); return; } + + // TODO: Create a vfs_list() function to get a list of files in a directory + // char *driver_path = "\\AxBoot\\drivers\\.efi"; + // char *driver_binary; + // debug("load_drivers(): Loading '%s'...\n", driver_name); + // + // size_t driver_size = vfs_read(audio_path, &driver_binary); + // + // audio.devpath[0].Header.Length[0] = sizeof(EFI_MEMMAP_DEVICE_PATH); + // audio.devpath[0].Header.Length[1] = sizeof(EFI_MEMMAP_DEVICE_PATH) >> 8; + // audio.devpath[0].Header.Type = 1; + // audio.devpath[0].Header.SubType = 3; + // audio.devpath[0].MemoryType = EfiLoaderData; + // audio.devpath[0].StartingAddress = (EFI_UINTPTR)driver_binary; + // audio.devpath[0].EndingAddress = (EFI_UINTPTR)driver_binary + driver_size; + // audio.devpath[1].Header.Length[0] = sizeof(EFI_DEVICE_PATH_PROTOCOL); + // audio.devpath[1].Header.Length[1] = sizeof(EFI_DEVICE_PATH_PROTOCOL) >> 8; + // audio.devpath[1].Header.Type = 0x7F; + // audio.devpath[1].Header.SubType = 0xFF; + // + // status = gSystemTable->BootServices->LoadImage(EFI_FALSE, gImageHandle, (EFI_DEVICE_PATH_PROTOCOL *)driver_devpath, driver_binary, driver_size, &driver_handle); + // if (EFI_ERROR(status)) { + // debug("load_drivers(): Failed to load driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status); + // return; + // } + // + // status = gSystemTable->BootServices->StartImage(driver_handle, NULL, NULL); + // if (EFI_ERROR(status)) { + // debug("load_drivers(): Failed to start driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status); + // return; + // } } \ No newline at end of file