From 00bcb28e49b52aef9fe9564942e9c7df511706cf Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Thu, 5 May 2022 22:57:12 +0900 Subject: [PATCH 1/5] Increase the row height +2px to fix overlap --- BrainLILODrv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BrainLILODrv.cpp b/BrainLILODrv.cpp index bc035be..1e96fd4 100644 --- a/BrainLILODrv.cpp +++ b/BrainLILODrv.cpp @@ -85,7 +85,7 @@ static void outputDebugMessage(const wchar_t *format, ...) va_end(args); OutputDebugString(buffer); - ExtTextOut(GetDC(NULL), 0, row * 12, ETO_CLIPPED, &rcScreen, + ExtTextOut(GetDC(NULL), 0, row * 14, ETO_CLIPPED, &rcScreen, buffer, wcslen(buffer), NULL); row++; From 5e107add0a0fa06ba7aa7e5eabde4bc8af18174a Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Thu, 5 May 2022 22:57:51 +0900 Subject: [PATCH 2/5] Wait 1sec before jumping to U-Boot --- BrainLILODrv.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BrainLILODrv.cpp b/BrainLILODrv.cpp index 1e96fd4..63ca665 100644 --- a/BrainLILODrv.cpp +++ b/BrainLILODrv.cpp @@ -180,6 +180,8 @@ __attribute__((noreturn)) static DWORD EDNA2_callKernelEntryPoint() outputDebugMessage(L"BrainLILO: injecting code to internal ram"); EDNA2_installPhysicalInvoker(); outputDebugMessage(L"BrainLILO: invoking"); + Sleep(1000); + EDNA2_runPhysicalInvoker(); } From 39e86e4af0dae22dcfa726b4811fa32b25aead47 Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Thu, 5 May 2022 22:59:40 +0900 Subject: [PATCH 3/5] Detect the appropriate binary and load it --- BrainLILODrv.cpp | 53 +++++++++++++++++----------------- models.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 models.h diff --git a/BrainLILODrv.cpp b/BrainLILODrv.cpp index 63ca665..4ab9292 100644 --- a/BrainLILODrv.cpp +++ b/BrainLILODrv.cpp @@ -42,6 +42,7 @@ #define BRAINLILODRV_API __declspec(dllexport) #include "BrainLILODrv.h" +#include "models.h" #define FILE_DEVICE_POWER FILE_DEVICE_ACPI @@ -185,29 +186,19 @@ __attribute__((noreturn)) static DWORD EDNA2_callKernelEntryPoint() EDNA2_runPhysicalInvoker(); } -static void ShowMessage(std::string msg, std::string title, UINT typ) +static void ShowMessage(std::wstring msg, std::wstring title, UINT typ) { - void *bufMsg; - void *bufTitle; - bufMsg = LocalAlloc(LPTR, msg.length() * sizeof(wchar_t)); - bufTitle = LocalAlloc(LPTR, title.length() * sizeof(wchar_t)); - mbstowcs((wchar_t *)bufMsg, msg.c_str(), msg.length()); - mbstowcs((wchar_t *)bufTitle, title.c_str(), title.length()); - MessageBox(NULL, (wchar_t *)bufMsg, (wchar_t *)bufTitle, typ); - LocalFree(bufMsg); - LocalFree(bufTitle); + MessageBox(NULL, msg.c_str(), title.c_str(), typ); } static bool doLinux() { - wchar_t wcBuf[256] = {}; + std::wifstream iVersion; + std::wstring line, model; + std::wregex modelRe(L"[A-Z]{2}-[A-Z0-9]+"); + std::wsmatch match; - std::ifstream iVersion; - std::string line, model; - std::regex modelRe("[A-Z]{2}-[A-Z0-9]+"); - std::smatch match; - - std::string fn("\\Storage Card\\loader\\"); + std::wstring fn(L"\\Storage Card\\loader\\"); HANDLE hUBoot; DWORD wReadSize; @@ -223,20 +214,30 @@ static bool doLinux() if (model.length() == 0) { - outputDebugMessage(L"Failed to match the model name"); - ShowMessage("Failed to match the model name", "BrainLILO", MB_ICONWARNING); + outputDebugMessage(L"BrainLILO: Failed to match the model name"); + MessageBox(NULL, L"Failed to match the model name", L"BrainLILO", MB_ICONWARNING); return false; } - outputDebugMessage(L"BrainLILO: Opening Bootloader file..."); - fn += model + ".bin"; + outputDebugMessage(L"BrainLILO: Internal model name: %s", model.c_str()); - mbstowcs(wcBuf, fn.c_str(), fn.length()); - hUBoot = CreateFile(wcBuf, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + auto iter = models.find(model); + if (iter != models.end()) + { + model = iter->second; + } else { + outputDebugMessage(L"BrainLILO: Internal model name %s is unknown, falling back to u-boot.bin", model.c_str()); + model = L"u-boot.bin"; + } + + fn += model; + outputDebugMessage(L"BrainLILO: Opening Bootloader file: %s", fn.c_str()); + + hUBoot = CreateFile(fn.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hUBoot == INVALID_HANDLE_VALUE) { - outputDebugMessage(L"Could not open the bootloader: %s", wcBuf); - ShowMessage("Could not open the bootloader: " + fn, "BrainLILO", MB_ICONWARNING); + outputDebugMessage(L"BrainLILO: Could not open the bootloader: %s", fn.c_str()); + ShowMessage(L"Could not open the bootloader: " + fn, L"BrainLILO", MB_ICONWARNING); return false; } @@ -249,7 +250,7 @@ static bool doLinux() if (!ReadFile(hUBoot, (void *)0xa0000000, FileSize, &wReadSize, NULL)) { outputDebugMessage(L"Could not read the bootloader"); - ShowMessage("Could not read the bootloader", "BrainLILO", MB_ICONWARNING); + ShowMessage(L"Could not read the bootloader", L"BrainLILO", MB_ICONWARNING); return false; } outputDebugMessage(L"BrainLILO: Bootloader copied! Closing file handle..."); diff --git a/models.h b/models.h new file mode 100644 index 0000000..45512d1 --- /dev/null +++ b/models.h @@ -0,0 +1,74 @@ +#include +#include + +const std::map models = { + {L"ED-CD2", L"gen1.bin"}, // AC880 + {L"ED-CD2D", L"gen1.bin"}, // AC830 + {L"ED-CD1", L"gen1.bin"}, // TC980 + {L"ED-CD4", L"gen1.bin"}, // GC590 + {L"ED-CD5", L"gen1.bin"}, // AC890 + {L"ED-CD6", L"gen1.bin"}, // AC900 + {L"ED-CD9", L"gen1.bin"}, // GC610 + {L"ED-CD8", L"gen1.bin"}, // AC910 + {L"ED-CD10", L"gen1.bin"}, // AC920 + {L"ED-NJ1", L"gen1.bin"}, // G4000 + {L"ED-NS1", L"gen1.bin"}, // G5000 + {L"ED-NS1", L"gen1.bin"}, // HC1 + {L"ED-NB1", L"gen1.bin"}, // A9000 + {L"ED-NA1", L"gen1.bin"}, // A7000 + {L"ED-NS1P", L"gen1.bin"}, // G5100 + {L"ED-NJ2", L"gen2.bin"}, // G4200 + {L"ED-NH2", L"gen2.bin"}, // G5200 + {L"ED-NH2", L"gen2.bin"}, // HC2 + {L"ED-NB2", L"gen2.bin"}, // A9200 + {L"ED-NA2", L"gen2.bin"}, // A7200 + {L"ED-NA3", L"gen2.bin"}, // A7300 + {L"SD-GH1", L"gen2.bin"}, // GX500 + {L"ED-NH3", L"gen2.bin"}, // G5300 + {L"ED-NH3", L"gen2.bin"}, // HC3 + {L"ED-NB3", L"gen2.bin"}, // A9300 + {L"ED-NR3", L"gen2.bin"}, // A9100 + {L"SD-GJ1", L"gen2.bin"}, // GX300 + {L"ED-NQ3", L"gen2.bin"}, // A7400 + {L"ED-SJ1", L"gen3_1.bin"}, // SJ1 + {L"ED-SH1", L"gen3_1.bin"}, // SH1 + {L"ED-HC4", L"gen3_1.bin"}, // HC4 + {L"ED-SB1", L"gen3_1.bin"}, // SB1 + {L"ED-SA1", L"gen3_1.bin"}, // SA1 + {L"ED-SR1", L"gen3_1.bin"}, // SR1 + {L"ED-SJ2", L"gen3_2.bin"}, // SJ2 + {L"ED-SH2", L"gen3_2.bin"}, // SH2 + {L"ED-HC5", L"gen3_2.bin"}, // HC5 + {L"ED-SB2", L"gen3_2.bin"}, // SB2 + {L"ED-SA2", L"gen3_2.bin"}, // SA2 + {L"ED-SJ3", L"gen3_3.bin"}, // SJ3 + {L"ED-SH3", L"gen3_3.bin"}, // SH3 + {L"ED-HC6", L"gen3_3.bin"}, // HC6 + {L"ED-SB3", L"gen3_3.bin"}, // SB3 + {L"ED-SA3", L"gen3_3.bin"}, // SA3 + {L"ED-SJ4", L"gen3_4.bin"}, // SJ4 + {L"ED-SH4", L"gen3_4.bin"}, // SH4 + {L"ED-H77", L"gen3_4.bin"}, // H7700 + {L"ED-SB4", L"gen3_4.bin"}, // SB4 + {L"ED-SA4", L"gen3_4.bin"}, // SA4 + {L"ED-SR2", L"gen3_4.bin"}, // SR2 + {L"ED-SJ5", L"gen3_5.bin"}, // SJ5 + {L"ED-SH5", L"gen3_5.bin"}, // SH5 + {L"ED-H78", L"gen3_5.bin"}, // H7800 + {L"ED-SB5", L"gen3_5.bin"}, // SB5 + {L"ED-SA5", L"gen3_5.bin"}, // SA5 + {L"ED-AJ1", L"gen3_5.bin"}, // AJ1 + {L"ED-AA1", L"gen3_5.bin"}, // AA1 + {L"ED-SH6", L"gen3_6.bin"}, // SH6 + {L"ED-SS6", L"gen3_6.bin"}, // SS6 + {L"ED-H80", L"gen3_6.bin"}, // H8000 + {L"ED-SB6", L"gen3_6.bin"}, // SB6 + {L"ED-AJ2", L"gen3_6.bin"}, // AJ2 + {L"ED-AA2", L"gen3_6.bin"}, // AA2 + {L"ED-SH7", L"gen3_7.bin"}, // SH7 + {L"ED-SS7", L"gen3_7.bin"}, // SS7 + {L"ED-H91", L"gen3_7.bin"}, // H9100 + {L"ED-H81", L"gen3_7.bin"}, // H8100 + {L"ED-SB7", L"gen3_7.bin"}, // SB7 + {L"ED-SR3", L"gen3_7.bin"}, // SR3 +}; From f2bb98655ab12cf81a70d9af3fcdb2fd78eff3a3 Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Thu, 5 May 2022 23:00:03 +0900 Subject: [PATCH 4/5] Change the prefix to the default prefix of cegcc-build --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae75a59..ccdf195 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION_MAJOR=2 VERSION_MINOR=0 VERSION_PATCH=0 -PREFIX?=/opt/mingw32ce/bin +PREFIX?=/opt/cegcc CC=$(PREFIX)/bin/arm-mingw32ce-gcc CXX=$(PREFIX)/bin/arm-mingw32ce-g++ From 81292bf242ce129a2f6d43901d1c53652482063c Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Thu, 5 May 2022 23:00:24 +0900 Subject: [PATCH 5/5] Enable optimization to avoid a link error --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ccdf195..8dd235d 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ DLLFLAGS=-DEV_PLATFORM_WIN32 -DUNICODE -D_UNICODE -DEV_UNSAFE_SWPRINTF -mwin32 \ -shared DRVFLAGS= -DEV_PLATFORM_WIN32 -DUNICODE -D_UNICODE -DEV_UNSAFE_SWPRINTF -mwin32 \ --O0 -mcpu=arm926ej-s -D_WIN32_WCE=0x600 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \ +-O2 -mcpu=arm926ej-s -D_WIN32_WCE=0x600 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \ -D_FILE_OFFSET_BITS=64 -DNDEBUG -Wall -static \ -Wl,--image-base,0x100000,--allow-multiple-definition \ -lcoredll -shared