[Boot cfg] Proper usage of storage and structs

This commit is contained in:
Kostas Missos 2019-03-07 23:41:07 +02:00
parent 3b9bf65071
commit ca68818efe
5 changed files with 42 additions and 27 deletions

View file

@ -61,7 +61,7 @@ u8 warmboot_reboot[] = {
#define SEPT_STG2_ADDR (SEPT_PK1T_ADDR + 0x60E0) #define SEPT_STG2_ADDR (SEPT_PK1T_ADDR + 0x60E0)
#define SEPT_PKG_SZ (0x2F100 + WB_RST_SIZE) #define SEPT_PKG_SZ (0x2F100 + WB_RST_SIZE)
extern boot_cfg_t *b_cfg; extern boot_cfg_t b_cfg;
extern hekate_config h_cfg; extern hekate_config h_cfg;
extern void *sd_file_read(char *path); extern void *sd_file_read(char *path);
extern void sd_mount(); extern void sd_mount();
@ -135,7 +135,7 @@ int reboot_to_sept(const u8 *tsec_fw)
// Save auto boot config to payload, if any. // Save auto boot config to payload, if any.
boot_cfg_t *tmp_cfg = malloc(sizeof(boot_cfg_t)); boot_cfg_t *tmp_cfg = malloc(sizeof(boot_cfg_t));
memcpy(tmp_cfg, b_cfg, sizeof(boot_cfg_t)); memcpy(tmp_cfg, &b_cfg, sizeof(boot_cfg_t));
tmp_cfg->boot_cfg |= (BOOT_CFG_AUTOBOOT_EN | BOOT_CFG_SEPT_RUN); tmp_cfg->boot_cfg |= (BOOT_CFG_AUTOBOOT_EN | BOOT_CFG_SEPT_RUN);

View file

@ -5,7 +5,7 @@ SECTIONS {
. = __ipl_start; . = __ipl_start;
.text : { .text : {
*(.text._start); *(.text._start);
. = . + 36; *(._boot_cfg);
*(.text*); *(.text*);
} }
.data : { .data : {

View file

@ -68,8 +68,14 @@ static bool sd_mounted;
u8 *Kc_MENU_LOGO; u8 *Kc_MENU_LOGO;
#endif //MENU_LOGO_ENABLE #endif //MENU_LOGO_ENABLE
boot_cfg_t *b_cfg;
hekate_config h_cfg; hekate_config h_cfg;
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = {
.magic = BL_MAGIC,
.version = (BL_VER_MJ + '0') | ((BL_VER_MN + '0') << 8) | ((BL_VER_HF + '0') << 16),
.rsvd0 = 0,
.rsvd1 = 0
};
bool sd_mount() bool sd_mount()
{ {
@ -614,9 +620,9 @@ void ini_list_launcher()
if (ments[j].data == cfg_tmp) if (ments[j].data == cfg_tmp)
{ {
b_cfg->boot_cfg = BOOT_CFG_FROM_LAUNCH; b_cfg.boot_cfg = BOOT_CFG_FROM_LAUNCH;
b_cfg->autoboot = j - non_cfg; b_cfg.autoboot = j - non_cfg;
b_cfg->autoboot_list = 1; b_cfg.autoboot_list = 1;
break; break;
} }
@ -750,9 +756,9 @@ void launch_firmware()
non_cfg++; non_cfg++;
if (ments[j].data == cfg_tmp) if (ments[j].data == cfg_tmp)
{ {
b_cfg->boot_cfg = BOOT_CFG_FROM_LAUNCH; b_cfg.boot_cfg = BOOT_CFG_FROM_LAUNCH;
b_cfg->autoboot = j - non_cfg; b_cfg.autoboot = j - non_cfg;
b_cfg->autoboot_list = 0; b_cfg.autoboot_list = 0;
break; break;
} }
@ -889,15 +895,15 @@ void auto_launch_firmware()
boot_entry_id++; boot_entry_id++;
// Override autoboot, otherwise save it for a possbile sept run. // Override autoboot, otherwise save it for a possbile sept run.
if (b_cfg->boot_cfg & BOOT_CFG_AUTOBOOT_EN) if (b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN)
{ {
h_cfg.autoboot = b_cfg->autoboot; h_cfg.autoboot = b_cfg.autoboot;
h_cfg.autoboot_list = b_cfg->autoboot_list; h_cfg.autoboot_list = b_cfg.autoboot_list;
} }
else else
{ {
b_cfg->autoboot = h_cfg.autoboot; b_cfg.autoboot = h_cfg.autoboot;
b_cfg->autoboot_list = h_cfg.autoboot_list; b_cfg.autoboot_list = h_cfg.autoboot_list;
} }
continue; continue;
@ -917,7 +923,7 @@ void auto_launch_firmware()
} }
} }
if (h_cfg.autohosoff && !(b_cfg->boot_cfg & BOOT_CFG_AUTOBOOT_EN)) if (h_cfg.autohosoff && !(b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN))
check_power_off_from_hos(); check_power_off_from_hos();
if (h_cfg.autoboot_list) if (h_cfg.autoboot_list)
@ -977,7 +983,7 @@ void auto_launch_firmware()
check_sept(); check_sept();
u8 *bitmap = NULL; u8 *bitmap = NULL;
if (!(b_cfg->boot_cfg & BOOT_CFG_FROM_LAUNCH)) if (!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH))
{ {
if (bootlogoCustomEntry != NULL) // Check if user set custom logo path at the boot entry. if (bootlogoCustomEntry != NULL) // Check if user set custom logo path at the boot entry.
{ {
@ -1050,13 +1056,13 @@ void auto_launch_firmware()
free(Kc_MENU_LOGO); free(Kc_MENU_LOGO);
#endif //MENU_LOGO_ENABLE #endif //MENU_LOGO_ENABLE
if (b_cfg->boot_cfg & BOOT_CFG_FROM_LAUNCH) if (b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH)
display_backlight_brightness(h_cfg.backlight, 0); display_backlight_brightness(h_cfg.backlight, 0);
else if (h_cfg.bootwait) else if (h_cfg.bootwait)
display_backlight_brightness(h_cfg.backlight, 1000); display_backlight_brightness(h_cfg.backlight, 1000);
// Wait before booting. If VOL- is pressed go into bootloader menu. // Wait before booting. If VOL- is pressed go into bootloader menu.
if (!(b_cfg->boot_cfg & BOOT_CFG_FROM_LAUNCH)) if (!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH))
{ {
btn = btn_wait_timeout(h_cfg.bootwait * 1000, BTN_VOL_DOWN); btn = btn_wait_timeout(h_cfg.bootwait * 1000, BTN_VOL_DOWN);
@ -1087,7 +1093,7 @@ out:
sd_unmount(); sd_unmount();
gfx_con.mute = false; gfx_con.mute = false;
b_cfg->boot_cfg &= ~(BOOT_CFG_AUTOBOOT_EN | BOOT_CFG_FROM_LAUNCH); b_cfg.boot_cfg &= ~(BOOT_CFG_AUTOBOOT_EN | BOOT_CFG_FROM_LAUNCH);
} }
void about() void about()
@ -1266,9 +1272,6 @@ extern void pivot_stack(u32 stack_top);
void ipl_main() void ipl_main()
{ {
// Set boot config address.
b_cfg = (boot_cfg_t *)(IPL_LOAD_ADDR + PATCHED_RELOC_SZ);
// Do initial HW configuration. This is compatible with consecutive reruns without a reset. // Do initial HW configuration. This is compatible with consecutive reruns without a reset.
config_hw(); config_hw();

View file

@ -37,7 +37,7 @@
#include "../utils/util.h" #include "../utils/util.h"
extern sdmmc_t sd_sdmmc; extern sdmmc_t sd_sdmmc;
extern boot_cfg_t *b_cfg; extern boot_cfg_t b_cfg;
void _config_oscillators() void _config_oscillators()
{ {
@ -147,7 +147,7 @@ void _mbist_workaround()
void _config_se_brom() void _config_se_brom()
{ {
// Skip SBK/SSK if sept was run. // Skip SBK/SSK if sept was run.
if (!(b_cfg->boot_cfg & BOOT_CFG_SEPT_RUN)) if (!(b_cfg.boot_cfg & BOOT_CFG_SEPT_RUN))
{ {
// Bootrom part we skipped. // Bootrom part we skipped.
u32 sbk[4] = { u32 sbk[4] = {

View file

@ -55,13 +55,25 @@ typedef int bool;
#define BOOT_CFG_FROM_LAUNCH (1 << 1) #define BOOT_CFG_FROM_LAUNCH (1 << 1)
#define BOOT_CFG_SEPT_RUN (1 << 7) #define BOOT_CFG_SEPT_RUN (1 << 7)
#define EXTRA_CFG_KEYS (1 << 0)
#define EXTRA_CFG_PAYLOAD (1 << 1)
#define EXTRA_CFG_MODULE (1 << 2)
typedef struct __attribute__((__packed__)) _boot_cfg_t typedef struct __attribute__((__packed__)) _boot_cfg_t
{ {
u8 boot_cfg; u8 boot_cfg;
u8 autoboot; u8 autoboot;
u8 autoboot_list; u8 autoboot_list;
u8 rsvd_cfg; u8 extra_cfg;
u8 rsvd[32]; u8 rsvd[128];
} boot_cfg_t; } boot_cfg_t;
typedef struct __attribute__((__packed__)) _ipl_ver_meta_t
{
u32 magic;
u32 version;
u16 rsvd0;
u16 rsvd1;
} ipl_ver_meta_t;
#endif #endif