[BOOT:LIB] More work on efiinit.c

EfiInitpCreateApplicationEntry() is almost complete.
This commit is contained in:
Quinn Stephens 2024-08-24 10:36:32 -04:00
parent 0743fa0106
commit 8f56881d02
2 changed files with 82 additions and 15 deletions

View File

@ -235,7 +235,8 @@ typedef struct {
} BOOT_DEVICE, *PBOOT_DEVICE; } BOOT_DEVICE, *PBOOT_DEVICE;
typedef enum { typedef enum {
BCDE_DATA_TYPE_APPLICATION_DEVICE = 0x11000001 BCDE_DATA_TYPE_APPLICATION_DEVICE = 0x11000001,
BCDE_DATA_TYPE_APPLICATION_PATH = 0x22000002
} BCDE_DATA_TYPE; } BCDE_DATA_TYPE;
typedef struct { typedef struct {

View File

@ -16,6 +16,7 @@ Abstract:
#include <ntrtl.h> #include <ntrtl.h>
#include <string.h> #include <string.h>
#include <wchar.h> #include <wchar.h>
#include "bootlib.h"
#include "bootmgr.h" #include "bootmgr.h"
#include "efi.h" #include "efi.h"
@ -254,6 +255,46 @@ Return Value:
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS
EfiInitpConvertEfiFilePath (
IN EFI_DEVICE_PATH *EfiFilePath,
IN BCDE_DATA_TYPE OptionType,
IN OUT PBOOT_APPLICATION_ENTRY_OPTION Option,
IN ULONG BufferSize
)
/*++
Routine Description:
Converts an EFI file path into BCD format.
Arguments:
EfiFilePath - The EFI file path to be converted.
OptionType - The data type to be assigned to option.
Option - Pointer to the destination option structure.
BufferSize - The amount of available space in the buffer.
Return Value:
STATUS_SUCCESS if successful.
other NTSTATUS value if failure occurs.
--*/
{
(VOID)EfiFilePath;
(VOID)OptionType;
(VOID)Option;
(VOID)BufferSize;
return STATUS_SUCCESS;
}
VOID VOID
EfiInitpCreateApplicationEntry ( EfiInitpCreateApplicationEntry (
IN EFI_SYSTEM_TABLE *SystemTable, IN EFI_SYSTEM_TABLE *SystemTable,
@ -304,11 +345,11 @@ Return Value:
{ {
NTSTATUS Status; NTSTATUS Status;
ULONG BufferRemaining; ULONG BufferRemaining, OptionsSize, Size;
PWCHAR BcdOptionString; PWCHAR BcdOptionString;
BOOLEAN BcdIdentifierSet; BOOLEAN BcdIdentifierSet;
UNICODE_STRING UnicodeString; UNICODE_STRING UnicodeString;
PBOOT_APPLICATION_ENTRY_OPTION Option; PBOOT_APPLICATION_ENTRY_OPTION Option, PrevOption;
PBCDE_DEVICE BootDeviceElement; PBCDE_DEVICE BootDeviceElement;
(VOID)SystemTable; (VOID)SystemTable;
@ -318,6 +359,7 @@ Return Value:
*BufferUsed = 0; *BufferUsed = 0;
*BootDevice = NULL; *BootDevice = NULL;
OptionsSize = 0;
BcdIdentifierSet = FALSE; BcdIdentifierSet = FALSE;
// //
@ -328,6 +370,13 @@ Return Value:
return; return;
} }
//
// Set up application entry structure.
//
RtlZeroMemory(Entry, sizeof(BOOT_APPLICATION_ENTRY));
Entry->Signature = BOOT_APPLICATION_ENTRY_SIGNATURE;
BufferRemaining -= FIELD_OFFSET(BOOT_APPLICATION_ENTRY, Options);
// //
// Terminate load options string. // Terminate load options string.
// //
@ -336,13 +385,6 @@ Return Value:
LoadOptions[LoadOptionsSize - 1] = L'\0'; LoadOptions[LoadOptionsSize - 1] = L'\0';
} }
//
// Set up application entry structure.
//
RtlZeroMemory(Entry, sizeof(BOOT_APPLICATION_ENTRY));
Entry->Signature = BOOT_APPLICATION_ENTRY_SIGNATURE;
*BufferUsed = sizeof(BOOT_APPLICATION_ENTRY);
// //
// Parse BCD GUID if present. // Parse BCD GUID if present.
// //
@ -361,20 +403,44 @@ Return Value:
// Convert the EFI device path into a boot device option. // Convert the EFI device path into a boot device option.
// //
Option = &Entry->Options; Option = &Entry->Options;
BufferRemaining -= FIELD_OFFSET(BOOT_APPLICATION_ENTRY, Options);
Status = EfiInitpConvertEfiDevicePath(EfiDevicePath, BCDE_DATA_TYPE_APPLICATION_DEVICE, Option, BufferRemaining); Status = EfiInitpConvertEfiDevicePath(EfiDevicePath, BCDE_DATA_TYPE_APPLICATION_DEVICE, Option, BufferRemaining);
if (!NT_SUCCESS(Status)) { if (!NT_SUCCESS(Status)) {
Option->IsInvalid = TRUE; Option->IsInvalid = TRUE;
*BufferUsed = sizeof(BOOT_APPLICATION_ENTRY_OPTION); goto exit;
return;
} }
BootDeviceElement = (PBCDE_DEVICE)((PUCHAR)Option + Option->DataOffset); BootDeviceElement = (PBCDE_DEVICE)((PUCHAR)Option + Option->DataOffset);
*BootDevice = &BootDeviceElement->Device; *BootDevice = &BootDeviceElement->Device;
Size = BlGetBootOptionSize(Option);
OptionsSize += Size;
BufferRemaining -= Size;
// //
// TODO: This routine is not fully implemented. // Convert the EFI file path into a boot file path option.
// TODO: UDP/PXE boot is not supported.
// //
PrevOption = Option;
Option = (PBOOT_APPLICATION_ENTRY_OPTION)((PUCHAR)&Entry->Options + OptionsSize);
Status = EfiInitpConvertEfiFilePath(EfiFilePath, BCDE_DATA_TYPE_APPLICATION_PATH, Option, BufferRemaining);
if (!NT_SUCCESS(Status)) {
goto exit;
}
PrevOption->NextOptionOffset = (PUCHAR)Option - (PUCHAR)&Entry->Options;
Size = BlGetBootOptionSize(Option);
OptionsSize += Size;
BufferRemaining -= Size;
//
// TODO: This section is incomplete.
//
PrevOption = Option;
Option = (PBOOT_APPLICATION_ENTRY_OPTION)((PUCHAR)&Entry->Options + OptionsSize);
// Status = Unknown(LoadOptions, &Entry->Options, RemainingSize, &OptionsSize, &PrevOption, &Size);
if (!NT_SUCCESS(Status)) {
goto exit;
}
exit:
*BufferUsed = BufferSize - BufferRemaining;
} }
PBOOT_INPUT_PARAMETERS PBOOT_INPUT_PARAMETERS