Skip to content

Commit

Permalink
fix(emulator): fix rsod drawing in emulator
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
cepetr committed Oct 3, 2024
1 parent 50c28e5 commit db89004
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 34 deletions.
8 changes: 1 addition & 7 deletions core/SConscript.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,9 @@ else:

CPPDEFINES_MOD += [
'TRANSLATIONS',
'RSOD_IN_COREAPP',
]

if TREZOR_MODEL not in ('1', ):
CPPDEFINES_MOD += [
'FANCY_FATAL_ERROR',
]

CPPDEFINES_MOD += ['USE_SVC_SHUTDOWN']

if FEATURE_FLAGS["RDI"]:
CPPDEFINES_MOD += ['RDI']

Expand Down
2 changes: 1 addition & 1 deletion core/embed/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void coreapp_init(applet_t *applet) {

// Shows RSOD (Red Screen of Death)
static void show_rsod(const systask_postmortem_t *pminfo) {
#ifdef FANCY_FATAL_ERROR
#ifdef RSOD_IN_COREAPP
applet_t coreapp;
coreapp_init(&coreapp);

Expand Down
6 changes: 3 additions & 3 deletions core/embed/lib/rsod.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void rsod_terminal(const systask_postmortem_t* pminfo) {

#endif // KERNEL_MODE

#if (defined(FIRMWARE) || defined(BOOTLOADER)) && defined(FANCY_FATAL_ERROR)
#ifdef FANCY_FATAL_ERROR

#include "rust_ui.h"

Expand Down Expand Up @@ -139,7 +139,7 @@ void rsod_gui(const systask_postmortem_t* pminfo) {
display_rsod_rust(title, message, footer);
}

#endif
#endif // FANCY_FATAL_ERROR

#ifdef KERNEL_MODE

Expand All @@ -153,7 +153,7 @@ static void init_and_show_rsod(const systask_postmortem_t* pminfo) {
// Initialize necessary drivers
display_init(DISPLAY_RESET_CONTENT);

#if (defined(FIRMWARE) || defined(BOOTLOADER)) && defined(FANCY_FATAL_ERROR)
#ifdef FANCY_FATAL_ERROR
// Show the RSOD using Rust GUI
rsod_gui(pminfo);
#else
Expand Down
21 changes: 5 additions & 16 deletions core/embed/lib/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "terminal.h"
#include TREZOR_BOARD

#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include "display.h"
#include TREZOR_BOARD

#include "display.h"
#include "fonts/fonts.h"
#include "gfx_draw.h"
#include "mini_printf.h"
#include "terminal.h"

#define TERMINAL_COLS (DISPLAY_RESX / 6)
#define TERMINAL_ROWS (DISPLAY_RESY / 8)
Expand Down Expand Up @@ -169,29 +171,16 @@ void term_print(const char *text, int textlen) {
#endif
}

#ifdef TREZOR_EMULATOR
#define mini_vsnprintf vsnprintf
#include <stdio.h>
#else
#include "mini_printf.h"
#endif

// variadic term_print
void term_printf(const char *fmt, ...) {
if (!strchr(fmt, '%')) {
term_print(fmt, strlen(fmt));
#ifdef TREZOR_EMULATOR
printf("%s", fmt);
#endif
} else {
va_list va;
va_start(va, fmt);
char buf[256] = {0};
int len = mini_vsnprintf(buf, sizeof(buf), fmt, va);
term_print(buf, len);
#ifdef TREZOR_EMULATOR
vprintf(fmt, va);
#endif
va_end(va);
}
}
2 changes: 1 addition & 1 deletion core/embed/trezorhal/unix/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void display_copy_mono1p(const gfx_bitblt_t *bb) {
gfx_bitblt_t bb_new = *bb;
bb_new.dst_row =
(uint8_t *)drv->buffer->pixels + (drv->buffer->pitch * bb_new.dst_y);
bb_new.dst_stride = DISPLAY_RESX;
bb_new.dst_stride = drv->buffer->pitch;

gfx_rgb565_copy_mono1p(&bb_new);
}
Expand Down
13 changes: 7 additions & 6 deletions core/embed/unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@
#include <sys/types.h>
#include <unistd.h>

#include "common.h"
#include "display.h"
#include "extmod/misc.h"
#include "extmod/vfs_posix.h"
#include "flash.h"
#include "flash_otp.h"
#include "genhdr/mpversion.h"
#include "input.h"
#include "rsod.h"
#include "system.h"
#include "systimer.h"
#include "touch.h"

#include "py/builtin.h"
#include "py/compile.h"
#include "py/gc.h"
Expand All @@ -53,10 +59,6 @@
#include "py/repl.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "systimer.h"
#include "touch.h"

#include "common.h"

// Command line options, with their defaults
STATIC bool compile_only = false;
Expand Down Expand Up @@ -487,8 +489,7 @@ MP_NOINLINE int main_(int argc, char **argv) {

pre_process_options(argc, argv);

systick_init();
systimer_init();
system_init(&rsod_panic_handler);

display_init(DISPLAY_RESET_CONTENT);

Expand Down

0 comments on commit db89004

Please sign in to comment.