mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-15 01:26:34 +00:00
fusee: perform only pmic reboots on mariko
This commit is contained in:
parent
c06f0440fd
commit
557903cfa7
2 changed files with 159 additions and 80 deletions
|
@ -22,9 +22,11 @@
|
|||
#include "fuse.h"
|
||||
#include "pmc.h"
|
||||
#include "timers.h"
|
||||
#include "i2c.h"
|
||||
#include "panic.h"
|
||||
#include "car.h"
|
||||
#include "btn.h"
|
||||
#include "max77620.h"
|
||||
#include "../../../fusee/common/log.h"
|
||||
#include "../../../fusee/common/vsprintf.h"
|
||||
#include "../../../fusee/common/display/video_fb.h"
|
||||
|
@ -37,6 +39,37 @@
|
|||
#undef u8
|
||||
#undef u32
|
||||
|
||||
static bool is_soc_mariko(void) {
|
||||
return fuse_get_soc_type() == 1;
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) static void shutdown_system(bool reboot) {
|
||||
/* Ensure that i2c5 is in a coherent state. */
|
||||
i2c_config(I2C_5);
|
||||
clkrst_reboot(CARDEVICE_I2C5);
|
||||
i2c_init(I2C_5);
|
||||
|
||||
/* Get value, set or clear software reset mask. */
|
||||
uint8_t on_off_2_val = 0;
|
||||
i2c_query(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG2, &on_off_2_val, 1);
|
||||
if (reboot) {
|
||||
on_off_2_val |= MAX77620_ONOFFCNFG2_SFT_RST_WK;
|
||||
} else {
|
||||
on_off_2_val &= ~(MAX77620_ONOFFCNFG2_SFT_RST_WK);
|
||||
}
|
||||
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG2, &on_off_2_val, 1);
|
||||
|
||||
/* Set software reset mask. */
|
||||
uint8_t on_off_1_val = 0;
|
||||
i2c_query(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, &on_off_1_val, 1);
|
||||
on_off_1_val |= MAX77620_ONOFFCNFG1_SFT_RST;
|
||||
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, &on_off_1_val, 1);
|
||||
|
||||
while (true) {
|
||||
/* Wait for reboot. */
|
||||
}
|
||||
}
|
||||
|
||||
extern uint8_t __reboot_start__[], __reboot_end__[];
|
||||
|
||||
void wait(uint32_t microseconds) {
|
||||
|
@ -70,6 +103,10 @@ __attribute__((noreturn)) void pmc_reboot(uint32_t scratch0) {
|
|||
}
|
||||
|
||||
__attribute__((noreturn)) void reboot_to_self(void) {
|
||||
if (is_soc_mariko()) {
|
||||
/* If mariko, we can't reboot to self/payload, so just reboot. */
|
||||
shutdown_system(true);
|
||||
} else {
|
||||
/* Patch SDRAM init to perform an SVC immediately after second write */
|
||||
APBDEV_PMC_SCRATCH45_0 = 0x2E38DFFF;
|
||||
APBDEV_PMC_SCRATCH46_0 = 0x6001DC28;
|
||||
|
@ -106,7 +143,7 @@ __attribute__((noreturn)) void reboot_to_self(void) {
|
|||
while (true) {
|
||||
/* Wait for reboot. */
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void wait_for_button_and_reboot(void) {
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
#include "car.h"
|
||||
#include "timers.h"
|
||||
#include "btn.h"
|
||||
#include "i2c.h"
|
||||
#include "panic.h"
|
||||
#include "max77620.h"
|
||||
#include "../../../fusee/common/log.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -37,6 +39,37 @@
|
|||
#undef u8
|
||||
#undef u32
|
||||
|
||||
static bool is_soc_mariko(void) {
|
||||
return fuse_get_soc_type() == 1;
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) static void shutdown_system(bool reboot) {
|
||||
/* Ensure that i2c5 is in a coherent state. */
|
||||
i2c_config(I2C_5);
|
||||
clkrst_reboot(CARDEVICE_I2C5);
|
||||
i2c_init(I2C_5);
|
||||
|
||||
/* Get value, set or clear software reset mask. */
|
||||
uint8_t on_off_2_val = 0;
|
||||
i2c_query(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG2, &on_off_2_val, 1);
|
||||
if (reboot) {
|
||||
on_off_2_val |= MAX77620_ONOFFCNFG2_SFT_RST_WK;
|
||||
} else {
|
||||
on_off_2_val &= ~(MAX77620_ONOFFCNFG2_SFT_RST_WK);
|
||||
}
|
||||
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG2, &on_off_2_val, 1);
|
||||
|
||||
/* Set software reset mask. */
|
||||
uint8_t on_off_1_val = 0;
|
||||
i2c_query(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, &on_off_1_val, 1);
|
||||
on_off_1_val |= MAX77620_ONOFFCNFG1_SFT_RST;
|
||||
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, &on_off_1_val, 1);
|
||||
|
||||
while (true) {
|
||||
/* Wait for reboot. */
|
||||
}
|
||||
}
|
||||
|
||||
void wait(uint32_t microseconds) {
|
||||
uint32_t old_time = TIMERUS_CNTR_1US_0;
|
||||
while (TIMERUS_CNTR_1US_0 - old_time <= microseconds) {
|
||||
|
@ -67,6 +100,10 @@ __attribute__((noreturn)) void pmc_reboot(uint32_t scratch0) {
|
|||
}
|
||||
|
||||
__attribute__((noreturn)) static void reboot_to_payload(void) {
|
||||
if (is_soc_mariko()) {
|
||||
/* Reboot to payload isn't possible on mariko, so just do normal reboot. */
|
||||
shutdown_system(true);
|
||||
} else {
|
||||
/* Patch SDRAM init to perform an SVC immediately after second write */
|
||||
APBDEV_PMC_SCRATCH45_0 = 0x2E38DFFF;
|
||||
APBDEV_PMC_SCRATCH46_0 = 0x6001DC28;
|
||||
|
@ -82,6 +119,7 @@ __attribute__((noreturn)) static void reboot_to_payload(void) {
|
|||
/* Trigger warm reboot. */
|
||||
pmc_reboot(1 << 0);
|
||||
while (true) { }
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void reboot_to_fusee_primary(void) {
|
||||
|
@ -94,7 +132,10 @@ __attribute__((noreturn)) void reboot_to_fusee_primary(void) {
|
|||
}
|
||||
|
||||
__attribute__((noreturn)) void reboot_to_sept(const void *tsec_fw, size_t tsec_fw_length, const void *stage2, size_t stage2_size) {
|
||||
|
||||
if (is_soc_mariko()) {
|
||||
/* Reboot to sept isn't possible on mariko, so just do normal reboot. */
|
||||
shutdown_system(true);
|
||||
} else {
|
||||
/* Copy tsec firmware. */
|
||||
for (size_t i = 0; i < tsec_fw_length; i += sizeof(uint32_t)) {
|
||||
write32le((void *)0x40010F00, i, read32le(tsec_fw, i));
|
||||
|
@ -121,6 +162,7 @@ __attribute__((noreturn)) void reboot_to_sept(const void *tsec_fw, size_t tsec_f
|
|||
/* Trigger warm reboot. */
|
||||
pmc_reboot(1 << 0);
|
||||
while (true) { }
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void reboot_to_iram_payload(void *payload, size_t payload_size) {
|
||||
|
|
Loading…
Reference in a new issue