From abcb1dec4644e6fa77ab9b70e7e201e336d2d9f1 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Thu, 30 Apr 2020 14:44:27 +0300 Subject: [PATCH] boot cfg: Allow Launching UMS from boot. By using `BOOT_CFG_AUTOBOOT_EN` in `boot_cfg` and `EXTRA_CFG_NYX_UMS` in `extra_cfg` you can launch UMS from boot. The `ums` variable must be populated with one of the following: ``` NYX_UMS_SD_CARD 0 NYX_UMS_EMMC_BOOT0 1 NYX_UMS_EMMC_BOOT1 2 NYX_UMS_EMMC_GPP 3 NYX_UMS_EMUMMC_BOOT0 4 NYX_UMS_EMUMMC_BOOT1 5 NYX_UMS_EMUMMC_GPP 6 ``` --- bootloader/main.c | 17 ++++++++++++--- bootloader/utils/types.h | 17 +++++++++++++-- bootloader/utils/util.h | 1 + nyx/nyx_gui/frontend/gui.c | 6 ++++++ nyx/nyx_gui/frontend/gui_tools.c | 37 ++++++++++++++++++++++++++++++++ nyx/nyx_gui/frontend/gui_tools.h | 1 + nyx/nyx_gui/utils/types.h | 17 +++++++++++++-- nyx/nyx_gui/utils/util.h | 1 + 8 files changed, 90 insertions(+), 7 deletions(-) diff --git a/bootloader/main.c b/bootloader/main.c index e32f1fc..a9d6f8e 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -696,10 +696,19 @@ void nyx_load_run() nyx_str->info.errors = h_cfg.errors; nyx_str->cfg = 0; - if (b_cfg.extra_cfg & EXTRA_CFG_NYX_DUMP) + if (b_cfg.extra_cfg) { - b_cfg.extra_cfg &= ~(EXTRA_CFG_NYX_DUMP); - nyx_str->cfg |= NYX_CFG_DUMP; + if (b_cfg.extra_cfg & EXTRA_CFG_NYX_DUMP) + { + b_cfg.extra_cfg &= ~(EXTRA_CFG_NYX_DUMP); + nyx_str->cfg |= NYX_CFG_DUMP; + } + if (b_cfg.extra_cfg & EXTRA_CFG_NYX_UMS) + { + b_cfg.extra_cfg &= ~(EXTRA_CFG_NYX_UMS); + nyx_str->cfg |= NYX_CFG_UMS; + nyx_str->cfg |= b_cfg.ums << 24; + } } nyx_str->version = ipl_ver.version - 0x303030; // Convert ASCII to numbers. @@ -758,6 +767,8 @@ static void _auto_launch_firmware() EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD; check_sept(NULL); } + else if (b_cfg.extra_cfg & EXTRA_CFG_NYX_UMS) + EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD; if (!h_cfg.sept_run) auto_launch_update(); diff --git a/bootloader/utils/types.h b/bootloader/utils/types.h index 96044dc..42c45f7 100644 --- a/bootloader/utils/types.h +++ b/bootloader/utils/types.h @@ -62,9 +62,21 @@ typedef int bool; #define EXTRA_CFG_PAYLOAD (1 << 1) #define EXTRA_CFG_MODULE (1 << 2) +#define EXTRA_CFG_NYX_UMS (1 << 5) #define EXTRA_CFG_NYX_RELOAD (1 << 6) #define EXTRA_CFG_NYX_DUMP (1 << 7) +typedef enum _nyx_ums_type +{ + NYX_UMS_SD_CARD = 0, + NYX_UMS_EMMC_BOOT0, + NYX_UMS_EMMC_BOOT1, + NYX_UMS_EMMC_GPP, + NYX_UMS_EMUMMC_BOOT0, + NYX_UMS_EMUMMC_BOOT1, + NYX_UMS_EMUMMC_GPP +} nyx_ums_type; + typedef struct __attribute__((__packed__)) _boot_cfg_t { u8 boot_cfg; @@ -75,9 +87,10 @@ typedef struct __attribute__((__packed__)) _boot_cfg_t { struct { - char id[8]; - char emummc_path[0x78]; + char id[8]; // 7 char ASCII null teminated. + char emummc_path[0x78]; // emuMMC/XXX, ASCII null teminated. }; + u8 ums; // nyx_ums_type. u8 xt_str[0x80]; }; } boot_cfg_t; diff --git a/bootloader/utils/util.h b/bootloader/utils/util.h index 3ee1671..d918194 100644 --- a/bootloader/utils/util.h +++ b/bootloader/utils/util.h @@ -23,6 +23,7 @@ typedef enum { + NYX_CFG_UMS = (1 << 6), NYX_CFG_DUMP = (1 << 7), } nyx_cfg_t; diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 860c325..e4172be 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -1978,6 +1978,12 @@ static void _nyx_main_menu(lv_theme_t * th) lv_task_t *task_run_dump = lv_task_create(sept_run_dump, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, NULL); lv_task_once(task_run_dump); } + else if (nyx_str->cfg & NYX_CFG_UMS) + { + nyx_str->cfg &= ~(NYX_CFG_UMS); + lv_task_t *task_run_ums = lv_task_create(nyx_run_ums, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, (void *)&nyx_str->cfg); + lv_task_once(task_run_ums); + } } void nyx_load_and_run() diff --git a/nyx/nyx_gui/frontend/gui_tools.c b/nyx/nyx_gui/frontend/gui_tools.c index c3b5f4e..c753a0e 100644 --- a/nyx/nyx_gui/frontend/gui_tools.c +++ b/nyx/nyx_gui/frontend/gui_tools.c @@ -592,6 +592,43 @@ static lv_res_t _action_ums_emuemmc_gpp(lv_obj_t *btn) return LV_RES_OK; } + +void nyx_run_ums(void *param) +{ + u32 *cfg = (u32 *)param; + + u8 type = (*cfg) >> 24; + *cfg = *cfg & 0xFFFFFF; + + // Disable read only flag. + usb_msc_emmc_read_only = false; + + switch (type) + { + case NYX_UMS_SD_CARD: + action_ums_sd(NULL); + break; + case NYX_UMS_EMMC_BOOT0: + _action_ums_emmc_boot0(NULL); + break; + case NYX_UMS_EMMC_BOOT1: + _action_ums_emmc_boot1(NULL); + break; + case NYX_UMS_EMMC_GPP: + _action_ums_emmc_gpp(NULL); + break; + case NYX_UMS_EMUMMC_BOOT0: + _action_ums_emuemmc_boot0(NULL); + break; + case NYX_UMS_EMUMMC_BOOT1: + _action_ums_emuemmc_boot1(NULL); + break; + case NYX_UMS_EMUMMC_GPP: + _action_ums_emuemmc_gpp(NULL); + break; + } +} + static lv_res_t _emmc_read_only_toggle(lv_obj_t *btn) { nyx_generic_onoff_toggle(btn); diff --git a/nyx/nyx_gui/frontend/gui_tools.h b/nyx/nyx_gui/frontend/gui_tools.h index 559b422..7295488 100644 --- a/nyx/nyx_gui/frontend/gui_tools.h +++ b/nyx/nyx_gui/frontend/gui_tools.h @@ -22,6 +22,7 @@ lv_obj_t *ums_mbox; void create_tab_tools(lv_theme_t *th, lv_obj_t *parent); +void nyx_run_ums(void *param); void sept_run_dump(void *param); bool get_autorcm_status(bool change); lv_res_t action_ums_sd(lv_obj_t *btn); diff --git a/nyx/nyx_gui/utils/types.h b/nyx/nyx_gui/utils/types.h index 96044dc..42c45f7 100644 --- a/nyx/nyx_gui/utils/types.h +++ b/nyx/nyx_gui/utils/types.h @@ -62,9 +62,21 @@ typedef int bool; #define EXTRA_CFG_PAYLOAD (1 << 1) #define EXTRA_CFG_MODULE (1 << 2) +#define EXTRA_CFG_NYX_UMS (1 << 5) #define EXTRA_CFG_NYX_RELOAD (1 << 6) #define EXTRA_CFG_NYX_DUMP (1 << 7) +typedef enum _nyx_ums_type +{ + NYX_UMS_SD_CARD = 0, + NYX_UMS_EMMC_BOOT0, + NYX_UMS_EMMC_BOOT1, + NYX_UMS_EMMC_GPP, + NYX_UMS_EMUMMC_BOOT0, + NYX_UMS_EMUMMC_BOOT1, + NYX_UMS_EMUMMC_GPP +} nyx_ums_type; + typedef struct __attribute__((__packed__)) _boot_cfg_t { u8 boot_cfg; @@ -75,9 +87,10 @@ typedef struct __attribute__((__packed__)) _boot_cfg_t { struct { - char id[8]; - char emummc_path[0x78]; + char id[8]; // 7 char ASCII null teminated. + char emummc_path[0x78]; // emuMMC/XXX, ASCII null teminated. }; + u8 ums; // nyx_ums_type. u8 xt_str[0x80]; }; } boot_cfg_t; diff --git a/nyx/nyx_gui/utils/util.h b/nyx/nyx_gui/utils/util.h index 3ee1671..d918194 100644 --- a/nyx/nyx_gui/utils/util.h +++ b/nyx/nyx_gui/utils/util.h @@ -23,6 +23,7 @@ typedef enum { + NYX_CFG_UMS = (1 << 6), NYX_CFG_DUMP = (1 << 7), } nyx_cfg_t;