163 lines
3.7 KiB
C
163 lines
3.7 KiB
C
/*++
|
|
|
|
Copyright (c) 2024, Quinn Stephens.
|
|
Provided under the BSD 3-Clause license.
|
|
|
|
Module Name:
|
|
|
|
bootlib.c
|
|
|
|
Abstract:
|
|
|
|
Provides boot library utilities.
|
|
|
|
--*/
|
|
|
|
#include <ntrtl.h>
|
|
#include "bootlib.h"
|
|
|
|
#define MIN_INPUT_PARAMETERS_SIZE ( \
|
|
sizeof(BOOT_INPUT_PARAMETERS) + \
|
|
sizeof(BOOT_MEMORY_INFO) + \
|
|
sizeof(BOOT_FIRMWARE_DATA) + \
|
|
sizeof(BOOT_RETURN_DATA) \
|
|
)
|
|
|
|
PBOOT_INPUT_PARAMETERS BlpApplicationParameters;
|
|
BOOT_APPLICATION_ENTRY BlpApplicationEntry;
|
|
PBOOT_DEVICE BlpBootDevice;
|
|
|
|
NTSTATUS
|
|
InitializeLibrary (
|
|
IN PBOOT_INPUT_PARAMETERS InputParameters,
|
|
IN PBOOT_LIBRARY_PARAMETERS LibraryParameters
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes the boot library.
|
|
|
|
Arguments:
|
|
|
|
InputParameters - Pointer to the application's input parameters.
|
|
|
|
LibraryParameters - Pointer to the library parameters.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful.
|
|
|
|
--*/
|
|
|
|
{
|
|
NTSTATUS Status;
|
|
PBOOT_MEMORY_INFO MemoryInfo;
|
|
PBOOT_INPUT_APPLICATION_ENTRY ApplicationEntry;
|
|
PBOOT_FIRMWARE_DATA FirmwareData;
|
|
PBOOT_BLOCK_IDENTIFIER BlockDevice;
|
|
PBOOT_APPLICATION_OPTION Option;
|
|
|
|
(VOID)LibraryParameters;
|
|
|
|
if (InputParameters == NULL ||
|
|
InputParameters->Signature != BOOT_INPUT_PARAMETERS_SIGNATURE ||
|
|
InputParameters->Size < MIN_INPUT_PARAMETERS_SIZE) {
|
|
return STATUS_INVALID_PARAMETER;
|
|
}
|
|
|
|
MemoryInfo = (PBOOT_MEMORY_INFO)((PUCHAR)InputParameters + InputParameters->MemoryInfoOffset);
|
|
ApplicationEntry = (PBOOT_INPUT_APPLICATION_ENTRY)((PUCHAR)InputParameters + InputParameters->ApplicationEntryOffset);
|
|
BlpBootDevice = (PBOOT_DEVICE)((PUCHAR)InputParameters + InputParameters->BootDeviceOffset);
|
|
FirmwareData = (PBOOT_FIRMWARE_DATA)((PUCHAR)InputParameters + InputParameters->FirmwareDataOffset);
|
|
|
|
//
|
|
// Initialize firmware library.
|
|
// It is important to do this early so that
|
|
// ConsolePrint() and DebugPrint() can be used.
|
|
//
|
|
Status = BlpFwInitialize(0, FirmwareData);
|
|
if (!NT_SUCCESS(Status)) {
|
|
return Status;
|
|
}
|
|
|
|
ConsolePrint(L"> Alcyone EFI Boot Manager\r\n");
|
|
ConsolePrintf(L"Image base: %x %x\r\nImage size: %x\r\n", HIDWORD((ULONG_PTR)InputParameters->ImageBase), LODWORD((ULONG_PTR)InputParameters->ImageBase), InputParameters->ImageSize);
|
|
|
|
DebugPrint(L"Initializing boot library...\r\n");
|
|
|
|
if (ApplicationEntry->Signature != BOOT_INPUT_APPLICATION_ENTRY_SIGNATURE) {
|
|
DebugPrint(L"InitializeLibrary(): ApplicationEntry Signature is invalid\r\n");
|
|
return STATUS_INVALID_PARAMETER_9;
|
|
}
|
|
|
|
//
|
|
// Save input parameters and application entry.
|
|
//
|
|
BlpApplicationParameters = InputParameters;
|
|
BlpApplicationEntry.Attributes = ApplicationEntry->Attributes;
|
|
RtlCopyMemory(&BlpApplicationEntry.BcdIdentifier, &ApplicationEntry->BcdIdentifier, sizeof(GUID));
|
|
BlpApplicationEntry.Options = &ApplicationEntry->Options;
|
|
|
|
Status = BlpMmInitialize(MemoryInfo, InputParameters->TranslationType, LibraryParameters);
|
|
if (!NT_SUCCESS(Status)) {
|
|
return Status;
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
NTSTATUS
|
|
BlInitializeLibrary (
|
|
IN PBOOT_INPUT_PARAMETERS InputParameters,
|
|
IN PBOOT_LIBRARY_PARAMETERS LibraryParameters
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes the boot library. Wrapper for InitializeLibrary().
|
|
|
|
Arguments:
|
|
|
|
InputParameters - Pointer to the application's input parameters.
|
|
|
|
LibraryParameters - Pointer to the library parameters.
|
|
|
|
Return Value:
|
|
|
|
Any value returned by InitializeLibrary().
|
|
|
|
--*/
|
|
|
|
{
|
|
return InitializeLibrary(InputParameters, LibraryParameters);
|
|
}
|
|
|
|
NTSTATUS
|
|
BlDestroyLibrary (
|
|
VOID
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Cleans up after the boot library.
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS.
|
|
|
|
--*/
|
|
|
|
{
|
|
return STATUS_SUCCESS;
|
|
}
|