diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 11 | ||||
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/dhry/cmd_dhry.c | 2 | ||||
-rw-r--r-- | lib/efi_loader/Makefile | 2 | ||||
-rw-r--r-- | lib/fdtdec.c | 2 | ||||
-rw-r--r-- | lib/net_utils.c | 4 | ||||
-rw-r--r-- | lib/rsa/rsa-sign.c | 13 | ||||
-rw-r--r-- | lib/rsa/rsa-verify.c | 2 | ||||
-rw-r--r-- | lib/strto.c | 84 | ||||
-rw-r--r-- | lib/uuid.c | 14 | ||||
-rw-r--r-- | lib/vsprintf.c | 2 |
11 files changed, 98 insertions, 40 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index ad4d75e0a40..7b445d01641 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -40,6 +40,14 @@ config CC_OPTIMIZE_LIBS_FOR_SPEED If unsure, say N. +config CHARSET + bool + default y if UT_UNICODE || EFI_LOADER || UFS + help + Enables support for various conversions between different + character sets, such as between unicode representations and + different 'code pages'. + config DYNAMIC_CRC_TABLE bool "Enable Dynamic tables for CRC" help @@ -558,8 +566,7 @@ config HEXDUMP config SPL_HEXDUMP bool "Enable hexdump in SPL" - depends on HEXDUMP - default y + depends on SPL && HEXDUMP help This enables functions for printing dumps of binary data in SPL. diff --git a/lib/Makefile b/lib/Makefile index 5cd0c9c6389..07c2ccd7cfd 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,7 +25,7 @@ obj-$(CONFIG_AES) += aes/ obj-$(CONFIG_$(SPL_TPL_)BINMAN_FDT) += binman.o ifndef API_BUILD -ifneq ($(CONFIG_UT_UNICODE)$(CONFIG_EFI_LOADER),) +ifneq ($(CONFIG_CHARSET),) obj-y += charset.o endif endif diff --git a/lib/dhry/cmd_dhry.c b/lib/dhry/cmd_dhry.c index d55ab54df97..77b52a23003 100644 --- a/lib/dhry/cmd_dhry.c +++ b/lib/dhry/cmd_dhry.c @@ -16,7 +16,7 @@ static int do_dhry(struct cmd_tbl *cmdtp, int flag, int argc, int iterations = 1000000; if (argc > 1) - iterations = simple_strtoul(argv[1], NULL, 10); + iterations = dectoul(argv[1], NULL); start = get_timer(0); dhry(iterations); diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 9b369430e25..08469d9cd95 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -23,7 +23,7 @@ endif ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE),y) EFI_CAPSULE_KEY_PATH := $(subst $\",,$(CONFIG_EFI_CAPSULE_KEY_PATH)) ifeq ("$(wildcard $(EFI_CAPSULE_KEY_PATH))","") -$(error .esl cerificate not found. Configure your CONFIG_EFI_CAPSULE_KEY_PATH) +$(error .esl certificate not found. Configure your CONFIG_EFI_CAPSULE_KEY_PATH) endif endif diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 3f178b975ae..337c4443b03 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -403,7 +403,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name, continue; /* Get the alias number */ - number = simple_strtoul(path + name_len, NULL, 10); + number = dectoul(path + name_len, NULL); if (number < 0 || number >= maxcount) { debug("%s: warning: alias '%s' is out of range\n", __func__, path); diff --git a/lib/net_utils.c b/lib/net_utils.c index 0a8a557319c..72a3b098a70 100644 --- a/lib/net_utils.c +++ b/lib/net_utils.c @@ -23,7 +23,7 @@ struct in_addr string_to_ip(const char *s) return addr; for (addr.s_addr = 0, i = 0; i < 4; ++i) { - ulong val = s ? simple_strtoul(s, &e, 10) : 0; + ulong val = s ? dectoul(s, &e) : 0; if (val > 255) { addr.s_addr = 0; return addr; @@ -52,7 +52,7 @@ void string_to_enetaddr(const char *addr, uint8_t *enetaddr) return; for (i = 0; i < 6; ++i) { - enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; + enetaddr[i] = addr ? hextoul(addr, &end) : 0; if (addr) addr = (*end) ? end + 1 : end; } diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c index f4ed11e74a4..085dc89bf7b 100644 --- a/lib/rsa/rsa-sign.c +++ b/lib/rsa/rsa-sign.c @@ -338,6 +338,7 @@ static int rsa_init(void) static int rsa_engine_init(const char *engine_id, ENGINE **pe) { + const char *key_pass; ENGINE *e; int ret; @@ -362,10 +363,20 @@ static int rsa_engine_init(const char *engine_id, ENGINE **pe) goto err_set_rsa; } + key_pass = getenv("MKIMAGE_SIGN_PIN"); + if (key_pass) { + if (!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0)) { + fprintf(stderr, "Couldn't set PIN\n"); + ret = -1; + goto err_set_pin; + } + } + *pe = e; return 0; +err_set_pin: err_set_rsa: ENGINE_finish(e); err_engine_init: @@ -473,7 +484,7 @@ static int rsa_sign_with_key(EVP_PKEY *pkey, struct padding_algo *padding_algo, #endif EVP_MD_CTX_destroy(context); - debug("Got signature: %d bytes, expected %zu\n", *sig_size, size); + debug("Got signature: %zu bytes, expected %d\n", size, EVP_PKEY_size(pkey)); *sigp = sig; *sig_size = size; diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c index bb8cc61d94b..3840764e420 100644 --- a/lib/rsa/rsa-verify.c +++ b/lib/rsa/rsa-verify.c @@ -556,7 +556,7 @@ int rsa_verify(struct image_sign_info *info, */ if (info->checksum->checksum_len > info->crypto->key_len) { - debug("%s: invlaid checksum-algorithm %s for %s\n", + debug("%s: invalid checksum-algorithm %s for %s\n", __func__, info->checksum->name, info->crypto->name); return -EINVAL; } diff --git a/lib/strto.c b/lib/strto.c index c00bb5895df..7bba1e3e549 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -14,33 +14,55 @@ #include <linux/ctype.h> /* from lib/kstrtox.c */ -static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) +static const char *_parse_integer_fixup_radix(const char *s, uint *basep) { - if (*base == 0) { - if (s[0] == '0') { - if (tolower(s[1]) == 'x' && isxdigit(s[2])) - *base = 16; - else - *base = 8; - } else - *base = 10; + /* Look for a 0x prefix */ + if (s[0] == '0') { + int ch = tolower(s[1]); + + if (ch == 'x') { + *basep = 16; + s += 2; + } else if (!*basep) { + /* Only select octal if we don't have a base */ + *basep = 8; + } } - if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x') - s += 2; + + /* Use decimal by default */ + if (!*basep) + *basep = 10; + return s; } -unsigned long simple_strtoul(const char *cp, char **endp, - unsigned int base) +/** + * decode_digit() - Decode a single character into its numeric digit value + * + * This ignore case + * + * @ch: Character to convert (expects '0'..'9', 'a'..'f' or 'A'..'F') + * @return value of digit (0..0xf) or 255 if the character is invalid + */ +static uint decode_digit(int ch) +{ + if (!isxdigit(ch)) + return 256; + + ch = tolower(ch); + + return ch <= '9' ? ch - '0' : ch - 'a' + 0xa; +} + +ulong simple_strtoul(const char *cp, char **endp, uint base) { - unsigned long result = 0; - unsigned long value; + ulong result = 0; + uint value; cp = _parse_integer_fixup_radix(cp, &base); - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; + while (value = decode_digit(*cp), value < base) { + result = result * base + value; cp++; } @@ -50,6 +72,16 @@ unsigned long simple_strtoul(const char *cp, char **endp, return result; } +ulong hextoul(const char *cp, char **endp) +{ + return simple_strtoul(cp, endp, 16); +} + +ulong dectoul(const char *cp, char **endp) +{ + return simple_strtoul(cp, endp, 10); +} + int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) { char *tail; @@ -127,12 +159,12 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) { - unsigned long long result = 0, value; + unsigned long long result = 0; + uint value; cp = _parse_integer_fixup_radix(cp, &base); - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0' - : (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) { + while (value = decode_digit(*cp), value < base) { result = result * base + value; cp++; } @@ -143,6 +175,14 @@ unsigned long long simple_strtoull(const char *cp, char **endp, return result; } +long long simple_strtoll(const char *cp, char **endp, unsigned int base) +{ + if (*cp == '-') + return -simple_strtoull(cp + 1, endp, base); + + return simple_strtoull(cp, endp, base); +} + long trailing_strtoln(const char *str, const char *end) { const char *p; @@ -152,7 +192,7 @@ long trailing_strtoln(const char *str, const char *end) if (isdigit(end[-1])) { for (p = end - 1; p > str; p--) { if (!isdigit(*p)) - return simple_strtoul(p + 1, NULL, 10); + return dectoul(p + 1, NULL); } } diff --git a/lib/uuid.c b/lib/uuid.c index 5bc68674d02..67267c66a3c 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -164,26 +164,26 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, } if (str_format == UUID_STR_FORMAT_STD) { - tmp32 = cpu_to_be32(simple_strtoul(uuid_str, NULL, 16)); + tmp32 = cpu_to_be32(hextoul(uuid_str, NULL)); memcpy(uuid_bin, &tmp32, 4); - tmp16 = cpu_to_be16(simple_strtoul(uuid_str + 9, NULL, 16)); + tmp16 = cpu_to_be16(hextoul(uuid_str + 9, NULL)); memcpy(uuid_bin + 4, &tmp16, 2); - tmp16 = cpu_to_be16(simple_strtoul(uuid_str + 14, NULL, 16)); + tmp16 = cpu_to_be16(hextoul(uuid_str + 14, NULL)); memcpy(uuid_bin + 6, &tmp16, 2); } else { - tmp32 = cpu_to_le32(simple_strtoul(uuid_str, NULL, 16)); + tmp32 = cpu_to_le32(hextoul(uuid_str, NULL)); memcpy(uuid_bin, &tmp32, 4); - tmp16 = cpu_to_le16(simple_strtoul(uuid_str + 9, NULL, 16)); + tmp16 = cpu_to_le16(hextoul(uuid_str + 9, NULL)); memcpy(uuid_bin + 4, &tmp16, 2); - tmp16 = cpu_to_le16(simple_strtoul(uuid_str + 14, NULL, 16)); + tmp16 = cpu_to_le16(hextoul(uuid_str + 14, NULL)); memcpy(uuid_bin + 6, &tmp16, 2); } - tmp16 = cpu_to_be16(simple_strtoul(uuid_str + 19, NULL, 16)); + tmp16 = cpu_to_be16(hextoul(uuid_str + 19, NULL)); memcpy(uuid_bin + 8, &tmp16, 2); tmp64 = cpu_to_be64(simple_strtoull(uuid_str + 24, NULL, 16)); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index c14176dd393..d7ee35b4773 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -858,7 +858,7 @@ bool str2long(const char *p, ulong *num) { char *endptr; - *num = simple_strtoul(p, &endptr, 16); + *num = hextoul(p, &endptr); return *p != '\0' && *endptr == '\0'; } |