2016-10-10 01:34:53 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Luma3DS
|
2020-04-25 14:26:21 +02:00
|
|
|
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
2016-10-10 01:34:53 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2017-06-05 02:02:04 +02:00
|
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
|
|
* author attributions in that material or in the Appropriate Legal
|
|
|
|
* Notices displayed by works containing it.
|
|
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
|
|
* or requiring that modified versions of such material be marked in
|
|
|
|
* reasonable ways as different from the original version.
|
2016-10-10 01:34:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "emunand.h"
|
|
|
|
#include "fs.h"
|
|
|
|
#include "firm.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "exceptions.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "buttons.h"
|
|
|
|
#include "pin.h"
|
2017-02-08 12:34:07 +01:00
|
|
|
#include "crypto.h"
|
2017-05-18 01:05:56 +02:00
|
|
|
#include "memory.h"
|
2017-05-23 02:44:04 +02:00
|
|
|
#include "screen.h"
|
2019-03-13 16:34:11 +01:00
|
|
|
#include "i2c.h"
|
2017-08-28 14:46:18 +02:00
|
|
|
#include "fatfs/sdmmc/sdmmc.h"
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2019-03-15 20:36:20 +01:00
|
|
|
extern u8 __itcm_start__[], __itcm_lma__[], __itcm_bss_start__[], __itcm_end__[];
|
|
|
|
|
2016-10-10 01:34:53 +02:00
|
|
|
extern CfgData configData;
|
2017-04-13 03:38:36 +02:00
|
|
|
extern ConfigurationStatus needConfig;
|
2016-10-10 01:34:53 +02:00
|
|
|
extern FirmwareSource firmSource;
|
|
|
|
|
2017-08-21 19:32:39 +02:00
|
|
|
bool isSdMode;
|
2018-04-05 23:20:30 +02:00
|
|
|
u16 launchedPath[80+1];
|
2017-08-20 17:00:47 +02:00
|
|
|
BootType bootType;
|
2017-05-18 01:05:56 +02:00
|
|
|
|
2017-05-23 16:11:39 +02:00
|
|
|
void main(int argc, char **argv, u32 magicWord)
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2017-08-20 16:08:54 +02:00
|
|
|
bool isFirmProtEnabled,
|
|
|
|
isSafeMode = false,
|
2018-08-21 18:57:45 +02:00
|
|
|
needToInitSd = false,
|
2017-08-21 19:32:39 +02:00
|
|
|
isNoForceFlagSet = false,
|
2019-03-15 20:36:20 +01:00
|
|
|
isInvalidLoader = false,
|
2017-08-21 19:32:39 +02:00
|
|
|
isNtrBoot;
|
2016-10-10 01:34:53 +02:00
|
|
|
FirmwareType firmType;
|
|
|
|
FirmwareSource nandType;
|
2017-08-20 16:08:54 +02:00
|
|
|
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
|
|
|
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
2019-03-15 21:43:12 +01:00
|
|
|
u32 firmlaunchTidLow = 0;
|
2019-03-13 16:34:11 +01:00
|
|
|
|
2017-08-20 16:08:54 +02:00
|
|
|
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
2017-08-21 19:32:39 +02:00
|
|
|
isNtrBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1];
|
2018-06-14 18:13:57 +02:00
|
|
|
|
2017-08-20 16:08:54 +02:00
|
|
|
if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal (B9S) boot
|
2017-05-18 01:05:56 +02:00
|
|
|
{
|
2017-08-21 19:32:39 +02:00
|
|
|
bootType = isNtrBoot ? B9SNTR : B9S;
|
|
|
|
|
2017-05-23 16:11:39 +02:00
|
|
|
u32 i;
|
2018-04-05 23:20:30 +02:00
|
|
|
for(i = 0; i < sizeof(launchedPath)/2 - 1 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16
|
2017-05-23 16:11:39 +02:00
|
|
|
launchedPath[i] = argv[0][i];
|
|
|
|
launchedPath[i] = 0;
|
|
|
|
}
|
|
|
|
else if(magicWord == 0xBABE && argc == 2) //Firmlaunch
|
|
|
|
{
|
2017-08-21 19:32:39 +02:00
|
|
|
bootType = FIRMLAUNCH;
|
|
|
|
|
2017-05-23 16:11:39 +02:00
|
|
|
u32 i;
|
|
|
|
u16 *p = (u16 *)argv[0];
|
2018-04-05 23:20:30 +02:00
|
|
|
for(i = 0; i < sizeof(launchedPath)/2 - 1 && p[i] != 0; i++)
|
2017-05-23 16:11:39 +02:00
|
|
|
launchedPath[i] = p[i];
|
|
|
|
launchedPath[i] = 0;
|
2019-03-15 20:36:20 +01:00
|
|
|
|
2019-03-15 21:43:12 +01:00
|
|
|
for(i = 0; i < 8; i++)
|
|
|
|
firmlaunchTidLow = (argv[1][2 * i] > '9' ? argv[1][2 * i] - 'a' + 10 : argv[1][2 * i] - '0') | (firmlaunchTidLow << 4);
|
2017-05-23 16:11:39 +02:00
|
|
|
}
|
2017-08-20 16:08:54 +02:00
|
|
|
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
2017-05-24 15:18:31 +02:00
|
|
|
{
|
2017-08-21 19:32:39 +02:00
|
|
|
if(isNtrBoot) bootType = NTR;
|
|
|
|
else
|
2017-08-20 16:08:54 +02:00
|
|
|
{
|
2017-08-21 19:32:39 +02:00
|
|
|
const char *path;
|
|
|
|
if(!((vu8 *)bootPartitionsStatus)[2])
|
|
|
|
{
|
|
|
|
bootType = FIRM0;
|
|
|
|
path = "firm0:";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bootType = FIRM1;
|
|
|
|
path = "firm1:";
|
|
|
|
}
|
|
|
|
|
|
|
|
for(u32 i = 0; i < 7; i++) //Copy and convert the path to UTF-16
|
|
|
|
launchedPath[i] = path[i];
|
2017-08-20 16:08:54 +02:00
|
|
|
}
|
2017-08-21 19:32:39 +02:00
|
|
|
|
|
|
|
setupKeyslots();
|
2017-05-24 15:18:31 +02:00
|
|
|
}
|
2019-03-15 20:36:20 +01:00
|
|
|
else isInvalidLoader = true;
|
|
|
|
|
|
|
|
// Set up the additional sections, overwrites argc
|
|
|
|
memcpy(__itcm_start__, __itcm_lma__, __itcm_bss_start__ - __itcm_start__);
|
|
|
|
memset(__itcm_bss_start__, 0, __itcm_end__ - __itcm_bss_start__);
|
|
|
|
I2C_init();
|
|
|
|
if(isInvalidLoader) error("Launched using an unsupported loader.");
|
|
|
|
|
|
|
|
installArm9Handlers();
|
2017-05-18 01:05:56 +02:00
|
|
|
|
2017-05-20 02:08:25 +02:00
|
|
|
if(memcmp(launchedPath, u"sdmc", 8) == 0)
|
2017-05-18 01:05:56 +02:00
|
|
|
{
|
|
|
|
if(!mountFs(true, false)) error("Failed to mount SD.");
|
|
|
|
isSdMode = true;
|
|
|
|
}
|
2017-05-20 02:08:25 +02:00
|
|
|
else if(memcmp(launchedPath, u"nand", 8) == 0)
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2017-05-20 04:38:23 +02:00
|
|
|
if(!mountFs(false, true)) error("Failed to mount CTRNAND.");
|
2016-10-10 01:34:53 +02:00
|
|
|
isSdMode = false;
|
|
|
|
}
|
2017-08-21 19:32:39 +02:00
|
|
|
else if(bootType == NTR || memcmp(launchedPath, u"firm", 8) == 0)
|
2017-05-24 15:18:31 +02:00
|
|
|
{
|
|
|
|
if(mountFs(true, false)) isSdMode = true;
|
|
|
|
else if(mountFs(false, true)) isSdMode = false;
|
|
|
|
else error("Failed to mount SD and CTRNAND.");
|
2017-08-21 19:32:39 +02:00
|
|
|
|
|
|
|
if(bootType == NTR)
|
|
|
|
{
|
|
|
|
while(HID_PAD & NTRBOOT_BUTTONS);
|
|
|
|
loadHomebrewFirm(0);
|
|
|
|
mcuPowerOff();
|
|
|
|
}
|
2017-05-24 15:18:31 +02:00
|
|
|
}
|
2017-05-18 01:05:56 +02:00
|
|
|
else
|
2017-05-20 00:18:41 +02:00
|
|
|
{
|
2017-05-20 04:38:23 +02:00
|
|
|
char mountPoint[5];
|
|
|
|
|
|
|
|
u32 i;
|
|
|
|
for(i = 0; i < 4 && launchedPath[i] != u':'; i++)
|
2017-05-20 02:08:25 +02:00
|
|
|
mountPoint[i] = (char)launchedPath[i];
|
2017-05-20 04:38:23 +02:00
|
|
|
mountPoint[i] = 0;
|
|
|
|
|
2017-05-23 17:13:43 +02:00
|
|
|
error("Launched from an unsupported location: %s.", mountPoint);
|
2017-05-20 00:18:41 +02:00
|
|
|
}
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2019-04-19 10:01:00 +02:00
|
|
|
detectAndProcessExceptionDumps();
|
|
|
|
|
2016-10-10 01:34:53 +02:00
|
|
|
//Attempt to read the configuration file
|
|
|
|
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
|
|
|
|
|
|
|
|
//Determine if this is a firmlaunch boot
|
2017-08-21 19:32:39 +02:00
|
|
|
if(bootType == FIRMLAUNCH)
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2016-10-13 18:45:38 +02:00
|
|
|
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2019-03-15 21:43:12 +01:00
|
|
|
switch(firmlaunchTidLow & 0xF)
|
2016-11-12 01:49:52 +01:00
|
|
|
{
|
2019-03-15 21:43:12 +01:00
|
|
|
case 2:
|
|
|
|
firmType = (FirmwareType)((firmlaunchTidLow >> 8) & 0xF);
|
2016-11-12 01:49:52 +01:00
|
|
|
break;
|
2019-03-15 21:43:12 +01:00
|
|
|
case 3:
|
2016-11-12 01:49:52 +01:00
|
|
|
firmType = SAFE_FIRM;
|
|
|
|
break;
|
2019-03-15 21:43:12 +01:00
|
|
|
case 1:
|
2016-11-12 01:49:52 +01:00
|
|
|
firmType = SYSUPDATER_FIRM;
|
|
|
|
break;
|
|
|
|
}
|
2016-10-10 01:34:53 +02:00
|
|
|
|
|
|
|
nandType = (FirmwareSource)BOOTCFG_NAND;
|
|
|
|
firmSource = (FirmwareSource)BOOTCFG_FIRM;
|
2017-08-20 16:08:54 +02:00
|
|
|
isFirmProtEnabled = !BOOTCFG_NTRCARDBOOT;
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
goto boot;
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
firmType = NATIVE_FIRM;
|
2017-08-20 17:00:47 +02:00
|
|
|
isFirmProtEnabled = bootType != NTR;
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
//Get pressed buttons
|
|
|
|
u32 pressed = HID_PAD;
|
|
|
|
|
|
|
|
//If it's a MCU reboot, try to force boot options
|
2017-05-17 14:53:29 +02:00
|
|
|
if(CFG_BOOTENV && needConfig != CREATE_CONFIGURATION)
|
2016-11-15 19:29:48 +01:00
|
|
|
{
|
|
|
|
//Always force a SysNAND boot when quitting AGB_FIRM
|
|
|
|
if(CFG_BOOTENV == 7)
|
|
|
|
{
|
|
|
|
nandType = FIRMWARE_SYSNAND;
|
|
|
|
firmSource = (BOOTCFG_NAND != 0) == (BOOTCFG_FIRM != 0) ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM;
|
|
|
|
|
2017-04-14 14:54:31 +02:00
|
|
|
//Prevent multiple boot options-forcing
|
2017-06-22 15:49:23 +02:00
|
|
|
if(nandType != BOOTCFG_NAND || firmSource != BOOTCFG_FIRM) isNoForceFlagSet = true;
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
goto boot;
|
|
|
|
}
|
|
|
|
|
2018-08-21 18:57:45 +02:00
|
|
|
//Account for DSiWare soft resets if exiting TWL_FIRM
|
|
|
|
if(CFG_BOOTENV == 3)
|
|
|
|
{
|
|
|
|
static const u8 TLNC[] = {0x54, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x43};
|
|
|
|
if(memcmp((void *)0x20000C00, TLNC, 10) == 0) needToInitSd = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force the last used boot options if autobooting a TWL title, or unless a button is pressed
|
2016-11-15 19:29:48 +01:00
|
|
|
or the no-forcing flag is set */
|
2018-08-21 18:57:45 +02:00
|
|
|
if(needToInitSd || memcmp((void *)0x20000300, "TLNC", 4) == 0 || (!pressed && !BOOTCFG_NOFORCEFLAG))
|
2016-11-15 19:29:48 +01:00
|
|
|
{
|
|
|
|
nandType = (FirmwareSource)BOOTCFG_NAND;
|
|
|
|
firmSource = (FirmwareSource)BOOTCFG_FIRM;
|
|
|
|
|
|
|
|
goto boot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 pinMode = MULTICONFIG(PIN);
|
2020-04-17 02:01:35 +02:00
|
|
|
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT);
|
2017-04-15 15:58:07 +02:00
|
|
|
bool pinExists = pinMode != 0 && verifyPin(pinMode);
|
2016-11-15 19:29:48 +01:00
|
|
|
|
2020-04-17 02:01:35 +02:00
|
|
|
/* If the PIN has been verified, wait to make it easier to press the SAFE_MODE combo or the configuration menu button
|
|
|
|
(if not already pressed, for the latter) */
|
|
|
|
if(pinExists && !shouldLoadConfigMenu)
|
|
|
|
{
|
|
|
|
while(HID_PAD & PIN_BUTTONS);
|
|
|
|
wait(2000ULL);
|
2016-11-15 19:29:48 +01:00
|
|
|
|
2020-04-17 02:01:35 +02:00
|
|
|
//Update pressed buttons
|
|
|
|
pressed = HID_PAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT);
|
2016-11-15 19:29:48 +01:00
|
|
|
if(shouldLoadConfigMenu)
|
|
|
|
{
|
2017-05-20 05:09:48 +02:00
|
|
|
configMenu(pinExists, pinMode);
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
//Update pressed buttons
|
|
|
|
pressed = HID_PAD;
|
|
|
|
}
|
|
|
|
|
2017-05-17 14:53:29 +02:00
|
|
|
if(!CFG_BOOTENV && pressed == SAFE_MODE)
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2016-11-15 19:29:48 +01:00
|
|
|
nandType = FIRMWARE_SYSNAND;
|
|
|
|
firmSource = FIRMWARE_SYSNAND;
|
|
|
|
|
|
|
|
isSafeMode = true;
|
2018-08-21 18:57:45 +02:00
|
|
|
needToInitSd = true;
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
goto boot;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 splashMode = MULTICONFIG(SPLASH);
|
|
|
|
|
|
|
|
if(splashMode == 1 && loadSplash()) pressed = HID_PAD;
|
|
|
|
|
2017-07-06 17:28:26 +02:00
|
|
|
bool autoBootEmu = CONFIG(AUTOBOOTEMU);
|
|
|
|
|
2016-11-15 19:29:48 +01:00
|
|
|
if((pressed & (BUTTON_START | BUTTON_L1)) == BUTTON_START)
|
|
|
|
{
|
2017-06-10 02:39:00 +02:00
|
|
|
loadHomebrewFirm(0);
|
2016-11-15 19:29:48 +01:00
|
|
|
pressed = HID_PAD;
|
|
|
|
}
|
2017-07-06 18:09:18 +02:00
|
|
|
else if((((pressed & SINGLE_PAYLOAD_BUTTONS) || (!autoBootEmu && (pressed & DPAD_BUTTONS))) && !(pressed & (BUTTON_L1 | BUTTON_R1))) ||
|
|
|
|
(((pressed & L_PAYLOAD_BUTTONS) || (autoBootEmu && (pressed & DPAD_BUTTONS))) && (pressed & BUTTON_L1))) loadHomebrewFirm(pressed);
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2020-04-17 02:01:35 +02:00
|
|
|
if(splashMode == 2 && loadSplash()) pressed = HID_PAD;
|
|
|
|
|
|
|
|
//Check SAFE_MODE combo again
|
|
|
|
if(!CFG_BOOTENV && pressed == SAFE_MODE)
|
|
|
|
{
|
|
|
|
nandType = FIRMWARE_SYSNAND;
|
|
|
|
firmSource = FIRMWARE_SYSNAND;
|
|
|
|
|
|
|
|
isSafeMode = true;
|
|
|
|
needToInitSd = true;
|
|
|
|
|
|
|
|
goto boot;
|
|
|
|
}
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2016-11-15 19:29:48 +01:00
|
|
|
//If booting from CTRNAND, always use SysNAND
|
|
|
|
if(!isSdMode) nandType = FIRMWARE_SYSNAND;
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2016-11-15 19:29:48 +01:00
|
|
|
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
|
|
|
|
else if(pressed & BUTTON_R1)
|
|
|
|
{
|
2017-05-17 14:53:29 +02:00
|
|
|
if(CONFIG(USEEMUFIRM))
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2017-05-17 14:53:29 +02:00
|
|
|
nandType = FIRMWARE_SYSNAND;
|
|
|
|
firmSource = FIRMWARE_EMUNAND;
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
2016-11-15 19:29:48 +01:00
|
|
|
else
|
|
|
|
{
|
2017-05-17 14:53:29 +02:00
|
|
|
nandType = FIRMWARE_EMUNAND;
|
|
|
|
firmSource = FIRMWARE_SYSNAND;
|
2016-11-15 19:29:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2016-11-15 19:29:48 +01:00
|
|
|
/* Else, boot the NAND the user set to autoboot or the opposite one, depending on L,
|
|
|
|
with their own FIRM */
|
2017-07-06 17:28:26 +02:00
|
|
|
else firmSource = nandType = (autoBootEmu == ((pressed & BUTTON_L1) == BUTTON_L1)) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND;
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
//If we're booting EmuNAND or using EmuNAND FIRM, determine which one from the directional pad buttons, or otherwise from the config
|
|
|
|
if(nandType == FIRMWARE_EMUNAND || firmSource == FIRMWARE_EMUNAND)
|
|
|
|
{
|
|
|
|
FirmwareSource tempNand;
|
|
|
|
switch(pressed & DPAD_BUTTONS)
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2016-11-15 19:29:48 +01:00
|
|
|
case BUTTON_UP:
|
|
|
|
tempNand = FIRMWARE_EMUNAND;
|
|
|
|
break;
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
tempNand = FIRMWARE_EMUNAND2;
|
|
|
|
break;
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
tempNand = FIRMWARE_EMUNAND3;
|
|
|
|
break;
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
tempNand = FIRMWARE_EMUNAND4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tempNand = (FirmwareSource)(1 + MULTICONFIG(DEFAULTEMU));
|
|
|
|
break;
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
2016-11-15 19:29:48 +01:00
|
|
|
|
|
|
|
if(nandType == FIRMWARE_EMUNAND) nandType = tempNand;
|
|
|
|
else firmSource = tempNand;
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
|
|
|
|
2016-11-15 19:29:48 +01:00
|
|
|
boot:
|
|
|
|
|
2016-10-10 01:34:53 +02:00
|
|
|
//If we need to boot EmuNAND, make sure it exists
|
|
|
|
if(nandType != FIRMWARE_SYSNAND)
|
|
|
|
{
|
2017-05-26 03:07:39 +02:00
|
|
|
locateEmuNand(&nandType);
|
2016-10-10 01:34:53 +02:00
|
|
|
if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND;
|
2017-08-28 14:46:18 +02:00
|
|
|
else if((*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) //Make sure the SD card isn't write protected
|
|
|
|
error("The SD card is locked, EmuNAND can not be used.\nPlease turn the write protection switch off.");
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Same if we're using EmuNAND as the FIRM source
|
|
|
|
else if(firmSource != FIRMWARE_SYSNAND)
|
2017-05-26 03:07:39 +02:00
|
|
|
locateEmuNand(&firmSource);
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2017-08-27 16:24:04 +02:00
|
|
|
if(bootType != FIRMLAUNCH)
|
2016-10-10 01:34:53 +02:00
|
|
|
{
|
2017-08-20 17:00:47 +02:00
|
|
|
configData.bootConfig = ((bootType == NTR ? 1 : 0) << 7) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType;
|
2017-04-13 03:38:36 +02:00
|
|
|
writeConfig(false);
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES);
|
2017-06-10 02:39:00 +02:00
|
|
|
u32 firmVersion = loadNintendoFirm(&firmType, firmSource, loadFromStorage, isSafeMode);
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2017-06-09 02:31:14 +02:00
|
|
|
bool doUnitinfoPatch = CONFIG(PATCHUNITINFO);
|
2018-05-24 00:55:38 +02:00
|
|
|
u32 res = 0;
|
2016-10-10 01:34:53 +02:00
|
|
|
switch(firmType)
|
|
|
|
{
|
|
|
|
case NATIVE_FIRM:
|
2018-08-21 18:57:45 +02:00
|
|
|
res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isFirmProtEnabled, needToInitSd, doUnitinfoPatch);
|
2016-10-10 01:34:53 +02:00
|
|
|
break;
|
|
|
|
case TWL_FIRM:
|
2017-05-23 02:44:04 +02:00
|
|
|
res = patchTwlFirm(firmVersion, loadFromStorage, doUnitinfoPatch);
|
2016-10-10 01:34:53 +02:00
|
|
|
break;
|
|
|
|
case AGB_FIRM:
|
2017-06-28 20:22:58 +02:00
|
|
|
res = patchAgbFirm(loadFromStorage, doUnitinfoPatch);
|
2016-10-10 01:34:53 +02:00
|
|
|
break;
|
2016-11-12 01:49:52 +01:00
|
|
|
case SAFE_FIRM:
|
|
|
|
case SYSUPDATER_FIRM:
|
|
|
|
case NATIVE_FIRM1X2X:
|
2017-06-09 02:31:14 +02:00
|
|
|
res = patch1x2xNativeAndSafeFirm();
|
2016-11-12 01:49:52 +01:00
|
|
|
break;
|
2016-10-10 01:34:53 +02:00
|
|
|
}
|
|
|
|
|
2017-05-23 17:13:43 +02:00
|
|
|
if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
|
2016-10-10 01:34:53 +02:00
|
|
|
|
2017-08-21 19:32:39 +02:00
|
|
|
if(bootType != FIRMLAUNCH) deinitScreens();
|
2017-05-23 02:44:04 +02:00
|
|
|
launchFirm(0, NULL);
|
2017-02-08 12:34:07 +01:00
|
|
|
}
|