diff options
author | Tom Rini <trini@konsulko.com> | 2021-03-15 19:15:38 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-03-15 19:15:38 +0300 |
commit | 22fc991dafee0142fc6bf621e7bd558bd58020b4 (patch) | |
tree | e5da8826fd735de968519f432864dc1545d96017 /lib | |
parent | 1876b390f31afca15de334e499aa071b0bf64a44 (diff) | |
parent | 4103e13534141c31e4e9bf40848ab3a61dabce81 (diff) | |
download | u-boot-22fc991dafee0142fc6bf621e7bd558bd58020b4.tar.xz |
Merge tag 'v2021.04-rc4' into next
Prepare v2021.04-rc4
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 4 | ||||
-rw-r--r-- | lib/addr_map.c | 6 | ||||
-rw-r--r-- | lib/charset.c | 96 | ||||
-rw-r--r-- | lib/efi_loader/efi_console.c | 2 | ||||
-rw-r--r-- | lib/efi_loader/efi_unicode_collation.c | 21 |
5 files changed, 96 insertions, 33 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index b35a71ac36..7288340614 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -6,6 +6,8 @@ config ADDR_MAP Enables helper code for implementing non-identity virtual-physical memory mappings for 32bit CPUs. + This library only works in the post-relocation phase. + config SYS_NUM_ADDR_MAP int "Size of the address-map table" depends on ADDR_MAP @@ -22,7 +24,7 @@ config BCH config BINMAN_FDT bool "Allow access to binman information in the device tree" - depends on BINMAN && OF_CONTROL + depends on BINMAN && DM && OF_CONTROL default y help This enables U-Boot to access information about binman entries, diff --git a/lib/addr_map.c b/lib/addr_map.c index 09771f3a5a..fb2ef40007 100644 --- a/lib/addr_map.c +++ b/lib/addr_map.c @@ -6,11 +6,7 @@ #include <common.h> #include <addr_map.h> -static struct { - phys_addr_t paddr; - phys_size_t size; - unsigned long vaddr; -} address_map[CONFIG_SYS_NUM_ADDR_MAP]; +struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP]; phys_addr_t addrmap_virt_to_phys(void * vaddr) { diff --git a/lib/charset.c b/lib/charset.c index 2177014ee1..f44c58d9d8 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -8,9 +8,16 @@ #include <common.h> #include <charset.h> #include <capitalization.h> +#include <cp437.h> #include <efi_loader.h> +#include <errno.h> #include <malloc.h> +/** + * codepage_437 - Unicode to codepage 437 translation table + */ +const u16 codepage_437[128] = CP437; + static struct capitalization_table capitalization_table[] = #ifdef CONFIG_EFI_UNICODE_CAPITALIZATION UNICODE_CAPITALIZATION_TABLE; @@ -25,7 +32,7 @@ static struct capitalization_table capitalization_table[] = * * @read_u8: - stream reader * @src: - string buffer passed to stream reader, optional - * Return: - Unicode code point + * Return: - Unicode code point, or -1 */ static int get_code(u8 (*read_u8)(void *data), void *data) { @@ -71,7 +78,7 @@ static int get_code(u8 (*read_u8)(void *data), void *data) } return ch; error: - return '?'; + return -1; } /** @@ -113,14 +120,21 @@ static u8 read_console(void *data) int console_read_unicode(s32 *code) { - if (!tstc()) { - /* No input available */ - return 1; - } + for (;;) { + s32 c; - /* Read Unicode code */ - *code = get_code(read_console, NULL); - return 0; + if (!tstc()) { + /* No input available */ + return 1; + } + + /* Read Unicode code */ + c = get_code(read_console, NULL); + if (c > 0) { + *code = c; + return 0; + } + } } s32 utf8_get(const char **src) @@ -466,3 +480,67 @@ uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size) return dest; } + +int utf_to_cp(s32 *c, const u16 *codepage) +{ + if (*c >= 0x80) { + int j; + + /* Look up codepage translation */ + for (j = 0; j < 0x80; ++j) { + if (*c == codepage[j]) { + *c = j + 0x80; + return 0; + } + } + *c = '?'; + return -ENOENT; + } + return 0; +} + +int utf8_to_cp437_stream(u8 c, char *buffer) +{ + char *end; + const char *pos; + s32 s; + int ret; + + for (;;) { + pos = buffer; + end = buffer + strlen(buffer); + *end++ = c; + *end = 0; + s = utf8_get(&pos); + if (s > 0) { + *buffer = 0; + ret = utf_to_cp(&s, codepage_437); + return s; + } + if (pos == end) + return 0; + *buffer = 0; + } +} + +int utf8_to_utf32_stream(u8 c, char *buffer) +{ + char *end; + const char *pos; + s32 s; + + for (;;) { + pos = buffer; + end = buffer + strlen(buffer); + *end++ = c; + *end = 0; + s = utf8_get(&pos); + if (s > 0) { + *buffer = 0; + return s; + } + if (pos == end) + return 0; + *buffer = 0; + } +} diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index edcfce7bec..c4003554c2 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -311,7 +311,7 @@ static void query_console_size(void) const char *stdout_name = env_get("stdout"); int rows = 25, cols = 80; - if (stdout_name && !strcmp(stdout_name, "vidconsole") && + if (stdout_name && !strncmp(stdout_name, "vidconsole", 10) && IS_ENABLED(CONFIG_DM_VIDEO)) { struct stdio_dev *stdout_dev = stdio_get_by_name("vidconsole"); diff --git a/lib/efi_loader/efi_unicode_collation.c b/lib/efi_loader/efi_unicode_collation.c index f6c875bc33..36be798f64 100644 --- a/lib/efi_loader/efi_unicode_collation.c +++ b/lib/efi_loader/efi_unicode_collation.c @@ -23,7 +23,7 @@ static const char illegal[] = "+,<=>:;\"/\\|?*[]\x7f"; static const u16 codepage[] = CP1250; #else /* Unicode code points for code page 437 characters 0x80 - 0xff */ -static const u16 codepage[] = CP437; +static const u16 *codepage = codepage_437; #endif /* GUID of the EFI_UNICODE_COLLATION_PROTOCOL2 */ @@ -300,23 +300,10 @@ static bool EFIAPI efi_str_to_fat(struct efi_unicode_collation_protocol *this, break; } c = utf_to_upper(c); - if (c >= 0x80) { - int j; - - /* Look for codepage translation */ - for (j = 0; j < 0x80; ++j) { - if (c == codepage[j]) { - c = j + 0x80; - break; - } - } - if (j >= 0x80) { - c = '_'; - ret = true; - } - } else if (c && (c < 0x20 || strchr(illegal, c))) { - c = '_'; + if (utf_to_cp(&c, codepage) || + (c && (c < 0x20 || strchr(illegal, c)))) { ret = true; + c = '_'; } fat[i] = c; |