Don't print HackBGRT on every output line

This commit is contained in:
Lauri Kenttä
2023-11-25 19:57:02 +02:00
parent 77dd2bd699
commit aac8a38cbb
3 changed files with 23 additions and 23 deletions

View File

@@ -6,7 +6,7 @@ BOOLEAN ReadConfigFile(struct HackBGRT_config* config, EFI_FILE_HANDLE root_dir,
UINTN data_bytes = 0; UINTN data_bytes = 0;
data = LoadFileWithPadding(root_dir, path, &data_bytes, 4); data = LoadFileWithPadding(root_dir, path, &data_bytes, 4);
if (!data) { if (!data) {
Log(1, L"HackBGRT: Failed to load configuration (%s)!\n", path); Log(1, L"Failed to load configuration (%s)!\n", path);
return FALSE; return FALSE;
} }
CHAR16* str; CHAR16* str;
@@ -72,8 +72,8 @@ static void SetBMPWithRandom(struct HackBGRT_config* config, int weight, enum Ha
config->image_weight_sum += weight; config->image_weight_sum += weight;
UINT32 random = (((UINT64) Random() & 0xffffffff) * config->image_weight_sum) >> 32; UINT32 random = (((UINT64) Random() & 0xffffffff) * config->image_weight_sum) >> 32;
UINT32 limit = ((UINT64) 0xffffffff * weight) >> 32; UINT32 limit = ((UINT64) 0xffffffff * weight) >> 32;
Log(config->debug, L"HackBGRT: n=%d, action=%d, x=%d, y=%d, o=%d, path=%s, random = %x, limit = %x\n", weight, action, x, y, o, path, random, limit); Log(config->debug, L"%s n=%d, action=%d, x=%d, y=%d, o=%d, path=%s, rand=%x/%x\n", random <= limit ? L"Using" : L"Skipping", weight, action, x, y, o, path, random, limit);
if (!config->image_weight_sum || random <= limit) { if (random <= limit) {
config->action = action; config->action = action;
config->image_path = path; config->image_path = path;
config->orientation = o; config->orientation = o;
@@ -108,7 +108,7 @@ static void ReadConfigImage(struct HackBGRT_config* config, const CHAR16* line)
} else if (StrStr(line, L"keep")) { } else if (StrStr(line, L"keep")) {
action = HackBGRT_KEEP; action = HackBGRT_KEEP;
} else { } else {
Log(1, L"HackBGRT: Invalid image line: %s\n", line); Log(1, L"Invalid image line: %s\n", line);
return; return;
} }
int weight = n && (!f || n < f) ? Atoi(n) : 1; int weight = n && (!f || n < f) ? Atoi(n) : 1;
@@ -125,7 +125,7 @@ static void ReadConfigResolution(struct HackBGRT_config* config, const CHAR16* l
config->resolution_x = *x == '-' ? -(int)Atoi(x+1) : (int)Atoi(x); config->resolution_x = *x == '-' ? -(int)Atoi(x+1) : (int)Atoi(x);
config->resolution_y = *y == '-' ? -(int)Atoi(y+1) : (int)Atoi(y); config->resolution_y = *y == '-' ? -(int)Atoi(y+1) : (int)Atoi(y);
} else { } else {
Log(1, L"HackBGRT: Invalid resolution line: %s\n", line); Log(1, L"Invalid resolution line: %s\n", line);
} }
} }

View File

@@ -14,7 +14,7 @@ enum HackBGRT_action {
* @see struct HackBGRT_config * @see struct HackBGRT_config
*/ */
enum HackBGRT_coordinate { enum HackBGRT_coordinate {
HackBGRT_coord_keep = -1000000001 HackBGRT_coord_keep = -1000001
}; };
/** /**

View File

@@ -112,7 +112,7 @@ ACPI_SDT_HEADER* CreateXsdt(ACPI_SDT_HEADER* xsdt0, UINTN entries) {
UINT32 xsdt_len = sizeof(ACPI_SDT_HEADER) + entries * sizeof(UINT64); UINT32 xsdt_len = sizeof(ACPI_SDT_HEADER) + entries * sizeof(UINT64);
BS->AllocatePool(EfiACPIReclaimMemory, xsdt_len, (void**)&xsdt); BS->AllocatePool(EfiACPIReclaimMemory, xsdt_len, (void**)&xsdt);
if (!xsdt) { if (!xsdt) {
Log(1, L"HackBGRT: Failed to allocate memory for XSDT.\n"); Log(1, L"Failed to allocate memory for XSDT.\n");
return 0; return 0;
} }
BS->SetMem(xsdt, xsdt_len, 0); BS->SetMem(xsdt, xsdt_len, 0);
@@ -212,7 +212,7 @@ static BMP* MakeBMP(int w, int h, UINT8 r, UINT8 g, UINT8 b) {
BMP* bmp = 0; BMP* bmp = 0;
BS->AllocatePool(EfiBootServicesData, 54 + w * h * 4, (void**) &bmp); BS->AllocatePool(EfiBootServicesData, 54 + w * h * 4, (void**) &bmp);
if (!bmp) { if (!bmp) {
Log(1, L"HackBGRT: Failed to allocate a blank BMP!\n"); Log(1, L"Failed to allocate a blank BMP!\n");
BS->Stall(1000000); BS->Stall(1000000);
return 0; return 0;
} }
@@ -247,7 +247,7 @@ static BMP* LoadBMP(EFI_FILE_HANDLE root_dir, const CHAR16* path) {
if (!path) { if (!path) {
return MakeBMP(1, 1, 0, 0, 0); // empty path = black image return MakeBMP(1, 1, 0, 0, 0); // empty path = black image
} }
Log(config.debug, L"HackBGRT: Loading %s.\n", path); Log(config.debug, L"Loading %s.\n", path);
UINTN size = 0; UINTN size = 0;
BMP* bmp = LoadFile(root_dir, path, &size); BMP* bmp = LoadFile(root_dir, path, &size);
if (bmp) { if (bmp) {
@@ -262,9 +262,9 @@ static BMP* LoadBMP(EFI_FILE_HANDLE root_dir, const CHAR16* path) {
return bmp; return bmp;
} }
BS->FreePool(bmp); BS->FreePool(bmp);
Log(1, L"HackBGRT: Invalid BMP (%s)!\n", path); Log(1, L"Invalid BMP (%s)!\n", path);
} else { } else {
Log(1, L"HackBGRT: Failed to load BMP (%s)!\n", path); Log(1, L"Failed to load BMP (%s)!\n", path);
} }
BS->Stall(1000000); BS->Stall(1000000);
return MakeBMP(16, 16, 255, 0, 0); // error = red image return MakeBMP(16, 16, 255, 0, 0); // error = red image
@@ -330,7 +330,7 @@ void HackBgrt(EFI_FILE_HANDLE root_dir) {
// Replace missing = allocate new. // Replace missing = allocate new.
BS->AllocatePool(EfiACPIReclaimMemory, sizeof(*bgrt), (void**)&bgrt); BS->AllocatePool(EfiACPIReclaimMemory, sizeof(*bgrt), (void**)&bgrt);
if (!bgrt) { if (!bgrt) {
Log(1, L"HackBGRT: Failed to allocate memory for BGRT.\n"); Log(1, L"Failed to allocate memory for BGRT.\n");
return; return;
} }
} }
@@ -383,7 +383,7 @@ void HackBgrt(EFI_FILE_HANDLE root_dir) {
bgrt->image_offset_y = max(0, min(max_y, new_y + (new_reso_y - new_bmp->height) / 2)); bgrt->image_offset_y = max(0, min(max_y, new_y + (new_reso_y - new_bmp->height) / 2));
Log(config.debug, Log(config.debug,
L"HackBGRT: BMP at (%d, %d), center (%d, %d), resolution (%d, %d), orientation %d.\n", L"BMP at (%d, %d), center (%d, %d), resolution (%d, %d), orientation %d.\n",
(int) bgrt->image_offset_x, (int) bgrt->image_offset_y, (int) bgrt->image_offset_x, (int) bgrt->image_offset_y,
new_x, new_y, new_reso_x, new_reso_y, new_x, new_y, new_reso_x, new_reso_y,
new_orientation * 90 new_orientation * 90
@@ -400,9 +400,9 @@ void HackBgrt(EFI_FILE_HANDLE root_dir) {
static EFI_HANDLE LoadApp(int print_failure, EFI_HANDLE image_handle, EFI_LOADED_IMAGE* image, const CHAR16* path) { static EFI_HANDLE LoadApp(int print_failure, EFI_HANDLE image_handle, EFI_LOADED_IMAGE* image, const CHAR16* path) {
EFI_DEVICE_PATH* boot_dp = FileDevicePath(image->DeviceHandle, (CHAR16*) path); EFI_DEVICE_PATH* boot_dp = FileDevicePath(image->DeviceHandle, (CHAR16*) path);
EFI_HANDLE result = 0; EFI_HANDLE result = 0;
Log(config.debug, L"HackBGRT: Loading application %s.\n", path); Log(config.debug, L"Loading application %s.\n", path);
if (EFI_ERROR(BS->LoadImage(0, image_handle, boot_dp, 0, 0, &result))) { if (EFI_ERROR(BS->LoadImage(0, image_handle, boot_dp, 0, 0, &result))) {
Log(config.debug || print_failure, L"HackBGRT: Failed to load application %s.\n", path); Log(config.debug || print_failure, L"Failed to load application %s.\n", path);
} }
return result; return result;
} }
@@ -419,19 +419,19 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
EFI_LOADED_IMAGE* image; EFI_LOADED_IMAGE* image;
if (EFI_ERROR(BS->HandleProtocol(image_handle, TmpGuidPtr((EFI_GUID) EFI_LOADED_IMAGE_PROTOCOL_GUID), (void**) &image))) { if (EFI_ERROR(BS->HandleProtocol(image_handle, TmpGuidPtr((EFI_GUID) EFI_LOADED_IMAGE_PROTOCOL_GUID), (void**) &image))) {
Log(config.debug, L"HackBGRT: LOADED_IMAGE_PROTOCOL failed.\n"); Log(config.debug, L"LOADED_IMAGE_PROTOCOL failed.\n");
goto fail; goto fail;
} }
EFI_FILE_IO_INTERFACE* io; EFI_FILE_IO_INTERFACE* io;
if (EFI_ERROR(BS->HandleProtocol(image->DeviceHandle, TmpGuidPtr((EFI_GUID) EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID), (void**) &io))) { if (EFI_ERROR(BS->HandleProtocol(image->DeviceHandle, TmpGuidPtr((EFI_GUID) EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID), (void**) &io))) {
Log(config.debug, L"HackBGRT: FILE_SYSTEM_PROTOCOL failed.\n"); Log(config.debug, L"FILE_SYSTEM_PROTOCOL failed.\n");
goto fail; goto fail;
} }
EFI_FILE_HANDLE root_dir; EFI_FILE_HANDLE root_dir;
if (EFI_ERROR(io->OpenVolume(io, &root_dir))) { if (EFI_ERROR(io->OpenVolume(io, &root_dir))) {
Log(config.debug, L"HackBGRT: Failed to open root directory.\n"); Log(config.debug, L"Failed to open root directory.\n");
goto fail; goto fail;
} }
@@ -439,7 +439,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
if (EFI_ERROR(BS->OpenProtocol(image_handle, TmpGuidPtr((EFI_GUID) EFI_SHELL_PARAMETERS_PROTOCOL_GUID), (void**) &shell_param_proto, 0, 0, EFI_OPEN_PROTOCOL_GET_PROTOCOL)) || shell_param_proto->Argc <= 1) { if (EFI_ERROR(BS->OpenProtocol(image_handle, TmpGuidPtr((EFI_GUID) EFI_SHELL_PARAMETERS_PROTOCOL_GUID), (void**) &shell_param_proto, 0, 0, EFI_OPEN_PROTOCOL_GET_PROTOCOL)) || shell_param_proto->Argc <= 1) {
const CHAR16* config_path = L"\\EFI\\HackBGRT\\config.txt"; const CHAR16* config_path = L"\\EFI\\HackBGRT\\config.txt";
if (!ReadConfigFile(&config, root_dir, config_path)) { if (!ReadConfigFile(&config, root_dir, config_path)) {
Log(1, L"HackBGRT: No config, no command line!\n", config_path); Log(1, L"No config, no command line!\n", config_path);
goto fail; goto fail;
} }
} else { } else {
@@ -479,13 +479,13 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
if (try_ms_quietly) { if (try_ms_quietly) {
goto ready_to_boot; goto ready_to_boot;
} }
Log(1, L"HackBGRT: Reverting to %s.\n", config.boot_path); Log(1, L"Reverting to %s.\n", config.boot_path);
Log(-1, L"Press escape to cancel or any other key (or wait 15 seconds) to boot.\n"); Log(-1, L"Press escape to cancel or any other key (or wait 15 seconds) to boot.\n");
if (ReadKey(15000).ScanCode == SCAN_ESC) { if (ReadKey(15000).ScanCode == SCAN_ESC) {
goto fail; goto fail;
} }
} else ready_to_boot: if (config.debug) { } else ready_to_boot: if (config.debug) {
Log(-1, L"HackBGRT: Ready to boot.\n"); Log(-1, L"Ready to boot.\n");
Log(-1, L"If all goes well, you can set debug=0 and log=0 in config.txt.\n"); Log(-1, L"If all goes well, you can set debug=0 and log=0 in config.txt.\n");
Log(-1, L"Press escape to cancel or any other key (or wait 15 seconds) to boot.\n"); Log(-1, L"Press escape to cancel or any other key (or wait 15 seconds) to boot.\n");
if (ReadKey(15000).ScanCode == SCAN_ESC) { if (ReadKey(15000).ScanCode == SCAN_ESC) {
@@ -496,10 +496,10 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *ST_) {
ClearLogVariable(); ClearLogVariable();
} }
if (EFI_ERROR(BS->StartImage(next_image_handle, 0, 0))) { if (EFI_ERROR(BS->StartImage(next_image_handle, 0, 0))) {
Log(1, L"HackBGRT: Failed to start %s.\n", config.boot_path); Log(1, L"Failed to start %s.\n", config.boot_path);
goto fail; goto fail;
} }
Log(1, L"HackBGRT: Started %s. Why are we still here?!\n", config.boot_path); Log(1, L"Started %s. Why are we still here?!\n", config.boot_path);
Log(-1, L"Please check that %s is not actually HackBGRT!\n", config.boot_path); Log(-1, L"Please check that %s is not actually HackBGRT!\n", config.boot_path);
goto fail; goto fail;