Detect the appropriate binary and load it

This commit is contained in:
Takumi Sueda 2022-05-05 22:59:40 +09:00
parent 5e107add0a
commit 39e86e4af0
2 changed files with 101 additions and 26 deletions

View File

@ -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...");

74
models.h Normal file
View File

@ -0,0 +1,74 @@
#include <map>
#include <string>
const std::map<std::wstring, std::wstring> 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
};