The Linux kernel fonts that were ported to barebox were all (and still are in Linux) CP437 fonts.
This doesn't matter when the framebuffer console is only displaying barebox' own 7-bit ASCII output, but in combination with barebox running as EFI loader, the framebuffer console may end up being EFI stdout: - EFI applications like GRUB output UTF-16 - barebox' efi/loader/protocols/console.c duly converts it into UTF-8 - barebox' Framebuffer console processes that thinking it's CP437 To be able to use e.g. the box drawing characters that we already have in the CP437, let's change the framebuffer console default to expect UTF-8. This will increase code size a bit, but is the appropriate thing to do nowadays. Still gate it behind an option that allows restoring the old behavior. Reported-by: Lucie L. Hartmann Signed-off-by: Ahmad Fatoum <[email protected]> --- drivers/video/Kconfig | 14 ++++++++++++++ drivers/video/fbconsole.c | 24 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index d9f49724c819..ce1023722142 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -13,6 +13,20 @@ config FRAMEBUFFER_CONSOLE select FONTS prompt "framebuffer console support" +config FRAMEBUFFER_CONSOLE_UTF8 + bool "UTF-8 output for framebuffer console" + depends on FRAMEBUFFER_CONSOLE + select CHARSET + default y + help + Maps UTF-8 console output to CP437 font positions, enabling + the framebuffer console to render accented Latin characters, + mathematical symbols, and additional box-drawing characters + using the existing bitmap fonts. + + Say n here if your own output is intentionally CP437 or you want + to save the few hundred bytes needed to do UTF-8 decoding. + config DRIVER_VIDEO_FB_SSD1307 bool "Solomon SSD1307 framebuffer support" depends on (I2C || SPI) && GPIOLIB diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c index ab1c4dfed0a4..f44a3e0636ab 100644 --- a/drivers/video/fbconsole.c +++ b/drivers/video/fbconsole.c @@ -10,6 +10,8 @@ #include <gui/image_renderer.h> #include <gui/graphic_utils.h> #include <linux/font.h> +#include <linux/ctype.h> +#include <charset.h> enum state_t { LIT, /* Literal input */ @@ -76,6 +78,8 @@ struct fbc_priv { int active; int in_console; + + char utf8_buf[5]; /* UTF-8 stream decoder buffer */ }; static int fbc_getc(struct console_device *cdev) @@ -630,10 +634,26 @@ static void fbc_putc(struct console_device *cdev, char c) case LIT: switch (c) { case '\033': + priv->utf8_buf[0] = '\0'; priv->state = ESC; break; - default: - printchar(priv, c); + case '\0': + break; + default: { + int cp = c; + + if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE_UTF8)) { + /* All our fonts are CP437, so convert it + * directly to that code page. + */ + cp = utf8_to_cp437_stream(c, priv->utf8_buf); + if (!cp) + break; + } + + printchar(priv, cp); + break; + } } break; case ESC: -- 2.47.3
