video: improve UEFI experience on DM_VIDEO
cover video: improve UEFI experience on DM_VIDEO
While U-Boot supported graphical output on monitors for ages, the actual user experience on the DM_VIDEO console is somewhat lacking, especially when UEFI applications use the screen via boot services.
This series fixes some of the shortcomings:
- Patch 1 includes a rudimentary cursor output, which so far was completely missing from the (DM_VIDEO) console.
- Patches 2-5 add support for larger bitmap fonts, which are helpful on high resolution screens as found on modern laptops, for instance. These also pull in two larger bitmaps fonts from the Linux kernel.
- Patches 6-8 fix the display of those fonts when used by UEFI applications, which assume Unicode encoding. Beside the actual mapping function this also adds some EFI selftests, which would need to be verifed manually on the screen.
The last three patches are somewhat less refined, they probably require some more discussion.
Please have a look!
Cheers,
Andre
Andre Przywara (8):
video: Add cursor support for DM_VIDEO consoles
video: vidconsole: Support wider bitmap fonts
video: Kconfig: convert CONFIG_VIDEO_FONT_4X6 to Kconfig
video: Add sun12x22 framebuffer front
video: Add Terminus 16x32 font
efi-selftest: Add international characters test
efi_selftest: Add box drawing character selftest
video: Convert UTF-8 input stream to the 437 code page
drivers/video/Makefile | 1 + drivers/video/console_normal.c | 26 +- drivers/video/fonts/Kconfig | 18 + drivers/video/utf8_cp437.c | 169 + drivers/video/vidconsole-uclass.c | 48 +- include/video_console.h | 10 + include/video_font.h | 4 + include/video_font_4x6.h | 2 +- include/video_font_sun12x22.h | 6165 ++++++++++++++++++++ include/video_font_ter16x32.h | 2069 +++++++ lib/efi_selftest/efi_selftest_textoutput.c | 16 + scripts/config_whitelist.txt | 1 - 12 files changed, 8521 insertions(+), 8 deletions(-) create mode 100644 drivers/video/utf8_cp437.c create mode 100644 include/video_font_sun12x22.h create mode 100644 include/video_font_ter16x32.h
Signature · 1 line
2.17.6
PATCH 1/8 video: Add cursor support for DM_VIDEO consoles
So far the DM_VIDEO console is completely lacking any cursor, which makes typing and correcting quite irritating.
Add a simple cursor display by writing a SPACE glyph in the background colour to the next character position on the screen. Any typed character will naturally overwrite it, so we need to only explicitly clear it if the next character will appear somewhere else (newline, backspace).
--- drivers/video/console_normal.c | 1 + drivers/video/vidconsole-uclass.c | 42 +++++++++++++++++++++++++++++++ include/video_console.h | 1 + 3 files changed, 44 insertions(+)
drivers/video/console_normal.c +1 -0
@@ -160,6 +160,7 @@ static int console_normal_probe(struct udevice *dev) vc_priv->y_charsize =VIDEO_FONT_HEIGHT ; vc_priv->cols = vid_priv->xsize /VIDEO_FONT_WIDTH ; vc_priv->rows = vid_priv->ysize /VIDEO_FONT_HEIGHT ; + vc_priv->cursor_visible = true;return 0 ; }
drivers/video/vidconsole-uclass.c +42 -0
96 lines not on this page · raw message
include/video_console.h +1 -0
@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +bool cursor_visible;char escape_buf[32 ]; };
Signature · 1 line
2.17.6
Re: [PATCH 1/8] video: Add cursor support for DM_VIDEO consoles
Quoted 7 lines · Andre Przywara
So far the
DM_VIDEOconsole is completely lacking any cursor, which makes typing and correcting quite irritating.Add a simple cursor display by writing a SPACE glyph in the background colour to the next character position on the screen. Any typed character will naturally overwrite it, so we need to only explicitly clear it if the next character will appear somewhere else (newline, backspace).
Does this work with (non-monospaced) Truetype fonts? Moving backwards in Truetype is awkward.
Best regards
Heinrich
Quoted 141 lines
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/console_normal.c | 1 + drivers/video/vidconsole-uclass.c | 42 +++++++++++++++++++++++++++++++ include/video_console.h | 1 + 3 files changed, 44 insertions(+)drivers/video/console_normal.c +1
-0@@ -160,6 +160,7 @@ static int console_normal_probe(struct udevice *dev) vc_priv->y_charsize =VIDEO_FONT_HEIGHT ; vc_priv->cols = vid_priv->xsize /VIDEO_FONT_WIDTH ; vc_priv->rows = vid_priv->ysize /VIDEO_FONT_HEIGHT ; + vc_priv->cursor_visible = true;return 0 ; }drivers/video/vidconsole-uclass.c +42
-0@@ -70,6 +70,26 @@ static int vidconsole_entry_start(struct udevice *dev)return ops->entry_start (dev); } +static void draw_cursor (struct udevice *dev,bool state) +{ +struct vidconsole_priv *priv =dev_get_uclass_priv (dev); +struct video_priv *vid_priv =dev_get_uclass_priv (dev->parent); +u32 tmp; + +if (!priv->cursor_visible) +return ; + +if (state) { + tmp = vid_priv->colour_bg; + vid_priv->colour_bg = vid_priv->colour_fg; + } + +vidconsole_putc_xy (dev, priv->xcur_frac, priv->ycur,' ' ); + +if (state) + vid_priv->colour_bg = tmp; +} +/* Move backwards one space */ static int vidconsole_back (struct udevice *dev) {@@ -77,6 +97,8 @@ static int vidconsole_back(struct udevice *dev)struct vidconsole_ops *ops =vidconsole_get_ops (dev);int ret; +draw_cursor (dev, false); +if (ops->backspace) { ret = ops->backspace (dev);if (ret != -ENOSYS )@@ -103,6 +125,8 @@ static void vidconsole_newline(struct udevice *dev)const int rows =CONFIG_CONSOLE_SCROLL_LINES ;int i, ret; +draw_cursor (dev, false); + priv->xcur_frac = priv->xstart_frac; priv->ycur += priv->y_charsize;@@ -342,6 +366,14 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)break ; } +case 'l' : +draw_cursor (dev, false); + priv->cursor_visible =0 ; +break ; +case 'h' : + priv->cursor_visible =1 ; +draw_cursor (dev, true); +break ;case 'J' : {int mode;@@ -516,6 +548,11 @@ int vidconsole_put_char(struct udevice *dev, char ch)struct vidconsole_priv *priv =dev_get_uclass_priv (dev);int ret; +/* +* We don't need to clear the cursor since we are going to overwrite +* that character anyway. +*/ +if (priv->escape) {vidconsole_escape_char (dev, ch);return 0 ;@@ -530,6 +567,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)/* beep */ break ;case '\r' : +draw_cursor (dev, false); priv->xcur_frac = priv->xstart_frac;break ;case '\n' :@@ -537,6 +575,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)vidconsole_entry_start (dev);break ;case '\t' :/* Tab (8 chars alignment) */ +draw_cursor (dev, false); priv->xcur_frac = ((priv->xcur_frac / priv->tab_width_frac) +1 ) * priv->tab_width_frac;@@ -554,6 +593,8 @@ int vidconsole_put_char(struct udevice *dev, char ch)break ; } +draw_cursor (dev, true); +return 0 ; }@@ -620,6 +661,7 @@ static int vidconsole_pre_probe(struct udevice *dev)struct video_priv *vid_priv =dev_get_uclass_priv (vid); priv->xsize_frac =VID_TO_POS (vid_priv->xsize); + priv->cursor_visible = false;return 0 ; }include/video_console.h +1
-0@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +bool cursor_visible;char escape_buf[32 ]; };
Re: [PATCH 1/8] video: Add cursor support for DM_VIDEO consoles
On Mon, 10 Jan 2022 10:41:14 +0100
Heinrich Schuchardt <[email protected]> wrote:
Hi,
Quoted 11 lines · Andre Przywara
Quoted 7 lines
So far the
DM_VIDEOconsole is completely lacking any cursor, which makes typing and correcting quite irritating.Add a simple cursor display by writing a SPACE glyph in the background colour to the next character position on the screen. Any typed character will naturally overwrite it, so we need to only explicitly clear it if the next character will appear somewhere else (newline, backspace).
Does this work with (non-monospaced) Truetype fonts? Moving backwards in Truetype is awkward.
I don't know, I need to try this again. I think I tried TrueType (before adding wide character bitmap support), but ran into some issues, might well be due to the proportional fonts only.
In general I think *proper* cursor support can be tricky and tedious, so this version here is deliberately made simple, to have at least *some* cursor.
Shall we enable this code only for monospace fonts (both TT and bitmap)?
Cheers,
Andre
Quoted 141 lines
Quoted 140 lines
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/console_normal.c | 1 + drivers/video/vidconsole-uclass.c | 42 +++++++++++++++++++++++++++++++ include/video_console.h | 1 + 3 files changed, 44 insertions(+)drivers/video/console_normal.c +1
-0@@ -160,6 +160,7 @@ static int console_normal_probe(struct udevice *dev) vc_priv->y_charsize =VIDEO_FONT_HEIGHT ; vc_priv->cols = vid_priv->xsize /VIDEO_FONT_WIDTH ; vc_priv->rows = vid_priv->ysize /VIDEO_FONT_HEIGHT ; + vc_priv->cursor_visible = true;return 0 ; }drivers/video/vidconsole-uclass.c +42
-0@@ -70,6 +70,26 @@ static int vidconsole_entry_start(struct udevice *dev)return ops->entry_start (dev); } +static void draw_cursor (struct udevice *dev,bool state) +{ +struct vidconsole_priv *priv =dev_get_uclass_priv (dev); +struct video_priv *vid_priv =dev_get_uclass_priv (dev->parent); +u32 tmp; + +if (!priv->cursor_visible) +return ; + +if (state) { + tmp = vid_priv->colour_bg; + vid_priv->colour_bg = vid_priv->colour_fg; + } + +vidconsole_putc_xy (dev, priv->xcur_frac, priv->ycur,' ' ); + +if (state) + vid_priv->colour_bg = tmp; +} +/* Move backwards one space */ static int vidconsole_back (struct udevice *dev) {@@ -77,6 +97,8 @@ static int vidconsole_back(struct udevice *dev)struct vidconsole_ops *ops =vidconsole_get_ops (dev);int ret; +draw_cursor (dev, false); +if (ops->backspace) { ret = ops->backspace (dev);if (ret != -ENOSYS )@@ -103,6 +125,8 @@ static void vidconsole_newline(struct udevice *dev)const int rows =CONFIG_CONSOLE_SCROLL_LINES ;int i, ret; +draw_cursor (dev, false); + priv->xcur_frac = priv->xstart_frac; priv->ycur += priv->y_charsize;@@ -342,6 +366,14 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)break ; } +case 'l' : +draw_cursor (dev, false); + priv->cursor_visible =0 ; +break ; +case 'h' : + priv->cursor_visible =1 ; +draw_cursor (dev, true); +break ;case 'J' : {int mode;@@ -516,6 +548,11 @@ int vidconsole_put_char(struct udevice *dev, char ch)struct vidconsole_priv *priv =dev_get_uclass_priv (dev);int ret; +/* +* We don't need to clear the cursor since we are going to overwrite +* that character anyway. +*/ +if (priv->escape) {vidconsole_escape_char (dev, ch);return 0 ;@@ -530,6 +567,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)/* beep */ break ;case '\r' : +draw_cursor (dev, false); priv->xcur_frac = priv->xstart_frac;break ;case '\n' :@@ -537,6 +575,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)vidconsole_entry_start (dev);break ;case '\t' :/* Tab (8 chars alignment) */ +draw_cursor (dev, false); priv->xcur_frac = ((priv->xcur_frac / priv->tab_width_frac) +1 ) * priv->tab_width_frac;@@ -554,6 +593,8 @@ int vidconsole_put_char(struct udevice *dev, char ch)break ; } +draw_cursor (dev, true); +return 0 ; }@@ -620,6 +661,7 @@ static int vidconsole_pre_probe(struct udevice *dev)struct video_priv *vid_priv =dev_get_uclass_priv (vid); priv->xsize_frac =VID_TO_POS (vid_priv->xsize); + priv->cursor_visible = false;return 0 ; }include/video_console.h +1
-0@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +bool cursor_visible;char escape_buf[32 ]; };
Re: [PATCH 1/8] video: Add cursor support for DM_VIDEO consoles
In reply to Andre PrzywaraHi Andre,
Quoted 9 lines · Andre Przywara
So far the
DM_VIDEOconsole is completely lacking any cursor, which makes typing and correcting quite irritating.Add a simple cursor display by writing a SPACE glyph in the background colour to the next character position on the screen. Any typed character will naturally overwrite it, so we need to only explicitly clear it if the next character will appear somewhere else (newline, backspace).
Quoted 6 lines
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/console_normal.c | 1 + drivers/video/vidconsole-uclass.c | 42 +++++++++++++++++++++++++++++++ include/video_console.h | 1 + 3 files changed, 44 insertions(+)
See console_truetype_backspace() for how backspace works with truetype fonts.
For the normal console:
Tested on: sandbox
Please see nit below
Quoted 18 lines
drivers/video/console_normal.c +1
-0@@ -160,6 +160,7 @@ static int console_normal_probe(struct udevice *dev) vc_priv->y_charsize =VIDEO_FONT_HEIGHT ; vc_priv->cols = vid_priv->xsize /VIDEO_FONT_WIDTH ; vc_priv->rows = vid_priv->ysize /VIDEO_FONT_HEIGHT ; + vc_priv->cursor_visible = true;return 0 ; }drivers/video/vidconsole-uclass.c +0
-0
drivers/video/vidconsole-uclass.c static int vidconsole_entry_start(struct udevice *dev) · line 73
Quoted 4 lines
drivers/video/vidconsole-uclass.c +1
-0@@ -70,6 +70,26 @@ static int vidconsole_entry_start(struct udevice *dev)return ops->entry_start (dev); } +static void draw_cursor (struct udevice *dev,bool state)
Please add function comment
Quoted 105 lines
drivers/video/vidconsole-uclass.c +41
-0+{ +struct vidconsole_priv *priv =dev_get_uclass_priv (dev); +struct video_priv *vid_priv =dev_get_uclass_priv (dev->parent); +u32 tmp; + +if (!priv->cursor_visible) +return ; + +if (state) { + tmp = vid_priv->colour_bg; + vid_priv->colour_bg = vid_priv->colour_fg; + } + +vidconsole_putc_xy (dev, priv->xcur_frac, priv->ycur,' ' ); + +if (state) + vid_priv->colour_bg = tmp; +} +/* Move backwards one space */ static int vidconsole_back (struct udevice *dev) {@@ -77,6 +97,8 @@ static int vidconsole_back(struct udevice *dev)struct vidconsole_ops *ops =vidconsole_get_ops (dev);int ret; +draw_cursor (dev, false); +if (ops->backspace) { ret = ops->backspace (dev);if (ret != -ENOSYS )@@ -103,6 +125,8 @@ static void vidconsole_newline(struct udevice *dev)const int rows =CONFIG_CONSOLE_SCROLL_LINES ;int i, ret; +draw_cursor (dev, false); + priv->xcur_frac = priv->xstart_frac; priv->ycur += priv->y_charsize;@@ -342,6 +366,14 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)break ; } +case 'l' : +draw_cursor (dev, false); + priv->cursor_visible =0 ; +break ; +case 'h' : + priv->cursor_visible =1 ; +draw_cursor (dev, true); +break ;case 'J' : {int mode;@@ -516,6 +548,11 @@ int vidconsole_put_char(struct udevice *dev, char ch)struct vidconsole_priv *priv =dev_get_uclass_priv (dev);int ret; +/* +* We don't need to clear the cursor since we are going to overwrite +* that character anyway. +*/ +if (priv->escape) {vidconsole_escape_char (dev, ch);return 0 ;@@ -530,6 +567,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)/* beep */ break ;case '\r' : +draw_cursor (dev, false); priv->xcur_frac = priv->xstart_frac;break ;case '\n' :@@ -537,6 +575,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)vidconsole_entry_start (dev);break ;case '\t' :/* Tab (8 chars alignment) */ +draw_cursor (dev, false); priv->xcur_frac = ((priv->xcur_frac / priv->tab_width_frac) +1 ) * priv->tab_width_frac;@@ -554,6 +593,8 @@ int vidconsole_put_char(struct udevice *dev, char ch)break ; } +draw_cursor (dev, true); +return 0 ; }@@ -620,6 +661,7 @@ static int vidconsole_pre_probe(struct udevice *dev)struct video_priv *vid_priv =dev_get_uclass_priv (vid); priv->xsize_frac =VID_TO_POS (vid_priv->xsize); + priv->cursor_visible = false;return 0 ; }include/video_console.h +0
-0
include/video_console.h struct vidconsole_priv { · line 86
Quoted 4 lines
include/video_console.h +1
-0@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +bool cursor_visible;
Please add to struct comment
Quoted 6 lines
include/video_console.h +0
-1char escape_buf[32 ]; }; --2.17.6
Regards,
Simon
PATCH 2/8 video: vidconsole: Support wider bitmap fonts
In reply to Andre PrzywaraCurrently the DM_VIDEO console only supports bitmap fonts with up to 8 pixels wide glyphs. Add support for fonts with glyphs up to 32 pixels wide, as those might prove useful on high resolution screens.
This is done by expanding the glyph bits buffer to 32bits, and aligning the font data to the high bits, counting down from there. The compiler should optimise away any unneeded accesses for narrower fonts.
--- drivers/video/console_normal.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
drivers/video/console_normal.c +20 -5
@@ -13,6 +13,9 @@#include <video_console.h> #include <video_font.h> /* Get font data, width and height */ +#define VIDEO_FONT_STRIDE ((VIDEO_FONT_WIDTH + 7) / 8) +#define VIDEO_FONT_GLYPH_BYTES (VIDEO_FONT_STRIDE * VIDEO_FONT_HEIGHT) +static int console_normal_set_row (struct udevice *dev,uint row,int clr) {struct video_priv *vid_priv =dev_get_uclass_priv (dev->parent);
@@ -98,8 +101,20 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,return -EAGAIN ;for (row =0 ; row <VIDEO_FONT_HEIGHT ; row++) { -unsigned int idx = (u8 )ch *VIDEO_FONT_HEIGHT + row; -uchar bits = video_fontdata[idx]; +uint32_t bits = video_fontdata[(u8 )ch *VIDEO_FONT_GLYPH_BYTES + + row *VIDEO_FONT_STRIDE ] <<24 ; + +if (VIDEO_FONT_WIDTH >8 ) + bits |= video_fontdata[ch *VIDEO_FONT_GLYPH_BYTES + + row *VIDEO_FONT_STRIDE +1 ] <<16 ; + +if (VIDEO_FONT_WIDTH >16 ) + bits |= video_fontdata[ch *VIDEO_FONT_GLYPH_BYTES + + row *VIDEO_FONT_STRIDE +2 ] <<8 ; + +if (VIDEO_FONT_WIDTH >24 ) + bits |= video_fontdata[ch *VIDEO_FONT_GLYPH_BYTES + + row *VIDEO_FONT_STRIDE +3 ];switch (vid_priv->bpix) {case VIDEO_BPP8 :
@@ -107,7 +122,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,uint8_t *dst = line;for (i =0 ; i <VIDEO_FONT_WIDTH ; i++) { - *dst++ = (bits &0x80 ) ? + *dst++ = (bits &BIT (31 )) ? vid_priv->colour_fg : vid_priv->colour_bg; bits <<=1 ;
@@ -119,7 +134,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,uint16_t *dst = line;for (i =0 ; i <VIDEO_FONT_WIDTH ; i++) { - *dst++ = (bits &0x80 ) ? + *dst++ = (bits &BIT (31 )) ? vid_priv->colour_fg : vid_priv->colour_bg; bits <<=1 ;
@@ -131,7 +146,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,uint32_t *dst = line;for (i =0 ; i <VIDEO_FONT_WIDTH ; i++) { - *dst++ = (bits &0x80 ) ? + *dst++ = (bits &BIT (31 )) ? vid_priv->colour_fg : vid_priv->colour_bg; bits <<=1 ;
Signature · 1 line
2.17.6
Re: [PATCH 2/8] video: vidconsole: Support wider bitmap fonts
Quoted 5 lines · Andre Przywara
Currently the
DM_VIDEOconsole only supports bitmap fonts with up to 8 pixels wide glyphs. Add support for fonts with glyphs up to 32 pixels wide, as those might prove useful on high resolution screens.
Quoted 9 lines
This is done by expanding the glyph bits buffer to 32bits, and aligning the font data to the high bits, counting down from there. The compiler should optimise away any unneeded accesses for narrower fonts.
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/console_normal.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
PATCH 3/8 video: Kconfig: convert CONFIG_VIDEO_FONT_4X6 to Kconfig
In reply to Andre PrzywaraWe used to have two boards using a very tiny font, replacing the standard 8x16 font used on most framebuffers. This was done outside of Kconfig though, so move this over now.
As those boards have been removed lately, there are currently no users, but we will gain more font support in a later patch.
Fix the build for the 4x6 font on the way.
--- drivers/video/fonts/Kconfig | 12 ++++++++++++ include/video_font_4x6.h | 2 +- scripts/config_whitelist.txt | 1 - 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/video/fonts/Kconfig +12 -0
@@ -2,6 +2,18 @@ # Video fonts # +choice + prompt "Bitmap font for framebuffers" + default VIDEO_FONT_8X16 + +config VIDEO_FONT_4X6 + bool "Tiny 4x6 font" + +config VIDEO_FONT_8X16 + bool "Standard VGA font" + +endchoice + menu "TrueType Fonts" config CONSOLE_TRUETYPE_NIMBUS
include/video_font_4x6.h +1 -1
@@ -46,7 +46,7 @@ __END__;#define VIDEO_FONT_HEIGHT 6#define VIDEO_FONT_SIZE (VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT) -static unsigned char video_fontdata[VIDEO_FONT_SIZE ] = { +static unsigned char __maybe_unused video_fontdata[VIDEO_FONT_SIZE ] = {/*{*/ /* Char 0: ' ' */
scripts/config_whitelist.txt +0 -1
@@ -3051,7 +3051,6 @@ CONFIG_VERY_BIG_RAM CONFIG_VIDEO_BCM2835 CONFIG_VIDEO_BMP_LOGO CONFIG_VIDEO_DA8XX -CONFIG_VIDEO_FONT_4X6 CONFIG_VIDEO_LOGO CONFIG_VIDEO_MXS_MODE_SYSTEM CONFIG_VIDEO_STD_TIMINGS
Signature · 1 line
2.17.6
Re: [PATCH 3/8] video: Kconfig: convert CONFIG_VIDEO_FONT_4X6 to Kconfig
Quoted 8 lines · Andre Przywara
We used to have two boards using a very tiny font, replacing the standard 8x16 font used on most framebuffers. This was done outside of
Kconfigthough, so move this over now.As those boards have been removed lately, there are currently no users, but we will gain more font support in a later patch.
Quoted 9 lines
Fix the build for the 4x6 font on the way.
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/fonts/Kconfig | 12 ++++++++++++ include/video_font_4x6.h | 2 +- scripts/config_whitelist.txt | 1 - 3 files changed, 13 insertions(+), 2 deletions(-)
PATCH 4/8 video: Add sun12x22 framebuffer front
In reply to Andre PrzywaraNow that the dm_video console can cope with fonts wider than 8 pixels, let's add the neat 12x22 font mimicing the one used on the boot console of of older Sun workstations. This should be more readable on high resolution screens.
This file has been taken from Linux, only the required U-Boot macros have been added.
--- drivers/video/fonts/Kconfig | 3 + include/video_font.h | 2 + include/video_font_sun12x22.h | 6165 +++++++++++++++++++++++++++++++++ 3 files changed, 6170 insertions(+) create mode 100644 include/video_font_sun12x22.h
drivers/video/fonts/Kconfig +3 -0
@@ -12,6 +12,9 @@ config VIDEO_FONT_4X6 config VIDEO_FONT_8X16 bool "Standard VGA font" +config VIDEO_FONT_SUN12X22 + bool "Sun 12x22 font" + endchoice menu "TrueType Fonts"
include/video_font.h +2 -0
@@ -9,6 +9,8 @@#ifdef CONFIG_VIDEO_FONT_4X6 #include <video_font_4x6.h> +#elif defined(CONFIG_VIDEO_FONT_SUN12X22 ) +#include <video_font_sun12x22.h> #else #include <video_font_data.h> #endif
include/video_font_sun12x22.h new file +6165 -0
2,983 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.6
Part of the diff is not shown here. View the raw message.
Re: [PATCH 4/8] video: Add sun12x22 framebuffer front
PATCH 5/8 video: Add Terminus 16x32 font
In reply to Andre PrzywaraThe dm_video console can now cope with fonts wider than 8 pixels, so let's include a rather large 16x32 font, well suited for HiDPI displays found on modern laptops.
This file has been taken from Linux, only the required U-Boot macros have been added.
--- drivers/video/fonts/Kconfig | 3 + include/video_font.h | 2 + include/video_font_ter16x32.h | 2069 +++++++++++++++++++++++++++++++++ 3 files changed, 2074 insertions(+) create mode 100644 include/video_font_ter16x32.h
drivers/video/fonts/Kconfig +3 -0
@@ -15,6 +15,9 @@ config VIDEO_FONT_8X16 config VIDEO_FONT_SUN12X22 bool "Sun 12x22 font" +config VIDEO_FONT_TER16X32 + bool "Terminus 16x32 font" + endchoice menu "TrueType Fonts"
include/video_font.h +2 -0
@@ -11,6 +11,8 @@#include <video_font_4x6.h> #elif defined(CONFIG_VIDEO_FONT_SUN12X22 )#include <video_font_sun12x22.h> +#elif defined(CONFIG_VIDEO_FONT_TER16X32 ) +#include <video_font_ter16x32.h> #else #include <video_font_data.h> #endif
include/video_font_ter16x32.h new file +2069 -0
2,069 lines not on this page · raw message
Signature · 1 line
2.17.6
Re: [PATCH 5/8] video: Add Terminus 16x32 font
Hi Andrew,
Quoted 8 lines · Andre Przywara
The
dm_videoconsole can now cope with fonts wider than 8 pixels, so let's include a rather large 16x32 font, well suited for HiDPI displays found on modern laptops.This file has been taken from Linux, only the required U-Boot macros have been added.
Quoted 7 lines
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/fonts/Kconfig | 3 + include/video_font.h | 2 + include/video_font_ter16x32.h | 2069 +++++++++++++++++++++++++++++++++ 3 files changed, 2074 insertions(+) create mode 100644 include/video_font_ter16x32.h
But you might consider using a truetype font?
- Simon
PATCH 6/8 efi-selftest: Add international characters test
In reply to Andre PrzywaraUEFI relies entirely on unicode output, which actual fonts displayed on the screen might not be ready for.
Add a test displaying some international characters, to reveal missing glyphs, especially in our builtin fonts.
This would be needed to be manually checked on the screen for correctness.
--- lib/efi_selftest/efi_selftest_textoutput.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/efi_selftest/efi_selftest_textoutput.c +5 -0
@@ -118,6 +118,11 @@ static int execute(void)efi_st_printf ("Unicode not handled properly\n" );return EFI_ST_FAILURE ; } + ret = con_out->output_string (con_out,L"Österreich Edelweiß Smørrebrød Smörgås Niño René >Ἑλλάς<\n" ); +if (ret !=EFI_ST_SUCCESS ) { +efi_st_error ("OutputString failed for international chars\n" ); +return EFI_ST_FAILURE ; + }efi_st_printf ("\n" );return EFI_ST_SUCCESS ;
Signature · 1 line
2.17.6
Re: [PATCH 6/8] efi-selftest: Add international characters test
Quoted 18 lines · Andre Przywara
UEFI relies entirely on unicode output, which actual fonts displayed on the screen might not be ready for.
Add a test displaying some international characters, to reveal missing glyphs, especially in our builtin fonts.
This would be needed to be manually checked on the screen for correctness.Signed-off-by Andre Przywara <[email protected]>--- lib/efi_selftest/efi_selftest_textoutput.c | 5 +++++ 1 file changed, 5 insertions(+)lib/efi_selftest/efi_selftest_textoutput.c +0
-0
lib/efi_selftest/efi_selftest_textoutput.c static int execute(void) · line 121
Quoted 4 lines
lib/efi_selftest/efi_selftest_textoutput.c +1
-0@@ -118,6 +118,11 @@ static int execute(void)efi_st_printf ("Unicode not handled properly\n" );return EFI_ST_FAILURE ; } + ret = con_out->output_string (con_out,L"Österreich Edelweiß Smørrebrød Smörgås Niño René >Ἑλλάς<\n" );
%s/L"/u"/
Please, don't use UTF-8 in code as some tools don't support it. Instead use \u escape codes:
const u16 text[] =
u"\u00d6\sterreich Edelwei\u00df \Sm\u00f8rrebr\u00f8d Sm\u00f6rg" u"\u00e5s Ni\u00f1o Ren\u00e9 >\u1f19\u03bb\u03bb\u03ac\u03c2<\n";
Best regards
Heinrich
Quoted 7 lines
lib/efi_selftest/efi_selftest_textoutput.c +4
-0+if (ret !=EFI_ST_SUCCESS ) { +efi_st_error ("OutputString failed for international chars\n" ); +return EFI_ST_FAILURE ; + }efi_st_printf ("\n" );return EFI_ST_SUCCESS ;
PATCH 7/8 efi_selftest: Add box drawing character selftest
In reply to Andre PrzywaraUEFI applications rely on Unicode output capability, and might use that for drawing pseudo-graphical interfaces using Unicode defined box drawing characters.
Add a simple test to display the most basic box characters, which would need to be checked manually on the screen for correctness. To facilitate this, add a three second delay after the output at this point.
--- lib/efi_selftest/efi_selftest_textoutput.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
lib/efi_selftest/efi_selftest_textoutput.c +11 -0
@@ -123,6 +123,17 @@ static int execute(void)efi_st_error ("OutputString failed for international chars\n" );return EFI_ST_FAILURE ; } + ret = con_out->output_string (con_out,L"┌─┬─┐\n" ); + ret |= con_out->output_string (con_out,L"│ │ │\n" ); + ret |= con_out->output_string (con_out,L"├─┼─┤\n" ); + ret |= con_out->output_string (con_out,L"│ │ │\n" ); + ret |= con_out->output_string (con_out,L"└─┴─┘\n" ); +if (ret !=EFI_ST_SUCCESS ) { +efi_st_error ("OutputString failed for box drawing chars\n" ); +return EFI_ST_FAILURE ; + } + con_out->output_string (con_out,L"waiting for admiration...\n" ); +EFI_CALL (systab.boottime->stall (3000000 ));efi_st_printf ("\n" );return EFI_ST_SUCCESS ;
Signature · 1 line
2.17.6
Re: [PATCH 7/8] efi_selftest: Add box drawing character selftest
Quoted 19 lines · Andre Przywara
UEFI applications rely on Unicode output capability, and might use that for drawing pseudo-graphical interfaces using Unicode defined box drawing characters.
Add a simple test to display the most basic box characters, which would need to be checked manually on the screen for correctness. To facilitate this, add a three second delay after the output at this point.
Signed-off-by Andre Przywara <[email protected]>--- lib/efi_selftest/efi_selftest_textoutput.c | 11 +++++++++++ 1 file changed, 11 insertions(+)lib/efi_selftest/efi_selftest_textoutput.c +0
-0
lib/efi_selftest/efi_selftest_textoutput.c static int execute(void) · line 130
Quoted 8 lines
lib/efi_selftest/efi_selftest_textoutput.c +5
-0@@ -123,6 +123,17 @@ static int execute(void)efi_st_error ("OutputString failed for international chars\n" );return EFI_ST_FAILURE ; } + ret = con_out->output_string (con_out,L"┌─┬─┐\n" ); + ret |= con_out->output_string (con_out,L"│ │ │\n" ); + ret |= con_out->output_string (con_out,L"├─┼─┤\n" ); + ret |= con_out->output_string (con_out,L"│ │ │\n" ); + ret |= con_out->output_string (con_out,L"└─┴─┘\n" );
%s/L"/u"/
Unicode characters in code are not supported by all tools. The interpretation may further depend on the users locale. Please, use \u escape sequences. A single output_string() call is enough. A notice for the user might be helpful. So I suggest:
This should render as four boxes with text
┌─────────────┬───────────────┐ │ left top │ right top │ ├─────────────┼───────────────┤ │ left bottom │ right bottom │ └─────────────┴───────────────┘
const u16 text[] =
u"This should render as four boxes with text\n" u"\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502"
u" left top \u2502 right top \u2502\n\u251c\u2500"
u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 " u"left bottom \u2502 right bottom \u2502\n\u2514\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2518\n";
Best regards
Heinrich
Quoted 9 lines
lib/efi_selftest/efi_selftest_textoutput.c +6
-0+if (ret !=EFI_ST_SUCCESS ) { +efi_st_error ("OutputString failed for box drawing chars\n" ); +return EFI_ST_FAILURE ; + } + con_out->output_string (con_out,L"waiting for admiration...\n" ); +EFI_CALL (systab.boottime->stall (3000000 ));efi_st_printf ("\n" );return EFI_ST_SUCCESS ;
Re: [PATCH 7/8] efi_selftest: Add box drawing character selftest
On Mon, 10 Jan 2022 10:23:20 +0100
Heinrich Schuchardt <[email protected]> wrote:
Hi Heinrich,
Quoted 43 lines · Andre Przywara
Quoted 19 lines
UEFI applications rely on Unicode output capability, and might use that for drawing pseudo-graphical interfaces using Unicode defined box drawing characters.
Add a simple test to display the most basic box characters, which would need to be checked manually on the screen for correctness. To facilitate this, add a three second delay after the output at this point.
Signed-off-by Andre Przywara <[email protected]>--- lib/efi_selftest/efi_selftest_textoutput.c | 11 +++++++++++ 1 file changed, 11 insertions(+)lib/efi_selftest/efi_selftest_textoutput.c +0
-0lib/efi_selftest/efi_selftest_textoutput.c static int execute(void) · line 130
Quoted 8 lines
lib/efi_selftest/efi_selftest_textoutput.c +5
-0@@ -123,6 +123,17 @@ static int execute(void)efi_st_error ("OutputString failed for international chars\n" );return EFI_ST_FAILURE ; } + ret = con_out->output_string (con_out,L"┌─┬─┐\n" ); + ret |= con_out->output_string (con_out,L"│ │ │\n" ); + ret |= con_out->output_string (con_out,L"├─┼─┤\n" ); + ret |= con_out->output_string (con_out,L"│ │ │\n" ); + ret |= con_out->output_string (con_out,L"└─┴─┘\n" );%s/L"/u"/
Unicode characters in code are not supported by all tools. The interpretation may further depend on the users locale. Please, use \u escape sequences. A single
output_string()call is enough. A notice for the user might be helpful. So I suggest:This should render as four boxes with text
┌─────────────┬───────────────┐ │ left top │ right top │ ├─────────────┼───────────────┤ │ left bottom │ right bottom │ └─────────────┴───────────────┘
Quoted 13 lines
const u16 text[] =
u"This should render as four boxes with text\n" u"\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502"
u" left top \u2502 right top \u2502\n\u251c\u2500"
u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 " u"left bottom \u2502 right bottom \u2502\n\u2514\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534" u"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" u"\u2500\u2500\u2500\u2500\u2518\n";
Ha, very good, thanks for the hints! And for typing all those numbers! I was wondering about UTF-8 in source, but since my ancient Slackware could deal with it, I deemed it safe ;-)
Will fix it accordingly!
Cheers,
Andre
Quoted 10 lines
Quoted 9 lines
lib/efi_selftest/efi_selftest_textoutput.c +6
-0+if (ret !=EFI_ST_SUCCESS ) { +efi_st_error ("OutputString failed for box drawing chars\n" ); +return EFI_ST_FAILURE ; + } + con_out->output_string (con_out,L"waiting for admiration...\n" ); +EFI_CALL (systab.boottime->stall (3000000 ));efi_st_printf ("\n" );return EFI_ST_SUCCESS ;
PATCH 8/8 video: Convert UTF-8 input stream to the 437 code page
In reply to Andre PrzywaraThe bitmap fonts (VGA 8x16 and friends) we import from Linux use the 437 code page to map their glyphs. For U-Boot's own purposes this is probably fine, but UEFI applications output Unicode, which only matches in the very basic first 127 characters.
Add a function that converts UTF-8 character sequences into the respective CP437 code point, as far as the characters defined in there allow this. This includes quite some international and box drawing characters, which are used by UEFI applications.
--- drivers/video/Makefile | 1 + drivers/video/utf8_cp437.c | 169 ++++++++++++++++++++++++++++++ drivers/video/vidconsole-uclass.c | 6 +- include/video_console.h | 9 ++ 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 drivers/video/utf8_cp437.c
drivers/video/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_DISPLAY) += display-uclass.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi-host-uclass.o obj-$(CONFIG_DM_VIDEO) += video-uclass.o vidconsole-uclass.o obj-$(CONFIG_DM_VIDEO) += video_bmp.o +obj-$(CONFIG_DM_VIDEO) += utf8_cp437.o obj-$(CONFIG_PANEL) += panel-uclass.o obj-$(CONFIG_DM_PANEL_HX8238D) += hx8238d.o obj-$(CONFIG_SIMPLE_PANEL) += simple_panel.o
drivers/video/utf8_cp437.c new file +169 -0
169 lines not on this page · raw message
drivers/video/vidconsole-uclass.c +5 -1
@@ -546,6 +546,7 @@ static int vidconsole_output_glyph(struct udevice *dev, char ch)int vidconsole_put_char (struct udevice *dev,char ch) {struct vidconsole_priv *priv =dev_get_uclass_priv (dev); +uint8_t cp437;int ret;/*
@@ -587,7 +588,10 @@ int vidconsole_put_char(struct udevice *dev, char ch) priv->last_ch =0 ;break ;default : - ret =vidconsole_output_glyph (dev, ch); + cp437 =convert_utf8_to_cp437 (ch, &priv->ucs); +if (cp437 ==0 ) +return 0 ; + ret =vidconsole_output_glyph (dev, cp437);if (ret <0 )return ret;break ;
include/video_console.h +9 -0
@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +u32 ucs;bool cursor_visible;char escape_buf[32 ]; };
@@ -304,6 +305,14 @@ static inline int vidconsole_memmove(struct udevice *dev, void *dst,return 0 ; } +/* +* Convert an UTF-8 byte into the corresponding character in the CP437 +* code page. Returns 0 if that character is part of a multi-byte sequence. +* for which *esc holds the state of. Repeatedly feed in more bytes until +* the return value returns a non-0 character. +*/ +uint8_t convert_utf8_to_cp437 (uint8_t c,uint32_t *esc); +#endif #endif
Signature · 1 line
2.17.6
Re: [PATCH 8/8] video: Convert UTF-8 input stream to the 437 code page
drivers/video/utf8_cp437.c
Quoted 36 lines · Andre Przywara
The bitmap fonts (VGA 8x16 and friends) we import from Linux use the 437 code page to map their glyphs. For U-Boot's own purposes this is probably fine, but UEFI applications output Unicode, which only matches in the very basic first 127 characters.
Add a function that converts UTF-8 character sequences into the respective CP437 code point, as far as the characters defined in there allow this. This includes quite some international and box drawing characters, which are used by UEFI applications.
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/Makefile | 1 + drivers/video/utf8_cp437.c | 169 ++++++++++++++++++++++++++++++ drivers/video/vidconsole-uclass.c | 6 +- include/video_console.h | 9 ++ 4 files changed, 184 insertions(+), 1 deletion(-)create mode 100644
drivers/video/utf8_cp437.cdrivers/video/Makefile +1
-0@@ -14,6 +14,7 @@ obj-$(CONFIG_DISPLAY) += display-uclass.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi-host-uclass.o obj-$(CONFIG_DM_VIDEO) += video-uclass.o vidconsole-uclass.o obj-$(CONFIG_DM_VIDEO) += video_bmp.o +obj-$(CONFIG_DM_VIDEO) += utf8_cp437.o obj-$(CONFIG_PANEL) += panel-uclass.o obj-$(CONFIG_DM_PANEL_HX8238D) += hx8238d.o obj-$(CONFIG_SIMPLE_PANEL) += simple_panel.odrivers/video/utf8_cp437.c new file +0
-0
A translation from Unicode to CP437 is needed in the FAT driver (but missing), in Unicode Collation Protocol and here in video. So this functionality should live in lib/charset.c.
Please, have a look at efi_fat_to_str() in lib/efi_loader/efi_unicode_collation.c. We should avoid code duplication.
Maybe we should drop CP1250 support to make our effort simpler? No defconfig uses it.
Quoted 42 lines
drivers/video/utf8_cp437.c new file +41
-0@@ -0,0 +1,169 @@ +/* +* Convert UTF-8 bytes into a code page 437 character. +* Based on the table in the Code_page_437 Wikipedia page. +*/ + +#include <linux/types.h> + +uint8_t code_points_00a0[] = { +255 ,173 ,155 ,156 ,7 ,157 ,7 ,21 , +7 ,7 ,166 ,174 ,170 ,7 ,7 ,7 , +248 ,241 ,253 ,7 ,7 ,230 ,20 ,250 , +7 ,7 ,167 ,175 ,172 ,171 ,7 ,168 , +7 ,7 ,7 ,7 ,142 ,143 ,146 ,128 , +7 ,144 ,7 ,7 ,7 ,7 ,7 ,7 , +7 ,165 ,7 ,7 ,7 ,7 ,153 ,7 , +7 ,7 ,7 ,7 ,154 ,7 ,7 ,225 , +133 ,160 ,131 ,7 ,132 ,134 ,145 ,135 , +138 ,130 ,136 ,137 ,141 ,161 ,140 ,139 , +7 ,164 ,149 ,162 ,147 ,7 ,148 ,246 , +7 ,151 ,163 ,150 ,129 ,7 ,7 ,152 , +}; + +uint8_t code_points_2550[] = { +205 ,186 ,213 ,214 ,201 ,184 ,183 ,187 , +212 ,211 ,200 ,190 ,189 ,188 ,198 ,199 , +204 ,181 ,182 ,185 ,209 ,210 ,203 ,207 , +208 ,202 ,216 ,215 ,206 +}; + +static uint8_t utf8_convert_11bit (uint16_t code) +{ +switch (code) { +case 0x0192 :return 159 ; +case 0x0393 :return 226 ; +case 0x0398 :return 233 ; +case 0x03A3 :return 228 ; +case 0x03A6 :return 232 ; +case 0x03A9 :return 234 ; +case 0x03B1 :return 224 ; +case 0x03B4 :return 235 ; +case 0x03B5 :return 238 ;
drivers/video/utf8_cp437.c line 51
Quoted 10 lines
drivers/video/utf8_cp437.c new file +10
-0+case 0x03C0 :return 227 ; +case 0x03C3 :return 229 ; +case 0x03C4 :return 231 ; +case 0x03C6 :return 237 ; + } + +return 0 ; +}; + +static uint8_t utf8_convert_2xxx (uint16_t code)
This is duplicate to include/cp437.h
Quoted 60 lines
drivers/video/utf8_cp437.c new file +60
-0+{ +switch (code) { +case 0x2022 :return 7 ; +case 0x203C :return 19 ; +case 0x207F :return 252 ; +case 0x20A7 :return 158 ; +case 0x2190 :return 27 ; +case 0x2191 :return 24 ; +case 0x2192 :return 26 ; +case 0x2193 :return 25 ; +case 0x2194 :return 29 ; +case 0x2195 :return 18 ; +case 0x21A8 :return 23 ; +case 0x2219 :return 249 ; +case 0x221A :return 251 ; +case 0x221E :return 236 ; +case 0x221F :return 28 ; +case 0x2229 :return 239 ; +case 0x2248 :return 247 ; +case 0x2261 :return 240 ; +case 0x2264 :return 243 ; +case 0x2265 :return 242 ; +case 0x2310 :return 169 ; +case 0x2320 :return 244 ; +case 0x2321 :return 245 ; +case 0x2500 :return 196 ; +case 0x2502 :return 179 ; +case 0x250C :return 218 ; +case 0x2510 :return 191 ; +case 0x2514 :return 192 ; +case 0x2518 :return 217 ; +case 0x251C :return 195 ; +case 0x2524 :return 180 ; +case 0x252C :return 194 ; +case 0x2534 :return 193 ; +case 0x253C :return 197 ; +case 0x2580 :return 223 ; +case 0x2584 :return 220 ; +case 0x2588 :return 219 ; +case 0x258C :return 221 ; +case 0x2590 :return 222 ; +case 0x2591 :return 176 ; +case 0x2592 :return 177 ; +case 0x2593 :return 178 ; +case 0x25A0 :return 254 ; +case 0x25AC :return 22 ; +case 0x25B2 :return 30 ; +case 0x25BA :return 16 ; +case 0x25BC :return 31 ; +case 0x25C4 :return 17 ; +case 0x25CB :return 9 ; +case 0x25D8 :return 8 ; +case 0x25D9 :return 10 ; +case 0x263A :return 1 ; +case 0x263B :return 2 ; +case 0x263C :return 15 ; +case 0x2640 :return 12 ; +case 0x2642 :return 11 ; +case 0x2660 :return 6 ; +case 0x2663 :return 5 ;
drivers/video/utf8_cp437.c line 121
Quoted 10 lines
drivers/video/utf8_cp437.c new file +10
-0+case 0x2665 :return 3 ; +case 0x2666 :return 4 ; +case 0x266A :return 13 ; +case 0x266B :return 14 ; + } + +return 0 ; +} + +uint8_t convert_uc16_to_cp437 (uint16_t code)
We should not duplicate efi_fat_to_str() but use a common function.
drivers/video/utf8_cp437.c line 132
Quoted 11 lines
drivers/video/utf8_cp437.c new file +11
-0+{ +if (code <0x7f )// ASCII +return code; +if (code <0xa0 )// high control characters +return code; +if (code <0x100 )// international characters +return code_points_00a0[code -0xa0 ]; +if (code <0x800 ) +return utf8_convert_11bit (code); +if (code >=0x2550 && code <0x256d )// block graphics +return code_points_2550[code -0x2550 ];
How about ÄÖÜß and other European letters?
include/video_console.h
Quoted 62 lines
drivers/video/utf8_cp437.c new file +37
-0+ +return utf8_convert_2xxx (code); +} + +uint8_t convert_utf8_to_cp437 (uint8_t c,uint32_t *esc) +{ +int shift; +uint16_t ucs; + +if (c <127 )// ASCII +return c; +if (c ==127 ) +return 8 ;// DEL (?) + +switch (c &0xf0 ) { +case 0xc0 :case 0xd0 :// two bytes sequence + *esc = (1U <<24 ) | ((c &0x1f ) <<6 ); +return 0 ; +case 0xe0 :// three bytes sequence + *esc = (2U <<24 ) | ((c &0x0f ) <<12 ); +return 0 ; +case 0xf0 :// four bytes sequence + *esc = (3U <<24 ) | ((c &0x07 ) <<18 ); +return 0 ; +case 0x80 :case 0x90 :case 0xa0 :case 0xb0 :// continuation + shift = (*esc >>24 ) -1 ; + ucs = *esc &0xffffff ; +if (shift) { + *esc = (shift <<24 ) | ucs | (c &0x3f ) << (shift *6 ); +return 0 ; + } + *esc =0 ; +return convert_uc16_to_cp437 (ucs | (c &0x3f )); + } + +return 0 ; +}drivers/video/vidconsole-uclass.c +5
-1@@ -546,6 +546,7 @@ static int vidconsole_output_glyph(struct udevice *dev, char ch)int vidconsole_put_char (struct udevice *dev,char ch) {struct vidconsole_priv *priv =dev_get_uclass_priv (dev); +uint8_t cp437;int ret;/* @@ -587,7 +588,10 @@ int vidconsole_put_char(struct udevice *dev, char ch) priv->last_ch =0 ;break ;default : - ret =vidconsole_output_glyph (dev, ch); + cp437 =convert_utf8_to_cp437 (ch, &priv->ucs); +if (cp437 ==0 ) +return 0 ; + ret =vidconsole_output_glyph (dev, cp437);if (ret <0 )return ret;break ;include/video_console.h +0
-0
This should go to include/charset.h.
Best regards
Heinrich
Quoted 12 lines
index
a908f1412e8..f2d05e7f4e7100644include/video_console.h +1
-0@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +u32 ucs;bool cursor_visible;char escape_buf[32 ]; };
include/video_console.h static inline int vidconsole_memmove(struct udevice *dev, void *dst, · line 312
Quoted 8 lines
include/video_console.h +5
-0@@ -304,6 +305,14 @@ static inline int vidconsole_memmove(struct udevice *dev, void *dst,return 0 ; } +/* +* Convert an UTF-8 byte into the corresponding character in the CP437 +* code page. Returns 0 if that character is part of a multi-byte sequence. +* for which *esc holds the state of. Repeatedly feed in more bytes until +* the return value returns a non-0 character.
Please, follow the style described in https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation. This will allow inclusion in the HTML documentation (see https://u-boot.readthedocs.io/en/latest/api/index.html).
Best regards
Heinrich
Quoted 6 lines
include/video_console.h +3
-0+*/ +uint8_t convert_utf8_to_cp437 (uint8_t c,uint32_t *esc); +#endif #endif
Re: [PATCH 8/8] video: Convert UTF-8 input stream to the 437 code page
On Mon, 10 Jan 2022 09:18:45 +0100
Heinrich Schuchardt <[email protected]> wrote:
Hi Heinrich,
Quoted 35 lines
Quoted 34 lines · Andre Przywara
The bitmap fonts (VGA 8x16 and friends) we import from Linux use the 437 code page to map their glyphs. For U-Boot's own purposes this is probably fine, but UEFI applications output Unicode, which only matches in the very basic first 127 characters.
Add a function that converts UTF-8 character sequences into the respective CP437 code point, as far as the characters defined in there allow this. This includes quite some international and box drawing characters, which are used by UEFI applications.
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/Makefile | 1 + drivers/video/utf8_cp437.c | 169 ++++++++++++++++++++++++++++++ drivers/video/vidconsole-uclass.c | 6 +- include/video_console.h | 9 ++ 4 files changed, 184 insertions(+), 1 deletion(-)create mode 100644
drivers/video/utf8_cp437.cdrivers/video/Makefile +1
-0@@ -14,6 +14,7 @@ obj-$(CONFIG_DISPLAY) += display-uclass.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi-host-uclass.o obj-$(CONFIG_DM_VIDEO) += video-uclass.o vidconsole-uclass.o obj-$(CONFIG_DM_VIDEO) += video_bmp.o +obj-$(CONFIG_DM_VIDEO) += utf8_cp437.o obj-$(CONFIG_PANEL) += panel-uclass.o obj-$(CONFIG_DM_PANEL_HX8238D) += hx8238d.o obj-$(CONFIG_SIMPLE_PANEL) += simple_panel.odrivers/video/utf8_cp437.c new file +0
-0
Quoted 8 lines
drivers/video/utf8_cp437.c
Quoted 2 lines
drivers/video/utf8_cp437.c new file +0
-0A translation from Unicode to CP437 is needed in the FAT driver (but missing), in Unicode Collation Protocol and here in video. So this functionality should live in
lib/charset.c.
Please, have a look atefi_fat_to_str()inlib/efi_loader/efi_unicode_collation.c. We should avoid code duplication.
Ah, didn't know, thanks for the heads up! Happy to move the code in there, and will also look for prior art.
Quoted 2 lines
Maybe we should drop CP1250 support to make our effort simpler? No defconfig uses it.
I need to have a closer look.
Quoted 48 lines
Quoted 48 lines
drivers/video/utf8_cp437.c new file +46
-0@@ -0,0 +1,169 @@ +/* +* Convert UTF-8 bytes into a code page 437 character. +* Based on the table in the Code_page_437 Wikipedia page. +*/ + +#include <linux/types.h> + +uint8_t code_points_00a0[] = { +255 ,173 ,155 ,156 ,7 ,157 ,7 ,21 , +7 ,7 ,166 ,174 ,170 ,7 ,7 ,7 , +248 ,241 ,253 ,7 ,7 ,230 ,20 ,250 , +7 ,7 ,167 ,175 ,172 ,171 ,7 ,168 , +7 ,7 ,7 ,7 ,142 ,143 ,146 ,128 , +7 ,144 ,7 ,7 ,7 ,7 ,7 ,7 , +7 ,165 ,7 ,7 ,7 ,7 ,153 ,7 , +7 ,7 ,7 ,7 ,154 ,7 ,7 ,225 , +133 ,160 ,131 ,7 ,132 ,134 ,145 ,135 , +138 ,130 ,136 ,137 ,141 ,161 ,140 ,139 , +7 ,164 ,149 ,162 ,147 ,7 ,148 ,246 , +7 ,151 ,163 ,150 ,129 ,7 ,7 ,152 , +}; + +uint8_t code_points_2550[] = { +205 ,186 ,213 ,214 ,201 ,184 ,183 ,187 , +212 ,211 ,200 ,190 ,189 ,188 ,198 ,199 , +204 ,181 ,182 ,185 ,209 ,210 ,203 ,207 , +208 ,202 ,216 ,215 ,206 +}; + +static uint8_t utf8_convert_11bit (uint16_t code) +{ +switch (code) { +case 0x0192 :return 159 ; +case 0x0393 :return 226 ; +case 0x0398 :return 233 ; +case 0x03A3 :return 228 ; +case 0x03A6 :return 232 ; +case 0x03A9 :return 234 ; +case 0x03B1 :return 224 ; +case 0x03B4 :return 235 ; +case 0x03B5 :return 238 ; +case 0x03C0 :return 227 ; +case 0x03C3 :return 229 ; +case 0x03C4 :return 231 ; +case 0x03C6 :return 237 ; + }
Quoted 8 lines
drivers/video/utf8_cp437.c line 51
Quoted 5 lines
drivers/video/utf8_cp437.c new file +5
-0+ +return 0 ; +}; + +static uint8_t utf8_convert_2xxx (uint16_t code)This is duplicate to
include/cp437.h
But this is the other way around, isn't it? The above is from CP437 to UCS-2, this one here is from UCS-2 to CP437 (and it's misnamed). But I can certainly move it in there.
Quoted 64 lines
Quoted 64 lines
drivers/video/utf8_cp437.c new file +64
-0+{ +switch (code) { +case 0x2022 :return 7 ; +case 0x203C :return 19 ; +case 0x207F :return 252 ; +case 0x20A7 :return 158 ; +case 0x2190 :return 27 ; +case 0x2191 :return 24 ; +case 0x2192 :return 26 ; +case 0x2193 :return 25 ; +case 0x2194 :return 29 ; +case 0x2195 :return 18 ; +case 0x21A8 :return 23 ; +case 0x2219 :return 249 ; +case 0x221A :return 251 ; +case 0x221E :return 236 ; +case 0x221F :return 28 ; +case 0x2229 :return 239 ; +case 0x2248 :return 247 ; +case 0x2261 :return 240 ; +case 0x2264 :return 243 ; +case 0x2265 :return 242 ; +case 0x2310 :return 169 ; +case 0x2320 :return 244 ; +case 0x2321 :return 245 ; +case 0x2500 :return 196 ; +case 0x2502 :return 179 ; +case 0x250C :return 218 ; +case 0x2510 :return 191 ; +case 0x2514 :return 192 ; +case 0x2518 :return 217 ; +case 0x251C :return 195 ; +case 0x2524 :return 180 ; +case 0x252C :return 194 ; +case 0x2534 :return 193 ; +case 0x253C :return 197 ; +case 0x2580 :return 223 ; +case 0x2584 :return 220 ; +case 0x2588 :return 219 ; +case 0x258C :return 221 ; +case 0x2590 :return 222 ; +case 0x2591 :return 176 ; +case 0x2592 :return 177 ; +case 0x2593 :return 178 ; +case 0x25A0 :return 254 ; +case 0x25AC :return 22 ; +case 0x25B2 :return 30 ; +case 0x25BA :return 16 ; +case 0x25BC :return 31 ; +case 0x25C4 :return 17 ; +case 0x25CB :return 9 ; +case 0x25D8 :return 8 ; +case 0x25D9 :return 10 ; +case 0x263A :return 1 ; +case 0x263B :return 2 ; +case 0x263C :return 15 ; +case 0x2640 :return 12 ; +case 0x2642 :return 11 ; +case 0x2660 :return 6 ; +case 0x2663 :return 5 ; +case 0x2665 :return 3 ; +case 0x2666 :return 4 ; +case 0x266A :return 13 ; +case 0x266B :return 14 ;
Quoted 8 lines
drivers/video/utf8_cp437.c line 121
Quoted 6 lines
drivers/video/utf8_cp437.c new file +6
-0+ } + +return 0 ; +} + +uint8_t convert_uc16_to_cp437 (uint16_t code)We should not duplicate
efi_fat_to_str()but use a common function.
Definitely, I wasn't aware of this code, thanks for the heads up.
Quoted 5 lines
Quoted 5 lines
drivers/video/utf8_cp437.c new file +5
-0+{ +if (code <0x7f )// ASCII +return code; +if (code <0xa0 )// high control characters +return code;
Quoted 8 lines
drivers/video/utf8_cp437.c line 132
Quoted 6 lines
drivers/video/utf8_cp437.c new file +6
-0+if (code <0x100 )// international characters +return code_points_00a0[code -0xa0 ]; +if (code <0x800 ) +return utf8_convert_11bit (code); +if (code >=0x2550 && code <0x256d )// block graphics +return code_points_2550[code -0x2550 ];How about ÄÖÜß and other European letters?
Any "Übergrößengeschäft" should be covered by the international characters section above, between 160 and 255. Do you miss anything in particular?
Quoted 84 lines
include/video_console.h
Quoted 62 lines
drivers/video/utf8_cp437.c new file +37
-0+ +return utf8_convert_2xxx (code); +} + +uint8_t convert_utf8_to_cp437 (uint8_t c,uint32_t *esc) +{ +int shift; +uint16_t ucs; + +if (c <127 )// ASCII +return c; +if (c ==127 ) +return 8 ;// DEL (?) + +switch (c &0xf0 ) { +case 0xc0 :case 0xd0 :// two bytes sequence + *esc = (1U <<24 ) | ((c &0x1f ) <<6 ); +return 0 ; +case 0xe0 :// three bytes sequence + *esc = (2U <<24 ) | ((c &0x0f ) <<12 ); +return 0 ; +case 0xf0 :// four bytes sequence + *esc = (3U <<24 ) | ((c &0x07 ) <<18 ); +return 0 ; +case 0x80 :case 0x90 :case 0xa0 :case 0xb0 :// continuation + shift = (*esc >>24 ) -1 ; + ucs = *esc &0xffffff ; +if (shift) { + *esc = (shift <<24 ) | ucs | (c &0x3f ) << (shift *6 ); +return 0 ; + } + *esc =0 ; +return convert_uc16_to_cp437 (ucs | (c &0x3f )); + } + +return 0 ; +}drivers/video/vidconsole-uclass.c +5
-1@@ -546,6 +546,7 @@ static int vidconsole_output_glyph(struct udevice *dev, char ch)int vidconsole_put_char (struct udevice *dev,char ch) {struct vidconsole_priv *priv =dev_get_uclass_priv (dev); +uint8_t cp437;int ret;/* @@ -587,7 +588,10 @@ int vidconsole_put_char(struct udevice *dev, char ch) priv->last_ch =0 ;break ;default : - ret =vidconsole_output_glyph (dev, ch); + cp437 =convert_utf8_to_cp437 (ch, &priv->ucs); +if (cp437 ==0 ) +return 0 ; + ret =vidconsole_output_glyph (dev, cp437);if (ret <0 )return ret;break ;include/video_console.h +0
-0This should go to
include/charset.h.Best regards
Heinrich
Quoted 15 lines
index
a908f1412e8..f2d05e7f4e7100644include/video_console.h +1
-0@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +u32 ucs;bool cursor_visible;char escape_buf[32 ]; };@@ -304,6 +305,14 @@ static inline int vidconsole_memmove(struct udevice *dev, void *dst,return 0 ; }
Quoted 11 lines
include/video_console.h static inline int vidconsole_memmove(struct udevice *dev, void *dst, · line 312
Quoted 5 lines
include/video_console.h +5
-0+/* +* Convert an UTF-8 byte into the corresponding character in the CP437 +* code page. Returns 0 if that character is part of a multi-byte sequence. +* for which *esc holds the state of. Repeatedly feed in more bytes until +* the return value returns a non-0 character. Please, follow the style described in
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation.
This will allow inclusion in the HTML documentation (see
https://u-boot.readthedocs.io/en/latest/api/index.html).
Sure, I love and use kerneldoc, just missed that in that three-year old patch ;-)
Cheers,
Andre
Quoted 8 lines
Quoted 7 lines
include/video_console.h +3
-0+*/ +uint8_t convert_utf8_to_cp437 (uint8_t c,uint32_t *esc); +#endif #endif
Re: [PATCH 8/8] video: Convert UTF-8 input stream to the 437 code page
In reply to Andre PrzywaraHi Andre,
Quoted 11 lines · Andre Przywara
The bitmap fonts (VGA 8x16 and friends) we import from Linux use the 437 code page to map their glyphs. For U-Boot's own purposes this is probably fine, but UEFI applications output Unicode, which only matches in the very basic first 127 characters.
Add a function that converts UTF-8 character sequences into the respective CP437 code point, as far as the characters defined in there allow this. This includes quite some international and box drawing characters, which are used by UEFI applications.
Quoted 9 lines
Signed-off-by Andre Przywara <[email protected]>--- drivers/video/Makefile | 1 + drivers/video/utf8_cp437.c | 169 ++++++++++++++++++++++++++++++ drivers/video/vidconsole-uclass.c | 6 +- include/video_console.h | 9 ++ 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 drivers/video/utf8_cp437.c
[..]
This code should only be enabled if UEFI is being used, to reduce code size.
Quoted 13 lines
include/video_console.h +1
-0@@ -83,6 +83,7 @@ struct vidconsole_priv {int escape_len;int row_saved;int col_saved; +u32 ucs;bool cursor_visible;char escape_buf[32 ]; };
include/video_console.h static inline int vidconsole_memmove(struct udevice *dev, void *dst, · line 314
Quoted 10 lines
include/video_console.h +7
-0@@ -304,6 +305,14 @@ static inline int vidconsole_memmove(struct udevice *dev, void *dst,return 0 ; } +/* +* Convert an UTF-8 byte into the corresponding character in the CP437 +* code page. Returns 0 if that character is part of a multi-byte sequence. +* for which *esc holds the state of. Repeatedly feed in more bytes until +* the return value returns a non-0 character. +*/ +uint8_t convert_utf8_to_cp437 (uint8_t c,uint32_t *esc);
Just a note that this should be below the next #endif :
include/video_console.h static inline int vidconsole_memmove(struct udevice *dev, void *dst, · line 316
Quoted 2 lines
include/video_console.h +1
-0+#endif
<here>
Quoted 5 lines
include/video_console.h +0
-1#endif --2.17.6
Regards,
Simon