2018-12-17 12:01:10 -08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
#include "lp0.h"
|
2018-12-17 12:39:35 -08:00
|
|
|
#include "mc.h"
|
2018-12-17 12:01:10 -08:00
|
|
|
#include "pmc.h"
|
2018-12-17 13:22:08 -08:00
|
|
|
#include "misc.h"
|
2018-12-17 13:58:28 -08:00
|
|
|
#include "fuse.h"
|
2018-12-17 14:40:30 -08:00
|
|
|
#include "car.h"
|
|
|
|
#include "emc.h"
|
2018-12-17 12:01:10 -08:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
void reboot(void) {
|
|
|
|
/* Write MAIN_RST */
|
|
|
|
APBDEV_PMC_CNTRL_0 = 0x10;
|
|
|
|
while (true) {
|
|
|
|
/* Wait for reboot. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lp0_entry_main(warmboot_metadata_t *meta) {
|
2018-12-17 13:58:28 -08:00
|
|
|
const uint32_t target_firmware = meta->target_firmware;
|
2018-12-17 12:01:10 -08:00
|
|
|
/* Before doing anything else, ensure some sanity. */
|
2018-12-17 13:58:28 -08:00
|
|
|
if (meta->magic != WARMBOOT_MAGIC || target_firmware > ATMOSPHERE_TARGET_FIRMWARE_MAX) {
|
2018-12-17 12:01:10 -08:00
|
|
|
reboot();
|
|
|
|
}
|
|
|
|
|
2018-12-17 12:39:35 -08:00
|
|
|
/* [4.0.0+] First thing warmboot does is disable BPMP access to memory. */
|
2018-12-17 13:58:28 -08:00
|
|
|
if (target_firmware >= ATMOSPHERE_TARGET_FIRMWARE_400) {
|
2018-12-17 12:39:35 -08:00
|
|
|
disable_bpmp_access_to_dram();
|
|
|
|
}
|
|
|
|
|
2018-12-17 13:22:08 -08:00
|
|
|
/* Configure debugging depending on FUSE_PRODUCTION_MODE */
|
2018-12-17 14:40:30 -08:00
|
|
|
misc_configure_device_dbg_settings();
|
2018-12-17 13:22:08 -08:00
|
|
|
|
2018-12-17 13:58:28 -08:00
|
|
|
/* Check for downgrade. */
|
|
|
|
/* NOTE: We implemented this as "return false" */
|
|
|
|
if (fuse_check_downgrade_status()) {
|
|
|
|
reboot();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target_firmware >= ATMOSPHERE_TARGET_FIRMWARE_300) {
|
|
|
|
/* Nintendo's firmware checks APBDEV_PMC_SECURE_SCRATCH32_0 against a per-warmboot binary value here. */
|
|
|
|
/* We won't bother with that. */
|
|
|
|
if (false /* APBDEV_PMC_SECURE_SCRATCH32_0 == WARMBOOT_MAGIC_NUMBER */) {
|
|
|
|
reboot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Check that we're running at the correct physical address. */
|
|
|
|
|
|
|
|
/* Setup fuses, disable bypass. */
|
|
|
|
fuse_configure_fuse_bypass();
|
|
|
|
|
2018-12-17 14:40:30 -08:00
|
|
|
/* Configure oscillators/timing in CAR. */
|
|
|
|
car_configure_oscillators();
|
|
|
|
|
|
|
|
/* Restore RAM configuration. */
|
|
|
|
misc_restore_ram_svop();
|
|
|
|
emc_configure_pmacro_training();
|
2018-12-17 13:58:28 -08:00
|
|
|
|
2018-12-17 12:01:10 -08:00
|
|
|
/* TODO: stuff */
|
|
|
|
|
|
|
|
while (true) { /* TODO: Halt BPMP */ }
|
|
|
|
}
|
|
|
|
|
|
|
|
|