Attention is currently required from: Dinesh Gehlot, Eran Mitrani, Intel coreboot Reviewers, Jakub "Kuba" Czapiga, Jayvik Desai, Kapil Porwal, Nick Vaccaro, Tarun.
Subrata Banik has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/86283?usp=email )
Change subject: lib: Refactor ux_locales_get_text API ......................................................................
lib: Refactor ux_locales_get_text API
This patch refactors the `ux_locales_get_text` API to handle fallback text (English) internally, rather than relying on the caller. It introduces message IDs for lookups, enabling the API to locate both the UX locale name and fallback text based on the ID.
This centralizes fallback handling and simplifies adding future messages without per-SoC duplication.
BUG=b:339673254 TEST=Built and booted google/brox. Verified eSOL display.
Change-Id: I4952802396265b9ee8d164d6e43a7f2b3599d6c0 Signed-off-by: Subrata Banik subratabanik@google.com --- M src/include/ux_locales.h M src/lib/ux_locales.c M src/soc/intel/alderlake/romstage/ux.c M src/soc/intel/meteorlake/romstage/fsp_params.c 4 files changed, 47 insertions(+), 24 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/86283/1
diff --git a/src/include/ux_locales.h b/src/include/ux_locales.h index 1affd92..3fea90c 100644 --- a/src/include/ux_locales.h +++ b/src/include/ux_locales.h @@ -5,6 +5,10 @@
#include <types.h>
+enum ux_locale_msg { + UX_LOCALE_MSG_MEMORY_TRAINING, +}; + /* Unmap the preram_locales if it has been mapped. No-op otherwise. */ void ux_locales_unmap(void);
@@ -13,6 +17,6 @@ * This function will try to read the language ID from vboot API, and search the * corresponding translation from CBFS preram_locales. */ -const char *ux_locales_get_text(const char *name); +const char *ux_locales_get_text(enum ux_locale_msg msg_id);
#endif // _UX_LOCALES_H_ diff --git a/src/lib/ux_locales.c b/src/lib/ux_locales.c index b389548..323a4a9 100644 --- a/src/lib/ux_locales.c +++ b/src/lib/ux_locales.c @@ -20,6 +20,23 @@ #define DELIM_STR 0x00 #define DELIM_NAME 0x01
+/* Description of different UX locales */ +#define UX_MEMORY_TRAINING_DESC "memory_training_desc" +#define UX_MEMORY_TRAINING_MSG "Your device is finishing an update. " \ + "This may take 1-2 minutes.\n" \ + "Please do not turn off your device." + +/* Mapping of different default UX local message based on message ID */ +static const struct { + enum ux_locale_msg locale_msg_id; + const char *ux_locale_name; + const char *ux_locale_text_msg; +} ux_locale_msg_list[] = { + { UX_LOCALE_MSG_MEMORY_TRAINING, UX_MEMORY_TRAINING_DESC, UX_MEMORY_TRAINING_MSG }, +}; + +#define UX_LOCAL_MSG_ELEMENT_COUNT sizeof(ux_locale_msg_list)/sizeof(ux_locale_msg_list[0]) + /* * Devices which support early vga have the capability to show localized text in * Code Page 437 encoding. (see src/drivers/pc80/vga/vga_font_8x16.c) @@ -113,18 +130,33 @@ return search_for(data, offset, size, int_to_str, DELIM_STR); }
-const char *ux_locales_get_text(const char *name) +const char *ux_locales_get_text(enum ux_locale_msg msg_id) { const char *data; size_t size, offset, name_offset, next_name_offset, next; uint32_t lang_id = 0; /* default language English (0) */ unsigned char version; + const char *fallback_text; + const char *name; + bool msg_id_found = false; + + /* Trying to locate UX message ID for `ux_locale_name` and `ux_locale_text_msg` */ + for (size_t i = 0; i < UX_LOCAL_MSG_ELEMENT_COUNT; i++) { + if (ux_locale_msg_list[i].locale_msg_id == msg_id) { + msg_id_found = true; + fallback_text = ux_locale_msg_list[i].ux_locale_text_msg; + name = ux_locale_msg_list[i].ux_locale_name; + } + } + + if (!msg_id_found) + return "Trying to display unknown message?";
data = locales_get_map(&size, false); if (!data || size == 0) { printk(BIOS_ERR, "%s: %s not found.\n", __func__, PRERAM_LOCALES_NAME); - return NULL; + return fallback_text; }
if (CONFIG(VBOOT)) { @@ -146,14 +178,14 @@ if (version != PRERAM_LOCALES_VERSION_BYTE) { printk(BIOS_ERR, "%s: The version %u is not the expected one %u\n", __func__, version, PRERAM_LOCALES_VERSION_BYTE); - return NULL; + return fallback_text; }
/* Search for name. Skip the version byte. */ offset = search_for_name(data, 1, size, name); if (offset >= size) { printk(BIOS_ERR, "%s: Name %s not found.\n", __func__, name); - return NULL; + return fallback_text; } name_offset = offset;
@@ -171,21 +203,21 @@ offset = search_for_id(data, name_offset, next_name_offset, 0); if (offset >= next_name_offset) { printk(BIOS_ERR, "%s: Neither %d nor 0 found.\n", __func__, lang_id); - return NULL; + return fallback_text; } }
/* Move to the corresponding localized_string. */ offset = move_next(data, offset, next_name_offset, DELIM_STR); if (offset >= next_name_offset) - return NULL; + return fallback_text;
/* Validity check that the returned string must be NULL terminated. */ next = move_next(data, offset, next_name_offset, DELIM_STR) - 1; if (next >= next_name_offset || data[next] != '\0') { printk(BIOS_ERR, "%s: %s is not NULL terminated.\n", __func__, PRERAM_LOCALES_NAME); - return NULL; + return fallback_text; }
return data + offset; diff --git a/src/soc/intel/alderlake/romstage/ux.c b/src/soc/intel/alderlake/romstage/ux.c index 0fb73c18..d0961c5 100644 --- a/src/soc/intel/alderlake/romstage/ux.c +++ b/src/soc/intel/alderlake/romstage/ux.c @@ -8,8 +8,6 @@
#include "ux.h"
-#define UX_MEMORY_TRAINING_DESC "memory_training_desc" - bool ux_inform_user_of_update_operation(const char *name) { timestamp_add_now(TS_ESOL_START); @@ -22,12 +20,8 @@
printk(BIOS_INFO, "Informing user on-display of %s.\n", name);
- const char *text = ux_locales_get_text(UX_MEMORY_TRAINING_DESC); - /* No localized text found; fallback to built-in English. */ - if (!text) - text = "Your device is finishing an update. " - "This may take 1-2 minutes.\n" - "Please do not turn off your device."; + const char *text = ux_locales_get_text(UX_LOCALE_MSG_MEMORY_TRAINING); + vga_write_text(VGA_TEXT_CENTER, VGA_TEXT_HORIZONTAL_MIDDLE, (const unsigned char *)text); ux_locales_unmap(); diff --git a/src/soc/intel/meteorlake/romstage/fsp_params.c b/src/soc/intel/meteorlake/romstage/fsp_params.c index 82706ed..dd9d2b5 100644 --- a/src/soc/intel/meteorlake/romstage/fsp_params.c +++ b/src/soc/intel/meteorlake/romstage/fsp_params.c @@ -436,8 +436,6 @@ fill_fspm_params[i](m_cfg, config); }
-#define UX_MEMORY_TRAINING_DESC "memory_training_desc" - #define VGA_INIT_CONTROL_ENABLE BIT(0) /* Tear down legacy VGA mode before exiting FSP-M. */ #define VGA_INIT_CONTROL_TEAR_DOWN BIT(1) @@ -465,12 +463,7 @@ if (!vga_init_control) return;
- const char *text = ux_locales_get_text(UX_MEMORY_TRAINING_DESC); - /* No localized text found; fallback to built-in English. */ - if (!text) - text = "Your device is finishing an update. " - "This may take 1-2 minutes.\n" - "Please do not turn off your device."; + const char *text = ux_locales_get_text(UX_LOCALE_MSG_MEMORY_TRAINING);
vbt = cbfs_map("vbt.bin", &vbt_size); if (!vbt) {