From c8052e5b501059e73c9bb9d6b3df0091d36a3213 Mon Sep 17 00:00:00 2001 From: Kostas Missos Date: Sun, 24 Feb 2019 02:34:04 +0200 Subject: [PATCH] [exosphere] Support for new exo config --- bootloader/hos/hos.c | 10 ++--- bootloader/hos/secmon_exo.c | 80 +++++++++++++++++++++++++++++-------- bootloader/hos/secmon_exo.h | 4 +- 3 files changed, 70 insertions(+), 24 deletions(-) diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 3f88d04..93c6203 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -2,7 +2,7 @@ * Copyright (c) 2018 naehrwert * Copyright (c) 2018 st4rk * Copyright (c) 2018 Ced2911 - * Copyright (c) 2018 CTCaer + * Copyright (c) 2018-2019 CTCaer * Copyright (c) 2018 balika011 * * This program is free software; you can redistribute it and/or modify it @@ -518,9 +518,6 @@ int hos_launch(ini_sec_t *cfg) gfx_printf(&gfx_con, "Rebuilt and loaded pkg2\n"); - // Unmount SD card. - sd_unmount(); - gfx_printf(&gfx_con, "\n%kBooting...%k\n", 0xFF96FF00, 0xFFCCCCCC); // Clear pkg1/pkg2 keys. @@ -573,7 +570,10 @@ int hos_launch(ini_sec_t *cfg) // Config Exosphère if booting full Atmosphère. if (ctxt.atmosphere && ctxt.secmon) - config_exosphere(ctxt.pkg1_id->id, ctxt.pkg1_id->kb, ctxt.debugmode); + config_exosphere(ctxt.pkg1_id->id, ctxt.pkg1_id->kb, (void *)ctxt.pkg1_id->warmboot_base, ctxt.pkg1, ctxt.debugmode); + + // Unmount SD card. + sd_unmount(); // Finalize MC carveout. if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_301) diff --git a/bootloader/hos/secmon_exo.c b/bootloader/hos/secmon_exo.c index 70612ab..9a5d75d 100644 --- a/bootloader/hos/secmon_exo.c +++ b/bootloader/hos/secmon_exo.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 CTCaer + * Copyright (C) 2018-2019 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -17,25 +17,43 @@ #include #include "hos.h" +#include "../mem/heap.h" +#include "../storage/sdmmc.h" #include "../utils/types.h" -// Exosphère mailbox defines. -#define EXO_MAGIC_ADDR 0x40002E40 -#define EXO_MAGIC_VAL 0x31434258 -#define EXO_FWNO_ADDR 0x40002E44 -#define EXO_FLAGS_ADDR 0x40002E48 -#define EXO_FLAG_620_KGN (1 << 0) -#define EXO_FLAG_DBG_PRIV (1 << 1) -#define EXO_FLAG_DBG_USER (1 << 2) +typedef struct _exo_cfg_t +{ + vu32 magic; + vu32 fwno; + vu32 flags; + vu32 rsvd; +} exo_cfg_t; -void config_exosphere(const char *id, u32 kb, bool debug) +typedef struct _atm_meta_t +{ + uint32_t magic; + uint32_t fwno; +} wb_cfg_t; + +#define ATM_WB_HEADER_OFF 0x244 +#define ATM_WB_MAGIC 0x30544257 + +// Exosphère mailbox defines. +#define EXO_CFG_DEPR_ADDR 0x40002E40 // Deprecated. +#define EXO_CFG_ADDR 0x8000F000 +#define EXO_MAGIC_DEPR_VAL 0x31434258 +#define EXO_MAGIC_VAL 0x304F5845 +#define EXO_FLAG_620_KGN (1 << 0) +#define EXO_FLAG_DBG_PRIV (1 << 1) +#define EXO_FLAG_DBG_USER (1 << 2) + +void config_exosphere(const char *id, u32 kb, void *warmboot, void *pkg1, bool debug) { u32 exoFwNo = 0; u32 exoFlags = 0; - vu32 *mb_exo_magic = (vu32 *)EXO_MAGIC_ADDR; - vu32 *mb_exo_fw_no = (vu32 *)EXO_FWNO_ADDR; - vu32 *mb_exo_flags = (vu32 *)EXO_FLAGS_ADDR; + volatile exo_cfg_t *exo_cfg_depr = (exo_cfg_t *)EXO_CFG_DEPR_ADDR; + volatile exo_cfg_t *exo_cfg = (exo_cfg_t *)EXO_CFG_ADDR; switch (kb) { @@ -53,14 +71,42 @@ void config_exosphere(const char *id, u32 kb, bool debug) break; } - if (kb >= KB_FIRMWARE_VERSION_620) + if (kb == KB_FIRMWARE_VERSION_620) exoFlags |= EXO_FLAG_620_KGN; if (debug) exoFlags |= EXO_FLAG_DBG_PRIV; // Set mailbox values. - *mb_exo_magic = EXO_MAGIC_VAL; - *mb_exo_fw_no = exoFwNo; - *mb_exo_flags = exoFlags; + exo_cfg_depr->magic = EXO_MAGIC_VAL; + exo_cfg->magic = EXO_MAGIC_VAL; + + exo_cfg_depr->fwno = exoFwNo; + exo_cfg->fwno = exoFwNo; + + exo_cfg_depr->flags = exoFlags; + exo_cfg->flags = exoFlags; + + volatile wb_cfg_t *wb_cfg = (wb_cfg_t *)(warmboot + ATM_WB_HEADER_OFF); + + if (wb_cfg->magic == ATM_WB_MAGIC) + { + wb_cfg->fwno = exoFwNo; + + sdmmc_storage_t storage; + sdmmc_t sdmmc; + + // Set warmboot binary rsa modulus. + u8 *rsa_mod = (u8 *)malloc(512); + + sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4); + sdmmc_storage_set_mmc_partition(&storage, 1); + sdmmc_storage_read(&storage, 1, 1, rsa_mod); + sdmmc_storage_end(&storage); + + // Patch AutoRCM. + rsa_mod[0x10] = 0xF7; + + memcpy(warmboot + 0x10, rsa_mod + 0x10, 0x100); + } } diff --git a/bootloader/hos/secmon_exo.h b/bootloader/hos/secmon_exo.h index f22f02e..41db58d 100644 --- a/bootloader/hos/secmon_exo.h +++ b/bootloader/hos/secmon_exo.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 CTCaer + * Copyright (C) 2018-2019 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -19,6 +19,6 @@ #include "../utils/types.h" -void config_exosphere(const char *id, u32 kb, bool debug); +void config_exosphere(const char *id, u32 kb, void *warmboot, void *pkg1, bool debug); #endif