Author: ion
Date: Mon Sep 7 23:48:21 2015
New Revision: 69104
URL:
http://svn.reactos.org/svn/reactos?rev=69104&view=rev
Log:
[BOOTMGFW]
- And again with the fucking non-recursion.
Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/include/bl.h
Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/b…
==============================================================================
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c [iso-8859-1] Mon Sep 7 23:48:21
2015
@@ -12,10 +12,109 @@
/* DATA VARIABLES ************************************************************/
+#include <initguid.h>
+DEFINE_GUID(GUID_WINDOWS_BOOTMGR,
+ 0x9DEA862C,
+ 0x5CDD,
+ 0x4E70,
+ 0xAC, 0xC1, 0xF3, 0x2B, 0x34, 0x4D, 0x47, 0x95);
+
ULONGLONG ApplicationStartTime;
ULONGLONG PostTime;
+GUID BmApplicationIdentifier;
/* FUNCTIONS *****************************************************************/
+
+PGUID
+BlGetApplicationIdentifier (
+ VOID
+ )
+{
+ return NULL;
+}
+
+PWCHAR BootDirectory;
+
+NTSTATUS
+BmFwInitializeBootDirectoryPath()
+{
+#if 0
+ PWCHAR FinalPath;
+ NTSTATUS Status;
+ PWCHAR BcdDirectory;
+ UNICODE_STRING BcdPath;
+ ULONG FinalSize, FileHandle, DeviceHandle;
+
+ BcdPath.MaximumLength = 0;
+ BcdPath.Buffer = NULL;
+
+ FinalPath = NULL;
+
+ FileHandle = -1;
+ DeviceHandle = -1;
+
+ Status = BlpDeviceOpen(BlpBootDevice, 1u, 0, &DeviceHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ goto Quickie;
+ }
+
+ Status = BmpFwGetApplicationDirectoryPath(&BcdPath);
+ BcdDirectory = BcdPath.Buffer;
+ if (!NT_SUCCESS(Status))
+ {
+ goto Quickie;
+ }
+
+ FinalSize = BcdPath.MaximumLength + sizeof(L"\\BCD") -
sizeof(UNICODE_NULL);
+ if (FinalSize < BcdPath.MaximumLength)
+ {
+ goto Quickie;
+ }
+
+ FinalPath = BlMmAllocateHeap(FinalSize);
+ if (!FinalPath)
+ {
+ goto Quickie;
+ }
+
+ RtlZeroMemory(FinalPath, FinalSize);
+ RtlCopyMemory(FinalPath, BcdDirectory, BcdPath.MaximumLength);
+ wcsncat(FinalPath, L"\\BCD", FinalSize / sizeof(WCHAR));
+
+ EfiPrintf(L"Opening: %s\r\n", FinalPath);
+ Status = BlFileOpen(DeviceHandle, FinalPath, 1u, &FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ BootDirectory = BcdDirectory;
+ goto Quickie;
+ }
+
+ BootDirectory = L"\\EFI\\Microsoft\\Boot";
+
+Quickie:
+ if (BcdDirectory)
+ {
+ Status = BlMmFreeHeap(BcdDirectory);
+ }
+ if (FinalPath)
+ {
+ Status = BlMmFreeHeap(FinalPath);
+ }
+ if (FileHandle != -1)
+ {
+ Status = BlFileClose(FileHandle);
+ }
+ if (DeviceHandle != -1)
+ {
+ Status = BlDeviceClose(DeviceHandle);
+ }
+ return Status;
+#else
+ return STATUS_NOT_IMPLEMENTED;
+#endif
+}
+
/*++
* @name BmMain
@@ -37,8 +136,15 @@
{
NTSTATUS Status;
BL_LIBRARY_PARAMETERS LibraryParameters;
-
- EarlyPrint(L"ReactOS UEFI Boot Manager Initializing...\n");
+ PBL_RETURN_ARGUMENTS ReturnArguments;
+ BOOLEAN RebootOnError;
+ PGUID AppIdentifier;
+// HANDLE BcdHandle;
+
+ EfiPrintf(L"ReactOS UEFI Boot Manager Initializing...\n");
+
+ /* Reading the BCD can change this later on */
+ RebootOnError = FALSE;
/* Save the start/end-of-POST time */
ApplicationStartTime = __rdtsc();
@@ -53,9 +159,59 @@
/* Initialize the boot library */
Status = BlInitializeLibrary(BootParameters, &LibraryParameters);
-
- EarlyPrint(L"ReactOS UEFI Boot Manager Exiting: %lx\n", Status);
- EfiStall(3000000);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Check for failure due to invalid application entry */
+ if (Status != STATUS_INVALID_PARAMETER_9)
+ {
+ /* Specifically print out what happened */
+ EfiPrintf(L"BlInitializeLibrary failed 0x%x\r\n", Status);
+ }
+
+ /* Go to exit path */
+ goto Quickie;
+ }
+
+ /* Get the application identifier */
+ AppIdentifier = BlGetApplicationIdentifier();
+ if (!AppIdentifier)
+ {
+ /* None was given, so set our default one */
+ AppIdentifier = (PGUID)&GUID_WINDOWS_BOOTMGR;
+ }
+
+ /* Save our identifier */
+ BmApplicationIdentifier = *AppIdentifier;
+
+ /* Initialize the file system to open a handle to our root boot directory */
+ BmFwInitializeBootDirectoryPath();
+
+ //Status = BmOpenDataStore(&BcdHandle);
+
+ EfiPrintf(L"We are A-OK!\n");
+ EfiStall(10000000);
+
+Quickie:
+ /* Check if we should reboot */
+ if ((RebootOnError) ||
+ (BlpApplicationEntry.Flags & BL_APPLICATION_ENTRY_REBOOT_ON_ERROR))
+ {
+ /* Reboot the box */
+ BlFwReboot();
+ Status = STATUS_SUCCESS;
+ }
+ else
+ {
+ /* Return back to the caller with the error argument encoded */
+ ReturnArguments = (PVOID)((ULONG_PTR)BootParameters +
BootParameters->ReturnArgumentsOffset);
+ ReturnArguments->Version = BL_RETURN_ARGUMENTS_VERSION;
+ ReturnArguments->Status = Status;
+
+ /* Tear down the boot library*/
+ BlDestroyLibrary();
+ }
+
+ /* Return back status */
return Status;
}
Modified: trunk/reactos/boot/environ/app/bootmgr/efiemu.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/e…
==============================================================================
--- trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] Mon Sep 7 23:48:21 2015
@@ -665,7 +665,6 @@
RemainingSize = MaximumLength;
if (RemainingSize < sizeof(BL_APPLICATION_ENTRY))
{
- EarlyPrint(L"Remaining size too small!\n");
Status = STATUS_INVALID_PARAMETER;
goto Quickie;
}
@@ -709,7 +708,6 @@
if (!NT_SUCCESS(Status))
{
/* We failed, so mark the option as such and return an empty one */
- EarlyPrint(L"Failed to convert device path: %lx\n", Status);
Entry->BcdData.Empty = TRUE;
TotalOptionSize = sizeof(BL_BCD_OPTION);
goto Quickie;
@@ -731,7 +729,6 @@
{
/* lol */
Status = STATUS_NOT_IMPLEMENTED;
- EarlyPrint(L"UDP Boot not supported!\n");
}
else
{
@@ -745,7 +742,6 @@
/* Bail out on failure */
if (!NT_SUCCESS(Status))
{
- EarlyPrint(L"Failed to convert file path: %lx\n", Status);
goto Quickie;
}
@@ -784,7 +780,6 @@
RemainingSize);
if (!NT_SUCCESS(Status))
{
- EarlyPrint(L"Failed to convert OS device path: %lx\n",
Status);
goto Quickie;
}
@@ -811,7 +806,6 @@
RemainingSize);
if (!NT_SUCCESS(Status))
{
- EarlyPrint(L"Failed to convert OS file path: %lx\n", Status);
goto Quickie;
}
@@ -898,7 +892,6 @@
(VOID**)&LoadedImage);
if (Status != EFI_SUCCESS)
{
- EarlyPrint(L"Loaded image failed: %lx\n", Status);
return NULL;
}
@@ -912,7 +905,6 @@
(VOID**)&DevicePath);
if (Status != EFI_SUCCESS)
{
- EarlyPrint(L"Device Path failed: %lx\n", Status);
return NULL;
}
@@ -1020,10 +1012,6 @@
{
NTSTATUS Status;
PBOOT_APPLICATION_PARAMETER_BLOCK BootParameters;
- extern EFI_SYSTEM_TABLE *g_SystemTable;
-
- /* Temporary debugging string */
- g_SystemTable = SystemTable;
/* Convert EFI parameters to Windows Boot Application parameters */
BootParameters = EfiInitCreateInputParametersEx(ImageHandle, SystemTable);
@@ -1035,7 +1023,6 @@
else
{
/* Conversion failed, bail out */
- EarlyPrint(L"EFI Input Conversion failed\n");
Status = STATUS_INVALID_PARAMETER;
}
Modified: trunk/reactos/boot/environ/include/bl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
==============================================================================
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Sep 7 23:48:21 2015
@@ -29,9 +29,6 @@
#include <GraphicsOutput.h>
#include <UgaDraw.h>
-VOID
-EarlyPrint(_In_ PWCHAR Format, ...);
-
/* DEFINES *******************************************************************/
#define BL_APPLICATION_FLAG_CONVERTED_FROM_EFI 0x01
@@ -50,6 +47,7 @@
#define BL_FIRMWARE_DESCRIPTOR_VERSION 2
#define BL_APPLICATION_ENTRY_FLAG_NO_GUID 0x01
+#define BL_APPLICATION_ENTRY_REBOOT_ON_ERROR 0x20
#define BL_CONTEXT_PAGING_ON 1
#define BL_CONTEXT_INTERRUPTS_ON 2
@@ -407,7 +405,8 @@
typedef struct _BL_RETURN_ARGUMENTS
{
ULONG Version;
- ULONG ReturnArgumentData[6];
+ NTSTATUS Status;
+ ULONG ReturnArgumentData[5];
} BL_RETURN_ARGUMENTS, *PBL_RETURN_ARGUMENTS;
typedef struct _BL_MEMORY_DESCRIPTOR
@@ -784,7 +783,18 @@
_In_ ULONG Flags
);
+VOID
+BlDestroyLibrary (
+ VOID
+ );
+
/* FIRMWARE ROUTINES *********************************************************/
+
+VOID
+EfiPrintf (
+ _In_ PWCHAR Format,
+ ...
+ );
NTSTATUS
EfiAllocatePages (
@@ -878,6 +888,11 @@
_Out_ UINTN *FrameBufferSize
);
+VOID
+EfiResetSystem (
+ _In_ EFI_RESET_TYPE ResetType
+ );
+
/* PLATFORM TIMER ROUTINES ***************************************************/
NTSTATUS
@@ -899,6 +914,11 @@
NTSTATUS
BlUtlInitialize (
+ VOID
+ );
+
+VOID
+BlFwReboot (
VOID
);