mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +00:00
ams: initial support for 9.0.0
This commit is contained in:
parent
6ee8720028
commit
93d83c5bb9
31 changed files with 374 additions and 123 deletions
Binary file not shown.
Binary file not shown.
|
@ -27,11 +27,12 @@
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_700 8
|
#define ATMOSPHERE_TARGET_FIRMWARE_700 8
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_800 9
|
#define ATMOSPHERE_TARGET_FIRMWARE_800 9
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_810 10
|
#define ATMOSPHERE_TARGET_FIRMWARE_810 10
|
||||||
|
#define ATMOSPHERE_TARGET_FIRMWARE_900 11
|
||||||
|
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_810
|
#define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_900
|
||||||
|
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE_100
|
#define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE_100
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_810
|
#define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_900
|
||||||
|
|
||||||
/* TODO: What should this be, for release? */
|
/* TODO: What should this be, for release? */
|
||||||
#define ATMOSPHERE_TARGET_FIRMWARE_DEFAULT_FOR_DEBUG ATMOSPHERE_TARGET_FIRMWARE_CURRENT
|
#define ATMOSPHERE_TARGET_FIRMWARE_DEFAULT_FOR_DEBUG ATMOSPHERE_TARGET_FIRMWARE_CURRENT
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#define ATMOSPHERE_RELEASE_VERSION_MINOR 9
|
#define ATMOSPHERE_RELEASE_VERSION_MINOR 9
|
||||||
#define ATMOSPHERE_RELEASE_VERSION_MICRO 3
|
#define ATMOSPHERE_RELEASE_VERSION_MICRO 3
|
||||||
|
|
||||||
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR 8
|
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR 9
|
||||||
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR 1
|
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR 0
|
||||||
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO 0
|
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO 0
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -13,7 +13,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void setup_dram_magic_numbers(void) {
|
||||||
void bootup_misc_mmio(void) {
|
void bootup_misc_mmio(void) {
|
||||||
/* Initialize Fuse registers. */
|
/* Initialize Fuse registers. */
|
||||||
fuse_init();
|
fuse_init();
|
||||||
|
|
||||||
/* Verify Security Engine sanity. */
|
/* Verify Security Engine sanity. */
|
||||||
se_set_in_context_save_mode(false);
|
se_set_in_context_save_mode(false);
|
||||||
/* TODO: se_verify_keys_unreadable(); */
|
/* TODO: se_verify_keys_unreadable(); */
|
||||||
|
@ -85,6 +85,9 @@ void bootup_misc_mmio(void) {
|
||||||
setup_dram_magic_numbers();
|
setup_dram_magic_numbers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* On 9.0.0+, Nintendo writes random values to context save scratch here, and locks the SRK scratch. */
|
||||||
|
/* There's no real need for us to do this, so we won't. */
|
||||||
|
|
||||||
/* Mark TMR5, TMR6, TMR7, TMR8, WDT0, WDT1, WDT2 and WDT3 as secure. */
|
/* Mark TMR5, TMR6, TMR7, TMR8, WDT0, WDT1, WDT2 and WDT3 as secure. */
|
||||||
SHARED_TIMER_SECURE_CFG_0 = 0xF1E0;
|
SHARED_TIMER_SECURE_CFG_0 = 0xF1E0;
|
||||||
|
|
||||||
|
@ -111,7 +114,7 @@ void bootup_misc_mmio(void) {
|
||||||
MAKE_MC_REG(MC_SECURITY_CFG1) = 0;
|
MAKE_MC_REG(MC_SECURITY_CFG1) = 0;
|
||||||
MAKE_MC_REG(MC_SECURITY_CFG3) = 3;
|
MAKE_MC_REG(MC_SECURITY_CFG3) = 3;
|
||||||
configure_default_carveouts();
|
configure_default_carveouts();
|
||||||
|
|
||||||
/* Mark registers secure world only. */
|
/* Mark registers secure world only. */
|
||||||
if (exosphere_get_target_firmware() == ATMOSPHERE_TARGET_FIRMWARE_100) {
|
if (exosphere_get_target_firmware() == ATMOSPHERE_TARGET_FIRMWARE_100) {
|
||||||
APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG0_0 = APB_SSER0_SATA_AUX | APB_SSER0_DTV | APB_SSER0_QSPI | APB_SSER0_SATA | APB_SSER0_LA;
|
APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG0_0 = APB_SSER0_SATA_AUX | APB_SSER0_DTV | APB_SSER0_QSPI | APB_SSER0_SATA | APB_SSER0_LA;
|
||||||
|
@ -174,7 +177,7 @@ void bootup_misc_mmio(void) {
|
||||||
(void)MAKE_MC_REG(MC_SMMU_TLB_CONFIG);
|
(void)MAKE_MC_REG(MC_SMMU_TLB_CONFIG);
|
||||||
MAKE_MC_REG(MC_SMMU_CONFIG) = 1; /* Enable SMMU. */
|
MAKE_MC_REG(MC_SMMU_CONFIG) = 1; /* Enable SMMU. */
|
||||||
(void)MAKE_MC_REG(MC_SMMU_TLB_CONFIG);
|
(void)MAKE_MC_REG(MC_SMMU_TLB_CONFIG);
|
||||||
|
|
||||||
/* Clear RESET Vector, setup CPU Secure Boot RESET Vectors. */
|
/* Clear RESET Vector, setup CPU Secure Boot RESET Vectors. */
|
||||||
uint32_t reset_vec;
|
uint32_t reset_vec;
|
||||||
if (exosphere_get_target_firmware() >= ATMOSPHERE_TARGET_FIRMWARE_500) {
|
if (exosphere_get_target_firmware() >= ATMOSPHERE_TARGET_FIRMWARE_500) {
|
||||||
|
@ -202,7 +205,7 @@ void bootup_misc_mmio(void) {
|
||||||
intr_set_enabled(INTERRUPT_ID_SECURITY_ENGINE, 1);
|
intr_set_enabled(INTERRUPT_ID_SECURITY_ENGINE, 1);
|
||||||
intr_set_cpu_mask(INTERRUPT_ID_SECURITY_ENGINE, 8);
|
intr_set_cpu_mask(INTERRUPT_ID_SECURITY_ENGINE, 8);
|
||||||
intr_set_edge_level(INTERRUPT_ID_SECURITY_ENGINE, 0);
|
intr_set_edge_level(INTERRUPT_ID_SECURITY_ENGINE, 0);
|
||||||
|
|
||||||
if (exosphere_get_target_firmware() >= ATMOSPHERE_TARGET_FIRMWARE_400) {
|
if (exosphere_get_target_firmware() >= ATMOSPHERE_TARGET_FIRMWARE_400) {
|
||||||
intr_set_priority(INTERRUPT_ID_ACTIVITY_MONITOR_4X, 0);
|
intr_set_priority(INTERRUPT_ID_ACTIVITY_MONITOR_4X, 0);
|
||||||
intr_set_group(INTERRUPT_ID_ACTIVITY_MONITOR_4X, 0);
|
intr_set_group(INTERRUPT_ID_ACTIVITY_MONITOR_4X, 0);
|
||||||
|
@ -216,7 +219,7 @@ void bootup_misc_mmio(void) {
|
||||||
uart_config(UART_A);
|
uart_config(UART_A);
|
||||||
clkrst_reboot(CARDEVICE_UARTA);
|
clkrst_reboot(CARDEVICE_UARTA);
|
||||||
uart_init(UART_A, 115200);
|
uart_init(UART_A, 115200);
|
||||||
|
|
||||||
intr_register_handler(INTERRUPT_ID_SECURITY_ENGINE, se_operation_completed);
|
intr_register_handler(INTERRUPT_ID_SECURITY_ENGINE, se_operation_completed);
|
||||||
if (exosphere_get_target_firmware() >= ATMOSPHERE_TARGET_FIRMWARE_400) {
|
if (exosphere_get_target_firmware() >= ATMOSPHERE_TARGET_FIRMWARE_400) {
|
||||||
intr_register_handler(INTERRUPT_ID_ACTIVITY_MONITOR_4X, actmon_interrupt_handler);
|
intr_register_handler(INTERRUPT_ID_ACTIVITY_MONITOR_4X, actmon_interrupt_handler);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
@ -32,7 +32,7 @@ bool i2c_read(volatile tegra_i2c_t *regs, uint8_t device, void *dst, size_t dst_
|
||||||
/* Configure I2C pinmux. */
|
/* Configure I2C pinmux. */
|
||||||
void i2c_config(I2CDevice id) {
|
void i2c_config(I2CDevice id) {
|
||||||
volatile tegra_pinmux_t *pinmux = pinmux_get_regs();
|
volatile tegra_pinmux_t *pinmux = pinmux_get_regs();
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case I2C_1:
|
case I2C_1:
|
||||||
pinmux->gen1_i2c_scl = PINMUX_INPUT;
|
pinmux->gen1_i2c_scl = PINMUX_INPUT;
|
||||||
|
@ -74,7 +74,7 @@ void i2c_init(I2CDevice id) {
|
||||||
|
|
||||||
/* Wait a while until BUS_CLEAR_DONE is set. */
|
/* Wait a while until BUS_CLEAR_DONE is set. */
|
||||||
for (unsigned int i = 0; i < 10; i++) {
|
for (unsigned int i = 0; i < 10; i++) {
|
||||||
wait(20000);
|
wait(25);
|
||||||
if (regs->I2C_INTERRUPT_STATUS_REGISTER_0 & 0x800) {
|
if (regs->I2C_INTERRUPT_STATUS_REGISTER_0 & 0x800) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ void i2c_init(I2CDevice id) {
|
||||||
regs->I2C_INTERRUPT_STATUS_REGISTER_0 = int_status;
|
regs->I2C_INTERRUPT_STATUS_REGISTER_0 = int_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets a bit in a PMIC register over I2C during CPU shutdown. */
|
/* Sets a bit in a PMIC register over I2C during CPU shutdown. */
|
||||||
void i2c_send_pmic_cpu_shutdown_cmd(void) {
|
void i2c_send_pmic_cpu_shutdown_cmd(void) {
|
||||||
uint32_t val = 0;
|
uint32_t val = 0;
|
||||||
/* PMIC == Device 4:3C. */
|
/* PMIC == Device 4:3C. */
|
||||||
|
@ -162,7 +162,7 @@ void i2c_load_config(volatile tegra_i2c_t *regs) {
|
||||||
bool i2c_query(I2CDevice id, uint8_t device, uint8_t r, void *dst, size_t dst_size) {
|
bool i2c_query(I2CDevice id, uint8_t device, uint8_t r, void *dst, size_t dst_size) {
|
||||||
volatile tegra_i2c_t *regs = i2c_get_registers_from_id(id);
|
volatile tegra_i2c_t *regs = i2c_get_registers_from_id(id);
|
||||||
uint32_t val = r;
|
uint32_t val = r;
|
||||||
|
|
||||||
/* Write single byte register ID to device. */
|
/* Write single byte register ID to device. */
|
||||||
if (!i2c_write(regs, device, &val, 1)) {
|
if (!i2c_write(regs, device, &val, 1)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -171,12 +171,12 @@ bool i2c_query(I2CDevice id, uint8_t device, uint8_t r, void *dst, size_t dst_si
|
||||||
if (dst_size > 4) {
|
if (dst_size > 4) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i2c_read(regs, device, dst, dst_size);
|
return i2c_read(regs, device, dst, dst_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Writes a value to a register over I2C. */
|
/* Writes a value to a register over I2C. */
|
||||||
bool i2c_send(I2CDevice id, uint8_t device, uint8_t r, void *src, size_t src_size) {
|
bool i2c_send(I2CDevice id, uint8_t device, uint8_t r, void *src, size_t src_size) {
|
||||||
uint32_t val = r;
|
uint32_t val = r;
|
||||||
if (src_size == 0) {
|
if (src_size == 0) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -240,7 +240,7 @@ bool i2c_read(volatile tegra_i2c_t *regs, uint8_t device, void *dst, size_t dst_
|
||||||
while (regs->I2C_I2C_STATUS_0 & 0x100) {
|
while (regs->I2C_I2C_STATUS_0 & 0x100) {
|
||||||
/* Wait until not busy. */
|
/* Wait until not busy. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure success. */
|
/* Ensure success. */
|
||||||
if ((regs->I2C_I2C_STATUS_0 & 0xF) != 0) {
|
if ((regs->I2C_I2C_STATUS_0 & 0xF) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -43,6 +43,7 @@ static const uint8_t mkey_vectors_dev[MASTERKEY_REVISION_MAX][0x10] =
|
||||||
{0x6F, 0xD2, 0x84, 0x1D, 0x05, 0xEC, 0x40, 0x94, 0x5F, 0x18, 0xB3, 0x81, 0x09, 0x98, 0x8D, 0x4E}, /* Master key 05 encrypted with Master key 06. */
|
{0x6F, 0xD2, 0x84, 0x1D, 0x05, 0xEC, 0x40, 0x94, 0x5F, 0x18, 0xB3, 0x81, 0x09, 0x98, 0x8D, 0x4E}, /* Master key 05 encrypted with Master key 06. */
|
||||||
{0x37, 0xAF, 0xAB, 0x35, 0x79, 0x09, 0xD9, 0x48, 0x29, 0xD2, 0xDB, 0xA5, 0xA5, 0xF5, 0x30, 0x19}, /* Master key 06 encrypted with Master key 07. */
|
{0x37, 0xAF, 0xAB, 0x35, 0x79, 0x09, 0xD9, 0x48, 0x29, 0xD2, 0xDB, 0xA5, 0xA5, 0xF5, 0x30, 0x19}, /* Master key 06 encrypted with Master key 07. */
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: Master key 07 encrypted with Master key 08. */
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: Master key 07 encrypted with Master key 08. */
|
||||||
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: Master key 08 encrypted with Master key 09. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Retail unit keys. */
|
/* Retail unit keys. */
|
||||||
|
@ -57,6 +58,7 @@ static const uint8_t mkey_vectors[MASTERKEY_REVISION_MAX][0x10] =
|
||||||
{0x1E, 0x1E, 0x22, 0xC0, 0x5A, 0x33, 0x3C, 0xB9, 0x0B, 0xA9, 0x03, 0x04, 0xBA, 0xDB, 0x07, 0x57}, /* Master key 05 encrypted with Master key 06. */
|
{0x1E, 0x1E, 0x22, 0xC0, 0x5A, 0x33, 0x3C, 0xB9, 0x0B, 0xA9, 0x03, 0x04, 0xBA, 0xDB, 0x07, 0x57}, /* Master key 05 encrypted with Master key 06. */
|
||||||
{0xA4, 0xD4, 0x52, 0x6F, 0xD1, 0xE4, 0x36, 0xAA, 0x9F, 0xCB, 0x61, 0x27, 0x1C, 0x67, 0x65, 0x1F}, /* Master key 06 encrypted with Master key 07. */
|
{0xA4, 0xD4, 0x52, 0x6F, 0xD1, 0xE4, 0x36, 0xAA, 0x9F, 0xCB, 0x61, 0x27, 0x1C, 0x67, 0x65, 0x1F}, /* Master key 06 encrypted with Master key 07. */
|
||||||
{0xEA, 0x60, 0xB3, 0xEA, 0xCE, 0x8F, 0x24, 0x46, 0x7D, 0x33, 0x9C, 0xD1, 0xBC, 0x24, 0x98, 0x29}, /* Master key 07 encrypted with Master key 08. */
|
{0xEA, 0x60, 0xB3, 0xEA, 0xCE, 0x8F, 0x24, 0x46, 0x7D, 0x33, 0x9C, 0xD1, 0xBC, 0x24, 0x98, 0x29}, /* Master key 07 encrypted with Master key 08. */
|
||||||
|
{0x4D, 0xD9, 0x98, 0x42, 0x45, 0x0D, 0xB1, 0x3C, 0x52, 0x0C, 0x9A, 0x44, 0xBB, 0xAD, 0xAF, 0x80}, /* Master key 08 encrypted with Master key 09. */
|
||||||
};
|
};
|
||||||
|
|
||||||
bool check_mkey_revision(unsigned int revision, bool is_retail) {
|
bool check_mkey_revision(unsigned int revision, bool is_retail) {
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
/* This is glue code to enable master key support across versions. */
|
/* This is glue code to enable master key support across versions. */
|
||||||
|
|
||||||
/* TODO: Update to 0xA on release of new master key. */
|
/* TODO: Update to 0xB on release of new master key. */
|
||||||
#define MASTERKEY_REVISION_MAX 0x9
|
#define MASTERKEY_REVISION_MAX 0xA
|
||||||
|
|
||||||
#define MASTERKEY_REVISION_100_230 0x00
|
#define MASTERKEY_REVISION_100_230 0x00
|
||||||
#define MASTERKEY_REVISION_300 0x01
|
#define MASTERKEY_REVISION_300 0x01
|
||||||
|
@ -29,8 +29,9 @@
|
||||||
#define MASTERKEY_REVISION_500_510 0x04
|
#define MASTERKEY_REVISION_500_510 0x04
|
||||||
#define MASTERKEY_REVISION_600_610 0x05
|
#define MASTERKEY_REVISION_600_610 0x05
|
||||||
#define MASTERKEY_REVISION_620 0x06
|
#define MASTERKEY_REVISION_620 0x06
|
||||||
#define MASTERKEY_REVISION_700_800 0x07
|
#define MASTERKEY_REVISION_700_800 0x07
|
||||||
#define MASTERKEY_REVISION_810_CURRENT 0x08
|
#define MASTERKEY_REVISION_810 0x08
|
||||||
|
#define MASTERKEY_REVISION_900_CURRENT 0x09
|
||||||
|
|
||||||
#define MASTERKEY_NUM_NEW_DEVICE_KEYS (MASTERKEY_REVISION_MAX - MASTERKEY_REVISION_400_410)
|
#define MASTERKEY_NUM_NEW_DEVICE_KEYS (MASTERKEY_REVISION_MAX - MASTERKEY_REVISION_400_410)
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,8 @@ static const uint8_t new_device_key_sources[MASTERKEY_NUM_NEW_DEVICE_KEYS][0x10]
|
||||||
{0x70, 0x08, 0x1B, 0x97, 0x44, 0x64, 0xF8, 0x91, 0x54, 0x9D, 0xC6, 0x84, 0x8F, 0x1A, 0xB2, 0xE4}, /* 6.x New Device Key Source. */
|
{0x70, 0x08, 0x1B, 0x97, 0x44, 0x64, 0xF8, 0x91, 0x54, 0x9D, 0xC6, 0x84, 0x8F, 0x1A, 0xB2, 0xE4}, /* 6.x New Device Key Source. */
|
||||||
{0x8E, 0x09, 0x1F, 0x7A, 0xBB, 0xCA, 0x6A, 0xFB, 0xB8, 0x9B, 0xD5, 0xC1, 0x25, 0x9C, 0xA9, 0x17}, /* 6.2.0 New Device Key Source. */
|
{0x8E, 0x09, 0x1F, 0x7A, 0xBB, 0xCA, 0x6A, 0xFB, 0xB8, 0x9B, 0xD5, 0xC1, 0x25, 0x9C, 0xA9, 0x17}, /* 6.2.0 New Device Key Source. */
|
||||||
{0x8F, 0x77, 0x5A, 0x96, 0xB0, 0x94, 0xFD, 0x8D, 0x28, 0xE4, 0x19, 0xC8, 0x16, 0x1C, 0xDB, 0x3D}, /* 7.0.0 New Device Key Source. */
|
{0x8F, 0x77, 0x5A, 0x96, 0xB0, 0x94, 0xFD, 0x8D, 0x28, 0xE4, 0x19, 0xC8, 0x16, 0x1C, 0xDB, 0x3D}, /* 7.0.0 New Device Key Source. */
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: 8.1.0 New Device Key Source to be added on next change-of-keys. */
|
{0x67, 0x62, 0xD4, 0x8E, 0x55, 0xCF, 0xFF, 0x41, 0x31, 0x15, 0x3B, 0x24, 0x0C, 0x7C, 0x07, 0xAE}, /* 8.1.0 New Device Key Source. */
|
||||||
|
{0x4A, 0xC3, 0x4E, 0x14, 0x8B, 0x96, 0x4A, 0xD5, 0xD4, 0x99, 0x73, 0xC4, 0x45, 0xAB, 0x8B, 0x49}, /* 9.0.0 New Device Key Source. */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t new_device_keygen_sources[MASTERKEY_NUM_NEW_DEVICE_KEYS][0x10] = {
|
static const uint8_t new_device_keygen_sources[MASTERKEY_NUM_NEW_DEVICE_KEYS][0x10] = {
|
||||||
|
@ -52,7 +53,8 @@ static const uint8_t new_device_keygen_sources[MASTERKEY_NUM_NEW_DEVICE_KEYS][0x
|
||||||
{0x99, 0xFA, 0x98, 0xBD, 0x15, 0x1C, 0x72, 0xFD, 0x7D, 0x9A, 0xD5, 0x41, 0x00, 0xFD, 0xB2, 0xEF}, /* 6.x New Device Keygen Source. */
|
{0x99, 0xFA, 0x98, 0xBD, 0x15, 0x1C, 0x72, 0xFD, 0x7D, 0x9A, 0xD5, 0x41, 0x00, 0xFD, 0xB2, 0xEF}, /* 6.x New Device Keygen Source. */
|
||||||
{0x81, 0x3C, 0x6C, 0xBF, 0x5D, 0x21, 0xDE, 0x77, 0x20, 0xD9, 0x6C, 0xE3, 0x22, 0x06, 0xAE, 0xBB}, /* 6.2.0 New Device Keygen Source. */
|
{0x81, 0x3C, 0x6C, 0xBF, 0x5D, 0x21, 0xDE, 0x77, 0x20, 0xD9, 0x6C, 0xE3, 0x22, 0x06, 0xAE, 0xBB}, /* 6.2.0 New Device Keygen Source. */
|
||||||
{0x86, 0x61, 0xB0, 0x16, 0xFA, 0x7A, 0x9A, 0xEA, 0xF6, 0xF5, 0xBE, 0x1A, 0x13, 0x5B, 0x6D, 0x9E}, /* 7.0.0 New Device Keygen Source. */
|
{0x86, 0x61, 0xB0, 0x16, 0xFA, 0x7A, 0x9A, 0xEA, 0xF6, 0xF5, 0xBE, 0x1A, 0x13, 0x5B, 0x6D, 0x9E}, /* 7.0.0 New Device Keygen Source. */
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: 8.1.0 New Device Key Source to be added on next change-of-keys. */
|
{0xA6, 0x81, 0x71, 0xE7, 0xB5, 0x23, 0x74, 0xB0, 0x39, 0x8C, 0xB7, 0xFF, 0xA0, 0x62, 0x9F, 0x8D}, /* 8.1.0 New Device Keygen Source. */
|
||||||
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: 9.0.0 New Device Keygen Source to be added on next change-of-keys. */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t new_device_keygen_sources_dev[MASTERKEY_NUM_NEW_DEVICE_KEYS][0x10] = {
|
static const uint8_t new_device_keygen_sources_dev[MASTERKEY_NUM_NEW_DEVICE_KEYS][0x10] = {
|
||||||
|
@ -61,7 +63,8 @@ static const uint8_t new_device_keygen_sources_dev[MASTERKEY_NUM_NEW_DEVICE_KEYS
|
||||||
{0xF6, 0xD8, 0x59, 0x63, 0x8F, 0x47, 0xCB, 0x4A, 0xD8, 0x74, 0x05, 0x7F, 0x88, 0x92, 0x33, 0xA5}, /* 6.x New Device Keygen Source. */
|
{0xF6, 0xD8, 0x59, 0x63, 0x8F, 0x47, 0xCB, 0x4A, 0xD8, 0x74, 0x05, 0x7F, 0x88, 0x92, 0x33, 0xA5}, /* 6.x New Device Keygen Source. */
|
||||||
{0x20, 0xAB, 0xF2, 0x0F, 0x05, 0xE3, 0xDE, 0x2E, 0xA1, 0xFB, 0x37, 0x5E, 0x8B, 0x22, 0x1A, 0x38}, /* 6.2.0 New Device Keygen Source. */
|
{0x20, 0xAB, 0xF2, 0x0F, 0x05, 0xE3, 0xDE, 0x2E, 0xA1, 0xFB, 0x37, 0x5E, 0x8B, 0x22, 0x1A, 0x38}, /* 6.2.0 New Device Keygen Source. */
|
||||||
{0x60, 0xAE, 0x56, 0x68, 0x11, 0xE2, 0x0C, 0x99, 0xDE, 0x05, 0xAE, 0x68, 0x78, 0x85, 0x04, 0xAE}, /* 7.0.0 New Device Keygen Source. */
|
{0x60, 0xAE, 0x56, 0x68, 0x11, 0xE2, 0x0C, 0x99, 0xDE, 0x05, 0xAE, 0x68, 0x78, 0x85, 0x04, 0xAE}, /* 7.0.0 New Device Keygen Source. */
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: 8.1.0 New Device Key Source to be added on next change-of-keys. */
|
{0x94, 0xD6, 0xA8, 0xC0, 0x95, 0xAF, 0xD0, 0xA6, 0x27, 0x53, 0x5E, 0xE5, 0x8E, 0x70, 0x1F, 0x87}, /* 8.1.0 New Device Keygen Source. */
|
||||||
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: 9.0.0 New Device Keygen Source to be added on next change-of-keys. */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void derive_new_device_keys(unsigned int keygen_keyslot) {
|
static void derive_new_device_keys(unsigned int keygen_keyslot) {
|
||||||
|
@ -141,6 +144,7 @@ static void setup_se(void) {
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
derive_new_device_keys(KEYSLOT_SWITCH_5XNEWDEVICEKEYGENKEY);
|
derive_new_device_keys(KEYSLOT_SWITCH_5XNEWDEVICEKEYGENKEY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +334,7 @@ static bool validate_package2_metadata(package2_meta_t *metadata) {
|
||||||
|
|
||||||
/* Perform version checks. */
|
/* Perform version checks. */
|
||||||
/* We will be compatible with all package2s released before current, but not newer ones. */
|
/* We will be compatible with all package2s released before current, but not newer ones. */
|
||||||
if (metadata->version_max >= PACKAGE2_MINVER_THEORETICAL && metadata->version_min < PACKAGE2_MAXVER_810_CURRENT) {
|
if (metadata->version_max >= PACKAGE2_MINVER_THEORETICAL && metadata->version_min < PACKAGE2_MAXVER_900_CURRENT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,6 +460,7 @@ static void copy_warmboot_bin_to_dram() {
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
warmboot_src = (uint8_t *)0x4003E000;
|
warmboot_src = (uint8_t *)0x4003E000;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -532,6 +537,9 @@ void load_package2(coldboot_crt0_reloc_list_t *reloc_list) {
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
MAKE_REG32(PMC_BASE + 0x360) = 0x14A;
|
MAKE_REG32(PMC_BASE + 0x360) = 0x14A;
|
||||||
break;
|
break;
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
|
MAKE_REG32(PMC_BASE + 0x360) = 0x16B;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,8 @@ static inline uintptr_t get_nx_bootloader_mailbox_base(unsigned int targetfw) {
|
||||||
#define PACKAGE2_MAXVER_600_610 0x8
|
#define PACKAGE2_MAXVER_600_610 0x8
|
||||||
#define PACKAGE2_MAXVER_620 0x9
|
#define PACKAGE2_MAXVER_620 0x9
|
||||||
#define PACKAGE2_MAXVER_700_800 0xA
|
#define PACKAGE2_MAXVER_700_800 0xA
|
||||||
#define PACKAGE2_MAXVER_810_CURRENT 0xB
|
#define PACKAGE2_MAXVER_810 0xB
|
||||||
|
#define PACKAGE2_MAXVER_900_CURRENT 0xC
|
||||||
|
|
||||||
#define PACKAGE2_MINVER_100 0x3
|
#define PACKAGE2_MINVER_100 0x3
|
||||||
#define PACKAGE2_MINVER_200 0x4
|
#define PACKAGE2_MINVER_200 0x4
|
||||||
|
@ -82,7 +83,8 @@ static inline uintptr_t get_nx_bootloader_mailbox_base(unsigned int targetfw) {
|
||||||
#define PACKAGE2_MINVER_600_610 0x9
|
#define PACKAGE2_MINVER_600_610 0x9
|
||||||
#define PACKAGE2_MINVER_620 0xA
|
#define PACKAGE2_MINVER_620 0xA
|
||||||
#define PACKAGE2_MINVER_700_800 0xB
|
#define PACKAGE2_MINVER_700_800 0xB
|
||||||
#define PACKAGE2_MINVER_810_CURRENT 0xC
|
#define PACKAGE2_MINVER_810 0xC
|
||||||
|
#define PACKAGE2_MINVER_900_CURRENT 0xD
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -77,6 +77,7 @@ static void enable_lp0_wake_events(void) {
|
||||||
|
|
||||||
static void notify_pmic_shutdown(void) {
|
static void notify_pmic_shutdown(void) {
|
||||||
clkrst_reboot(CARDEVICE_I2C5);
|
clkrst_reboot(CARDEVICE_I2C5);
|
||||||
|
i2c_init(I2C_5);
|
||||||
if (fuse_get_bootrom_patch_version() >= 0x7F) {
|
if (fuse_get_bootrom_patch_version() >= 0x7F) {
|
||||||
i2c_send_pmic_cpu_shutdown_cmd();
|
i2c_send_pmic_cpu_shutdown_cmd();
|
||||||
}
|
}
|
||||||
|
@ -132,7 +133,7 @@ static void setup_bpmp_sc7_firmware(void) {
|
||||||
BPMP_VECTOR_UNK = 0x40003004; /* Reboot. */
|
BPMP_VECTOR_UNK = 0x40003004; /* Reboot. */
|
||||||
BPMP_VECTOR_IRQ = 0x40003004; /* Reboot. */
|
BPMP_VECTOR_IRQ = 0x40003004; /* Reboot. */
|
||||||
BPMP_VECTOR_FIQ = 0x40003004; /* Reboot. */
|
BPMP_VECTOR_FIQ = 0x40003004; /* Reboot. */
|
||||||
|
|
||||||
/* Hold the BPMP in reset. */
|
/* Hold the BPMP in reset. */
|
||||||
MAKE_CAR_REG(0x300) = 2;
|
MAKE_CAR_REG(0x300) = 2;
|
||||||
|
|
||||||
|
@ -141,7 +142,7 @@ static void setup_bpmp_sc7_firmware(void) {
|
||||||
for (unsigned int i = 0; i < sc7fw_bin_size; i += 4) {
|
for (unsigned int i = 0; i < sc7fw_bin_size; i += 4) {
|
||||||
write32le(lp0_entry_code, i, read32le(sc7fw_bin, i));
|
write32le(lp0_entry_code, i, read32le(sc7fw_bin, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_dcache_range(lp0_entry_code, lp0_entry_code + sc7fw_bin_size);
|
flush_dcache_range(lp0_entry_code, lp0_entry_code + sc7fw_bin_size);
|
||||||
|
|
||||||
/* Take the BPMP out of reset. */
|
/* Take the BPMP out of reset. */
|
||||||
|
@ -181,7 +182,7 @@ static void save_tzram_state(void) {
|
||||||
flush_dcache_range(tzram_encryption_dst, tzram_encryption_dst + LP0_TZRAM_SAVE_SIZE);
|
flush_dcache_range(tzram_encryption_dst, tzram_encryption_dst + LP0_TZRAM_SAVE_SIZE);
|
||||||
flush_dcache_range(tzram_encryption_src, tzram_encryption_src + LP0_TZRAM_SAVE_SIZE);
|
flush_dcache_range(tzram_encryption_src, tzram_encryption_src + LP0_TZRAM_SAVE_SIZE);
|
||||||
|
|
||||||
/* Use the all-zero cmac buffer as an IV. */
|
/* Use the all-zero cmac buffer as an IV. */
|
||||||
se_aes_256_cbc_encrypt(KEYSLOT_SWITCH_LP0TZRAMKEY, tzram_encryption_dst, LP0_TZRAM_SAVE_SIZE, tzram_encryption_src, LP0_TZRAM_SAVE_SIZE, tzram_cmac);
|
se_aes_256_cbc_encrypt(KEYSLOT_SWITCH_LP0TZRAMKEY, tzram_encryption_dst, LP0_TZRAM_SAVE_SIZE, tzram_encryption_src, LP0_TZRAM_SAVE_SIZE, tzram_cmac);
|
||||||
flush_dcache_range(tzram_encryption_dst, tzram_encryption_dst + LP0_TZRAM_SAVE_SIZE);
|
flush_dcache_range(tzram_encryption_dst, tzram_encryption_dst + LP0_TZRAM_SAVE_SIZE);
|
||||||
|
|
||||||
|
@ -189,12 +190,12 @@ static void save_tzram_state(void) {
|
||||||
for (unsigned int i = 0; i < LP0_TZRAM_SAVE_SIZE; i += 4) {
|
for (unsigned int i = 0; i < LP0_TZRAM_SAVE_SIZE; i += 4) {
|
||||||
write32le(tzram_store_address, i, read32le(tzram_encryption_dst, i));
|
write32le(tzram_store_address, i, read32le(tzram_encryption_dst, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_dcache_range(tzram_store_address, tzram_store_address + LP0_TZRAM_SAVE_SIZE);
|
flush_dcache_range(tzram_store_address, tzram_store_address + LP0_TZRAM_SAVE_SIZE);
|
||||||
|
|
||||||
/* Compute CMAC. */
|
/* Compute CMAC. */
|
||||||
se_compute_aes_256_cmac(KEYSLOT_SWITCH_LP0TZRAMKEY, tzram_cmac, sizeof(tzram_cmac), tzram_encryption_src, LP0_TZRAM_SAVE_SIZE);
|
se_compute_aes_256_cmac(KEYSLOT_SWITCH_LP0TZRAMKEY, tzram_cmac, sizeof(tzram_cmac), tzram_encryption_src, LP0_TZRAM_SAVE_SIZE);
|
||||||
|
|
||||||
/* Write CMAC, lock registers. */
|
/* Write CMAC, lock registers. */
|
||||||
APBDEV_PMC_SECURE_SCRATCH112_0 = tzram_cmac[0];
|
APBDEV_PMC_SECURE_SCRATCH112_0 = tzram_cmac[0];
|
||||||
APBDEV_PMC_SECURE_SCRATCH113_0 = tzram_cmac[1];
|
APBDEV_PMC_SECURE_SCRATCH113_0 = tzram_cmac[1];
|
||||||
|
@ -240,7 +241,7 @@ void save_se_and_power_down_cpu(void) {
|
||||||
/* Save context for warmboot to restore. */
|
/* Save context for warmboot to restore. */
|
||||||
save_tzram_state();
|
save_tzram_state();
|
||||||
save_se_state();
|
save_se_state();
|
||||||
|
|
||||||
/* Patch the bootrom to disable warmboot signature checks. */
|
/* Patch the bootrom to disable warmboot signature checks. */
|
||||||
MAKE_REG32(PMC_BASE + 0x118) = 0x2202E012;
|
MAKE_REG32(PMC_BASE + 0x118) = 0x2202E012;
|
||||||
MAKE_REG32(PMC_BASE + 0x11C) = 0x6001DC28;
|
MAKE_REG32(PMC_BASE + 0x11C) = 0x6001DC28;
|
||||||
|
@ -248,14 +249,14 @@ void save_se_and_power_down_cpu(void) {
|
||||||
if (!configitem_is_retail()) {
|
if (!configitem_is_retail()) {
|
||||||
uart_send(UART_A, "OYASUMI", 8);
|
uart_send(UART_A, "OYASUMI", 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize_powerdown();
|
finalize_powerdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t cpu_suspend(uint64_t power_state, uint64_t entrypoint, uint64_t argument) {
|
uint32_t cpu_suspend(uint64_t power_state, uint64_t entrypoint, uint64_t argument) {
|
||||||
/* TODO: 6.0.0 introduces heavy deja vu mitigations. */
|
/* TODO: 6.0.0 introduces heavy deja vu mitigations. */
|
||||||
/* Exosphere may want to implement these. */
|
/* Exosphere may want to implement these. */
|
||||||
|
|
||||||
/* Ensure SMC call is to enter deep sleep. */
|
/* Ensure SMC call is to enter deep sleep. */
|
||||||
if ((power_state & 0x17FFF) != 0x1001B) {
|
if ((power_state & 0x17FFF) != 0x1001B) {
|
||||||
return 0xFFFFFFFD;
|
return 0xFFFFFFFD;
|
||||||
|
@ -285,7 +286,7 @@ uint32_t cpu_suspend(uint64_t power_state, uint64_t entrypoint, uint64_t argumen
|
||||||
|
|
||||||
/* Prepare the current core for sleep. */
|
/* Prepare the current core for sleep. */
|
||||||
configure_flow_regs_for_sleep();
|
configure_flow_regs_for_sleep();
|
||||||
|
|
||||||
/* Save core context. */
|
/* Save core context. */
|
||||||
set_core_entrypoint_and_argument(get_core_id(), entrypoint, argument);
|
set_core_entrypoint_and_argument(get_core_id(), entrypoint, argument);
|
||||||
save_current_core_context();
|
save_current_core_context();
|
||||||
|
|
|
@ -186,6 +186,7 @@ void set_version_specific_smcs(void) {
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
/* No more LoadSecureExpModKey. */
|
/* No more LoadSecureExpModKey. */
|
||||||
g_smc_user_table[0xE].handler = NULL;
|
g_smc_user_table[0xE].handler = NULL;
|
||||||
g_smc_user_table[0xC].id = 0xC300D60C;
|
g_smc_user_table[0xC].id = 0xC300D60C;
|
||||||
|
|
|
@ -53,6 +53,7 @@ static bool is_user_keyslot_valid(unsigned int keyslot) {
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
default:
|
default:
|
||||||
return keyslot <= 5;
|
return keyslot <= 5;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,9 @@ typedef enum {
|
||||||
FS_VER_8_1_0,
|
FS_VER_8_1_0,
|
||||||
FS_VER_8_1_0_EXFAT,
|
FS_VER_8_1_0_EXFAT,
|
||||||
|
|
||||||
|
FS_VER_9_0_0,
|
||||||
|
FS_VER_9_0_0_EXFAT,
|
||||||
|
|
||||||
FS_VER_MAX,
|
FS_VER_MAX,
|
||||||
} emummc_fs_ver_t;
|
} emummc_fs_ver_t;
|
||||||
|
|
||||||
|
|
|
@ -411,6 +411,9 @@ static const uint8_t g_fs_hashes[FS_VER_MAX][0x8] = {
|
||||||
|
|
||||||
"\x6B\x09\xB6\x7B\x29\xC0\x20\x24", /* FS_VER_8_1_0 */
|
"\x6B\x09\xB6\x7B\x29\xC0\x20\x24", /* FS_VER_8_1_0 */
|
||||||
"\xB4\xCA\xE1\xF2\x49\x65\xD9\x2E", /* FS_VER_8_1_0_EXFAT */
|
"\xB4\xCA\xE1\xF2\x49\x65\xD9\x2E", /* FS_VER_8_1_0_EXFAT */
|
||||||
|
|
||||||
|
"\x46\x87\x40\x76\x1E\x19\x3E\xB7", /* FS_VER_9_0_0 */
|
||||||
|
"\x7C\x95\x13\x76\xE5\xC1\x2D\xF8", /* FS_VER_9_0_0_EXFAT */
|
||||||
};
|
};
|
||||||
|
|
||||||
kip1_header_t *apply_kip_ips_patches(kip1_header_t *kip, size_t kip_size, emummc_fs_ver_t *out_fs_ver) {
|
kip1_header_t *apply_kip_ips_patches(kip1_header_t *kip, size_t kip_size, emummc_fs_ver_t *out_fs_ver) {
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "se.h"
|
#include "se.h"
|
||||||
|
@ -102,7 +102,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(100, proc_id_recv)[] = {0xA9BF
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(200, proc_id_send)[] = {0x48, 0x31, 0x41, 0xF9, 0xE9, 0x03, 0x18, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0xC8, 0x6A, 0x29, 0xF8};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(200, proc_id_send)[] = {0x48, 0x31, 0x41, 0xF9, 0xE9, 0x03, 0x18, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0xC8, 0x6A, 0x29, 0xF8};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(200, proc_id_send)[] = {0xA9BF2FEA, 0x2A1803EB, 0xD37EF56B, 0xF86B6B8B, 0x92FFFFE9, 0x8A090168, 0xD2FFFFE9, 0x8A09016B, 0xD2FFFFC9, 0xEB09017F, 0x54000040, 0xF9413148, 0xA8C12FEA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(200, proc_id_send)[] = {0xA9BF2FEA, 0x2A1803EB, 0xD37EF56B, 0xF86B6B8B, 0x92FFFFE9, 0x8A090168, 0xD2FFFFE9, 0x8A09016B, 0xD2FFFFC9, 0xEB09017F, 0x54000040, 0xF9413148, 0xA8C12FEA};
|
||||||
/*
|
/*
|
||||||
stp x10, x11, [sp, #-0x10]!
|
stp x10, x11, [sp, #-0x10]!
|
||||||
mov w10, w15
|
mov w10, w15
|
||||||
lsl x10, x10, #2
|
lsl x10, x10, #2
|
||||||
|
@ -138,7 +138,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(200, proc_id_recv)[] = {0xA9BF
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(300, proc_id_send)[] = {0x48, 0x55, 0x41, 0xF9, 0xE9, 0x03, 0x18, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0xC8, 0x6A, 0x29, 0xF8};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(300, proc_id_send)[] = {0x48, 0x55, 0x41, 0xF9, 0xE9, 0x03, 0x18, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0xC8, 0x6A, 0x29, 0xF8};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(300, proc_id_send)[] = {0xA9BF2FEA, 0x2A1803EB, 0xD37EF56B, 0xF86B6B8B, 0x92FFFFE9, 0x8A090168, 0xD2FFFFE9, 0x8A09016B, 0xD2FFFFC9, 0xEB09017F, 0x54000040, 0xF9415548, 0xA8C12FEA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(300, proc_id_send)[] = {0xA9BF2FEA, 0x2A1803EB, 0xD37EF56B, 0xF86B6B8B, 0x92FFFFE9, 0x8A090168, 0xD2FFFFE9, 0x8A09016B, 0xD2FFFFC9, 0xEB09017F, 0x54000040, 0xF9415548, 0xA8C12FEA};
|
||||||
/*
|
/*
|
||||||
stp x10, x11, [sp, #-0x10]!
|
stp x10, x11, [sp, #-0x10]!
|
||||||
mov w10, w15
|
mov w10, w15
|
||||||
lsl x10, x10, #2
|
lsl x10, x10, #2
|
||||||
|
@ -174,7 +174,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(300, proc_id_recv)[] = {0xA9BF
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(302, proc_id_send)[] = {0x48, 0x55, 0x41, 0xF9, 0xE9, 0x03, 0x18, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0xC8, 0x6A, 0x29, 0xF8};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(302, proc_id_send)[] = {0x48, 0x55, 0x41, 0xF9, 0xE9, 0x03, 0x18, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0xC8, 0x6A, 0x29, 0xF8};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(302, proc_id_send)[] = {0xA9BF2FEA, 0x2A1803EB, 0xD37EF56B, 0xF86B6B8B, 0x92FFFFE9, 0x8A090168, 0xD2FFFFE9, 0x8A09016B, 0xD2FFFFC9, 0xEB09017F, 0x54000040, 0xF9415548, 0xA8C12FEA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(302, proc_id_send)[] = {0xA9BF2FEA, 0x2A1803EB, 0xD37EF56B, 0xF86B6B8B, 0x92FFFFE9, 0x8A090168, 0xD2FFFFE9, 0x8A09016B, 0xD2FFFFC9, 0xEB09017F, 0x54000040, 0xF9415548, 0xA8C12FEA};
|
||||||
/*
|
/*
|
||||||
stp x10, x11, [sp, #-0x10]!
|
stp x10, x11, [sp, #-0x10]!
|
||||||
mov w10, w15
|
mov w10, w15
|
||||||
lsl x10, x10, #2
|
lsl x10, x10, #2
|
||||||
|
@ -193,7 +193,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(302, proc_id_send)[] = {0xA9BF
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(302, proc_id_recv)[] = {0x08, 0x55, 0x41, 0xF9, 0xE9, 0x03, 0x0F, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0x48, 0x6B, 0x29, 0xF8};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(302, proc_id_recv)[] = {0x08, 0x55, 0x41, 0xF9, 0xE9, 0x03, 0x0F, 0x2A, 0x29, 0xF5, 0x7E, 0xD3, 0x48, 0x6B, 0x29, 0xF8};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(302, proc_id_recv)[] = {0xA9BF2FEA, 0x2A0F03EA, 0xD37EF54A, 0xF9405FEB, 0xF86A696A, 0xF9407BEB, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000040, 0xF9415568, 0xA8C12FEA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(302, proc_id_recv)[] = {0xA9BF2FEA, 0x2A0F03EA, 0xD37EF54A, 0xF9405FEB, 0xF86A696A, 0xF9407BEB, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000040, 0xF9415568, 0xA8C12FEA};
|
||||||
/*
|
/*
|
||||||
mov w10, w23
|
mov w10, w23
|
||||||
lsl x10, x10, #2
|
lsl x10, x10, #2
|
||||||
ldr x10, [x28, x10]
|
ldr x10, [x28, x10]
|
||||||
|
@ -210,7 +210,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(302, proc_id_recv)[] = {0xA9BF
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(400, proc_id_send)[] = {0xEA, 0x53, 0x40, 0xF9, 0x48, 0x59, 0x41, 0xF9, 0xE9, 0x03, 0x17, 0x2A, 0x29, 0xF5, 0x7E, 0xD3};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(400, proc_id_send)[] = {0xEA, 0x53, 0x40, 0xF9, 0x48, 0x59, 0x41, 0xF9, 0xE9, 0x03, 0x17, 0x2A, 0x29, 0xF5, 0x7E, 0xD3};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(400, proc_id_send)[] = {0x2A1703EA, 0xD37EF54A, 0xF86A6B8A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000060, 0xF94053EA, 0xF9415948, 0xF94053EA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(400, proc_id_send)[] = {0x2A1703EA, 0xD37EF54A, 0xF86A6B8A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000060, 0xF94053EA, 0xF9415948, 0xF94053EA};
|
||||||
/*
|
/*
|
||||||
ldr x13, [sp,#0x70]
|
ldr x13, [sp,#0x70]
|
||||||
mov w10, w14
|
mov w10, w14
|
||||||
lsl x10, x10, #2
|
lsl x10, x10, #2
|
||||||
|
@ -244,7 +244,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(400, proc_id_recv)[] = {0xF940
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(500, proc_id_send)[] = {0xEA, 0x43, 0x40, 0xF9, 0x48, 0x59, 0x41, 0xF9, 0xE9, 0x03, 0x17, 0x2A, 0x29, 0xF5, 0x7E, 0xD3};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(500, proc_id_send)[] = {0xEA, 0x43, 0x40, 0xF9, 0x48, 0x59, 0x41, 0xF9, 0xE9, 0x03, 0x17, 0x2A, 0x29, 0xF5, 0x7E, 0xD3};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_send)[] = {0x2A1703EA, 0xD37EF54A, 0xF86A6B6A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000060, 0xF94043EA, 0xF9415948, 0xF94043EA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_send)[] = {0x2A1703EA, 0xD37EF54A, 0xF86A6B6A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000060, 0xF94043EA, 0xF9415948, 0xF94043EA};
|
||||||
/*
|
/*
|
||||||
ldr x13, [sp, #0x70]
|
ldr x13, [sp, #0x70]
|
||||||
mov w10, w21
|
mov w10, w21
|
||||||
lsl x10, x10, #2
|
lsl x10, x10, #2
|
||||||
|
@ -257,7 +257,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_send)[] = {0x2A17
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #8
|
beq #8
|
||||||
ldr x8, [x24,#0x2b0]
|
ldr x8, [x24,#0x2b0]
|
||||||
ldr x10, [sp,#0xd8]
|
ldr x10, [sp,#0xd8]
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(500, proc_id_recv)[] = {0x08, 0x5B, 0x41, 0xF9, 0xEA, 0x6F, 0x40, 0xF9, 0xE9, 0x03, 0x15, 0x2A, 0x29, 0xF5, 0x7E, 0xD3};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(500, proc_id_recv)[] = {0x08, 0x5B, 0x41, 0xF9, 0xEA, 0x6F, 0x40, 0xF9, 0xE9, 0x03, 0x15, 0x2A, 0x29, 0xF5, 0x7E, 0xD3};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_recv)[] = {0xF9403BED, 0x2A1503EA, 0xD37EF54A, 0xF86A69AA, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000040, 0xF9415B08, 0xF9406FEA};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_recv)[] = {0xF9403BED, 0x2A1503EA, 0xD37EF54A, 0xF86A69AA, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000040, 0xF9415B08, 0xF9406FEA};
|
||||||
|
@ -274,7 +274,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_recv)[] = {0xF940
|
||||||
mov x9, #0xfffe000000000000
|
mov x9, #0xfffe000000000000
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #0x20
|
beq #0x20
|
||||||
|
|
||||||
stp x8, x9, [sp, #-0x10]!
|
stp x8, x9, [sp, #-0x10]!
|
||||||
ldr x8, [x24]
|
ldr x8, [x24]
|
||||||
ldr x8, [x8, #0x38]
|
ldr x8, [x8, #0x38]
|
||||||
|
@ -282,13 +282,13 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(500, proc_id_recv)[] = {0xF940
|
||||||
blr x8
|
blr x8
|
||||||
ldp x8, x9, [sp],#0x10
|
ldp x8, x9, [sp],#0x10
|
||||||
mov x8, x0
|
mov x8, x0
|
||||||
|
|
||||||
ldp x10, x11, [sp],#0x10
|
ldp x10, x11, [sp],#0x10
|
||||||
mov x0, x8
|
mov x0, x8
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(600, proc_id_send)[] = {0x08, 0x03, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x18, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x15, 0x2A, 0xB5, 0x0A, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(600, proc_id_send)[] = {0x08, 0x03, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x18, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x15, 0x2A, 0xB5, 0x0A, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(600, proc_id_send)[] = {0xA9BF2FEA, 0xF94037EB, 0x2A1503EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF9400308, 0xF9401D08, 0xAA1803E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(600, proc_id_send)[] = {0xA9BF2FEA, 0xF94037EB, 0x2A1503EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF9400308, 0xF9401D08, 0xAA1803E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
||||||
/*
|
/*
|
||||||
stp x10, x11, [sp, #-0x10]!
|
stp x10, x11, [sp, #-0x10]!
|
||||||
ldr x11, [sp, #0x80]
|
ldr x11, [sp, #0x80]
|
||||||
mov w10, w21
|
mov w10, w21
|
||||||
|
@ -301,7 +301,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(600, proc_id_send)[] = {0xA9BF
|
||||||
mov x9, #0xfffe000000000000
|
mov x9, #0xfffe000000000000
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #0x20
|
beq #0x20
|
||||||
|
|
||||||
stp x8, x9, [sp, #-0x10]!
|
stp x8, x9, [sp, #-0x10]!
|
||||||
ldr x8, [x24]
|
ldr x8, [x24]
|
||||||
ldr x8, [x8, #0x38]
|
ldr x8, [x8, #0x38]
|
||||||
|
@ -309,7 +309,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(600, proc_id_send)[] = {0xA9BF
|
||||||
blr x8
|
blr x8
|
||||||
ldp x8, x9, [sp],#0x10
|
ldp x8, x9, [sp],#0x10
|
||||||
mov x8, x0
|
mov x8, x0
|
||||||
|
|
||||||
ldp x10, x11, [sp],#0x10
|
ldp x10, x11, [sp],#0x10
|
||||||
mov x0, x8
|
mov x0, x8
|
||||||
*/
|
*/
|
||||||
|
@ -328,7 +328,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(600, proc_id_recv)[] = {0xA9BF
|
||||||
mov x9, #0xfffe000000000000
|
mov x9, #0xfffe000000000000
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #0x20
|
beq #0x20
|
||||||
|
|
||||||
stp x8, x9, [sp, #-0x10]!
|
stp x8, x9, [sp, #-0x10]!
|
||||||
ldr x8, [x21]
|
ldr x8, [x21]
|
||||||
ldr x8, [x8, #0x38]
|
ldr x8, [x8, #0x38]
|
||||||
|
@ -336,13 +336,13 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(600, proc_id_recv)[] = {0xA9BF
|
||||||
blr x8
|
blr x8
|
||||||
ldp x8, x9, [sp],#0x10
|
ldp x8, x9, [sp],#0x10
|
||||||
mov x8, x0
|
mov x8, x0
|
||||||
|
|
||||||
ldp x10, x11, [sp],#0x10
|
ldp x10, x11, [sp],#0x10
|
||||||
mov x0, x8
|
mov x0, x8
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(700, proc_id_send)[] = {0xA8, 0x02, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x15, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x19, 0x2A, 0x39, 0x0B, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(700, proc_id_send)[] = {0xA8, 0x02, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x15, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x19, 0x2A, 0x39, 0x0B, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(700, proc_id_send)[] = {0xA9BF2FEA, 0xF9403BEB, 0x2A1903EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF94002A8, 0xF9401D08, 0xAA1503E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(700, proc_id_send)[] = {0xA9BF2FEA, 0xF9403BEB, 0x2A1903EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF94002A8, 0xF9401D08, 0xAA1503E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
||||||
/*
|
/*
|
||||||
stp x10, x11, [sp, #-0x10]!
|
stp x10, x11, [sp, #-0x10]!
|
||||||
ldr x11, [sp, #0x98]
|
ldr x11, [sp, #0x98]
|
||||||
mov w10, w22
|
mov w10, w22
|
||||||
|
@ -355,7 +355,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(700, proc_id_send)[] = {0xA9BF
|
||||||
mov x9, #0xfffe000000000000
|
mov x9, #0xfffe000000000000
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #0x20
|
beq #0x20
|
||||||
|
|
||||||
stp x8, x9, [sp, #-0x10]!
|
stp x8, x9, [sp, #-0x10]!
|
||||||
ldr x8, [x27]
|
ldr x8, [x27]
|
||||||
ldr x8, [x8, #0x38]
|
ldr x8, [x8, #0x38]
|
||||||
|
@ -363,7 +363,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(700, proc_id_send)[] = {0xA9BF
|
||||||
blr x8
|
blr x8
|
||||||
ldp x8, x9, [sp],#0x10
|
ldp x8, x9, [sp],#0x10
|
||||||
mov x8, x0
|
mov x8, x0
|
||||||
|
|
||||||
ldp x10, x11, [sp],#0x10
|
ldp x10, x11, [sp],#0x10
|
||||||
mov x0, x8
|
mov x0, x8
|
||||||
*/
|
*/
|
||||||
|
@ -383,7 +383,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(700, proc_id_recv)[] = {0xA9BF
|
||||||
mov x9, #0xfffe000000000000
|
mov x9, #0xfffe000000000000
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #0x20
|
beq #0x20
|
||||||
|
|
||||||
stp x8, x9, [sp, #-0x10]!
|
stp x8, x9, [sp, #-0x10]!
|
||||||
ldr x8, [x21]
|
ldr x8, [x21]
|
||||||
ldr x8, [x8, #0x38]
|
ldr x8, [x8, #0x38]
|
||||||
|
@ -391,13 +391,13 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(700, proc_id_recv)[] = {0xA9BF
|
||||||
blr x8
|
blr x8
|
||||||
ldp x8, x9, [sp],#0x10
|
ldp x8, x9, [sp],#0x10
|
||||||
mov x8, x0
|
mov x8, x0
|
||||||
|
|
||||||
ldp x10, x11, [sp],#0x10
|
ldp x10, x11, [sp],#0x10
|
||||||
mov x0, x8
|
mov x0, x8
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(800, proc_id_send)[] = {0xA8, 0x02, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x15, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x19, 0x2A, 0x39, 0x0B, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(800, proc_id_send)[] = {0xA8, 0x02, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x15, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x19, 0x2A, 0x39, 0x0B, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(800, proc_id_send)[] = {0xA9BF2FEA, 0xF9403BEB, 0x2A1903EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF94002A8, 0xF9401D08, 0xAA1503E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(800, proc_id_send)[] = {0xA9BF2FEA, 0xF9403BEB, 0x2A1903EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF94002A8, 0xF9401D08, 0xAA1503E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
||||||
/*
|
/*
|
||||||
stp x10, x11, [sp, #-0x10]!
|
stp x10, x11, [sp, #-0x10]!
|
||||||
ldr x11, [sp, #0x98]
|
ldr x11, [sp, #0x98]
|
||||||
mov w10, w22
|
mov w10, w22
|
||||||
|
@ -410,7 +410,7 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(800, proc_id_send)[] = {0xA9BF
|
||||||
mov x9, #0xfffe000000000000
|
mov x9, #0xfffe000000000000
|
||||||
cmp x10, x9
|
cmp x10, x9
|
||||||
beq #0x20
|
beq #0x20
|
||||||
|
|
||||||
stp x8, x9, [sp, #-0x10]!
|
stp x8, x9, [sp, #-0x10]!
|
||||||
ldr x8, [x27]
|
ldr x8, [x27]
|
||||||
ldr x8, [x8, #0x38]
|
ldr x8, [x8, #0x38]
|
||||||
|
@ -418,19 +418,75 @@ static const instruction_t MAKE_KERNEL_PATCH_NAME(800, proc_id_send)[] = {0xA9BF
|
||||||
blr x8
|
blr x8
|
||||||
ldp x8, x9, [sp],#0x10
|
ldp x8, x9, [sp],#0x10
|
||||||
mov x8, x0
|
mov x8, x0
|
||||||
|
|
||||||
ldp x10, x11, [sp],#0x10
|
ldp x10, x11, [sp],#0x10
|
||||||
mov x0, x8
|
mov x0, x8
|
||||||
*/
|
*/
|
||||||
static const uint8_t MAKE_KERNEL_PATTERN_NAME(800, proc_id_recv)[] = {0x68, 0x03, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x1B, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xA9, 0x83, 0x50, 0xF8, 0xE8, 0x03, 0x16, 0x2A, 0xD6, 0x0A, 0x00, 0x11};
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(800, proc_id_recv)[] = {0x68, 0x03, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x1B, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xA9, 0x83, 0x50, 0xF8, 0xE8, 0x03, 0x16, 0x2A, 0xD6, 0x0A, 0x00, 0x11};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(800, proc_id_recv)[] = {0xA9BF2FEA, 0xF9404FEB, 0x2A1603EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF9400368, 0xF9401D08, 0xAA1B03E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(800, proc_id_recv)[] = {0xA9BF2FEA, 0xF9404FEB, 0x2A1603EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF9400368, 0xF9401D08, 0xAA1B03E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
||||||
|
|
||||||
|
/*
|
||||||
|
stp x10, x11, [sp, #-0x10]!
|
||||||
|
ldr x11, [sp, #0x68]
|
||||||
|
mov w10, w22
|
||||||
|
lsl x10, x10, #2
|
||||||
|
ldr x10, [x11, x10]
|
||||||
|
mov x9, #0x0000ffffffffffff
|
||||||
|
and x8, x10, x9
|
||||||
|
mov x9, #0xffff000000000000
|
||||||
|
and x10, x10, x9
|
||||||
|
mov x9, #0xfffe000000000000
|
||||||
|
cmp x10, x9
|
||||||
|
beq #0x20
|
||||||
|
|
||||||
|
stp x8, x9, [sp, #-0x10]!
|
||||||
|
ldr x8, [x23]
|
||||||
|
ldr x8, [x8, #0x38]
|
||||||
|
mov x0, x23
|
||||||
|
blr x8
|
||||||
|
ldp x8, x9, [sp],#0x10
|
||||||
|
mov x8, x0
|
||||||
|
|
||||||
|
ldp x10, x11, [sp],#0x10
|
||||||
|
mov x0, x8
|
||||||
|
*/
|
||||||
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(900, proc_id_send)[] = {0xE8, 0x02, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x17, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x16, 0x2A, 0xD6, 0x0A, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
||||||
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(900, proc_id_send)[] = {0xA9BF2FEA, 0xF94037EB, 0x2A1603EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF94002E8, 0xF9401D08, 0xAA1703E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
||||||
|
/*
|
||||||
|
stp x10, x11, [sp, #-0x10]!
|
||||||
|
ldr x11, [sp, #0x90]
|
||||||
|
mov w10, w23
|
||||||
|
lsl x10, x10, #2
|
||||||
|
ldr x10, [x11, x10]
|
||||||
|
mov x9, #0x0000ffffffffffff
|
||||||
|
and x8, x10, x9
|
||||||
|
mov x9, #0xffff000000000000
|
||||||
|
and x10, x10, x9
|
||||||
|
mov x9, #0xfffe000000000000
|
||||||
|
cmp x10, x9
|
||||||
|
beq #0x20
|
||||||
|
|
||||||
|
stp x8, x9, [sp, #-0x10]!
|
||||||
|
ldr x8, [x27]
|
||||||
|
ldr x8, [x8, #0x38]
|
||||||
|
mov x0, x27
|
||||||
|
blr x8
|
||||||
|
ldp x8, x9, [sp],#0x10
|
||||||
|
mov x8, x0
|
||||||
|
|
||||||
|
ldp x10, x11, [sp],#0x10
|
||||||
|
mov x0, x8
|
||||||
|
*/
|
||||||
|
static const uint8_t MAKE_KERNEL_PATTERN_NAME(900, proc_id_recv)[] = {0x68, 0x03, 0x40, 0xF9, 0x08, 0x1D, 0x40, 0xF9, 0xE0, 0x03, 0x1B, 0xAA, 0x00, 0x01, 0x3F, 0xD6, 0xE8, 0x03, 0x17, 0x2A, 0xF7, 0x0A, 0x00, 0x11, 0x08, 0xF5, 0x7E, 0xD3};
|
||||||
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(900, proc_id_recv)[] = {0xA9BF2FEA, 0xF9404BEB, 0x2A1703EA, 0xD37EF54A, 0xF86A696A, 0x92FFFFE9, 0x8A090148, 0xD2FFFFE9, 0x8A09014A, 0xD2FFFFC9, 0xEB09015F, 0x54000100, 0xA9BF27E8, 0xF9400368, 0xF9401D08, 0xAA1B03E0, 0xD63F0100, 0xA8C127E8, 0xAA0003E8, 0xA8C12FEA, 0xAA0803E0};
|
||||||
|
|
||||||
/* svcControlCodeMemory Patches */
|
/* svcControlCodeMemory Patches */
|
||||||
/* b.eq -> nop */
|
/* b.eq -> nop */
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(500, svc_control_codememory)[] = {MAKE_NOP};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(500, svc_control_codememory)[] = {MAKE_NOP};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(600, svc_control_codememory)[] = {MAKE_NOP};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(600, svc_control_codememory)[] = {MAKE_NOP};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(700, svc_control_codememory)[] = {MAKE_NOP};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(700, svc_control_codememory)[] = {MAKE_NOP};
|
||||||
static const instruction_t MAKE_KERNEL_PATCH_NAME(800, svc_control_codememory)[] = {MAKE_NOP};
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(800, svc_control_codememory)[] = {MAKE_NOP};
|
||||||
|
static const instruction_t MAKE_KERNEL_PATCH_NAME(900, svc_control_codememory)[] = {MAKE_NOP};
|
||||||
|
|
||||||
/* Hook Definitions. */
|
/* Hook Definitions. */
|
||||||
static const kernel_patch_t g_kernel_patches_100[] = {
|
static const kernel_patch_t g_kernel_patches_100[] = {
|
||||||
|
@ -592,6 +648,7 @@ static const kernel_patch_t g_kernel_patches_700[] = {
|
||||||
.patch_offset = 0x3C6E0,
|
.patch_offset = 0x3C6E0,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const kernel_patch_t g_kernel_patches_800[] = {
|
static const kernel_patch_t g_kernel_patches_800[] = {
|
||||||
{ /* Send Message Process ID Patch. */
|
{ /* Send Message Process ID Patch. */
|
||||||
.pattern_size = 0x1C,
|
.pattern_size = 0x1C,
|
||||||
|
@ -616,6 +673,30 @@ static const kernel_patch_t g_kernel_patches_800[] = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const kernel_patch_t g_kernel_patches_900[] = {
|
||||||
|
{ /* Send Message Process ID Patch. */
|
||||||
|
.pattern_size = 0x1C,
|
||||||
|
.pattern = MAKE_KERNEL_PATTERN_NAME(900, proc_id_send),
|
||||||
|
.pattern_hook_offset = 0x0,
|
||||||
|
.payload_num_instructions = sizeof(MAKE_KERNEL_PATCH_NAME(900, proc_id_send))/sizeof(instruction_t),
|
||||||
|
.branch_back_offset = 0x10,
|
||||||
|
.payload = MAKE_KERNEL_PATCH_NAME(900, proc_id_send)
|
||||||
|
},
|
||||||
|
{ /* Receive Message Process ID Patch. */
|
||||||
|
.pattern_size = 0x1C,
|
||||||
|
.pattern = MAKE_KERNEL_PATTERN_NAME(900, proc_id_recv),
|
||||||
|
.pattern_hook_offset = 0x0,
|
||||||
|
.payload_num_instructions = sizeof(MAKE_KERNEL_PATCH_NAME(900, proc_id_recv))/sizeof(instruction_t),
|
||||||
|
.branch_back_offset = 0x10,
|
||||||
|
.payload = MAKE_KERNEL_PATCH_NAME(900, proc_id_recv)
|
||||||
|
},
|
||||||
|
{ /* svcControlCodeMemory Patch. */
|
||||||
|
.payload_num_instructions = sizeof(MAKE_KERNEL_PATCH_NAME(900, svc_control_codememory))/sizeof(instruction_t),
|
||||||
|
.payload = MAKE_KERNEL_PATCH_NAME(900, svc_control_codememory),
|
||||||
|
.patch_offset = 0x43DFC,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#define KERNEL_PATCHES(vers) .num_patches = sizeof(g_kernel_patches_##vers)/sizeof(kernel_patch_t), .patches = g_kernel_patches_##vers,
|
#define KERNEL_PATCHES(vers) .num_patches = sizeof(g_kernel_patches_##vers)/sizeof(kernel_patch_t), .patches = g_kernel_patches_##vers,
|
||||||
|
|
||||||
/* Kernel Infos. */
|
/* Kernel Infos. */
|
||||||
|
@ -673,6 +754,15 @@ static const kernel_info_t g_kernel_infos[] = {
|
||||||
.embedded_ini_ptr = 0x168,
|
.embedded_ini_ptr = 0x168,
|
||||||
.free_code_space_offset = 0x607F0,
|
.free_code_space_offset = 0x607F0,
|
||||||
KERNEL_PATCHES(800)
|
KERNEL_PATCHES(800)
|
||||||
|
},
|
||||||
|
{ /* 9.0.0. */
|
||||||
|
.hash = {0xD7, 0x95, 0x65, 0x3A, 0x49, 0x4C, 0x5A, 0x9E, 0x2E, 0x04, 0xD6, 0x30, 0x7D, 0x79, 0xE1, 0xEE, 0x10, 0x2B, 0x30, 0xE0, 0x3E, 0xDD, 0x9F, 0xB3, 0x8A, 0x3C, 0x5E, 0xD3, 0x9B, 0x30, 0x11, 0x9B},
|
||||||
|
.hash_offset = 0x1C0,
|
||||||
|
.hash_size = 0x90000 - 0x1C0,
|
||||||
|
.embedded_ini_offset = 0x90000,
|
||||||
|
.embedded_ini_ptr = 0x180,
|
||||||
|
.free_code_space_offset = 0x65780,
|
||||||
|
KERNEL_PATCHES(900)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -680,7 +770,7 @@ static const kernel_info_t g_kernel_infos[] = {
|
||||||
uint8_t *search_pattern(void *_mem, size_t mem_size, const void *_pattern, size_t pattern_size) {
|
uint8_t *search_pattern(void *_mem, size_t mem_size, const void *_pattern, size_t pattern_size) {
|
||||||
const uint8_t *pattern = (const uint8_t *)_pattern;
|
const uint8_t *pattern = (const uint8_t *)_pattern;
|
||||||
uint8_t *mem = (uint8_t *)_mem;
|
uint8_t *mem = (uint8_t *)_mem;
|
||||||
|
|
||||||
uint32_t table[0x100];
|
uint32_t table[0x100];
|
||||||
for (unsigned int i = 0; i < sizeof(table)/sizeof(uint32_t); i++) {
|
for (unsigned int i = 0; i < sizeof(table)/sizeof(uint32_t); i++) {
|
||||||
table[i] = (uint32_t)pattern_size;
|
table[i] = (uint32_t)pattern_size;
|
||||||
|
@ -688,7 +778,7 @@ uint8_t *search_pattern(void *_mem, size_t mem_size, const void *_pattern, size_
|
||||||
for (unsigned int i = 0; i < pattern_size - 1; i++) {
|
for (unsigned int i = 0; i < pattern_size - 1; i++) {
|
||||||
table[pattern[i]] = (uint32_t)pattern_size - i - 1;
|
table[pattern[i]] = (uint32_t)pattern_size - i - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i <= mem_size - pattern_size; i += table[mem[i + pattern_size - 1]]) {
|
for (unsigned int i = 0; i <= mem_size - pattern_size; i += table[mem[i + pattern_size - 1]]) {
|
||||||
if (pattern[pattern_size - 1] == mem[i + pattern_size - 1] && memcmp(pattern, mem + i, pattern_size - 1) == 0) {
|
if (pattern[pattern_size - 1] == mem[i + pattern_size - 1] && memcmp(pattern, mem + i, pattern_size - 1) == 0) {
|
||||||
return mem + i;
|
return mem + i;
|
||||||
|
@ -701,7 +791,7 @@ const kernel_info_t *get_kernel_info(void *kernel, size_t size) {
|
||||||
uint8_t calculated_hash[0x20];
|
uint8_t calculated_hash[0x20];
|
||||||
uint8_t calculated_partial_hash[0x20];
|
uint8_t calculated_partial_hash[0x20];
|
||||||
se_calculate_sha256(calculated_hash, kernel, size);
|
se_calculate_sha256(calculated_hash, kernel, size);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(g_kernel_infos)/sizeof(kernel_info_t); i++) {
|
for (unsigned int i = 0; i < sizeof(g_kernel_infos)/sizeof(kernel_info_t); i++) {
|
||||||
if (g_kernel_infos[i].hash_size == 0 || size <= g_kernel_infos[i].hash_size) {
|
if (g_kernel_infos[i].hash_size == 0 || size <= g_kernel_infos[i].hash_size) {
|
||||||
if (memcmp(calculated_hash, g_kernel_infos[i].hash, sizeof(calculated_hash)) == 0) {
|
if (memcmp(calculated_hash, g_kernel_infos[i].hash, sizeof(calculated_hash)) == 0) {
|
||||||
|
@ -720,24 +810,24 @@ const kernel_info_t *get_kernel_info(void *kernel, size_t size) {
|
||||||
void package2_patch_kernel(void *_kernel, size_t size, bool is_sd_kernel, void **out_ini1) {
|
void package2_patch_kernel(void *_kernel, size_t size, bool is_sd_kernel, void **out_ini1) {
|
||||||
const kernel_info_t *kernel_info = get_kernel_info(_kernel, size);
|
const kernel_info_t *kernel_info = get_kernel_info(_kernel, size);
|
||||||
*out_ini1 = NULL;
|
*out_ini1 = NULL;
|
||||||
|
|
||||||
/* Apply IPS patches. */
|
/* Apply IPS patches. */
|
||||||
apply_kernel_ips_patches(_kernel, size);
|
apply_kernel_ips_patches(_kernel, size);
|
||||||
|
|
||||||
if (kernel_info == NULL && !is_sd_kernel) {
|
if (kernel_info == NULL && !is_sd_kernel) {
|
||||||
/* Should this be fatal? */
|
/* Should this be fatal? */
|
||||||
fatal_error("kernel_patcher: unable to identify kernel!\n");
|
fatal_error("kernel_patcher: unable to identify kernel!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_info == NULL && is_sd_kernel) {
|
if (kernel_info == NULL && is_sd_kernel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_info->embedded_ini_offset != 0) {
|
if (kernel_info->embedded_ini_offset != 0) {
|
||||||
*out_ini1 = (void *)((uintptr_t)_kernel + kernel_info->embedded_ini_offset);
|
*out_ini1 = (void *)((uintptr_t)_kernel + kernel_info->embedded_ini_offset);
|
||||||
*((volatile uint64_t *)((uintptr_t)_kernel + kernel_info->embedded_ini_ptr)) = (uint64_t)size;
|
*((volatile uint64_t *)((uintptr_t)_kernel + kernel_info->embedded_ini_ptr)) = (uint64_t)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply hooks and patches. */
|
/* Apply hooks and patches. */
|
||||||
uint8_t *kernel = (uint8_t *)_kernel;
|
uint8_t *kernel = (uint8_t *)_kernel;
|
||||||
size_t free_space_offset = kernel_info->free_code_space_offset;
|
size_t free_space_offset = kernel_info->free_code_space_offset;
|
||||||
|
@ -759,7 +849,7 @@ void package2_patch_kernel(void *_kernel, size_t size, bool is_sd_kernel, void *
|
||||||
/* TODO: What should be done in this case? */
|
/* TODO: What should be done in this case? */
|
||||||
fatal_error("kernel_patcher: insufficient space to apply patches!\n");
|
fatal_error("kernel_patcher: insufficient space to apply patches!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *pattern_loc = search_pattern(kernel, size, kernel_info->patches[i].pattern, kernel_info->patches[i].pattern_size);
|
uint8_t *pattern_loc = search_pattern(kernel, size, kernel_info->patches[i].pattern, kernel_info->patches[i].pattern_size);
|
||||||
if (pattern_loc == NULL) {
|
if (pattern_loc == NULL) {
|
||||||
/* TODO: Should we print an error/abort here? */
|
/* TODO: Should we print an error/abort here? */
|
||||||
|
@ -768,7 +858,7 @@ void package2_patch_kernel(void *_kernel, size_t size, bool is_sd_kernel, void *
|
||||||
/* Patch kernel to branch to our hook at the desired place. */
|
/* Patch kernel to branch to our hook at the desired place. */
|
||||||
volatile instruction_t *hook_start = (instruction_t *)(pattern_loc + kernel_info->patches[i].pattern_hook_offset);
|
volatile instruction_t *hook_start = (instruction_t *)(pattern_loc + kernel_info->patches[i].pattern_hook_offset);
|
||||||
*hook_start = MAKE_BRANCH((uint32_t)((uintptr_t)hook_start - (uintptr_t)kernel), free_space_offset);
|
*hook_start = MAKE_BRANCH((uint32_t)((uintptr_t)hook_start - (uintptr_t)kernel), free_space_offset);
|
||||||
|
|
||||||
/* Insert hook into free space. */
|
/* Insert hook into free space. */
|
||||||
volatile instruction_t *payload = (instruction_t *)(kernel + free_space_offset);
|
volatile instruction_t *payload = (instruction_t *)(kernel + free_space_offset);
|
||||||
for (unsigned int p = 0; p < kernel_info->patches[i].payload_num_instructions; p++) {
|
for (unsigned int p = 0; p < kernel_info->patches[i].payload_num_instructions; p++) {
|
||||||
|
@ -777,7 +867,7 @@ void package2_patch_kernel(void *_kernel, size_t size, bool is_sd_kernel, void *
|
||||||
if (kernel_info->patches[i].branch_back_offset) {
|
if (kernel_info->patches[i].branch_back_offset) {
|
||||||
payload[kernel_info->patches[i].payload_num_instructions] = MAKE_BRANCH(free_space_offset + sizeof(instruction_t) * kernel_info->patches[i].payload_num_instructions, (uint32_t)(kernel_info->patches[i].branch_back_offset + (uintptr_t)hook_start - (uintptr_t)kernel));
|
payload[kernel_info->patches[i].payload_num_instructions] = MAKE_BRANCH(free_space_offset + sizeof(instruction_t) * kernel_info->patches[i].payload_num_instructions, (uint32_t)(kernel_info->patches[i].branch_back_offset + (uintptr_t)hook_start - (uintptr_t)kernel));
|
||||||
}
|
}
|
||||||
|
|
||||||
free_space_offset += hook_size;
|
free_space_offset += hook_size;
|
||||||
free_space_size -= hook_size;
|
free_space_size -= hook_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,9 @@ int derive_nx_keydata(uint32_t target_firmware, const nx_keyblob_t *keyblobs, ui
|
||||||
desired_keyblob = MASTERKEY_REVISION_700_800;
|
desired_keyblob = MASTERKEY_REVISION_700_800;
|
||||||
break;
|
break;
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
desired_keyblob = MASTERKEY_REVISION_810_CURRENT;
|
desired_keyblob = MASTERKEY_REVISION_810;
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
|
desired_keyblob = MASTERKEY_REVISION_900_CURRENT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatal_error("Unknown target firmware: %02x!", target_firmware);
|
fatal_error("Unknown target firmware: %02x!", target_firmware);
|
||||||
|
@ -230,6 +232,7 @@ int derive_nx_keydata(uint32_t target_firmware, const nx_keyblob_t *keyblobs, ui
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
case ATMOSPHERE_TARGET_FIRMWARE_700:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
case ATMOSPHERE_TARGET_FIRMWARE_800:
|
||||||
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
case ATMOSPHERE_TARGET_FIRMWARE_810:
|
||||||
|
case ATMOSPHERE_TARGET_FIRMWARE_900:
|
||||||
decrypt_data_into_keyslot(0xA, 0xF, devicekey_4x_seed, 0x10);
|
decrypt_data_into_keyslot(0xA, 0xF, devicekey_4x_seed, 0x10);
|
||||||
decrypt_data_into_keyslot(0xF, 0xF, devicekey_seed, 0x10);
|
decrypt_data_into_keyslot(0xF, 0xF, devicekey_seed, 0x10);
|
||||||
decrypt_data_into_keyslot(0xE, 0xC, masterkey_4x_seed, 0x10);
|
decrypt_data_into_keyslot(0xE, 0xC, masterkey_4x_seed, 0x10);
|
||||||
|
|
|
@ -40,6 +40,7 @@ static const uint8_t mkey_vectors_dev[MASTERKEY_REVISION_MAX][0x10] =
|
||||||
{0x6F, 0xD2, 0x84, 0x1D, 0x05, 0xEC, 0x40, 0x94, 0x5F, 0x18, 0xB3, 0x81, 0x09, 0x98, 0x8D, 0x4E}, /* Master key 05 encrypted with Master key 06. */
|
{0x6F, 0xD2, 0x84, 0x1D, 0x05, 0xEC, 0x40, 0x94, 0x5F, 0x18, 0xB3, 0x81, 0x09, 0x98, 0x8D, 0x4E}, /* Master key 05 encrypted with Master key 06. */
|
||||||
{0x37, 0xAF, 0xAB, 0x35, 0x79, 0x09, 0xD9, 0x48, 0x29, 0xD2, 0xDB, 0xA5, 0xA5, 0xF5, 0x30, 0x19}, /* Master key 06 encrypted with Master key 07. */
|
{0x37, 0xAF, 0xAB, 0x35, 0x79, 0x09, 0xD9, 0x48, 0x29, 0xD2, 0xDB, 0xA5, 0xA5, 0xF5, 0x30, 0x19}, /* Master key 06 encrypted with Master key 07. */
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: Master key 07 encrypted with Master key 08. */
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: Master key 07 encrypted with Master key 08. */
|
||||||
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* TODO: Master key 08 encrypted with Master key 09. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Retail unit keys. */
|
/* Retail unit keys. */
|
||||||
|
@ -54,6 +55,7 @@ static const uint8_t mkey_vectors[MASTERKEY_REVISION_MAX][0x10] =
|
||||||
{0x1E, 0x1E, 0x22, 0xC0, 0x5A, 0x33, 0x3C, 0xB9, 0x0B, 0xA9, 0x03, 0x04, 0xBA, 0xDB, 0x07, 0x57}, /* Master key 05 encrypted with Master key 06. */
|
{0x1E, 0x1E, 0x22, 0xC0, 0x5A, 0x33, 0x3C, 0xB9, 0x0B, 0xA9, 0x03, 0x04, 0xBA, 0xDB, 0x07, 0x57}, /* Master key 05 encrypted with Master key 06. */
|
||||||
{0xA4, 0xD4, 0x52, 0x6F, 0xD1, 0xE4, 0x36, 0xAA, 0x9F, 0xCB, 0x61, 0x27, 0x1C, 0x67, 0x65, 0x1F}, /* Master key 06 encrypted with Master key 07. */
|
{0xA4, 0xD4, 0x52, 0x6F, 0xD1, 0xE4, 0x36, 0xAA, 0x9F, 0xCB, 0x61, 0x27, 0x1C, 0x67, 0x65, 0x1F}, /* Master key 06 encrypted with Master key 07. */
|
||||||
{0xEA, 0x60, 0xB3, 0xEA, 0xCE, 0x8F, 0x24, 0x46, 0x7D, 0x33, 0x9C, 0xD1, 0xBC, 0x24, 0x98, 0x29}, /* Master key 07 encrypted with Master key 08. */
|
{0xEA, 0x60, 0xB3, 0xEA, 0xCE, 0x8F, 0x24, 0x46, 0x7D, 0x33, 0x9C, 0xD1, 0xBC, 0x24, 0x98, 0x29}, /* Master key 07 encrypted with Master key 08. */
|
||||||
|
{0x4D, 0xD9, 0x98, 0x42, 0x45, 0x0D, 0xB1, 0x3C, 0x52, 0x0C, 0x9A, 0x44, 0xBB, 0xAD, 0xAF, 0x80}, /* Master key 08 encrypted with Master key 09. */
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool check_mkey_revision(unsigned int revision, bool is_retail) {
|
static bool check_mkey_revision(unsigned int revision, bool is_retail) {
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
/* This is glue code to enable master key support across versions. */
|
/* This is glue code to enable master key support across versions. */
|
||||||
|
|
||||||
/* TODO: Update to 0xA on release of new master key. */
|
/* TODO: Update to 0xB on release of new master key. */
|
||||||
#define MASTERKEY_REVISION_MAX 0x9
|
#define MASTERKEY_REVISION_MAX 0xA
|
||||||
|
|
||||||
#define MASTERKEY_REVISION_100_230 0x00
|
#define MASTERKEY_REVISION_100_230 0x00
|
||||||
#define MASTERKEY_REVISION_300 0x01
|
#define MASTERKEY_REVISION_300 0x01
|
||||||
|
@ -30,7 +30,8 @@
|
||||||
#define MASTERKEY_REVISION_600_610 0x05
|
#define MASTERKEY_REVISION_600_610 0x05
|
||||||
#define MASTERKEY_REVISION_620 0x06
|
#define MASTERKEY_REVISION_620 0x06
|
||||||
#define MASTERKEY_REVISION_700_800 0x07
|
#define MASTERKEY_REVISION_700_800 0x07
|
||||||
#define MASTERKEY_REVISION_810_CURRENT 0x08
|
#define MASTERKEY_REVISION_810 0x08
|
||||||
|
#define MASTERKEY_REVISION_900_CURRENT 0x09
|
||||||
|
|
||||||
#define MASTERKEY_NUM_NEW_DEVICE_KEYS (MASTERKEY_REVISION_MAX - MASTERKEY_REVISION_400_410)
|
#define MASTERKEY_NUM_NEW_DEVICE_KEYS (MASTERKEY_REVISION_MAX - MASTERKEY_REVISION_400_410)
|
||||||
|
|
||||||
|
|
|
@ -208,11 +208,13 @@ static uint32_t nxboot_get_target_firmware(const void *package1loader) {
|
||||||
}
|
}
|
||||||
case 0x0F: /* 7.0.0 - 7.0.1 */
|
case 0x0F: /* 7.0.0 - 7.0.1 */
|
||||||
return ATMOSPHERE_TARGET_FIRMWARE_700;
|
return ATMOSPHERE_TARGET_FIRMWARE_700;
|
||||||
case 0x10: { /* 8.0.0 - 8.1.0 */
|
case 0x10: { /* 8.0.0 - 9.0.0 */
|
||||||
if (memcmp(package1loader_header->build_timestamp, "20190314", 8) == 0) {
|
if (memcmp(package1loader_header->build_timestamp, "20190314", 8) == 0) {
|
||||||
return ATMOSPHERE_TARGET_FIRMWARE_800;
|
return ATMOSPHERE_TARGET_FIRMWARE_800;
|
||||||
} else if (memcmp(package1loader_header->build_timestamp, "20190531", 8) == 0) {
|
} else if (memcmp(package1loader_header->build_timestamp, "20190531", 8) == 0) {
|
||||||
return ATMOSPHERE_TARGET_FIRMWARE_810;
|
return ATMOSPHERE_TARGET_FIRMWARE_810;
|
||||||
|
} else if (memcmp(package1loader_header->build_timestamp, "20190809", 8) == 0) {
|
||||||
|
return ATMOSPHERE_TARGET_FIRMWARE_900;
|
||||||
} else {
|
} else {
|
||||||
fatal_error("[NXBOOT] Unable to identify package1!\n");
|
fatal_error("[NXBOOT] Unable to identify package1!\n");
|
||||||
}
|
}
|
||||||
|
@ -360,6 +362,10 @@ static void nxboot_configure_stratosphere(uint32_t target_firmware) {
|
||||||
if (target_firmware >= ATMOSPHERE_TARGET_FIRMWARE_400 && !(fuse_get_reserved_odm(7) & ~0x0000000F)) {
|
if (target_firmware >= ATMOSPHERE_TARGET_FIRMWARE_400 && !(fuse_get_reserved_odm(7) & ~0x0000000F)) {
|
||||||
kip_patches_set_enable_nogc();
|
kip_patches_set_enable_nogc();
|
||||||
}
|
}
|
||||||
|
/* Check if the fuses are < 9.0.0, but firmware is >= 9.0.0 */
|
||||||
|
if (target_firmware >= ATMOSPHERE_TARGET_FIRMWARE_900 && !(fuse_get_reserved_odm(7) & ~0x000003FF)) {
|
||||||
|
kip_patches_set_enable_nogc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +490,7 @@ uint32_t nxboot_main(void) {
|
||||||
FILE *boot0, *pk2file;
|
FILE *boot0, *pk2file;
|
||||||
void *exosphere_memaddr;
|
void *exosphere_memaddr;
|
||||||
exo_emummc_config_t exo_emummc_cfg;
|
exo_emummc_config_t exo_emummc_cfg;
|
||||||
|
|
||||||
/* Configure emummc or mount the real NAND. */
|
/* Configure emummc or mount the real NAND. */
|
||||||
if (!nxboot_configure_emummc(&exo_emummc_cfg)) {
|
if (!nxboot_configure_emummc(&exo_emummc_cfg)) {
|
||||||
emummc = NULL;
|
emummc = NULL;
|
||||||
|
@ -649,7 +655,7 @@ uint32_t nxboot_main(void) {
|
||||||
fatal_error("[NXBOOT] Failed to get TSEC key!\n");
|
fatal_error("[NXBOOT] Failed to get TSEC key!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display splash screen. */
|
/* Display splash screen. */
|
||||||
display_splash_screen_bmp(loader_ctx->custom_splash_path, (void *)0xC0000000);
|
display_splash_screen_bmp(loader_ctx->custom_splash_path, (void *)0xC0000000);
|
||||||
|
|
||||||
|
@ -801,7 +807,7 @@ uint32_t nxboot_main(void) {
|
||||||
|
|
||||||
/* Wait for the splash screen to have been displayed for as long as it should be. */
|
/* Wait for the splash screen to have been displayed for as long as it should be. */
|
||||||
splash_screen_wait_delay();
|
splash_screen_wait_delay();
|
||||||
|
|
||||||
/* Return the memory address for booting CPU0. */
|
/* Return the memory address for booting CPU0. */
|
||||||
return (uint32_t)exosphere_memaddr;
|
return (uint32_t)exosphere_memaddr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ static bool package2_validate_metadata(package2_meta_t *metadata, uint8_t data[]
|
||||||
|
|
||||||
/* Perform version checks. */
|
/* Perform version checks. */
|
||||||
/* We will be compatible with all package2s released before current, but not newer ones. */
|
/* We will be compatible with all package2s released before current, but not newer ones. */
|
||||||
if (metadata->version_max >= PACKAGE2_MINVER_THEORETICAL && metadata->version_min < PACKAGE2_MAXVER_810_CURRENT) {
|
if (metadata->version_max >= PACKAGE2_MINVER_THEORETICAL && metadata->version_min < PACKAGE2_MAXVER_900_CURRENT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@
|
||||||
#define PACKAGE2_MAXVER_600_610 0x8
|
#define PACKAGE2_MAXVER_600_610 0x8
|
||||||
#define PACKAGE2_MAXVER_620 0x9
|
#define PACKAGE2_MAXVER_620 0x9
|
||||||
#define PACKAGE2_MAXVER_700_800 0xA
|
#define PACKAGE2_MAXVER_700_800 0xA
|
||||||
#define PACKAGE2_MAXVER_810_CURRENT 0xB
|
#define PACKAGE2_MAXVER_810 0xB
|
||||||
|
#define PACKAGE2_MAXVER_900_CURRENT 0xC
|
||||||
|
|
||||||
#define PACKAGE2_MINVER_100 0x3
|
#define PACKAGE2_MINVER_100 0x3
|
||||||
#define PACKAGE2_MINVER_200 0x4
|
#define PACKAGE2_MINVER_200 0x4
|
||||||
|
@ -48,7 +49,8 @@
|
||||||
#define PACKAGE2_MINVER_600_610 0x9
|
#define PACKAGE2_MINVER_600_610 0x9
|
||||||
#define PACKAGE2_MINVER_620 0xA
|
#define PACKAGE2_MINVER_620 0xA
|
||||||
#define PACKAGE2_MINVER_700_800 0xB
|
#define PACKAGE2_MINVER_700_800 0xB
|
||||||
#define PACKAGE2_MINVER_810_CURRENT 0xC
|
#define PACKAGE2_MINVER_810 0xC
|
||||||
|
#define PACKAGE2_MINVER_900_CURRENT 0xD
|
||||||
|
|
||||||
#define NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS ((void *)(0xA9800000ull))
|
#define NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS ((void *)(0xA9800000ull))
|
||||||
|
|
||||||
|
|
|
@ -47,19 +47,26 @@ static const uint8_t AL16 zeroes[0x10] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Note: 9.0.0 did not change the TSEC firmware. Thus, the root key is the same. */
|
||||||
|
/* To avoid distribution of more and more sept binaries, we will simply derive the 9.0.0 master key */
|
||||||
|
/* on 8.1.0 and 9.0.0. Exosphere supports this already with no issues. */
|
||||||
|
|
||||||
static const uint8_t AL16 master_kek_seeds[DERIVATION_ID_MAX][0x10] = {
|
static const uint8_t AL16 master_kek_seeds[DERIVATION_ID_MAX][0x10] = {
|
||||||
{0x9A, 0x3E, 0xA9, 0xAB, 0xFD, 0x56, 0x46, 0x1C, 0x9B, 0xF6, 0x48, 0x7F, 0x5C, 0xFA, 0x09, 0x5C},
|
{0x9A, 0x3E, 0xA9, 0xAB, 0xFD, 0x56, 0x46, 0x1C, 0x9B, 0xF6, 0x48, 0x7F, 0x5C, 0xFA, 0x09, 0x5C},
|
||||||
{0xDE, 0xDC, 0xE3, 0x39, 0x30, 0x88, 0x16, 0xF8, 0xAE, 0x97, 0xAD, 0xEC, 0x64, 0x2D, 0x41, 0x41},
|
/* 8.1.0: {0xDE, 0xDC, 0xE3, 0x39, 0x30, 0x88, 0x16, 0xF8, 0xAE, 0x97, 0xAD, 0xEC, 0x64, 0x2D, 0x41, 0x41}, */
|
||||||
|
{0x1A, 0xEC, 0x11, 0x82, 0x2B, 0x32, 0x38, 0x7A, 0x2B, 0xED, 0xBA, 0x01, 0x47, 0x7E, 0x3B, 0x67},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t AL16 master_devkey_seeds[DERIVATION_ID_MAX][0x10] = {
|
static const uint8_t AL16 master_devkey_seeds[DERIVATION_ID_MAX][0x10] = {
|
||||||
{0x8F, 0x77, 0x5A, 0x96, 0xB0, 0x94, 0xFD, 0x8D, 0x28, 0xE4, 0x19, 0xC8, 0x16, 0x1C, 0xDB, 0x3D},
|
{0x8F, 0x77, 0x5A, 0x96, 0xB0, 0x94, 0xFD, 0x8D, 0x28, 0xE4, 0x19, 0xC8, 0x16, 0x1C, 0xDB, 0x3D},
|
||||||
{0x67, 0x62, 0xD4, 0x8E, 0x55, 0xCF, 0xFF, 0x41, 0x31, 0x15, 0x3B, 0x24, 0x0C, 0x7C, 0x07, 0xAE},
|
/* 8.1.0: {0x67, 0x62, 0xD4, 0x8E, 0x55, 0xCF, 0xFF, 0x41, 0x31, 0x15, 0x3B, 0x24, 0x0C, 0x7C, 0x07, 0xAE}, */
|
||||||
|
{0x4A, 0xC3, 0x4E, 0x14, 0x8B, 0x96, 0x4A, 0xD5, 0xD4, 0x99, 0x73, 0xC4, 0x45, 0xAB, 0x8B, 0x49},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t AL16 master_devkey_vectors[DERIVATION_ID_MAX][0x10] = {
|
static const uint8_t AL16 master_devkey_vectors[DERIVATION_ID_MAX][0x10] = {
|
||||||
{0xD8, 0xD3, 0x67, 0x4F, 0xF3, 0xA2, 0xA4, 0x4E, 0xE4, 0x04, 0x37, 0xC2, 0xD9, 0xCF, 0x41, 0x6F},
|
{0xD8, 0xD3, 0x67, 0x4F, 0xF3, 0xA2, 0xA4, 0x4E, 0xE4, 0x04, 0x37, 0xC2, 0xD9, 0xCF, 0x41, 0x6F},
|
||||||
{0x72, 0xD0, 0xAD, 0xEB, 0xE1, 0xF6, 0x35, 0x90, 0xB4, 0x43, 0xCC, 0x4B, 0xC4, 0xDC, 0x88, 0x0A},
|
/* 8.1.0: {0x72, 0xD0, 0xAD, 0xEB, 0xE1, 0xF6, 0x35, 0x90, 0xB4, 0x43, 0xCC, 0x4B, 0xC4, 0xDC, 0x88, 0x0A}, */
|
||||||
|
{0x8B, 0xD6, 0x13, 0x2F, 0xC3, 0x4D, 0x53, 0x2D, 0x10, 0xA1, 0x63, 0x85, 0x49, 0x2B, 0xCF, 0x3F},
|
||||||
};
|
};
|
||||||
|
|
||||||
void derive_keys(void) {
|
void derive_keys(void) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ void Utils::InitializeThreadFunc(void *args) {
|
||||||
/* Get required services. */
|
/* Get required services. */
|
||||||
DoWithSmSession([&]() {
|
DoWithSmSession([&]() {
|
||||||
Handle tmp_hnd = 0;
|
Handle tmp_hnd = 0;
|
||||||
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
|
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:m"};
|
||||||
for (unsigned int i = 0; i < sts::util::size(required_active_services); i++) {
|
for (unsigned int i = 0; i < sts::util::size(required_active_services); i++) {
|
||||||
R_ASSERT(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])));
|
R_ASSERT(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])));
|
||||||
svcCloseHandle(tmp_hnd);
|
svcCloseHandle(tmp_hnd);
|
||||||
|
|
|
@ -107,8 +107,6 @@ void __appExit(void) {
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
consoleDebugInit(debugDevice_SVC);
|
|
||||||
|
|
||||||
/* Change voltage from 3.3v to 1.8v for select devices. */
|
/* Change voltage from 3.3v to 1.8v for select devices. */
|
||||||
boot::ChangeGpioVoltageTo1_8v();
|
boot::ChangeGpioVoltageTo1_8v();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ enum FirmwareVersion : u32 {
|
||||||
FirmwareVersion_700 = 6,
|
FirmwareVersion_700 = 6,
|
||||||
FirmwareVersion_800 = 7,
|
FirmwareVersion_800 = 7,
|
||||||
FirmwareVersion_810 = 8,
|
FirmwareVersion_810 = 8,
|
||||||
FirmwareVersion_Current = FirmwareVersion_810,
|
FirmwareVersion_900 = 9,
|
||||||
|
FirmwareVersion_Current = FirmwareVersion_900,
|
||||||
FirmwareVersion_Max = 32,
|
FirmwareVersion_Max = 32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ enum AtmosphereTargetFirmware : u32 {
|
||||||
AtmosphereTargetFirmware_700 = 8,
|
AtmosphereTargetFirmware_700 = 8,
|
||||||
AtmosphereTargetFirmware_800 = 9,
|
AtmosphereTargetFirmware_800 = 9,
|
||||||
AtmosphereTargetFirmware_810 = 10,
|
AtmosphereTargetFirmware_810 = 10,
|
||||||
|
AtmosphereTargetFirmware_900 = 11,
|
||||||
};
|
};
|
||||||
|
|
||||||
FirmwareVersion GetRuntimeFirmwareVersion();
|
FirmwareVersion GetRuntimeFirmwareVersion();
|
||||||
|
|
|
@ -110,6 +110,7 @@ namespace sts::ncm {
|
||||||
static const TitleId Olsc;
|
static const TitleId Olsc;
|
||||||
static const TitleId Dt;
|
static const TitleId Dt;
|
||||||
static const TitleId Nd;
|
static const TitleId Nd;
|
||||||
|
static const TitleId Ngct;
|
||||||
|
|
||||||
static const TitleId SystemEnd;
|
static const TitleId SystemEnd;
|
||||||
|
|
||||||
|
@ -279,6 +280,7 @@ namespace sts::ncm {
|
||||||
inline constexpr const TitleId TitleId::Olsc = { 0x010000000000003Eul };
|
inline constexpr const TitleId TitleId::Olsc = { 0x010000000000003Eul };
|
||||||
inline constexpr const TitleId TitleId::Dt = { 0x010000000000003Ful };
|
inline constexpr const TitleId TitleId::Dt = { 0x010000000000003Ful };
|
||||||
inline constexpr const TitleId TitleId::Nd = { 0x0100000000000040ul };
|
inline constexpr const TitleId TitleId::Nd = { 0x0100000000000040ul };
|
||||||
|
inline constexpr const TitleId TitleId::Ngct = { 0x0100000000000041ul };
|
||||||
|
|
||||||
inline constexpr const TitleId TitleId::SystemEnd = { 0x01000000000007FFul };
|
inline constexpr const TitleId TitleId::SystemEnd = { 0x01000000000007FFul };
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace sts::cfg {
|
||||||
sm::ServiceName::Encode("pcv"),
|
sm::ServiceName::Encode("pcv"),
|
||||||
sm::ServiceName::Encode("gpio"),
|
sm::ServiceName::Encode("gpio"),
|
||||||
sm::ServiceName::Encode("pinmux"),
|
sm::ServiceName::Encode("pinmux"),
|
||||||
sm::ServiceName::Encode("psc:c")
|
sm::ServiceName::Encode("psc:m"),
|
||||||
};
|
};
|
||||||
constexpr size_t NumRequiredServicesForSdCardAccess = util::size(RequiredServicesForSdCardAccess);
|
constexpr size_t NumRequiredServicesForSdCardAccess = util::size(RequiredServicesForSdCardAccess);
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ namespace sts::cfg {
|
||||||
return ResultFsSdCardNotPresent;
|
return ResultFsSdCardNotPresent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R_ASSERT(fsMountSdcard(&g_sd_card_filesystem));
|
R_ASSERT(fsMountSdcard(&g_sd_card_filesystem));
|
||||||
g_sd_card_initialized = true;
|
g_sd_card_initialized = true;
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
|
|
|
@ -76,6 +76,9 @@ static void _CacheValues(void)
|
||||||
case AtmosphereTargetFirmware_810:
|
case AtmosphereTargetFirmware_810:
|
||||||
g_firmware_version = FirmwareVersion_810;
|
g_firmware_version = FirmwareVersion_810;
|
||||||
break;
|
break;
|
||||||
|
case AtmosphereTargetFirmware_900:
|
||||||
|
g_firmware_version = FirmwareVersion_900;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
break;
|
break;
|
||||||
|
@ -139,6 +142,11 @@ void SetFirmwareVersionForLibnx() {
|
||||||
minor = 1;
|
minor = 1;
|
||||||
micro = 0;
|
micro = 0;
|
||||||
break;
|
break;
|
||||||
|
case FirmwareVersion_900:
|
||||||
|
major = 9;
|
||||||
|
minor = 0;
|
||||||
|
micro = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -102,6 +102,136 @@ namespace sts::ldr {
|
||||||
bool g_has_nso[Nso_Count];
|
bool g_has_nso[Nso_Count];
|
||||||
NsoHeader g_nso_headers[Nso_Count];
|
NsoHeader g_nso_headers[Nso_Count];
|
||||||
|
|
||||||
|
/* Anti-downgrade. */
|
||||||
|
struct MinimumTitleVersion {
|
||||||
|
ncm::TitleId title_id;
|
||||||
|
u32 version;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr u32 MakeSystemVersion(u32 major, u32 minor, u32 micro) {
|
||||||
|
return (major << 26) | (minor << 20) | (micro << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MinimumTitleVersion g_MinimumTitleVersions810[] = {
|
||||||
|
{ncm::TitleId::Settings, 1},
|
||||||
|
{ncm::TitleId::Bus, 1},
|
||||||
|
{ncm::TitleId::Audio, 1},
|
||||||
|
{ncm::TitleId::NvServices, 1},
|
||||||
|
{ncm::TitleId::Ns, 1},
|
||||||
|
{ncm::TitleId::Ssl, 1},
|
||||||
|
{ncm::TitleId::Es, 1},
|
||||||
|
{ncm::TitleId::Creport, 1},
|
||||||
|
{ncm::TitleId::Ro, 1},
|
||||||
|
};
|
||||||
|
constexpr size_t g_MinimumTitleVersionsCount810 = util::size(g_MinimumTitleVersions810);
|
||||||
|
|
||||||
|
constexpr MinimumTitleVersion g_MinimumTitleVersions900[] = {
|
||||||
|
/* All non-Development System Modules. */
|
||||||
|
{ncm::TitleId::Usb, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Tma, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Boot2, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Settings, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Bus, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Bluetooth, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Bcat, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::Friends, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Nifm, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Ptm, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Shell, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::BsdSockets, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Hid, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Audio, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::LogManager, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Wlan, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Cs, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::Ldn, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::NvServices, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Pcv, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Ppc, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Pcie, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Account, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Ns, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Nfc, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Psc, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::CapSrv, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Am, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Ssl, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Nim, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Cec, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
/* {ncm::TitleId::Tspm, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
/* {ncm::TitleId::Spl, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::Lbl, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Btm, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Erpt, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Time, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::Vi, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Pctl, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Npns, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Eupld, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Glue, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Eclct, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Es, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Fatal, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Grc, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Creport, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Ro, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Profiler, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::Sdb, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Migration, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Jit, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::JpegDec, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::SafeMode, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::Olsc, MakeSystemVersion(9, 0, 0)},
|
||||||
|
/* {ncm::TitleId::Dt, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
/* {ncm::TitleId::Nd, MakeSystemVersion(9, 0, 0)}, */
|
||||||
|
{ncm::TitleId::Ngct, MakeSystemVersion(9, 0, 0)},
|
||||||
|
|
||||||
|
/* All Web Applets. */
|
||||||
|
{ncm::TitleId::AppletWeb, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::AppletShop, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::AppletOfflineWeb, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::AppletLoginShare, MakeSystemVersion(9, 0, 0)},
|
||||||
|
{ncm::TitleId::AppletWifiWebAuth, MakeSystemVersion(9, 0, 0)},
|
||||||
|
};
|
||||||
|
constexpr size_t g_MinimumTitleVersionsCount900 = util::size(g_MinimumTitleVersions900);
|
||||||
|
|
||||||
|
Result ValidateTitleVersion(ncm::TitleId title_id, u32 version) {
|
||||||
|
if (GetRuntimeFirmwareVersion() < FirmwareVersion_810) {
|
||||||
|
return ResultSuccess;
|
||||||
|
} else {
|
||||||
|
#ifdef LDR_VALIDATE_PROCESS_VERSION
|
||||||
|
const MinimumTitleVersion *entries = nullptr;
|
||||||
|
size_t num_entries = 0;
|
||||||
|
switch (GetRuntimeFirmwareVersion()) {
|
||||||
|
case FirmwareVersion_810:
|
||||||
|
entries = g_MinimumTitleVersions810;
|
||||||
|
num_entries = g_MinimumTitleVersionsCount810;
|
||||||
|
break;
|
||||||
|
case FirmwareVersion_900:
|
||||||
|
entries = g_MinimumTitleVersions900;
|
||||||
|
num_entries = g_MinimumTitleVersionsCount900;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
entries = nullptr;
|
||||||
|
num_entries = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < num_entries; i++) {
|
||||||
|
if (entries[i].title_id == title_id && entries[i].version > version) {
|
||||||
|
return ResultLoaderInvalidVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
#else
|
||||||
|
return ResultSuccess;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Helpers. */
|
/* Helpers. */
|
||||||
Result GetProgramInfoFromMeta(ProgramInfo *out, const Meta *meta) {
|
Result GetProgramInfoFromMeta(ProgramInfo *out, const Meta *meta) {
|
||||||
/* Copy basic info. */
|
/* Copy basic info. */
|
||||||
|
@ -115,7 +245,7 @@ namespace sts::ldr {
|
||||||
#define COPY_ACCESS_CONTROL(source, which) \
|
#define COPY_ACCESS_CONTROL(source, which) \
|
||||||
({ \
|
({ \
|
||||||
const size_t size = meta->source->which##_size; \
|
const size_t size = meta->source->which##_size; \
|
||||||
if (offset + size >= sizeof(out->ac_buffer)) { \
|
if (offset + size > sizeof(out->ac_buffer)) { \
|
||||||
return ResultLoaderInternalError; \
|
return ResultLoaderInternalError; \
|
||||||
} \
|
} \
|
||||||
out->source##_##which##_size = size; \
|
out->source##_##which##_size = size; \
|
||||||
|
@ -151,35 +281,6 @@ namespace sts::ldr {
|
||||||
return static_cast<Acid::PoolPartition>((meta->acid->flags & Acid::AcidFlag_PoolPartitionMask) >> Acid::AcidFlag_PoolPartitionShift);
|
return static_cast<Acid::PoolPartition>((meta->acid->flags & Acid::AcidFlag_PoolPartitionMask) >> Acid::AcidFlag_PoolPartitionShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool IsDisallowedVersion810(const ncm::TitleId title_id, const u32 version) {
|
|
||||||
return version == 0 &&
|
|
||||||
(title_id == ncm::TitleId::Settings ||
|
|
||||||
title_id == ncm::TitleId::Bus ||
|
|
||||||
title_id == ncm::TitleId::Audio ||
|
|
||||||
title_id == ncm::TitleId::NvServices ||
|
|
||||||
title_id == ncm::TitleId::Ns ||
|
|
||||||
title_id == ncm::TitleId::Ssl ||
|
|
||||||
title_id == ncm::TitleId::Es ||
|
|
||||||
title_id == ncm::TitleId::Creport ||
|
|
||||||
title_id == ncm::TitleId::Ro);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result ValidateTitleVersion(ncm::TitleId title_id, u32 version) {
|
|
||||||
if (GetRuntimeFirmwareVersion() < FirmwareVersion_810) {
|
|
||||||
return ResultSuccess;
|
|
||||||
} else {
|
|
||||||
#ifdef LDR_VALIDATE_PROCESS_VERSION
|
|
||||||
if (IsDisallowedVersion810(title_id, version)) {
|
|
||||||
return ResultLoaderInvalidVersion;
|
|
||||||
} else {
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return ResultSuccess;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Result LoadNsoHeaders(ncm::TitleId title_id, NsoHeader *nso_headers, bool *has_nso) {
|
Result LoadNsoHeaders(ncm::TitleId title_id, NsoHeader *nso_headers, bool *has_nso) {
|
||||||
/* Clear NSOs. */
|
/* Clear NSOs. */
|
||||||
std::memset(nso_headers, 0, sizeof(*nso_headers) * Nso_Count);
|
std::memset(nso_headers, 0, sizeof(*nso_headers) * Nso_Count);
|
||||||
|
|
|
@ -35,11 +35,11 @@ namespace sts::boot2 {
|
||||||
ncm::TitleId::Bus, /* bus */
|
ncm::TitleId::Bus, /* bus */
|
||||||
ncm::TitleId::Settings, /* settings */
|
ncm::TitleId::Settings, /* settings */
|
||||||
ncm::TitleId::Pcv, /* pcv */
|
ncm::TitleId::Pcv, /* pcv */
|
||||||
|
ncm::TitleId::Usb, /* usb */
|
||||||
};
|
};
|
||||||
constexpr size_t NumPreSdCardLaunchPrograms = util::size(PreSdCardLaunchPrograms);
|
constexpr size_t NumPreSdCardLaunchPrograms = util::size(PreSdCardLaunchPrograms);
|
||||||
|
|
||||||
constexpr ncm::TitleId AdditionalLaunchPrograms[] = {
|
constexpr ncm::TitleId AdditionalLaunchPrograms[] = {
|
||||||
ncm::TitleId::Usb, /* usb */
|
|
||||||
ncm::TitleId::Tma, /* tma */
|
ncm::TitleId::Tma, /* tma */
|
||||||
ncm::TitleId::Am, /* am */
|
ncm::TitleId::Am, /* am */
|
||||||
ncm::TitleId::NvServices, /* nvservices */
|
ncm::TitleId::NvServices, /* nvservices */
|
||||||
|
@ -80,11 +80,11 @@ namespace sts::boot2 {
|
||||||
ncm::TitleId::Migration, /* migration */
|
ncm::TitleId::Migration, /* migration */
|
||||||
ncm::TitleId::Grc, /* grc */
|
ncm::TitleId::Grc, /* grc */
|
||||||
ncm::TitleId::Olsc, /* olsc */
|
ncm::TitleId::Olsc, /* olsc */
|
||||||
|
ncm::TitleId::Ngct, /* ngct */
|
||||||
};
|
};
|
||||||
constexpr size_t NumAdditionalLaunchPrograms = util::size(AdditionalLaunchPrograms);
|
constexpr size_t NumAdditionalLaunchPrograms = util::size(AdditionalLaunchPrograms);
|
||||||
|
|
||||||
constexpr ncm::TitleId AdditionalMaintenanceLaunchPrograms[] = {
|
constexpr ncm::TitleId AdditionalMaintenanceLaunchPrograms[] = {
|
||||||
ncm::TitleId::Usb, /* usb */
|
|
||||||
ncm::TitleId::Tma, /* tma */
|
ncm::TitleId::Tma, /* tma */
|
||||||
ncm::TitleId::Am, /* am */
|
ncm::TitleId::Am, /* am */
|
||||||
ncm::TitleId::NvServices, /* nvservices */
|
ncm::TitleId::NvServices, /* nvservices */
|
||||||
|
@ -121,6 +121,7 @@ namespace sts::boot2 {
|
||||||
ncm::TitleId::Migration, /* migration */
|
ncm::TitleId::Migration, /* migration */
|
||||||
ncm::TitleId::Grc, /* grc */
|
ncm::TitleId::Grc, /* grc */
|
||||||
ncm::TitleId::Olsc, /* olsc */
|
ncm::TitleId::Olsc, /* olsc */
|
||||||
|
ncm::TitleId::Ngct, /* ngct */
|
||||||
};
|
};
|
||||||
constexpr size_t NumAdditionalMaintenanceLaunchPrograms = util::size(AdditionalMaintenanceLaunchPrograms);
|
constexpr size_t NumAdditionalMaintenanceLaunchPrograms = util::size(AdditionalMaintenanceLaunchPrograms);
|
||||||
|
|
||||||
|
@ -156,6 +157,7 @@ namespace sts::boot2 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (out_process_id) {
|
if (out_process_id) {
|
||||||
*out_process_id = process_id;
|
*out_process_id = process_id;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue