From a536ed419e6ab5ae71a589697c04ecd49414c223 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Sat, 28 Mar 2020 22:37:50 +0000 Subject: [PATCH] loader.efi: restore the init and fix the color setup The efi console init is avoided since conin setup was moved to probe. In case the console is re-initialized, we need to pick up colors from environment. --- stand/efi/libefi/efi_console.c | 37 ++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/stand/efi/libefi/efi_console.c b/stand/efi/libefi/efi_console.c index 60b5c0f984c5..a72fb4d561da 100644 --- a/stand/efi/libefi/efi_console.c +++ b/stand/efi/libefi/efi_console.c @@ -828,8 +828,9 @@ efi_cons_update_mode(void) { UINTN cols, rows; const teken_attr_t *a; + teken_attr_t attr; EFI_STATUS status; - char env[8]; + char env[8], *ptr; status = conout->QueryMode(conout, conout->Mode->Mode, &cols, &rows); if (EFI_ERROR(status) || cols * rows == 0) { @@ -866,18 +867,35 @@ efi_cons_update_mode(void) if (buffer != NULL) { teken_set_winsize(&teken, &tp); a = teken_get_defattr(&teken); + attr = *a; - snprintf(env, sizeof(env), "%d", a->ta_fgcolor); - env_setenv("teken.fg_color", EV_VOLATILE, env, - efi_set_colors, env_nounset); - snprintf(env, sizeof(env), "%d", a->ta_bgcolor); - env_setenv("teken.bg_color", EV_VOLATILE, env, - efi_set_colors, env_nounset); + /* + * On first run, we set up the efi_set_colors() + * callback. If the env is already set, we + * pick up fg and bg color values from the environment. + */ + ptr = getenv("teken.fg_color"); + if (ptr != NULL) { + attr.ta_fgcolor = strtol(ptr, NULL, 10); + ptr = getenv("teken.bg_color"); + attr.ta_bgcolor = strtol(ptr, NULL, 10); + + teken_set_defattr(&teken, &attr); + } else { + snprintf(env, sizeof(env), "%d", + attr.ta_fgcolor); + env_setenv("teken.fg_color", EV_VOLATILE, env, + efi_set_colors, env_nounset); + snprintf(env, sizeof(env), "%d", + attr.ta_bgcolor); + env_setenv("teken.bg_color", EV_VOLATILE, env, + efi_set_colors, env_nounset); + } for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { buffer[col + row * tp.tp_col].c = ' '; - buffer[col + row * tp.tp_col].a = *a; + buffer[col + row * tp.tp_col].a = attr; } } } @@ -908,9 +926,6 @@ efi_cons_init(int arg) { EFI_STATUS status; - if (conin != NULL) - return (0); - conout->EnableCursor(conout, TRUE); if (efi_cons_update_mode()) return (0);