From a664118fc7b97925fbd7b1c85262a78025224ba3 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Thu, 12 Dec 2019 00:13:32 +0200 Subject: [PATCH] r2p: Update r2p payload 2 modes: - With updater2p; Forces the reboot to payload binary to be hekate - Without; Checks if hekate and then if old --- README.md | 1 + bootloader/config/config.c | 4 ++++ bootloader/config/config.h | 1 + bootloader/hos/fss.c | 34 ++++++++++++++++++++++++++++++++-- bootloader/hos/fss.h | 2 +- bootloader/main.c | 2 ++ nyx/nyx_gui/config/config.c | 4 ++++ nyx/nyx_gui/config/config.h | 1 + nyx/nyx_gui/nyx.c | 2 ++ 9 files changed, 48 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 701ae0b..07aa253 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ You can find a template [Here](./res/hekate_ipl_template.ini) | verification=2 | 0: Disable Backup/Restore verification, 1: Sparse (block based, fast and not 100% reliable), 2: Full (sha256 based, slow and 100% reliable). | | autohosoff=1 | 0: Disable, 1: If woke up from HOS via an RTC alarm, shows logo, then powers off completely, 2: No logo, immediately powers off.| | autonogc=1 | 0: Disable, 1: Automatically applies nogc patch if unburnt fuses found and a >= 4.0.0 HOS is booted. | +| updater2p=0 | 0: Disable, 1: Force updates (if needed) the reboot2payload binary to be hekate. | | backlight=100 | Screen backlight level. 0-255. | diff --git a/bootloader/config/config.c b/bootloader/config/config.c index 38e5bcf..2c36b5d 100644 --- a/bootloader/config/config.c +++ b/bootloader/config/config.c @@ -43,6 +43,7 @@ void set_default_configuration() h_cfg.backlight = 100; h_cfg.autohosoff = 0; h_cfg.autonogc = 1; + h_cfg.updater2p = 0; h_cfg.brand = NULL; h_cfg.tagline = NULL; h_cfg.errors = 0; @@ -108,6 +109,9 @@ int create_config_entry() f_puts("\nautonogc=", &fp); itoa(h_cfg.autonogc, lbuf, 10); f_puts(lbuf, &fp); + f_puts("\nupdater2p=", &fp); + itoa(h_cfg.updater2p, lbuf, 10); + f_puts(lbuf, &fp); if (h_cfg.brand) { f_puts("\nbrand=", &fp); diff --git a/bootloader/config/config.h b/bootloader/config/config.h index 96ca8d0..a6fbc5c 100644 --- a/bootloader/config/config.h +++ b/bootloader/config/config.h @@ -29,6 +29,7 @@ typedef struct _hekate_config u32 backlight; u32 autohosoff; u32 autonogc; + u32 updater2p; char *brand; char *tagline; // Global temporary config. diff --git a/bootloader/hos/fss.c b/bootloader/hos/fss.c index b70b3fd..5d2455d 100644 --- a/bootloader/hos/fss.c +++ b/bootloader/hos/fss.c @@ -30,6 +30,9 @@ extern hekate_config h_cfg; +extern void *sd_file_read(const char *path, u32 *fsize); +extern bool is_ipl_updated(void *buf, char *path, bool force); + #define FSS0_MAGIC 0x30535346 #define CNT_TYPE_FSP 0 #define CNT_TYPE_EXO 1 @@ -62,7 +65,32 @@ typedef struct _fss_content_t char name[0x10]; } fss_content_t; -int parse_fss(launch_ctxt_t *ctxt, const char *value) +static void _update_r2p(const char *path) +{ + char *r2p_path = malloc(256); + u32 path_len = strlen(path); + strcpy(r2p_path, path); + + while(path_len) + { + if ((r2p_path[path_len - 1] == '/') || (r2p_path[path_len - 1] == 0x5C)) + { + r2p_path[path_len] = 0; + strcat(r2p_path, "reboot_payload.bin"); + u8 *r2p_payload = sd_file_read(r2p_path, NULL); + + is_ipl_updated(r2p_payload, r2p_path, h_cfg.updater2p ? true : false); + + free(r2p_payload); + break; + } + path_len--; + } + + free(r2p_path); +} + +int parse_fss(launch_ctxt_t *ctxt, const char *path) { FIL fp; @@ -78,7 +106,7 @@ int parse_fss(launch_ctxt_t *ctxt, const char *value) if (stock && ctxt->pkg1_id->kb <= KB_FIRMWARE_VERSION_620 && (!emu_cfg.enabled || h_cfg.emummc_force_disable)) return 1; - if (f_open(&fp, value, FA_READ) != FR_OK) + if (f_open(&fp, path, FA_READ) != FR_OK) return 0; ctxt->atmosphere = true; @@ -139,6 +167,8 @@ int parse_fss(launch_ctxt_t *ctxt, const char *value) gfx_printf("Done!\n"); f_close(&fp); + _update_r2p(path); + return 1; } diff --git a/bootloader/hos/fss.h b/bootloader/hos/fss.h index f3669df..e003647 100644 --- a/bootloader/hos/fss.h +++ b/bootloader/hos/fss.h @@ -19,6 +19,6 @@ #include "hos.h" -int parse_fss(launch_ctxt_t *ctxt, const char *value); +int parse_fss(launch_ctxt_t *ctxt, const char *path); #endif diff --git a/bootloader/main.c b/bootloader/main.c index e55c846..1f9cf10 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -862,6 +862,8 @@ static void _auto_launch_firmware() h_cfg.autohosoff = atoi(kv->val); else if (!strcmp("autonogc", kv->key)) h_cfg.autonogc = atoi(kv->val); + else if (!strcmp("updater2p", kv->key)) + h_cfg.updater2p = atoi(kv->val); else if (!strcmp("brand", kv->key)) { h_cfg.brand = malloc(strlen(kv->val) + 1); diff --git a/nyx/nyx_gui/config/config.c b/nyx/nyx_gui/config/config.c index af234b8..e1c566e 100644 --- a/nyx/nyx_gui/config/config.c +++ b/nyx/nyx_gui/config/config.c @@ -43,6 +43,7 @@ void set_default_configuration() h_cfg.backlight = 100; h_cfg.autohosoff = 0; h_cfg.autonogc = 1; + h_cfg.updater2p = 0; h_cfg.brand = NULL; h_cfg.tagline = NULL; h_cfg.errors = 0; @@ -108,6 +109,9 @@ int create_config_entry() f_puts("\nautonogc=", &fp); itoa(h_cfg.autonogc, lbuf, 10); f_puts(lbuf, &fp); + f_puts("\nupdater2p=", &fp); + itoa(h_cfg.updater2p, lbuf, 10); + f_puts(lbuf, &fp); if (h_cfg.brand) { f_puts("\nbrand=", &fp); diff --git a/nyx/nyx_gui/config/config.h b/nyx/nyx_gui/config/config.h index 32e934c..2dc37b0 100644 --- a/nyx/nyx_gui/config/config.h +++ b/nyx/nyx_gui/config/config.h @@ -29,6 +29,7 @@ typedef struct _hekate_config u32 backlight; u32 autohosoff; u32 autonogc; + u32 updater2p; char *brand; char *tagline; // Global temporary config. diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 79296e7..4812228 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -341,6 +341,8 @@ void load_saved_configuration() h_cfg.autohosoff = atoi(kv->val); else if (!strcmp("autonogc", kv->key)) h_cfg.autonogc = atoi(kv->val); + else if (!strcmp("updater2p", kv->key)) + h_cfg.updater2p = atoi(kv->val); else if (!strcmp("brand", kv->key)) { h_cfg.brand = malloc(strlen(kv->val) + 1);