210 lines
3.5 KiB
C
210 lines
3.5 KiB
C
/*++
|
|
|
|
Copyright (c) 2024, Quinn Stephens.
|
|
Provided under the BSD 3-Clause license.
|
|
|
|
Module Name:
|
|
|
|
bootlib.c
|
|
|
|
Abstract:
|
|
|
|
Provides boot library utilities.
|
|
|
|
--*/
|
|
|
|
#include "bootlib.h"
|
|
|
|
//
|
|
// Total size of required structures.
|
|
//
|
|
#define MIN_INPUT_PARAMETERS_SIZE ( \
|
|
sizeof(BOOT_INPUT_PARAMETERS) + \
|
|
sizeof(BOOT_MEMORY_INFO) + \
|
|
sizeof(BOOT_FIRMWARE_DATA) + \
|
|
sizeof(BOOT_RETURN_DATA) \
|
|
)
|
|
|
|
ULONG
|
|
BlGetBootOptionListSize (
|
|
IN PBOOT_APPLICATION_ENTRY_OPTION Options
|
|
);
|
|
|
|
ULONG
|
|
BlGetBootOptionSize (
|
|
IN PBOOT_APPLICATION_ENTRY_OPTION Option
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Gets the size of a boot option.
|
|
|
|
Arguments:
|
|
|
|
Option - the boot option to get the size of.
|
|
|
|
Return Value:
|
|
|
|
The size of the option.
|
|
|
|
--*/
|
|
|
|
{
|
|
ULONG TotalSize;
|
|
|
|
if (Option->DataOffset != 0) {
|
|
TotalSize = Option->DataOffset + Option->DataSize;
|
|
} else {
|
|
TotalSize = sizeof(BOOT_APPLICATION_ENTRY_OPTION);
|
|
}
|
|
|
|
if (Option->OtherOptionsOffset != 0) {
|
|
TotalSize += BlGetBootOptionListSize((PBOOT_APPLICATION_ENTRY_OPTION)((PUCHAR)Option + Option->OtherOptionsOffset));
|
|
}
|
|
|
|
return TotalSize;
|
|
}
|
|
|
|
ULONG
|
|
BlGetBootOptionListSize (
|
|
IN PBOOT_APPLICATION_ENTRY_OPTION Options
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Gets the total size of a list boot options.
|
|
|
|
Arguments:
|
|
|
|
Options - the boot option list to get the size of.
|
|
|
|
Return Value:
|
|
|
|
The size of the options.
|
|
|
|
--*/
|
|
|
|
{
|
|
ULONG TotalSize, NextOffset;
|
|
PBOOT_APPLICATION_ENTRY_OPTION Option;
|
|
|
|
TotalSize = 0;
|
|
NextOffset = 0;
|
|
do {
|
|
Option = (PBOOT_APPLICATION_ENTRY_OPTION)((PUCHAR)Options + NextOffset);
|
|
NextOffset = Option->NextOptionOffset;
|
|
TotalSize += BlGetBootOptionSize(Option);
|
|
} while (NextOffset != 0);
|
|
|
|
return TotalSize;
|
|
}
|
|
|
|
NTSTATUS
|
|
InitializeLibrary (
|
|
IN PBOOT_INPUT_PARAMETERS InputParameters,
|
|
IN PBOOT_LIBRARY_PARAMETERS LibraryParameters
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Internal routine to initialize the boot library.
|
|
|
|
Arguments:
|
|
|
|
InputParameters - pointer to the input parameters structure.
|
|
|
|
LibraryParameters - pointer to the library parameters structure.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful.
|
|
|
|
--*/
|
|
|
|
{
|
|
NTSTATUS Status;
|
|
PBOOT_FIRMWARE_DATA FirmwareData;
|
|
|
|
(VOID)LibraryParameters;
|
|
|
|
//
|
|
// Verify input parameters structure.
|
|
//
|
|
if (InputParameters == NULL ||
|
|
InputParameters->Signature != BOOT_INPUT_PARAMETERS_SIGNATURE ||
|
|
InputParameters->Size < MIN_INPUT_PARAMETERS_SIZE) {
|
|
return STATUS_INVALID_PARAMETER;
|
|
}
|
|
|
|
//
|
|
// Initialize firmware library.
|
|
//
|
|
FirmwareData = (PBOOT_FIRMWARE_DATA)((PUCHAR)InputParameters + InputParameters->FirmwareDataOffset);
|
|
Status = BlpFwInitialize(0, FirmwareData);
|
|
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.
|
|
|
|
Arguments:
|
|
|
|
InputParameters - pointer to the input parameters structure.
|
|
|
|
LibraryParameters - pointer to the library parameters structure.
|
|
|
|
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 if successful.
|
|
Error status if an error is encountered.
|
|
|
|
--*/
|
|
|
|
{
|
|
return STATUS_SUCCESS;
|
|
}
|