From 85bf7c86e082201fb7183deb0b0e690227f91273 Mon Sep 17 00:00:00 2001 From: hexkyz Date: Sat, 6 Jul 2019 20:58:01 +0100 Subject: [PATCH] fusee: cleanup and optimize boot sequence --- exosphere/lp0fw/src/car.h | 2 +- fusee/fusee-primary/src/car.c | 6 ++-- fusee/fusee-primary/src/car.h | 2 +- fusee/fusee-primary/src/hwinit.c | 4 +-- fusee/fusee-primary/src/main.c | 56 ++++++++++++++++++----------- fusee/fusee-primary/src/panic.c | 36 ++++++++++++++----- fusee/fusee-primary/src/panic.h | 1 - fusee/fusee-primary/src/stage2.h | 2 +- fusee/fusee-secondary/src/car.c | 6 ++-- fusee/fusee-secondary/src/car.h | 2 +- fusee/fusee-secondary/src/console.c | 36 ++++++++++--------- fusee/fusee-secondary/src/console.h | 4 +-- fusee/fusee-secondary/src/main.c | 40 +++++++++++---------- fusee/fusee-secondary/src/nxboot.c | 4 --- fusee/fusee-secondary/src/panic.c | 18 +++++----- fusee/fusee-secondary/src/stage2.h | 1 - sept/sept-primary/src/car.c | 6 ++-- sept/sept-primary/src/car.h | 2 +- sept/sept-secondary/src/car.c | 6 ++-- sept/sept-secondary/src/car.h | 2 +- sept/sept-secondary/src/hwinit.c | 4 +-- sept/sept-secondary/src/main.c | 12 +++---- sept/sept-secondary/src/stage2.h | 2 +- 23 files changed, 143 insertions(+), 111 deletions(-) diff --git a/exosphere/lp0fw/src/car.h b/exosphere/lp0fw/src/car.h index cb9ddde3c..12d66f3e9 100644 --- a/exosphere/lp0fw/src/car.h +++ b/exosphere/lp0fw/src/car.h @@ -79,7 +79,7 @@ typedef enum { CARDEVICE_UARTC = ((1 << 5) | 0x17), CARDEVICE_I2C1 = ((0 << 5) | 0xC), CARDEVICE_I2C5 = ((1 << 5) | 0xF), - CARDEVICE_UNK = ((3 << 5) | 0x1E), + CARDEVICE_TZRAM = ((3 << 5) | 0x1E), CARDEVICE_SE = ((3 << 5) | 0x1F), CARDEVICE_HOST1X = ((0 << 5) | 0x1C), CARDEVICE_TSEC = ((2 << 5) | 0x13), diff --git a/fusee/fusee-primary/src/car.c b/fusee/fusee-primary/src/car.c index c94fc4cd4..b8e03bd6c 100644 --- a/fusee/fusee-primary/src/car.c +++ b/fusee/fusee-primary/src/car.c @@ -25,7 +25,7 @@ static inline uint32_t get_clk_source_reg(CarDevice dev) { case CARDEVICE_UARTC: return 0x1A0; case CARDEVICE_I2C1: return 0x124; case CARDEVICE_I2C5: return 0x128; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0x42C; case CARDEVICE_HOST1X: return 0x180; case CARDEVICE_TSEC: return 0x1F4; @@ -48,7 +48,7 @@ static inline uint32_t get_clk_source_val(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 6; case CARDEVICE_I2C5: return 6; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 4; case CARDEVICE_TSEC: return 0; @@ -71,7 +71,7 @@ static inline uint32_t get_clk_source_div(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 0; case CARDEVICE_I2C5: return 0; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 3; case CARDEVICE_TSEC: return 2; diff --git a/fusee/fusee-primary/src/car.h b/fusee/fusee-primary/src/car.h index cc89161b0..36f850a5a 100644 --- a/fusee/fusee-primary/src/car.h +++ b/fusee/fusee-primary/src/car.h @@ -42,7 +42,7 @@ typedef enum { CARDEVICE_UARTC = ((1 << 5) | 0x17), CARDEVICE_I2C1 = ((0 << 5) | 0xC), CARDEVICE_I2C5 = ((1 << 5) | 0xF), - CARDEVICE_UNK = ((3 << 5) | 0x1E), + CARDEVICE_TZRAM = ((3 << 5) | 0x1E), CARDEVICE_SE = ((3 << 5) | 0x1F), CARDEVICE_HOST1X = ((0 << 5) | 0x1C), CARDEVICE_TSEC = ((2 << 5) | 0x13), diff --git a/fusee/fusee-primary/src/hwinit.c b/fusee/fusee-primary/src/hwinit.c index 7faee72b8..e99aa3644 100644 --- a/fusee/fusee-primary/src/hwinit.c +++ b/fusee/fusee-primary/src/hwinit.c @@ -236,8 +236,8 @@ void nx_hwinit() /* NOTE: [4.0.0+] This was removed. */ /* clkrst_reboot(CARDEVICE_SE); */ - /* Reboot unknown device. */ - clkrst_reboot(CARDEVICE_UNK); + /* Reboot TZRAM. */ + clkrst_reboot(CARDEVICE_TZRAM); /* Initialize I2C1. */ /* NOTE: [6.0.0+] This was moved to after the PMIC is configured. */ diff --git a/fusee/fusee-primary/src/main.c b/fusee/fusee-primary/src/main.c index 46e949536..779f6cae6 100644 --- a/fusee/fusee-primary/src/main.c +++ b/fusee/fusee-primary/src/main.c @@ -84,12 +84,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, return 1; } -static void setup_env(void) { +static void setup_display(void) { g_framebuffer = (void *)0xC0000000; - - /* Initialize hardware. */ - nx_hwinit(); - + /* Zero-fill the framebuffer and register it as printk provider. */ video_init(g_framebuffer); @@ -102,6 +99,19 @@ static void setup_env(void) { /* Turn on the backlight after initializing the lfb */ /* to avoid flickering. */ display_backlight(true); +} + +static void cleanup_display(void) { + /* Turn off the backlight. */ + display_backlight(false); + + /* Terminate the display. */ + display_end(); +} + +static void setup_env(void) { + /* Initialize hardware. */ + nx_hwinit(); /* Set up the exception handlers. */ setup_exception_handlers(); @@ -113,9 +123,6 @@ static void setup_env(void) { static void cleanup_env(void) { /* Unmount the SD card. */ unmount_sd(); - - display_backlight(false); - display_end(); } static void exit_callback(int rc) { @@ -128,12 +135,9 @@ int main(void) { const char *stage2_path; stage2_args_t *stage2_args; uint32_t stage2_version = 0; - ScreenLogLevel log_level = SCREEN_LOG_LEVEL_MANDATORY; - - /* Override the global logging level. */ - log_set_log_level(log_level); - - /* Initialize the display, console, etc. */ + ScreenLogLevel log_level = SCREEN_LOG_LEVEL_NONE; + + /* Initialize the boot environment. */ setup_env(); /* Check for panics. */ @@ -147,8 +151,16 @@ int main(void) { fatal_error("Failed to parse BCT.ini!\n"); } + /* Override the global logging level. */ + log_set_log_level(log_level); + + if (log_level != SCREEN_LOG_LEVEL_NONE) { + /* Initialize the display for debugging. */ + setup_display(); + } + /* Say hello. */ - print(SCREEN_LOG_LEVEL_MANDATORY, "Welcome to Atmosph\xe8re Fus\xe9" "e!\n"); + print(SCREEN_LOG_LEVEL_DEBUG | SCREEN_LOG_LEVEL_NO_PREFIX, "Welcome to Atmosph\xe8re Fus\xe9" "e!\n"); print(SCREEN_LOG_LEVEL_DEBUG, "Using color linear framebuffer at 0x%p!\n", g_framebuffer); /* Load the loader payload into DRAM. */ @@ -160,15 +172,19 @@ int main(void) { stage2_args = (stage2_args_t *)(g_chainloader_arg_data + strlen(stage2_path) + 1); /* May be unaligned. */ memcpy(&stage2_args->version, &stage2_version, 4); memcpy(&stage2_args->log_level, &log_level, sizeof(log_level)); - stage2_args->display_initialized = false; strcpy(stage2_args->bct0, bct0); g_chainloader_argc = 2; - /* Wait a while. */ - mdelay(1000); - - /* Deinitialize the display, console, etc. */ + /* Terminate the boot environment. */ cleanup_env(); + + if (log_level != SCREEN_LOG_LEVEL_NONE) { + /* Wait a while for debugging. */ + mdelay(1000); + + /* Terminate the display for debugging. */ + cleanup_display(); + } /* Finally, after the cleanup routines (__libc_fini_array, etc.) are called, jump to Stage2. */ __program_exit_callback = exit_callback; diff --git a/fusee/fusee-primary/src/panic.c b/fusee/fusee-primary/src/panic.c index be7b8d35d..b7c5f62da 100644 --- a/fusee/fusee-primary/src/panic.c +++ b/fusee/fusee-primary/src/panic.c @@ -22,6 +22,7 @@ #include "utils.h" #include "fs_utils.h" #include "lib/log.h" +#include "display/video_fb.h" static uint32_t g_panic_code = 0; @@ -56,6 +57,22 @@ static void _check_and_display_atmosphere_fatal_error(void) { } { + /* Zero-fill the framebuffer and register it as printk provider. */ + video_init((void *)0xC0000000); + + /* Initialize the display. */ + display_init(); + + /* Set the framebuffer. */ + display_init_framebuffer((void *)0xC0000000); + + /* Turn on the backlight after initializing the lfb */ + /* to avoid flickering. */ + display_backlight(true); + + /* Override the global logging level. */ + log_set_log_level(SCREEN_LOG_LEVEL_ERROR); + /* Copy fatal error context to the stack. */ atmosphere_fatal_error_ctx ctx = *(ATMOSPHERE_FATAL_ERROR_CONTEXT); @@ -79,6 +96,7 @@ static void _check_and_display_atmosphere_fatal_error(void) { print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX,"\nPress POWER to reboot\n"); } + /* Wait for button and reboot. */ wait_for_button_and_reboot(); } @@ -87,11 +105,9 @@ void check_and_display_panic(void) { _check_and_display_atmosphere_fatal_error(); /* We also handle our own panics. */ - /* In the case of our own panics, we assume that the display has already been initialized. */ - bool has_panic = APBDEV_PMC_RST_STATUS_0 != 0 || g_panic_code != 0; - uint32_t code = g_panic_code == 0 ? APBDEV_PMC_SCRATCH200_0 : g_panic_code; - - has_panic = has_panic && !(APBDEV_PMC_RST_STATUS_0 != 1 && code == PANIC_CODE_SAFEMODE); + bool has_panic = ((APBDEV_PMC_RST_STATUS_0 != 0) || (g_panic_code != 0)); + uint32_t code = (g_panic_code == 0) ? APBDEV_PMC_SCRATCH200_0 : g_panic_code; + has_panic = has_panic && !((APBDEV_PMC_RST_STATUS_0 != 1) && (code == PANIC_CODE_SAFEMODE)); if (has_panic) { uint32_t color; @@ -134,11 +150,13 @@ void check_and_display_panic(void) { break; } - if (g_panic_code == 0) { - display_init(); - } - + /* Initialize the display. */ + display_init(); + + /* Fill the screen. */ display_color_screen(color); + + /* Wait for button and reboot. */ wait_for_button_and_reboot(); } else { g_panic_code = 0; diff --git a/fusee/fusee-primary/src/panic.h b/fusee/fusee-primary/src/panic.h index 1f6654f30..3f14d05d3 100644 --- a/fusee/fusee-primary/src/panic.h +++ b/fusee/fusee-primary/src/panic.h @@ -28,7 +28,6 @@ #define PANIC_CODE_SAFEMODE 0x00000020 - #define AMS_FATAL_ERROR_MAX_STACKTRACE 0x20 #define AMS_FATAL_ERROR_MAX_STACKDUMP 0x100 diff --git a/fusee/fusee-primary/src/stage2.h b/fusee/fusee-primary/src/stage2.h index f3b2fdc7c..e89f550fd 100644 --- a/fusee/fusee-primary/src/stage2.h +++ b/fusee/fusee-primary/src/stage2.h @@ -34,6 +34,7 @@ #define STAGE2_NAME_KEY "stage2_path" #define STAGE2_ADDRESS_KEY "stage2_addr" #define STAGE2_ENTRYPOINT_KEY "stage2_entrypoint" + #define BCTO_MAX_SIZE 0x5800 typedef struct { @@ -45,7 +46,6 @@ typedef struct { typedef struct { uint32_t version; ScreenLogLevel log_level; - bool display_initialized; char bct0[BCTO_MAX_SIZE]; } stage2_args_t; diff --git a/fusee/fusee-secondary/src/car.c b/fusee/fusee-secondary/src/car.c index c94fc4cd4..b8e03bd6c 100644 --- a/fusee/fusee-secondary/src/car.c +++ b/fusee/fusee-secondary/src/car.c @@ -25,7 +25,7 @@ static inline uint32_t get_clk_source_reg(CarDevice dev) { case CARDEVICE_UARTC: return 0x1A0; case CARDEVICE_I2C1: return 0x124; case CARDEVICE_I2C5: return 0x128; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0x42C; case CARDEVICE_HOST1X: return 0x180; case CARDEVICE_TSEC: return 0x1F4; @@ -48,7 +48,7 @@ static inline uint32_t get_clk_source_val(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 6; case CARDEVICE_I2C5: return 6; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 4; case CARDEVICE_TSEC: return 0; @@ -71,7 +71,7 @@ static inline uint32_t get_clk_source_div(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 0; case CARDEVICE_I2C5: return 0; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 3; case CARDEVICE_TSEC: return 2; diff --git a/fusee/fusee-secondary/src/car.h b/fusee/fusee-secondary/src/car.h index cc89161b0..36f850a5a 100644 --- a/fusee/fusee-secondary/src/car.h +++ b/fusee/fusee-secondary/src/car.h @@ -42,7 +42,7 @@ typedef enum { CARDEVICE_UARTC = ((1 << 5) | 0x17), CARDEVICE_I2C1 = ((0 << 5) | 0xC), CARDEVICE_I2C5 = ((1 << 5) | 0xF), - CARDEVICE_UNK = ((3 << 5) | 0x1E), + CARDEVICE_TZRAM = ((3 << 5) | 0x1E), CARDEVICE_SE = ((3 << 5) | 0x1F), CARDEVICE_HOST1X = ((0 << 5) | 0x1C), CARDEVICE_TSEC = ((2 << 5) | 0x13), diff --git a/fusee/fusee-secondary/src/console.c b/fusee/fusee-secondary/src/console.c index 591de211f..e6e84d7d6 100644 --- a/fusee/fusee-secondary/src/console.c +++ b/fusee/fusee-secondary/src/console.c @@ -97,26 +97,23 @@ static ssize_t decode_utf8(uint32_t *out, const uint8_t *in) { } static void console_init_display(void) { - if (!g_display_initialized) { - /* Initialize the display. */ - display_init(); - } + /* Initialize the display. */ + display_init(); /* Set the framebuffer. */ display_init_framebuffer(g_framebuffer); /* Turn on the backlight after initializing the lfb */ /* to avoid flickering. */ - if (!g_display_initialized) { - display_backlight(true); - } + display_backlight(true); + /* Display is initialized. */ g_display_initialized = true; } static ssize_t console_write(struct _reent *r, void *fd, const char *ptr, size_t len) { size_t i = 0; - if (!g_display_initialized) { + if (!g_display_initialized && (g_framebuffer != NULL)) { console_init_display(); } while (i < len) { @@ -138,6 +135,8 @@ static int console_create(void) { errno = EEXIST; return -1; } + + /* Allocate memory for the framebuffer. */ g_framebuffer = memalign(0x1000, CONFIG_VIDEO_VISIBLE_ROWS * CONFIG_VIDEO_COLS * CONFIG_VIDEO_PIXEL_SIZE); if (g_framebuffer == NULL) { @@ -154,9 +153,7 @@ static int console_create(void) { return 0; } -int console_init(bool display_initialized) { - g_display_initialized = display_initialized; - +int console_init(void) { if (console_create() == -1) { return -1; } @@ -171,15 +168,15 @@ int console_init(bool display_initialized) { return 0; } -void *console_get_framebuffer(bool enable_display) { - if (g_framebuffer != NULL && enable_display) { +void *console_get_framebuffer(void) { + if (!g_display_initialized && (g_framebuffer != NULL)) { console_init_display(); } return g_framebuffer; } int console_display(const void *framebuffer) { - if (!g_display_initialized) { + if (!g_display_initialized && (g_framebuffer != NULL)) { console_init_display(); } display_init_framebuffer((void *)framebuffer); @@ -187,7 +184,7 @@ int console_display(const void *framebuffer) { } int console_resume(void) { - if (!g_display_initialized) { + if (!g_display_initialized && (g_framebuffer != NULL)) { console_init_display(); } else { display_init_framebuffer(g_framebuffer); @@ -196,10 +193,15 @@ int console_resume(void) { } int console_end(void) { - /* Deinitialize the framebuffer and display */ - if (g_display_initialized) { + if (g_display_initialized) { + /* Turn off the backlight. */ display_backlight(false); + + /* Terminate the display. */ display_end(); + + /* Display is terminated. */ + g_display_initialized = false; } free(g_framebuffer); g_framebuffer = NULL; diff --git a/fusee/fusee-secondary/src/console.h b/fusee/fusee-secondary/src/console.h index 3dba03d88..341773e7f 100644 --- a/fusee/fusee-secondary/src/console.h +++ b/fusee/fusee-secondary/src/console.h @@ -24,8 +24,8 @@ #include #include -int console_init(bool display_initialized); -void *console_get_framebuffer(bool enable_display); +int console_init(void); +void *console_get_framebuffer(void); int console_display(const void *framebuffer); /* Must be page-aligned */ int console_resume(void); int console_end(void); diff --git a/fusee/fusee-secondary/src/main.c b/fusee/fusee-secondary/src/main.c index 2db33a4bd..c7bc4a493 100644 --- a/fusee/fusee-secondary/src/main.c +++ b/fusee/fusee-secondary/src/main.c @@ -44,28 +44,26 @@ static stage2_args_t *g_stage2_args; static bool g_do_nxboot; static void setup_env(void) { - /* Set the console up. */ - if (console_init(g_stage2_args->display_initialized) == -1) { + /* Initialize the display and console. */ + if (console_init() < 0) { generic_panic(); } - + /* Set up exception handlers. */ setup_exception_handlers(); + /* Train DRAM. */ + train_dram(); + /* Initialize the file system by mounting the SD card. */ if (nxfs_init() < 0) { fatal_error("Failed to initialize the file system: %s\n", strerror(errno)); } - - /* Train DRAM. */ - train_dram(); } - static void cleanup_env(void) { - /* Unmount everything (this causes all open files to be flushed and closed) */ + /* Terminate the file system. */ nxfs_end(); - //console_end(); } static void exit_callback(int rc) { @@ -83,6 +81,7 @@ static void exit_callback(int rc) { int main(int argc, void **argv) { loader_ctx_t *loader_ctx = get_loader_ctx(); + /* Check argc. */ if (argc != STAGE2_ARGC) { generic_panic(); } @@ -90,6 +89,7 @@ int main(int argc, void **argv) { g_stage2_args = &g_stage2_args_store; memcpy(g_stage2_args, (stage2_args_t *)argv[STAGE2_ARGV_ARGUMENT_STRUCT], sizeof(*g_stage2_args)); + /* Check stage2 version field. */ if (g_stage2_args->version != 0) { generic_panic(); } @@ -97,9 +97,9 @@ int main(int argc, void **argv) { /* Override the global logging level. */ log_set_log_level(g_stage2_args->log_level); - /* Initialize the display, console, FS, etc. */ + /* Initialize the boot environment. */ setup_env(); - + print(SCREEN_LOG_LEVEL_DEBUG | SCREEN_LOG_LEVEL_NO_PREFIX, u8"Welcome to Atmosphère Fusée Stage 2!\n"); print(SCREEN_LOG_LEVEL_DEBUG, "Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]); @@ -114,17 +114,21 @@ int main(int argc, void **argv) { /* This will load all remaining binaries off of the SD. */ load_payload(g_stage2_args->bct0); - print(SCREEN_LOG_LEVEL_INFO, "Loaded payloads!\n"); - - g_do_nxboot = loader_ctx->chainload_entrypoint == 0; + + g_do_nxboot = (loader_ctx->chainload_entrypoint == 0); if (g_do_nxboot) { print(SCREEN_LOG_LEVEL_INFO, "Now performing nxboot.\n"); + + /* Start boot. */ uint32_t boot_memaddr = nxboot_main(); + /* Wait for the splash screen to have been displayed as long as it should be. */ splash_screen_wait_delay(); - /* Cleanup environment. */ + + /* Terminate the boot environment. */ cleanup_env(); + /* Finish boot. */ nxboot_finish(boot_memaddr); } else { @@ -133,11 +137,11 @@ int main(int argc, void **argv) { print(SCREEN_LOG_LEVEL_MANDATORY, "Now chainloading.\n"); g_chainloader_argc = 1; strcpy(g_chainloader_arg_data, path); + + /* Terminate the boot environment. */ + cleanup_env(); } - /* Deinitialize the display, console, FS, etc. */ - cleanup_env(); - /* Finally, after the cleanup routines (__libc_fini_array, etc.) are called, chainload or halt ourselves. */ __program_exit_callback = exit_callback; diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 2360198ec..ddc5ceee3 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -650,7 +650,6 @@ uint32_t nxboot_main(void) { } } - //fatal_error("Ran sept!"); /* Display splash screen. */ display_splash_screen_bmp(loader_ctx->custom_splash_path, (void *)0xC0000000); @@ -801,9 +800,6 @@ uint32_t nxboot_main(void) { print(SCREEN_LOG_LEVEL_INFO, "[NXBOOT] Powering on the CCPLEX...\n"); - /* Unmount everything. */ - nxfs_end(); - /* Return the memory address for booting CPU0. */ return (uint32_t)exosphere_memaddr; } diff --git a/fusee/fusee-secondary/src/panic.c b/fusee/fusee-secondary/src/panic.c index cbd81bfb2..4d161aea9 100644 --- a/fusee/fusee-secondary/src/panic.c +++ b/fusee/fusee-secondary/src/panic.c @@ -24,11 +24,9 @@ static uint32_t g_panic_code = 0; void check_and_display_panic(void) { /* We also handle our own panics. */ - /* In the case of our own panics, we assume that the display has already been initialized. */ - bool has_panic = APBDEV_PMC_RST_STATUS_0 != 0 || g_panic_code != 0; - uint32_t code = g_panic_code == 0 ? APBDEV_PMC_SCRATCH200_0 : g_panic_code; - - has_panic = has_panic && !(APBDEV_PMC_RST_STATUS_0 != 1 && code == PANIC_CODE_SAFEMODE); + bool has_panic = ((APBDEV_PMC_RST_STATUS_0 != 0) || (g_panic_code != 0)); + uint32_t code = (g_panic_code == 0) ? APBDEV_PMC_SCRATCH200_0 : g_panic_code; + has_panic = has_panic && !((APBDEV_PMC_RST_STATUS_0 != 1) && (code == PANIC_CODE_SAFEMODE)); if (has_panic) { uint32_t color; @@ -71,11 +69,13 @@ void check_and_display_panic(void) { break; } - if (g_panic_code == 0) { - display_init(); - } - + /* Initialize the display. */ + display_init(); + + /* Fill the screen. */ display_color_screen(color); + + /* Wait for button and reboot. */ wait_for_button_and_reboot(); } else { g_panic_code = 0; diff --git a/fusee/fusee-secondary/src/stage2.h b/fusee/fusee-secondary/src/stage2.h index 41861c5e6..7bbd3f2c0 100644 --- a/fusee/fusee-secondary/src/stage2.h +++ b/fusee/fusee-secondary/src/stage2.h @@ -30,7 +30,6 @@ typedef struct { uint32_t version; ScreenLogLevel log_level; - bool display_initialized; char bct0[BCTO_MAX_SIZE]; } stage2_args_t; diff --git a/sept/sept-primary/src/car.c b/sept/sept-primary/src/car.c index ba3a17401..182850340 100644 --- a/sept/sept-primary/src/car.c +++ b/sept/sept-primary/src/car.c @@ -25,7 +25,7 @@ static inline uint32_t get_clk_source_reg(CarDevice dev) { case CARDEVICE_UARTC: return 0x1A0; case CARDEVICE_I2C1: return 0x124; case CARDEVICE_I2C5: return 0x128; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0x42C; case CARDEVICE_HOST1X: return 0x180; case CARDEVICE_TSEC: return 0x1F4; @@ -48,7 +48,7 @@ static inline uint32_t get_clk_source_val(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 6; case CARDEVICE_I2C5: return 6; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 4; case CARDEVICE_TSEC: return 0; @@ -71,7 +71,7 @@ static inline uint32_t get_clk_source_div(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 0; case CARDEVICE_I2C5: return 0; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 3; case CARDEVICE_TSEC: return 2; diff --git a/sept/sept-primary/src/car.h b/sept/sept-primary/src/car.h index cc89161b0..36f850a5a 100644 --- a/sept/sept-primary/src/car.h +++ b/sept/sept-primary/src/car.h @@ -42,7 +42,7 @@ typedef enum { CARDEVICE_UARTC = ((1 << 5) | 0x17), CARDEVICE_I2C1 = ((0 << 5) | 0xC), CARDEVICE_I2C5 = ((1 << 5) | 0xF), - CARDEVICE_UNK = ((3 << 5) | 0x1E), + CARDEVICE_TZRAM = ((3 << 5) | 0x1E), CARDEVICE_SE = ((3 << 5) | 0x1F), CARDEVICE_HOST1X = ((0 << 5) | 0x1C), CARDEVICE_TSEC = ((2 << 5) | 0x13), diff --git a/sept/sept-secondary/src/car.c b/sept/sept-secondary/src/car.c index c94fc4cd4..b8e03bd6c 100644 --- a/sept/sept-secondary/src/car.c +++ b/sept/sept-secondary/src/car.c @@ -25,7 +25,7 @@ static inline uint32_t get_clk_source_reg(CarDevice dev) { case CARDEVICE_UARTC: return 0x1A0; case CARDEVICE_I2C1: return 0x124; case CARDEVICE_I2C5: return 0x128; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0x42C; case CARDEVICE_HOST1X: return 0x180; case CARDEVICE_TSEC: return 0x1F4; @@ -48,7 +48,7 @@ static inline uint32_t get_clk_source_val(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 6; case CARDEVICE_I2C5: return 6; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 4; case CARDEVICE_TSEC: return 0; @@ -71,7 +71,7 @@ static inline uint32_t get_clk_source_div(CarDevice dev) { case CARDEVICE_UARTC: return 0; case CARDEVICE_I2C1: return 0; case CARDEVICE_I2C5: return 0; - case CARDEVICE_UNK: return 0; + case CARDEVICE_TZRAM: return 0; case CARDEVICE_SE: return 0; case CARDEVICE_HOST1X: return 3; case CARDEVICE_TSEC: return 2; diff --git a/sept/sept-secondary/src/car.h b/sept/sept-secondary/src/car.h index cc89161b0..36f850a5a 100644 --- a/sept/sept-secondary/src/car.h +++ b/sept/sept-secondary/src/car.h @@ -42,7 +42,7 @@ typedef enum { CARDEVICE_UARTC = ((1 << 5) | 0x17), CARDEVICE_I2C1 = ((0 << 5) | 0xC), CARDEVICE_I2C5 = ((1 << 5) | 0xF), - CARDEVICE_UNK = ((3 << 5) | 0x1E), + CARDEVICE_TZRAM = ((3 << 5) | 0x1E), CARDEVICE_SE = ((3 << 5) | 0x1F), CARDEVICE_HOST1X = ((0 << 5) | 0x1C), CARDEVICE_TSEC = ((2 << 5) | 0x13), diff --git a/sept/sept-secondary/src/hwinit.c b/sept/sept-secondary/src/hwinit.c index 7faee72b8..e99aa3644 100644 --- a/sept/sept-secondary/src/hwinit.c +++ b/sept/sept-secondary/src/hwinit.c @@ -236,8 +236,8 @@ void nx_hwinit() /* NOTE: [4.0.0+] This was removed. */ /* clkrst_reboot(CARDEVICE_SE); */ - /* Reboot unknown device. */ - clkrst_reboot(CARDEVICE_UNK); + /* Reboot TZRAM. */ + clkrst_reboot(CARDEVICE_TZRAM); /* Initialize I2C1. */ /* NOTE: [6.0.0+] This was moved to after the PMIC is configured. */ diff --git a/sept/sept-secondary/src/main.c b/sept/sept-secondary/src/main.c index bc8f773c7..de476eb78 100644 --- a/sept/sept-secondary/src/main.c +++ b/sept/sept-secondary/src/main.c @@ -48,7 +48,6 @@ static void set_has_rebooted(bool rebooted) { MAKE_REG32(0x4003FFFC) = rebooted ? 0xFAFAFAFA : 0x00000000; } - static void exfiltrate_keys_and_reboot_if_needed(uint32_t version) { volatile tegra_pmc_t *pmc = pmc_get_regs(); uint8_t *enc_se_state = (uint8_t *)0x4003E000; @@ -124,7 +123,10 @@ static void cleanup_env(void) { /* Unmount the SD card. */ unmount_sd(); + /* Turn off the backlight. */ display_backlight(false); + + /* Terminate the display. */ display_end(); } @@ -150,7 +152,7 @@ int sept_main(uint32_t version) { /* Override the global logging level. */ log_set_log_level(log_level); - /* Initialize the display, console, etc. */ + /* Initialize the boot environment. */ setup_env(); /* Mark EMC scratch to say that sept has run. */ @@ -166,14 +168,10 @@ int sept_main(uint32_t version) { stage2_args = (stage2_args_t *)(g_chainloader_arg_data + strlen(stage2_path) + 1); /* May be unaligned. */ memcpy(&stage2_args->version, &stage2_version, 4); memcpy(&stage2_args->log_level, &log_level, sizeof(log_level)); - stage2_args->display_initialized = false; strcpy(stage2_args->bct0, ""); g_chainloader_argc = 2; - /* Wait a while. */ - mdelay(1500); - - /* Deinitialize the display, console, etc. */ + /* Terminate the boot environment. */ cleanup_env(); /* Finally, after the cleanup routines (__libc_fini_array, etc.) are called, jump to Stage2. */ diff --git a/sept/sept-secondary/src/stage2.h b/sept/sept-secondary/src/stage2.h index 09426a224..f8dec847c 100644 --- a/sept/sept-secondary/src/stage2.h +++ b/sept/sept-secondary/src/stage2.h @@ -34,6 +34,7 @@ #define STAGE2_NAME_KEY "stage2_path" #define STAGE2_ADDRESS_KEY "stage2_addr" #define STAGE2_ENTRYPOINT_KEY "stage2_entrypoint" + #define BCTO_MAX_SIZE 0x5800 typedef struct { @@ -45,7 +46,6 @@ typedef struct { typedef struct { uint32_t version; ScreenLogLevel log_level; - bool display_initialized; char bct0[BCTO_MAX_SIZE]; } stage2_args_t;