[BOOTMGFW]

- I/O Library initialization.
 - A few more random initialization routines. Skip TPM, BitLocker, Network and non-FAT filesystems for now.

svn path=/trunk/; revision=69073
This commit is contained in:
Alex Ionescu 2015-09-06 21:29:41 +00:00
parent a85d4e1dc4
commit e9b84c302b
9 changed files with 541 additions and 1 deletions

View file

@ -18,7 +18,11 @@ list(APPEND BOOTLIB_SOURCE
lib/mm/heapalloc.c
lib/mm/blkalloc.c
lib/mm/descriptor.c
lib/platform/time.c)
lib/platform/time.c
lib/io/io.c
lib/io/device.c
lib/io/file.c
lib/io/fat.c)
if(ARCH STREQUAL "i386")
list(APPEND BOOTLIB_ASM_SOURCE

View file

@ -78,6 +78,8 @@ EarlyPrint(_In_ PWCHAR Format, ...);
#define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE 0x10
#define BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED 0x20
#define BL_FS_REGISTER_AT_HEAD_FLAG 1
#define BL_MEMORY_CLASS_SHIFT 28
/* ENUMERATIONS **************************************************************/
@ -200,6 +202,38 @@ typedef enum _BL_MEMORY_ATTR
BlMemoryRuntime = 0x1000000
} BL_MEMORY_ATTR;
/* CALLBACKS *****************************************************************/
typedef
NTSTATUS
(*PBL_FS_INIT_CALLBACK) (
VOID
);
typedef
NTSTATUS
(*PBL_FS_DESTROY_CALLBACK) (
VOID
);
typedef
NTSTATUS
(*PBL_FS_MOUNT_CALLBACK) (
VOID
);
typedef
NTSTATUS
(*PBL_FS_PURGE_CALLBACK) (
VOID
);
typedef
NTSTATUS
(*PBL_FILE_DESTROY_CALLBACK) (
_In_ PVOID Entry
);
/* DATA STRUCTURES ***********************************************************/
typedef struct _BL_LIBRARY_PARAMETERS
@ -420,6 +454,34 @@ typedef struct _BL_ADDRESS_RANGE
ULONGLONG Maximum;
} BL_ADDRESS_RANGE, *PBL_ADDRESS_RANGE;
typedef struct _BL_FILE_ENTRY
{
ULONG DeviceIndex;
PBL_FILE_DESTROY_CALLBACK DestroyCallback;
} BL_FILE_ENTRY, *PBL_FILE_ENTRY;
typedef struct _BL_DEVICE_ENTRY
{
ULONG ReferenceCount;
} BL_DEVICE_ENTRY, *PBL_DEVICE_ENTRY;
typedef struct _BL_FILE_SYSTEM_ENTRY
{
LIST_ENTRY ListEntry;
PBL_FS_INIT_CALLBACK InitCallback;
PBL_FS_DESTROY_CALLBACK DestroyCallback;
PBL_FS_MOUNT_CALLBACK MountCallback;
PBL_FS_PURGE_CALLBACK PurgeCallback;
} BL_FILE_SYSTEM_ENTRY, *PBL_FILE_SYSTEM_ENTRY;
typedef struct _BL_FILE_SYSTEM_REGISTRATION_TABLE
{
PBL_FS_INIT_CALLBACK Init;
PBL_FS_DESTROY_CALLBACK Destroy;
PBL_FS_MOUNT_CALLBACK Mount;
PBL_FS_PURGE_CALLBACK Purge;
} BL_FILE_SYSTEM_REGISTRATION_TABLE;
/* INLINE ROUTINES ***********************************************************/
FORCEINLINE
@ -513,6 +575,26 @@ MmMdInitialize (
_In_ PBL_LIBRARY_PARAMETERS LibraryParameters
);
NTSTATUS
BlpDeviceInitialize (
VOID
);
NTSTATUS
BlpIoInitialize (
VOID
);
NTSTATUS
BlpFileInitialize (
VOID
);
NTSTATUS
FatInitialize (
VOID
);
/* FIRMWARE ROUTINES *********************************************************/
NTSTATUS
@ -546,6 +628,11 @@ EfiGetNtStatusCode (
_In_ EFI_STATUS EfiStatus
);
NTSTATUS
BlUtlInitialize (
VOID
);
/* BCD ROUTINES **************************************************************/
ULONG
@ -647,6 +734,11 @@ BlMmAllocateHeap (
_In_ ULONG Size
);
NTSTATUS
BlMmFreeHeap (
_In_ PVOID Buffer
);
extern ULONG MmDescriptorCallTreeCount;
extern ULONG BlpApplicationFlags;
extern BL_LIBRARY_PARAMETERS BlpLibraryParameters;

View file

@ -18,6 +18,8 @@ PWCHAR BlpApplicationBaseDirectory;
PBOOT_APPLICATION_PARAMETER_BLOCK BlpApplicationParameters;
BL_APPLICATION_ENTRY BlpApplicationEntry;
BOOLEAN BlpLibraryParametersInitialized;
BOOLEAN EnSubsystemInitialized;
LIST_ENTRY EnEventNotificationList;
/* FUNCTIONS *****************************************************************/
@ -176,6 +178,52 @@ InitializeLibrary (
return Status;
}
#if 0
/* Initialize support for Trusted Platform Module v1.2 */
BlpTpmInitialize();
#endif
/* Initialize the event manager */
EnSubsystemInitialized = 1;
InitializeListHead(&EnEventNotificationList);
/* Initialize the I/O Manager */
Status = BlpIoInitialize();
if (!NT_SUCCESS(Status))
{
/* Destroy memory manager in phase 1 and the event manager */
EarlyPrint(L"IO init failed\n");
//if (EnSubsystemInitialized) BlpEnDestroy();
//BlpMmDestroy(1);
return Status;
}
#if 0
/* Initialize the network stack */
Status = BlNetInitialize();
if (!NT_SUCCESS(Status))
{
/* Destroy the I/O, event, and memory managers in phase 1 */
BlpIoDestroy();
if (EnSubsystemInitialized) BlpEnDestroy();
BlpMmDestroy(1);
return Status;
}
#endif
/* Initialize the utility library */
Status = BlUtlInitialize();
if (!NT_SUCCESS(Status))
{
/* Destroy the network, I/O, event, and memory managers in phase 1 */
//BlNetDestroy();
//BlpIoDestroy();
//if (EnSubsystemInitialized) BlpEnDestroy();
//BlpMmDestroy(1);
EarlyPrint(L"Util init failed\n");
return Status;
}
EarlyPrint(L"TODO!\n");
Status = STATUS_NOT_IMPLEMENTED;

View file

@ -0,0 +1,72 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/io/device.c
* PURPOSE: Boot Library Device Management Routines
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
typedef struct _BL_DEVICE_INFORMATION
{
ULONG Unknown0;
ULONG Unknown1;
ULONG Unknown2;
ULONG Unknown3;
} BL_DEVICE_INFORMATION, *PBL_DEVICE_INFORMATION;
LIST_ENTRY DmRegisteredDevices;
ULONG DmTableEntries;
LIST_ENTRY DmRegisteredDevices;
PVOID* DmDeviceTable;
BL_DEVICE_INFORMATION DmDeviceIoInformation;
/* FUNCTIONS *****************************************************************/
NTSTATUS
BlpDeviceInitialize (
VOID
)
{
NTSTATUS Status;
/* Initialize the table count and list of devices */
DmTableEntries = 8;
InitializeListHead(&DmRegisteredDevices);
/* Initialize device information */
DmDeviceIoInformation.Unknown0 = 0;
DmDeviceIoInformation.Unknown1 = 0;
DmDeviceIoInformation.Unknown2 = 0;
DmDeviceIoInformation.Unknown3 = 0;
/* Allocate the device table */
DmDeviceTable = BlMmAllocateHeap(DmTableEntries * sizeof(PVOID));
if (DmDeviceTable)
{
/* Clear it */
RtlZeroMemory(DmDeviceTable, DmTableEntries * sizeof(PVOID));
#if 0
/* Initialize BitLocker support */
Status = FvebInitialize();
#else
Status = STATUS_SUCCESS;
#endif
}
else
{
/* No memory, we'll fail */
Status = STATUS_NO_MEMORY;
}
/* Return initialization state */
return Status;
}

View file

@ -0,0 +1,51 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/io/fat.c
* PURPOSE: Boot Library FAT File System Management Routines
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
PVOID* FatDeviceTable;
ULONG FatDeviceTableEntries;
PWCHAR FatpLongFileName;
/* FUNCTIONS *****************************************************************/
NTSTATUS
FatInitialize (
VOID
)
{
NTSTATUS Status;
/* Allocate the device table with 2 entries*/
FatDeviceTableEntries = 2;
FatDeviceTable = BlMmAllocateHeap(sizeof(PBL_FILE_ENTRY) *
FatDeviceTableEntries);
if (FatDeviceTable)
{
/* Zero it out */
RtlZeroMemory(FatDeviceTable,
sizeof(PBL_FILE_ENTRY) * FatDeviceTableEntries);
/* Allocate a 512 byte buffer for long file name conversion */
FatpLongFileName = BlMmAllocateHeap(512);
Status = FatpLongFileName != NULL ? STATUS_SUCCESS : STATUS_NO_MEMORY;
}
else
{
/* No memory, fail */
Status = STATUS_NO_MEMORY;
}
/* Return back to caller */
return Status;
}

View file

@ -0,0 +1,174 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/io/file.c
* PURPOSE: Boot Library File Management Routines
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
PVOID* FileTable;
ULONG FileEntries;
LIST_ENTRY RegisteredFileSystems;
BL_FILE_SYSTEM_REGISTRATION_TABLE FatRegisterFunctionTable =
{
FatInitialize,
#if 0
FatDestroy,
FatMount,
NULL
#endif
};
/* FUNCTIONS *****************************************************************/
NTSTATUS
BlpFileRegisterFileSystem (
_In_ PBL_FS_INIT_CALLBACK InitCallback,
_In_ PBL_FS_DESTROY_CALLBACK DestroyCallback,
_In_ PBL_FS_MOUNT_CALLBACK MountCallback,
_In_ PBL_FS_PURGE_CALLBACK PurgeCallback,
_In_ ULONG Flags
)
{
PBL_FILE_SYSTEM_ENTRY FsEntry;
NTSTATUS Status;
FsEntry = BlMmAllocateHeap(sizeof(*FsEntry));
if (!FsEntry)
{
return STATUS_NO_MEMORY;
}
Status = InitCallback();
if (NT_SUCCESS(Status))
{
BlMmFreeHeap(FsEntry);
return Status;
}
/* Register the callbacks */
FsEntry->MountCallback = MountCallback;
FsEntry->DestroyCallback = DestroyCallback;
FsEntry->InitCallback = InitCallback;
FsEntry->PurgeCallback = PurgeCallback;
/* Insert in the right location in the list */
if (Flags & BL_FS_REGISTER_AT_HEAD_FLAG)
{
InsertHeadList(&RegisteredFileSystems, &FsEntry->ListEntry);
}
else
{
InsertTailList(&RegisteredFileSystems, &FsEntry->ListEntry);
}
/* Return */
return STATUS_SUCCESS;
}
NTSTATUS
BlpFileInitialize (
VOID
)
{
NTSTATUS Status;
/* Allocate the file table */
FileEntries = 16;
FileTable = BlMmAllocateHeap(sizeof(PBL_FILE_ENTRY) * FileEntries);
if (!FileTable)
{
return STATUS_INVALID_PARAMETER;
}
/* Initialize it */
RtlZeroMemory(FileTable, sizeof(PBL_FILE_ENTRY) * FileEntries);
InitializeListHead(&RegisteredFileSystems);
#if 0
/* Initialize the network file system */
Status = BlpFileRegisterFileSystem(NetRegisterFunctionTable.Init,
NetRegisterFunctionTable.Destroy,
NetRegisterFunctionTable.Mount,
NetRegisterFunctionTable.Purge,
1);
if (NT_SUCCESS(Status))
{
/* Initialize NTFS */
Status = BlpFileRegisterFileSystem(NtfsRegisterFunctionTable.Init,
NtfsRegisterFunctionTable.Destroy,
NtfsRegisterFunctionTable.Mount,
NtfsRegisterFunctionTable.Purge,
0);
}
if (NT_SUCCESS(Status))
#endif
{
/* Initialize FAT */
Status = BlpFileRegisterFileSystem(FatRegisterFunctionTable.Init,
FatRegisterFunctionTable.Destroy,
FatRegisterFunctionTable.Mount,
FatRegisterFunctionTable.Purge,
0);
}
#if 0
if (NT_SUCCESS(Status))
{
/* Initialize EXFAT (FatPlus) */
Status = BlpFileRegisterFileSystem(FppRegisterFunctionTable.Init,
FppRegisterFunctionTable.Destroy,
FppRegisterFunctionTable.Mount,
FppRegisterFunctionTable.Purge,
0);
}
if (NT_SUCCESS(Status))
{
/* Initialize WIM */
Status = BlpFileRegisterFileSystem(WimRegisterFunctionTable.Init,
WimRegisterFunctionTable.Destroy,
WimRegisterFunctionTable.Mount,
WimRegisterFunctionTable.Purge,
0);
}
if (NT_SUCCESS(Status))
{
/* Initialize UDFS */
Status = BlpFileRegisterFileSystem(UdfsRegisterFunctionTable.Init,
UdfsRegisterFunctionTable.Destroy,
UdfsRegisterFunctionTable.Mount,
UdfsRegisterFunctionTable.Purge,
0);
}
if (NT_SUCCESS(Status))
{
/* Initialize El-Torito CDFS */
Status = BlpFileRegisterFileSystem(EtfsRegisterFunctionTable.Init,
EtfsRegisterFunctionTable.Destroy,
EtfsRegisterFunctionTable.Mount,
EtfsRegisterFunctionTable.Purge,
0);
}
#endif
/* Destroy the file manager if any of the file systems didn't initialize */
if (!NT_SUCCESS(Status))
{
if (FileTable)
{
//BlpFileDestroy();
}
}
return Status;
}

View file

@ -0,0 +1,56 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/io/io.c
* PURPOSE: Boot Library I/O Management Routines
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
ULONG IoMgrRoutineEntries;
PVOID* IoMgrDestroyRoutineTable;
/* FUNCTIONS *****************************************************************/
NTSTATUS
BlpIoInitialize (
VOID
)
{
NTSTATUS Status;
ULONG Size;
/* Allocate the I/O table */
IoMgrRoutineEntries = 4;
Size = IoMgrRoutineEntries * sizeof(PVOID);
IoMgrDestroyRoutineTable = BlMmAllocateHeap(Size);
if (IoMgrDestroyRoutineTable)
{
/* Zero it out */
RtlZeroMemory(IoMgrDestroyRoutineTable, Size);
/* Initialize the device manager */
Status = BlpDeviceInitialize();
/* Initialize the file manager */
if (NT_SUCCESS(Status))
{
Status = BlpFileInitialize();
}
}
else
{
/* No memory */
Status = STATUS_NO_MEMORY;
}
/* Return initialization status */
return Status;
}

View file

@ -10,6 +10,24 @@
#include "bl.h"
/* DATA VARIABLES ************************************************************/
PVOID UtlRsdt;
PVOID UtlXsdt;
PVOID UtlMcContext;
PVOID UtlMcDisplayMessageRoutine;
PVOID UtlMcUpdateMessageRoutine;
PVOID UtlProgressRoutine;
PVOID UtlProgressContext;
PVOID UtlProgressInfoRoutine;
ULONG UtlProgressGranularity;
ULONG UtlCurrentPercentComplete;
ULONG UtlNextUpdatePercentage;
BOOLEAN UtlProgressNeedsInfoUpdate;
PVOID UtlProgressInfo;
/* FUNCTIONS *****************************************************************/
/*++
@ -146,3 +164,26 @@ EfiGetNtStatusCode (
}
}
NTSTATUS
BlUtlInitialize (
VOID
)
{
UtlRsdt = 0;
UtlXsdt = 0;
UtlMcContext = 0;
UtlMcDisplayMessageRoutine = 0;
UtlMcUpdateMessageRoutine = 0;
UtlProgressRoutine = 0;
UtlProgressContext = 0;
UtlProgressInfoRoutine = 0;
UtlProgressGranularity = 0;
UtlCurrentPercentComplete = 0;
UtlNextUpdatePercentage = 0;
UtlProgressNeedsInfoUpdate = 0;
UtlProgressInfo = 0;
return STATUS_SUCCESS;
}

View file

@ -14,6 +14,8 @@
ULONGLONG BlpTimePerformanceFrequency;
/* FUNCTIONS *****************************************************************/
NTSTATUS
BlpTimeMeasureTscFrequency (
VOID