diff --git a/BOOT/ENVIRON/INC/bootlib.h b/BOOT/ENVIRON/INC/bootlib.h index 910348e..d45d80c 100644 --- a/BOOT/ENVIRON/INC/bootlib.h +++ b/BOOT/ENVIRON/INC/bootlib.h @@ -34,6 +34,17 @@ ConsolePrintf ( ... ); +// +// Enable/disable debug printing. +// +#ifdef _DEBUG +#define DebugPrint(String) ConsolePrint(String) +#define DebugPrintf(Format, ...) ConsolePrintf(Format, __VA_ARGS__) +#else +#define DebugPrint(String) +#define DebugPrintf(Format, ...) +#endif + ULONG BlGetBootOptionSize ( IN PBOOT_APPLICATION_OPTION Option diff --git a/BOOT/ENVIRON/LIB/bootlib.c b/BOOT/ENVIRON/LIB/bootlib.c index 56c6925..aa6fbc8 100644 --- a/BOOT/ENVIRON/LIB/bootlib.c +++ b/BOOT/ENVIRON/LIB/bootlib.c @@ -81,16 +81,25 @@ Return Value: // // 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; } + // + // Print image information. + // + ConsolePrintf(L"Image base: %x %x\r\n", (ULONG)((ULONG_PTR)InputParameters->ImageBase >> 32), (ULONG)((ULONG_PTR)InputParameters->ImageBase)); + ConsolePrintf(L"Image size: %x\r\n", InputParameters->ImageSize); + // // Check application entry signature. // if (ApplicationEntry->Signature != BOOT_INPUT_APPLICATION_ENTRY_SIGNATURE) { + DebugPrint(L"Application entry signature is invalid\r\n"); return STATUS_INVALID_PARAMETER_9; } @@ -104,53 +113,51 @@ Return Value: // // Print debug information. + // TODO: Remove this once the project is more stable? // - - ConsolePrintf(L"Image base: %x %x\r\n", (ULONG)((ULONG_PTR)InputParameters->ImageBase >> 32), (ULONG)((ULONG_PTR)InputParameters->ImageBase)); - ConsolePrintf(L"Image size: %x\r\n", InputParameters->ImageSize); - - ConsolePrint(L"Boot device type: "); +#ifdef _DEBUG + DebugPrint(L"Boot device type: "); switch (BlpBootDevice->Type) { case BOOT_DEVICE_TYPE_PARTITION: - ConsolePrint(L"partition\r\n"); + DebugPrint(L"partition\r\n"); BlockDevice = &BlpBootDevice->Partition.Parent; break; case BOOT_DEVICE_TYPE_PARTITION_EX: - ConsolePrint(L"partition\r\n"); + DebugPrint(L"partition\r\n"); BlockDevice = &BlpBootDevice->PartitionEx.Parent; break; default: - ConsolePrint(L"generic block device\r\n"); + DebugPrint(L"generic block device\r\n"); BlockDevice = &BlpBootDevice->Block; break; } - ConsolePrint(L"Boot device parent type: "); + DebugPrint(L"Boot device parent type: "); switch (BlockDevice->Type) { case BOOT_BLOCK_DEVICE_TYPE_HARDDRIVE: - ConsolePrint(L"hard drive\r\n"); + DebugPrint(L"hard drive\r\n"); break; case BOOT_BLOCK_DEVICE_TYPE_CDROM: - ConsolePrint(L"CD-ROM\r\n"); + DebugPrint(L"CD-ROM\r\n"); break; case BOOT_BLOCK_DEVICE_TYPE_RAMDISK: - ConsolePrint(L"RAM disk\r\n"); + DebugPrint(L"RAM disk\r\n"); break; default: - ConsolePrint(L"generic block device\r\n"); + DebugPrint(L"generic block device\r\n"); break; } Option = &ApplicationEntry->Options; for (ULONG Index = 0; !Option->IsInvalid; Index++) { - ConsolePrintf(L"Boot entry option %x: ", Index); + DebugPrintf(L"Boot entry option %x: ", Index); if (Option->Type == BCDE_DATA_TYPE_APPLICATION_PATH) { - ConsolePrint(L"application path \""); - ConsolePrint((PWSTR)((PUCHAR)Option + Option->DataOffset)); - ConsolePrint(L"\"\r\n"); + DebugPrint(L"application path \""); + DebugPrint((PWSTR)((PUCHAR)Option + Option->DataOffset)); + DebugPrint(L"\"\r\n"); } else { - ConsolePrintf(L"type %x, data size %x\r\n", Option->Type, Option->DataSize); + DebugPrintf(L"type %x, data size %x\r\n", Option->Type, Option->DataSize); } if (Option->NextOptionOffset == 0) { @@ -159,6 +166,7 @@ Return Value: Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)Option + Option->NextOptionOffset); } +#endif return STATUS_SUCCESS; }