Skip to content

Commit

Permalink
- Make proper use of BS2 header.
Browse files Browse the repository at this point in the history
- Add BS2 image hashes for future use.
  • Loading branch information
Extrems committed Jun 29, 2023
1 parent e48ee74 commit a3b3066
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 468 deletions.
6 changes: 6 additions & 0 deletions cube/swiss/include/gcm.h
Expand Up @@ -64,6 +64,12 @@ typedef struct {
u32 reserved;
} ApploaderHeader __attribute__((aligned(32)));

typedef struct {
u32 bss;
u32 bssLen;
u8 reserved[24];
} BS2Header __attribute__((aligned(32)));

typedef struct {
u32 magic;
u32 version;
Expand Down
4 changes: 2 additions & 2 deletions cube/swiss/source/aram/sidestep.c
Expand Up @@ -461,7 +461,7 @@ int ELFtoARAM(unsigned char *elf, char *argz, size_t argz_len)
return 1;
}

int BINtoARAM(unsigned char *bin, int len, unsigned int entrypoint)
int BINtoARAM(unsigned char *bin, size_t len, unsigned int entrypoint, unsigned int minaddress)
{
/*** Make sure ARAM subsystem is alive! ***/
AR_Reset();
Expand All @@ -472,7 +472,7 @@ int BINtoARAM(unsigned char *bin, int len, unsigned int entrypoint)
ARAMPut(bin, (char *) ARAMSTART, len);

/*** Now go run it ***/
ARAMRun(entrypoint, entrypoint, ARAMSTART, len);
ARAMRun(entrypoint, minaddress, ARAMSTART, len);

/*** Will never return ***/
return 1;
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/aram/sidestep.h
Expand Up @@ -36,7 +36,7 @@ typedef struct {
u32 DOLSize(DOLHEADER *dol);
int DOLtoARAM(unsigned char *dol, char *argz, size_t argz_len);
int ELFtoARAM(unsigned char *elf, char *argz, size_t argz_len);
int BINtoARAM(unsigned char *bin, int len, unsigned int entrypoint);
int BINtoARAM(unsigned char *bin, size_t len, unsigned int entrypoint, unsigned int minaddress);

#endif
#endif
15 changes: 8 additions & 7 deletions cube/swiss/source/devices/system/deviceHandler-SYS.c
Expand Up @@ -159,23 +159,24 @@ bool load_rom_ipl(DEVICEHANDLER_INTERFACE* device, void** buffer, unsigned int*
file_handle* file = calloc(1, sizeof(file_handle));
concat_path(file->name, device->initial->name, "swiss/patches/ipl.bin");

u32 bs2Header[8] ATTRIBUTE_ALIGN(32);
BS2Header bs2Header;
device->seekFile(file, 0x800, DEVICE_HANDLER_SEEK_SET);
if(device->readFile(file, bs2Header, sizeof(bs2Header)) == sizeof(bs2Header)) {
descrambler(0x800, bs2Header, sizeof(bs2Header));
if(device->readFile(file, &bs2Header, sizeof(BS2Header)) == sizeof(BS2Header)) {
descrambler(0x800, &bs2Header, sizeof(BS2Header));

if(in_range(bs2Header[0], 0x81300000, 0x814AF6E0)) {
u32 sizeToRead = (bs2Header[0] - 0x81300000 + 31) & ~31;
if(in_range(bs2Header.bss, 0x81300000, 0x814AF6E0)) {
u32 sizeToRead = (bs2Header.bss - 0x812FFFE0 + 31) & ~31;
void* bs2Image = memalign(32, sizeToRead);

if(bs2Image) {
device->seekFile(file, 0x800, DEVICE_HANDLER_SEEK_SET);
if(device->readFile(file, bs2Image, sizeToRead) == sizeToRead) {
device->closeFile(file);
free(file);

descrambler(0x820, bs2Image, sizeToRead);
descrambler(0x800, bs2Image, sizeToRead);
*buffer = bs2Image;
*length = sizeToRead;
*length = bs2Header.bss - 0x812FFFE0;
return true;
}
free(bs2Image);
Expand Down
31 changes: 21 additions & 10 deletions cube/swiss/source/nkit.c
Expand Up @@ -32,16 +32,27 @@ static const struct {
uint32_t size;
uint64_t hash;
} firm_dat[] = {
{ "GCLoader_0.9.0.beta.dol", 482720, 0x1EA769DDEC6A4D4A },
{ "GCLoader_0.10.0.beta.dol", 482816, 0xD2C965F3FBF90CE0 },
{ "GCLoader_Updater_1.0.0.dol", 483008, 0x1082431A5EB433EF },
{ "GCLoader_Updater_1.0.1.dol", 491136, 0xD1390E9DF955D140 },
{ "GCLoader_Updater_1.1.0.dol", 837984, 0x23AF174DA5A9370C },
{ "GCLoader_Updater_1.1.1.dol", 837984, 0x80A20D6470A6258F },
{ "GCLoader_Updater_1.1.2.dol", 837984, 0x41181F74E7E6E517 },
{ "GCLoader_Updater_2.0.0.BETA.dol", 838240, 0xDDB903C9CD1BCFAA },
{ "GCLoader_Updater_2.0.0.dol", 838240, 0xDCF7E6BE86E334A9 },
{ "GCLoader_Updater_2.0.1.BETA.dol", 1176704, 0x5264440845874534 },
{ "BS2.img", /* gc-npdp-gdev.bin */ 1449848, 0xB5337A8BCA0E5FD8 },
{ "BS2.img", /* gc-npdp-ntsc.bin */ 1448280, 0x4260AD4F5FDF0A5B },
{ "BS2.img", /* gc-npdp-pal.bin */ 1760152, 0xEE52F211A2606E5F },
{ "BS2.img", /* gc-ntsc-10.bin */ 1435200, 0x527D965731D24BED },
{ "BS2.img", /* gc-ntsc-11.bin */ 1583088, 0xBC8BFECC5C10F9C8 },
{ "BS2.img", /* gc-ntsc-12-001.bin */ 1586352, 0xF8D5D0BDB63F6AA0 },
{ "BS2.img", /* gc-ntsc-12-101.bin */ 1587504, 0xB2DF84B4FC5D19C9 },
{ "BS2.img", /* gc-pal-10.bin */ 1763048, 0xFE619244E43783CD },
{ "BS2.img", /* gc-pal-11.bin */ 1561776, 0x42ABF623D3ECE19D },
{ "BS2.img", /* gc-pal-12.bin */ 1766768, 0x730C642334E6899C },
{ "BS2.img", /* gc-tdev.bin */ 1607576, 0xA5B3C22DD481346A },
{ "GCLoader_0.9.0.beta.dol", 482720, 0x1EA769DDEC6A4D4A },
{ "GCLoader_0.10.0.beta.dol", 482816, 0xD2C965F3FBF90CE0 },
{ "GCLoader_Updater_1.0.0.dol", 483008, 0x1082431A5EB433EF },
{ "GCLoader_Updater_1.0.1.dol", 491136, 0xD1390E9DF955D140 },
{ "GCLoader_Updater_1.1.0.dol", 837984, 0x23AF174DA5A9370C },
{ "GCLoader_Updater_1.1.1.dol", 837984, 0x80A20D6470A6258F },
{ "GCLoader_Updater_1.1.2.dol", 837984, 0x41181F74E7E6E517 },
{ "GCLoader_Updater_2.0.0.BETA.dol", 838240, 0xDDB903C9CD1BCFAA },
{ "GCLoader_Updater_2.0.0.dol", 838240, 0xDCF7E6BE86E334A9 },
{ "GCLoader_Updater_2.0.1.BETA.dol", 1176704, 0x5264440845874534 },
};

static const dvddiskid NDDEMO = {
Expand Down

0 comments on commit a3b3066

Please sign in to comment.