Skip to content

Commit 856a4b3

Browse files
PabloMK7TuxSH
authored andcommitted
Put essential files in subfolder with console ID
1 parent 043e2d2 commit 856a4b3

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

arm9/source/fs.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,41 +441,56 @@ static bool backupEssentialFiles(void)
441441
{
442442
size_t sz = sizeof(fileCopyBuffer);
443443

444+
u32 deviceID = *(vu32*)0x01FFB804;
445+
char pathStart[0x20];
446+
sprintf(pathStart, "backups/%08lX/", deviceID);
447+
char fullPath[0x80];
448+
444449
bool ok = true;
445-
ok = ok && fileCopy("nand:/ro/sys/HWCAL0.dat", "backups/HWCAL0.dat", false, fileCopyBuffer, sz);
446-
ok = ok && fileCopy("nand:/ro/sys/HWCAL1.dat", "backups/HWCAL1.dat", false, fileCopyBuffer, sz);
450+
sprintf(fullPath, "%sHWCAL0.dat", pathStart);
451+
ok = ok && fileCopy("nand:/ro/sys/HWCAL0.dat", fullPath, false, fileCopyBuffer, sz);
452+
sprintf(fullPath, "%sHWCAL1.dat", pathStart);
453+
ok = ok && fileCopy("nand:/ro/sys/HWCAL1.dat", fullPath, false, fileCopyBuffer, sz);
447454

448-
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_A", "backups/LocalFriendCodeSeed_A", false, fileCopyBuffer, sz); // often doesn't exist
449-
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_B", "backups/LocalFriendCodeSeed_B", false, fileCopyBuffer, sz);
455+
sprintf(fullPath, "%sLocalFriendCodeSeed_A", pathStart);
456+
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_A", fullPath, false, fileCopyBuffer, sz); // often doesn't exist
457+
sprintf(fullPath, "%sLocalFriendCodeSeed_B", pathStart);
458+
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_B", fullPath, false, fileCopyBuffer, sz);
450459

451-
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_A", "backups/SecureInfo_A", false, fileCopyBuffer, sz);
452-
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_B", "backups/SecureInfo_B", false, fileCopyBuffer, sz); // often doesn't exist
460+
sprintf(fullPath, "%sSecureInfo_A", pathStart);
461+
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_A", fullPath, false, fileCopyBuffer, sz);
462+
sprintf(fullPath, "%sSecureInfo_B", pathStart);
463+
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_B", fullPath, false, fileCopyBuffer, sz); // often doesn't exist
453464

454465
if (!ok) return false;
455466

456467
alignedseqmemcpy(fileCopyBuffer, (const void *)0x10012000, 0x100);
457-
if (getFileSize("backups/otp.bin") != 0x100)
458-
ok = ok && fileWrite(fileCopyBuffer, "backups/otp.bin", 0x100);
468+
sprintf(fullPath, "%sotp.bin", pathStart);
469+
if (getFileSize(fullPath) != 0x100)
470+
ok = ok && fileWrite(fileCopyBuffer, fullPath, 0x100);
459471

460472
if (!ok) return false;
461473

462474
// On dev boards, but not O3DS IS_DEBUGGER, hwcal is on an EEPROM chip accessed via I2C
463475
u8 c = mcuConsoleInfo[0];
464476
if (c == 2 || c == 4 || (ISN3DS && c == 5) || c == 6)
465477
{
478+
sprintf(fullPath, "%sHWCAL_01_EEPROM.dat", pathStart);
466479
I2C_readRegBuf(I2C_DEV_EEPROM, 0, fileCopyBuffer, 0x1000); // Up to two instances of hwcal, with the second one @0x800
467-
if (getFileSize("backups/HWCAL_01_EEPROM.dat") != 0x1000)
468-
ok = ok && fileWrite(fileCopyBuffer, "backups/HWCAL_01_EEPROM.dat", 0x1000);
480+
if (getFileSize(fullPath) != 0x1000)
481+
ok = ok && fileWrite(fileCopyBuffer, fullPath, 0x1000);
469482
}
470483

471484
// B9S bootrom backups
472485
u32 hash[32/4];
473486
sha(hash, (const void *)0x08080000, 0x10000, SHA_256_MODE);
474-
if (memcmp(hash, boot9Sha256, 32) == 0 && getFileSize("backups/boot9.bin") != 0x10000)
475-
ok = ok && fileWrite((const void *)0x08080000, "backups/boot9.bin", 0x10000);
487+
sprintf(fullPath, "%sboot9.bin", pathStart);
488+
if (memcmp(hash, boot9Sha256, 32) == 0 && getFileSize(fullPath) != 0x10000)
489+
ok = ok && fileWrite((const void *)0x08080000, fullPath, 0x10000);
476490
sha(hash, (const void *)0x08090000, 0x10000, SHA_256_MODE);
477-
if (memcmp(hash, boot11Sha256, 32) == 0 && getFileSize("backups/boot11.bin") != 0x10000)
478-
ok = ok && fileWrite((const void *)0x08090000, "backups/boot11.bin", 0x10000);
491+
sprintf(fullPath, "%sboot11.bin", pathStart);
492+
if (memcmp(hash, boot11Sha256, 32) == 0 && getFileSize(fullPath) != 0x10000)
493+
ok = ok && fileWrite((const void *)0x08090000, fullPath, 0x10000);
479494

480495
return ok;
481496
}

0 commit comments

Comments
 (0)