* [PATCH] fbconsole: make UTF-8 the default encoding instead of CP437
@ 2026-05-02 11:29 Ahmad Fatoum
2026-05-07 10:38 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-05-02 11:29 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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 <a.fatoum@barebox.org>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fbconsole: make UTF-8 the default encoding instead of CP437
2026-05-02 11:29 [PATCH] fbconsole: make UTF-8 the default encoding instead of CP437 Ahmad Fatoum
@ 2026-05-07 10:38 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2026-05-07 10:38 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Sat, 02 May 2026 13:29:40 +0200, Ahmad Fatoum wrote:
> 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:
>
> [...]
Applied, thanks!
[1/1] fbconsole: make UTF-8 the default encoding instead of CP437
https://git.pengutronix.de/cgit/barebox/commit/?id=4744b855cee7 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-07 10:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-02 11:29 [PATCH] fbconsole: make UTF-8 the default encoding instead of CP437 Ahmad Fatoum
2026-05-07 10:38 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox