[PATCH 8/8] video: Convert UTF-8 input stream to the 437 code page

Simon Glass sjg at chromium.org
Sun Mar 13 23:23:12 CET 2022


Hi Andre,

On Sun, 9 Jan 2022 at 17:57, Andre Przywara <andre.przywara at arm.com> wrote:
>
> 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 <andre.przywara at arm.com>
> ---
>  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.

> diff --git a/include/video_console.h b/include/video_console.h
> index a908f1412e8..f2d05e7f4e7 100644
> --- a/include/video_console.h
> +++ b/include/video_console.h
> @@ -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);

Just a note that this should be below the next #endif  :

> +
>  #endif

<here>

>
>  #endif
> --
> 2.17.6
>

Regards,
Simon


More information about the U-Boot mailing list