diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 11 | ||||
-rw-r--r-- | lib/binman.c | 16 | ||||
-rw-r--r-- | lib/efi_driver/efi_uclass.c | 1 | ||||
-rw-r--r-- | lib/efi_loader/dtbdump.c | 86 | ||||
-rw-r--r-- | lib/efi_loader/efi_bootbin.c | 1 | ||||
-rw-r--r-- | lib/efi_loader/efi_bootmgr.c | 13 | ||||
-rw-r--r-- | lib/efi_loader/efi_boottime.c | 1 | ||||
-rw-r--r-- | lib/efi_loader/efi_capsule.c | 1 | ||||
-rw-r--r-- | lib/efi_loader/efi_console.c | 27 | ||||
-rw-r--r-- | lib/efi_loader/efi_device_path.c | 175 | ||||
-rw-r--r-- | lib/efi_loader/efi_device_path_utilities.c | 3 | ||||
-rw-r--r-- | lib/efi_loader/efi_disk.c | 1 | ||||
-rw-r--r-- | lib/efi_loader/efi_fdt.c | 1 | ||||
-rw-r--r-- | lib/efi_loader/efi_helper.c | 7 | ||||
-rw-r--r-- | lib/efi_loader/efi_net.c | 3 | ||||
-rw-r--r-- | lib/efi_loader/efi_tcg2.c | 1 | ||||
-rw-r--r-- | lib/linux_string.c | 6 | ||||
-rw-r--r-- | lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 8 | ||||
-rw-r--r-- | lib/slre.c | 78 | ||||
-rw-r--r-- | lib/tiny-printf.c | 48 |
20 files changed, 271 insertions, 217 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index b2aecd8a49e..6a89f797bef 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -253,6 +253,14 @@ config VPL_USE_TINY_PRINTF The supported format specifiers are %c, %s, %u/%d and %x. +config SPL_USE_TINY_PRINTF_POINTER_SUPPORT + bool "Extend tiny printf with the pointer formatting %p" + depends on SPL_USE_TINY_PRINTF + help + This option enables the formatting of pointers %p. It supports + %p and %pa / %pap. If this option is selected by SPL_NET + it also supports the formatting with %pm, %pM and %pI4. + config PANIC_HANG bool "Do not reset the system on fatal error" help @@ -275,7 +283,8 @@ config REGEX choice prompt "Pseudo-random library support type" depends on NET_RANDOM_ETHADDR || RANDOM_UUID || CMD_UUID || \ - RNG_SANDBOX || UT_LIB && AES || FAT_WRITE + RNG_SANDBOX || UT_LIB && AES || FAT_WRITE || CMD_BOOTP || \ + CMD_DHCP || CMD_DHCP6 default LIB_RAND help Select the library to provide pseudo-random number generator diff --git a/lib/binman.c b/lib/binman.c index 9047f5275f3..a594fe4c2ca 100644 --- a/lib/binman.c +++ b/lib/binman.c @@ -16,12 +16,15 @@ * struct binman_info - Information needed by the binman library * * @image: Node describing the image we are running from + * @skip_at_start: Number of bytes skipped at the start of the image. This is + * the value of the skip-at-start property for the image * @rom_offset: Offset from an image_pos to the memory-mapped address, or * ROM_OFFSET_NONE if the ROM is not memory-mapped. Can be positive or * negative */ struct binman_info { ofnode image; + uint skip_at_start; int rom_offset; }; @@ -80,7 +83,14 @@ static int binman_entry_find_internal(ofnode node, const char *name, int binman_entry_find(const char *name, struct binman_entry *entry) { - return binman_entry_find_internal(binman->image, name, entry); + int ret; + + ret = binman_entry_find_internal(binman->image, name, entry); + if (ret) + return log_msg_ret("bef", ret); + entry->image_pos -= binman->skip_at_start; + + return 0; } int binman_entry_map(ofnode parent, const char *name, void **bufp, int *sizep) @@ -107,7 +117,7 @@ ofnode binman_section_find_node(const char *name) void binman_set_rom_offset(int rom_offset) { - binman->rom_offset = rom_offset; + binman->rom_offset = rom_offset - binman->skip_at_start; } int binman_get_rom_offset(void) @@ -140,10 +150,12 @@ int binman_init(void) binman = malloc(sizeof(struct binman_info)); if (!binman) return log_msg_ret("space for binman", -ENOMEM); + memset(binman, '\0', sizeof(struct binman_info)); ret = find_image_node(&binman->image); if (ret) return log_msg_ret("node", -ENOENT); binman_set_rom_offset(ROM_OFFSET_NONE); + ofnode_read_u32(binman->image, "skip-at-start", &binman->skip_at_start); log_debug("binman: Selected image node '%s'\n", ofnode_get_name(binman->image)); diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c index 495be53cb77..7392c60f0f9 100644 --- a/lib/efi_driver/efi_uclass.c +++ b/lib/efi_driver/efi_uclass.c @@ -20,6 +20,7 @@ #define LOG_CATEGORY LOGC_EFI #include <dm.h> +#include <efi_device_path.h> #include <efi_driver.h> #include <log.h> #include <malloc.h> diff --git a/lib/efi_loader/dtbdump.c b/lib/efi_loader/dtbdump.c index a3d59a2fd3b..1e72404ecc1 100644 --- a/lib/efi_loader/dtbdump.c +++ b/lib/efi_loader/dtbdump.c @@ -29,6 +29,18 @@ static struct efi_system_table *systable; static const efi_guid_t efi_dt_fixup_protocol_guid = EFI_DT_FIXUP_PROTOCOL_GUID; static const efi_guid_t efi_file_info_guid = EFI_FILE_INFO_GUID; static const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID; +static bool nocolor; + +/** + * color() - set foreground color + * + * @color: foreground color + */ +static void color(u8 color) +{ + if (!nocolor) + cout->set_attribute(cout, color | EFI_BACKGROUND_BLACK); +} /** * print() - print string @@ -88,15 +100,34 @@ static void printx(unsigned char val) } /** + * cls() - clear screen + */ +static void cls(void) +{ + if (nocolor) + print(u"\r\n"); + else + cout->clear_screen(cout); +} + +/** * error() - print error string * * @string: error text */ static void error(u16 *string) { - cout->set_attribute(cout, EFI_LIGHTRED | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTRED); print(string); - cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTBLUE); +} + +/** + * efi_drain_input() - drain console input + */ +static void efi_drain_input(void) +{ + cin->reset(cin, true); } /** @@ -116,8 +147,6 @@ static efi_status_t efi_input_yn(void) efi_uintn_t index; efi_status_t ret; - /* Drain the console input */ - ret = cin->reset(cin, true); for (;;) { ret = bs->wait_for_event(1, &cin->wait_for_key, &index); if (ret != EFI_SUCCESS) @@ -158,8 +187,6 @@ static efi_status_t efi_input(u16 *buffer, efi_uintn_t buffer_size) u16 outbuf[2] = u" "; efi_status_t ret; - /* Drain the console input */ - ret = cin->reset(cin, true); *buffer = 0; for (;;) { ret = bs->wait_for_event(1, &cin->wait_for_key, &index); @@ -262,6 +289,9 @@ static u16 *skip_whitespace(u16 *pos) */ static bool starts_with(u16 *string, u16 *keyword) { + if (!string || !keyword) + return false; + for (; *keyword; ++string, ++keyword) { if (*string != *keyword) return false; @@ -737,6 +767,7 @@ static efi_status_t do_dump(void) error(u"Missing end node\r\n"); return EFI_LOAD_ERROR; } + print(u"\r\n"); return EFI_SUCCESS; default: error(u"Invalid device tree token\r\n"); @@ -749,6 +780,30 @@ static efi_status_t do_dump(void) } /** + * get_load_options() - get load options + * + * Return: load options or NULL + */ +static u16 *get_load_options(void) +{ + efi_status_t ret; + struct efi_loaded_image *loaded_image; + + ret = bs->open_protocol(handle, &loaded_image_guid, + (void **)&loaded_image, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + error(u"Loaded image protocol not found\r\n"); + return NULL; + } + + if (!loaded_image->load_options_size || !loaded_image->load_options) + return NULL; + + return loaded_image->load_options; +} + +/** * efi_main() - entry point of the EFI application. * * @handle: handle of the loaded image @@ -758,24 +813,31 @@ static efi_status_t do_dump(void) efi_status_t EFIAPI efi_main(efi_handle_t image_handle, struct efi_system_table *systab) { + u16 *load_options; + handle = image_handle; systable = systab; cerr = systable->std_err; cout = systable->con_out; cin = systable->con_in; bs = systable->boottime; + load_options = get_load_options(); + + if (starts_with(load_options, u"nocolor")) + nocolor = true; - cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK); - cout->clear_screen(cout); - cout->set_attribute(cout, EFI_WHITE | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTBLUE); + cls(); + color(EFI_WHITE); print(u"DTB Dump\r\n========\r\n\r\n"); - cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTBLUE); for (;;) { u16 command[BUFFER_SIZE]; u16 *pos; efi_uintn_t ret; + efi_drain_input(); print(u"=> "); ret = efi_input(command, sizeof(command)); if (ret == EFI_ABORTED) @@ -793,7 +855,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image_handle, do_help(); } - cout->set_attribute(cout, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK); - cout->clear_screen(cout); + color(EFI_LIGHTGRAY); + cls(); return EFI_SUCCESS; } diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index 94ba7c5589b..b394f0d60ce 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -10,6 +10,7 @@ #include <charset.h> #include <dm.h> #include <efi.h> +#include <efi_device_path.h> #include <efi_loader.h> #include <env.h> #include <image.h> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index c0df5cb9acd..1a3461f5a9d 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -12,6 +12,7 @@ #include <charset.h> #include <dm.h> #include <efi.h> +#include <efi_device_path.h> #include <log.h> #include <malloc.h> #include <net.h> @@ -479,6 +480,13 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, if (!ctx) return EFI_OUT_OF_RESOURCES; + s = env_get("ipaddr"); + if (!s && dhcp_run(0, NULL, false)) { + log_err("Error: Can't find a valid IP address\n"); + ret = EFI_DEVICE_ERROR; + goto err; + } + s = env_get("loadaddr"); if (!s) { log_err("Error: loadaddr is not set\n"); @@ -527,7 +535,7 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, * will be freed in return_to_efibootmgr event callback. */ loaded_dp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)image_addr, image_size); + image_addr, image_size); ret = efi_install_multiple_protocol_interfaces( &mem_handle, &efi_guid_device_path, loaded_dp, NULL); if (ret != EFI_SUCCESS) @@ -855,7 +863,8 @@ efi_bootmgr_enumerate_boot_options(struct eficonfig_media_boot_option *opt, lo.label = dev_name; lo.attributes = LOAD_OPTION_ACTIVE; lo.file_path = device_path; - lo.file_path_length = efi_dp_size(device_path) + sizeof(END); + lo.file_path_length = efi_dp_size(device_path) + + sizeof(EFI_DP_END); /* * Set the dedicated guid to optional_data, it is used to identify * the boot option that automatically generated by the bootmenu. diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index dbebb37dc04..24b0e52a2a2 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -11,6 +11,7 @@ #include <div64.h> #include <dm/device.h> #include <dm/root.h> +#include <efi_device_path.h> #include <efi_loader.h> #include <irq_func.h> #include <log.h> diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 1aa52ac7bb6..f19e78ae9d1 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> #include <efi_variable.h> #include <env.h> diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index 9d9f786a6db..953f6831466 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -9,6 +9,7 @@ #include <ansi.h> #include <charset.h> +#include <efi_device_path.h> #include <malloc.h> #include <time.h> #include <dm/device.h> @@ -30,6 +31,17 @@ struct cout_mode { __maybe_unused static struct efi_object uart_obj; +/* + * suppress emission of ANSI escape-characters for use by unit tests. Leave it + * as 0 for the default behaviour + */ +static bool no_ansi; + +void efi_console_set_ansi(bool allow_ansi) +{ + no_ansi = !allow_ansi; +} + static struct cout_mode efi_cout_modes[] = { /* EFI Mode 0 is 80x25 and always present */ { @@ -348,13 +360,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols) return 0; } -/** - * efi_setup_console_size() - update the mode table. - * - * By default the only mode available is 80x25. If the console has at least 50 - * lines, enable mode 80x50. If we can query the console size and it is neither - * 80x25 nor 80x50, set it as an additional mode. - */ void efi_setup_console_size(void) { int rows = 25, cols = 80; @@ -362,8 +367,12 @@ void efi_setup_console_size(void) if (IS_ENABLED(CONFIG_VIDEO)) ret = query_vidconsole(&rows, &cols); - if (ret) - ret = query_console_serial(&rows, &cols); + if (ret) { + if (no_ansi) + ret = 0; + else + ret = query_console_serial(&rows, &cols); + } if (ret) return; diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index c9bf2726fe2..7316a76f462 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -10,6 +10,7 @@ #include <blk.h> #include <dm.h> #include <dm/root.h> +#include <efi_device_path.h> #include <log.h> #include <net.h> #include <usb.h> @@ -21,11 +22,11 @@ #include <asm-generic/unaligned.h> #include <linux/compat.h> /* U16_MAX */ -/* template END node: */ -const struct efi_device_path END = { +/* template EFI_DP_END node: */ +const struct efi_device_path EFI_DP_END = { .type = DEVICE_PATH_TYPE_END, .sub_type = DEVICE_PATH_SUB_TYPE_END, - .length = sizeof(END), + .length = sizeof(EFI_DP_END), }; #if defined(CONFIG_MMC) @@ -46,10 +47,6 @@ static bool is_sd(struct blk_desc *desc) } #endif -/* - * Iterate to next block in device-path, terminating (returning NULL) - * at /End* node. - */ struct efi_device_path *efi_dp_next(const struct efi_device_path *dp) { if (dp == NULL) @@ -62,12 +59,6 @@ struct efi_device_path *efi_dp_next(const struct efi_device_path *dp) return (struct efi_device_path *)dp; } -/* - * Compare two device-paths, stopping when the shorter of the two hits - * an End* node. This is useful to, for example, compare a device-path - * representing a device with one representing a file on the device, or - * a device with a parent device. - */ int efi_dp_match(const struct efi_device_path *a, const struct efi_device_path *b) { @@ -90,20 +81,6 @@ int efi_dp_match(const struct efi_device_path *a, } } -/** - * efi_dp_shorten() - shorten device-path - * - * When creating a short boot option we want to use a device-path that is - * independent of the location where the block device is plugged in. - * - * UsbWwi() nodes contain a serial number, hard drive paths a partition - * UUID. Both should be unique. - * - * See UEFI spec, section 3.1.2 for "short-form device path". - * - * @dp: original device-path - * Return: shortened device-path or NULL - */ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) { while (dp) { @@ -180,16 +157,6 @@ static efi_handle_t find_handle(struct efi_device_path *dp, return best_handle; } -/** - * efi_dp_find_obj() - find handle by device path - * - * If @rem is provided, the handle with the longest partial match is returned. - * - * @dp: device path to search - * @guid: GUID of protocol that must be installed on path or NULL - * @rem: pointer to receive remaining device path - * Return: matching handle - */ efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, const efi_guid_t *guid, struct efi_device_path **rem) @@ -204,13 +171,6 @@ efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, return handle; } -/* - * Determine the last device path node that is not the end node. - * - * @dp device path - * Return: last node before the end node if it exists - * otherwise NULL - */ const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp) { struct efi_device_path *ret; @@ -224,7 +184,6 @@ const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp) return ret; } -/* get size of the first device path instance excluding end node */ efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp) { efi_uintn_t sz = 0; @@ -239,7 +198,6 @@ efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp) return sz; } -/* get size of multi-instance device path excluding end node */ efi_uintn_t efi_dp_size(const struct efi_device_path *dp) { const struct efi_device_path *p = dp; @@ -253,11 +211,10 @@ efi_uintn_t efi_dp_size(const struct efi_device_path *dp) return (void *)p - (void *)dp; } -/* copy multi-instance device path */ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) { struct efi_device_path *ndp; - size_t sz = efi_dp_size(dp) + sizeof(END); + size_t sz = efi_dp_size(dp) + sizeof(EFI_DP_END); if (!dp) return NULL; @@ -270,21 +227,6 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) return ndp; } -/** - * efi_dp_concat() - Concatenate two device paths and add and terminate them - * with an end node. - * - * @dp1: First device path - * @dp2: Second device path - * @split_end_node: - * * 0 to concatenate - * * 1 to concatenate with end node added as separator - * * size of dp1 excluding last end node to concatenate with end node as - * separator in case dp1 contains an end node - * - * Return: - * concatenated device path or NULL. Caller must free the returned value - */ struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, const struct efi_device_path *dp2, @@ -295,7 +237,7 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, if (!dp1 && !dp2) { /* return an end node */ - ret = efi_dp_dup(&END); + ret = efi_dp_dup(&EFI_DP_END); } else if (!dp1) { ret = efi_dp_dup(dp2); } else if (!dp2) { @@ -312,9 +254,9 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, sz1 = split_end_node; if (split_end_node) - end_size = 2 * sizeof(END); + end_size = 2 * sizeof(EFI_DP_END); else - end_size = sizeof(END); + end_size = sizeof(EFI_DP_END); p = efi_alloc(sz1 + sz2 + end_size); if (!p) return NULL; @@ -323,14 +265,14 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, p += sz1; if (split_end_node) { - memcpy(p, &END, sizeof(END)); - p += sizeof(END); + memcpy(p, &EFI_DP_END, sizeof(EFI_DP_END)); + p += sizeof(EFI_DP_END); } /* the end node of the second device path has to be retained */ memcpy(p, dp2, sz2); p += sz2; - memcpy(p, &END, sizeof(END)); + memcpy(p, &EFI_DP_END, sizeof(EFI_DP_END)); } return ret; @@ -342,26 +284,26 @@ struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, struct efi_device_path *ret; if (!node && !dp) { - ret = efi_dp_dup(&END); + ret = efi_dp_dup(&EFI_DP_END); } else if (!node) { ret = efi_dp_dup(dp); } else if (!dp) { size_t sz = node->length; - void *p = efi_alloc(sz + sizeof(END)); + void *p = efi_alloc(sz + sizeof(EFI_DP_END)); if (!p) return NULL; memcpy(p, node, sz); - memcpy(p + sz, &END, sizeof(END)); + memcpy(p + sz, &EFI_DP_END, sizeof(EFI_DP_END)); ret = p; } else { /* both dp and node are non-null */ size_t sz = efi_dp_size(dp); - void *p = efi_alloc(sz + node->length + sizeof(END)); + void *p = efi_alloc(sz + node->length + sizeof(EFI_DP_END)); if (!p) return NULL; memcpy(p, dp, sz); memcpy(p + sz, node, node->length); - memcpy(p + sz + node->length, &END, sizeof(END)); + memcpy(p + sz + node->length, &EFI_DP_END, sizeof(EFI_DP_END)); ret = p; } @@ -399,17 +341,17 @@ struct efi_device_path *efi_dp_append_instance( return efi_dp_dup(dpi); sz = efi_dp_size(dp); szi = efi_dp_instance_size(dpi); - p = efi_alloc(sz + szi + 2 * sizeof(END)); + p = efi_alloc(sz + szi + 2 * sizeof(EFI_DP_END)); if (!p) return NULL; ret = p; - memcpy(p, dp, sz + sizeof(END)); + memcpy(p, dp, sz + sizeof(EFI_DP_END)); p = (void *)p + sz; p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END; - p = (void *)p + sizeof(END); + p = (void *)p + sizeof(EFI_DP_END); memcpy(p, dpi, szi); p = (void *)p + szi; - memcpy(p, &END, sizeof(END)); + memcpy(p, &EFI_DP_END, sizeof(EFI_DP_END)); return ret; } @@ -424,17 +366,17 @@ struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp, if (!dp || !*dp) return NULL; sz = efi_dp_instance_size(*dp); - p = efi_alloc(sz + sizeof(END)); + p = efi_alloc(sz + sizeof(EFI_DP_END)); if (!p) return NULL; - memcpy(p, *dp, sz + sizeof(END)); + memcpy(p, *dp, sz + sizeof(EFI_DP_END)); *dp = (void *)*dp + sz; if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END) - *dp = (void *)*dp + sizeof(END); + *dp = (void *)*dp + sizeof(EFI_DP_END); else *dp = NULL; if (size) - *size = sz + sizeof(END); + *size = sz + sizeof(EFI_DP_END); return p; } @@ -449,9 +391,6 @@ bool efi_dp_is_multi_instance(const struct efi_device_path *dp) return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END; } -/* size of device-path not including END node for device and all parents - * up to the root device. - */ __maybe_unused static unsigned int dp_size(struct udevice *dev) { if (!dev || !dev->driver) @@ -820,29 +759,21 @@ static void *dp_part_fill(void *buf, struct blk_desc *desc, int part) return dp_part_node(buf, desc, part); } -/* Construct a device-path from a partition on a block device: */ struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part) { void *buf, *start; - start = buf = efi_alloc(dp_part_size(desc, part) + sizeof(END)); - if (!buf) + start = efi_alloc(dp_part_size(desc, part) + sizeof(EFI_DP_END)); + if (!start) return NULL; - buf = dp_part_fill(buf, desc, part); + buf = dp_part_fill(start, desc, part); - *((struct efi_device_path *)buf) = END; + *((struct efi_device_path *)buf) = EFI_DP_END; return start; } -/* - * Create a device node for a block device partition. - * - * @buf buffer to which the device path is written - * @desc block device descriptor - * @part partition number, 0 identifies a block device - */ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part) { efi_uintn_t dpsize; @@ -892,13 +823,6 @@ static void path_to_uefi(void *uefi, const char *src) *pos = 0; } -/** - * efi_dp_from_file() - append file path node to device path. - * - * @dp: device path or NULL - * @path: file path or NULL - * Return: device path or NULL in case of an error - */ struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, const char *path) { @@ -912,7 +836,7 @@ struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, if (fpsize > U16_MAX) return NULL; - buf = efi_alloc(dpsize + fpsize + sizeof(END)); + buf = efi_alloc(dpsize + fpsize + sizeof(EFI_DP_END)); if (!buf) return NULL; @@ -929,7 +853,7 @@ struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, pos += fpsize; } - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); return buf; } @@ -938,7 +862,7 @@ struct efi_device_path *efi_dp_from_uart(void) { void *buf, *pos; struct efi_device_path_uart *uart; - size_t dpsize = dp_size(dm_root()) + sizeof(*uart) + sizeof(END); + size_t dpsize = dp_size(dm_root()) + sizeof(*uart) + sizeof(EFI_DP_END); buf = efi_alloc(dpsize); if (!buf) @@ -949,7 +873,7 @@ struct efi_device_path *efi_dp_from_uart(void) uart->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_UART; uart->dp.length = sizeof(*uart); pos += sizeof(*uart); - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); return buf; } @@ -963,13 +887,13 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(struct udevice *dev) dpsize += dp_size(dev); - start = buf = efi_alloc(dpsize + sizeof(END)); - if (!buf) + start = efi_alloc(dpsize + sizeof(EFI_DP_END)); + if (!start) return NULL; - buf = dp_fill(buf, dev); + buf = dp_fill(start, dev); - *((struct efi_device_path *)buf) = END; + *((struct efi_device_path *)buf) = EFI_DP_END; return start; } @@ -979,7 +903,7 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(struct udevice *dev) * * Set the device path to an ethernet device path as provided by * efi_dp_from_eth() concatenated with a device path of subtype - * DEVICE_PATH_SUB_TYPE_MSG_IPV4, and an END node. + * DEVICE_PATH_SUB_TYPE_MSG_IPV4, and an EFI_DP_END node. * * @ip: IPv4 local address * @mask: network mask @@ -1010,7 +934,7 @@ static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, if (srv) memcpy(&dp.ipv4dp.remote_ip_address, srv, sizeof(*srv)); pos = &dp.end; - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); dp1 = efi_dp_from_eth(dev); if (!dp1) @@ -1023,17 +947,6 @@ static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, return dp2; } -/** - * efi_dp_from_http() - set device path from http - * - * Set the device path to an IPv4 path as provided by efi_dp_from_ipv4 - * concatenated with a device path of subtype DEVICE_PATH_SUB_TYPE_MSG_URI, - * and an END node. - * - * @server: URI of remote server - * @dev: net udevice - * Return: pointer to HTTP device path, NULL on error - */ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev) { struct efi_device_path *dp1, *dp2; @@ -1066,7 +979,7 @@ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev } uridp_len = sizeof(struct efi_device_path) + strlen(tmp) + 1; - uridp = efi_alloc(uridp_len + sizeof(END)); + uridp = efi_alloc(uridp_len + sizeof(EFI_DP_END)); if (!uridp) { log_err("Out of memory\n"); return NULL; @@ -1078,7 +991,7 @@ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev memcpy(uridp->uri, tmp, strlen(tmp) + 1); pos = (char *)uridp + uridp_len; - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)uridp, 0); @@ -1096,11 +1009,11 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, struct efi_device_path_memory *mdp; void *buf, *start; - start = buf = efi_alloc(sizeof(*mdp) + sizeof(END)); - if (!buf) + start = efi_alloc(sizeof(*mdp) + sizeof(EFI_DP_END)); + if (!start) return NULL; - mdp = buf; + mdp = start; mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY; mdp->dp.length = sizeof(*mdp); @@ -1109,7 +1022,7 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, mdp->end_address = start_address + size; buf = &mdp[1]; - *((struct efi_device_path *)buf) = END; + *((struct efi_device_path *)buf) = EFI_DP_END; return start; } diff --git a/lib/efi_loader/efi_device_path_utilities.c b/lib/efi_loader/efi_device_path_utilities.c index 552c5bb1f05..87d52df5066 100644 --- a/lib/efi_loader/efi_device_path_utilities.c +++ b/lib/efi_loader/efi_device_path_utilities.c @@ -7,6 +7,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> const efi_guid_t efi_guid_device_path_utilities_protocol = @@ -31,7 +32,7 @@ static efi_uintn_t EFIAPI get_device_path_size( efi_uintn_t sz = 0; EFI_ENTRY("%pD", device_path); - /* size includes the END node: */ + /* size includes the EFI_DP_END node: */ if (device_path) sz = efi_dp_size(device_path) + sizeof(struct efi_device_path); return EFI_EXIT(sz); diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 5452640354e..47b583cc5e1 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -11,6 +11,7 @@ #include <dm.h> #include <dm/device-internal.h> #include <dm/tag.h> +#include <efi_device_path.h> #include <event.h> #include <efi_driver.h> #include <efi_loader.h> diff --git a/lib/efi_loader/efi_fdt.c b/lib/efi_loader/efi_fdt.c index 1ba6641d821..bfaa9cfc207 100644 --- a/lib/efi_loader/efi_fdt.c +++ b/lib/efi_loader/efi_fdt.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> #include <env.h> #include <errno.h> diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 19fb5d03fec..44b806aadc4 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -7,6 +7,7 @@ #include <blkmap.h> #include <bootm.h> +#include <efi_device_path.h> #include <env.h> #include <image.h> #include <log.h> @@ -199,7 +200,7 @@ efi_status_t efi_load_option_dp_join(struct efi_device_path **dp, efi_free_pool(tmp_dp); if (!*dp) return EFI_OUT_OF_RESOURCES; - *dp_size += efi_dp_size(initrd_dp) + sizeof(END); + *dp_size += efi_dp_size(initrd_dp) + sizeof(EFI_DP_END); } if (fdt_dp) { @@ -209,10 +210,10 @@ efi_status_t efi_load_option_dp_join(struct efi_device_path **dp, efi_free_pool(tmp_dp); if (!*dp) return EFI_OUT_OF_RESOURCES; - *dp_size += efi_dp_size(fdt_dp) + sizeof(END); + *dp_size += efi_dp_size(fdt_dp) + sizeof(EFI_DP_END); } - *dp_size += sizeof(END); + *dp_size += sizeof(EFI_DP_END); return EFI_SUCCESS; } diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c index b3291b4f1d5..8e708d8d350 100644 --- a/lib/efi_loader/efi_net.c +++ b/lib/efi_loader/efi_net.c @@ -17,6 +17,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> #include <dm.h> #include <linux/sizes.h> @@ -51,7 +52,7 @@ static int next_dp_entry; static struct wget_http_info efi_wget_info = { .set_bootdev = false, .check_buffer_size = true, - + .silent = true, }; #endif diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 210a846ebc8..1832eeb5dce 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -10,6 +10,7 @@ #define LOG_CATEGORY LOGC_EFI #include <dm.h> +#include <efi_device_path.h> #include <efi_loader.h> #include <efi_variable.h> #include <efi_tcg2.h> diff --git a/lib/linux_string.c b/lib/linux_string.c index d5a5e08d98c..4b92cd923f2 100644 --- a/lib/linux_string.c +++ b/lib/linux_string.c @@ -31,13 +31,15 @@ char *skip_spaces(const char *str) * Note that the first trailing whitespace is replaced with a %NUL-terminator * in the given string @s. Returns a pointer to the first non-whitespace * character in @s. + * + * Note that if the string consist of only spaces, then the terminator is placed + * at the start of the string, with the return value pointing there also. */ char *strim(char *s) { size_t size; char *end; - s = skip_spaces(s); size = strlen(s); if (!size) return s; @@ -47,5 +49,5 @@ char *strim(char *s) end--; *(end + 1) = '\0'; - return s; + return skip_spaces(s); } diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c index ef51a5ac168..7459bfa468f 100644 --- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c @@ -60,6 +60,8 @@ #if LWIP_ALTCP_TLS && LWIP_ALTCP_TLS_MBEDTLS +#include "lwip/errno.h" + #include "lwip/altcp.h" #include "lwip/altcp_tls.h" #include "lwip/priv/altcp_priv.h" @@ -299,7 +301,8 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t * LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_handshake failed: %d\n", ret)); /* handshake failed, connection has to be closed */ if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) { - printf("Certificate verification failed\n"); + /* provide a cause for why the connection is closed to the called */ + errno = EPERM; } if (conn->err) { conn->err(conn->arg, ERR_CLSD); @@ -844,9 +847,6 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav altcp_mbedtls_free_config(conf); return NULL; } - if (authmode == MBEDTLS_SSL_VERIFY_NONE) { - printf("WARNING: no CA certificates, HTTPS connections not authenticated\n"); - } mbedtls_ssl_conf_authmode(&conf->conf, authmode); mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg); diff --git a/lib/slre.c b/lib/slre.c index 277a59a03a7..117815a6d60 100644 --- a/lib/slre.c +++ b/lib/slre.c @@ -30,7 +30,7 @@ #include <slre.h> enum {END, BRANCH, ANY, EXACT, ANYOF, ANYBUT, OPEN, CLOSE, BOL, EOL, - STAR, PLUS, STARQ, PLUSQ, QUEST, SPACE, NONSPACE, DIGIT}; + STAR, PLUS, STARQ, PLUSQ, QUEST, SPACE, NONSPACE, DIGIT, RANGE}; #ifdef SLRE_TEST static struct { @@ -55,7 +55,8 @@ static struct { {"QUEST", 1, "o"}, /* Match zero or one time, "?" */ {"SPACE", 0, ""}, /* Match whitespace, "\s" */ {"NONSPACE", 0, ""}, /* Match non-space, "\S" */ - {"DIGIT", 0, ""} /* Match digit, "\d" */ + {"DIGIT", 0, ""}, /* Match digit, "\d" */ + {"RANGE", 0, ""}, /* Range separator - */ }; #endif /* SLRE_TEST */ @@ -260,6 +261,15 @@ anyof(struct slre *r, const char **re) return; /* NOTREACHED */ break; + case '-': + if (r->data_size == old_data_size || **re == ']') { + /* First or last character, just match - itself. */ + store_char_in_data(r, '-'); + break; + } + store_char_in_data(r, 0); + store_char_in_data(r, RANGE); + break; case '\\': esc = get_escape_char(re); if ((esc & 0xff) == 0) { @@ -413,10 +423,7 @@ int slre_compile(struct slre *r, const char *re) { r->err_str = NULL; - r->code_size = r->data_size = r->num_caps = r->anchored = 0; - - if (*re == '^') - r->anchored++; + r->code_size = r->data_size = r->num_caps = 0; emit(r, OPEN); /* This will capture what matches full RE */ emit(r, 0); @@ -475,29 +482,54 @@ is_any_of(const unsigned char *p, int len, const char *s, int *ofs) ch = s[*ofs]; - for (i = 0; i < len; i++) - if (p[i] == ch) { - (*ofs)++; - return 1; + for (i = 0; i < len; i++) { + if (p[i] == '\0') { + switch (p[++i]) { + case NONSPACE: + if (!isspace(ch)) + goto match; + break; + case SPACE: + if (isspace(ch)) + goto match; + break; + case DIGIT: + if (isdigit(ch)) + goto match; + break; + case RANGE: + /* + * a-z is represented in the data array as {'a', \0, RANGE, 'z'} + */ + ++i; + if (p[i - 3] <= (unsigned char)ch && (unsigned char)ch <= p[i]) + goto match; + break; + } + continue; } + if (p[i] == ch) + goto match; + } return 0; + +match: + (*ofs)++; + return 1; } static int is_any_but(const unsigned char *p, int len, const char *s, int *ofs) { - int i, ch; - - ch = s[*ofs]; + int dummy = *ofs; - for (i = 0; i < len; i++) { - if (p[i] == ch) - return 0; + if (is_any_of(p, len, s, &dummy)) { + return 0; + } else { + (*ofs)++; + return 1; } - - (*ofs)++; - return 1; } static int @@ -650,13 +682,9 @@ slre_match(const struct slre *r, const char *buf, int len, { int i, ofs = 0, res = 0; - if (r->anchored) { + for (i = 0; i <= len && res == 0; i++) { + ofs = i; res = match(r, 0, buf, len, &ofs, caps); - } else { - for (i = 0; i < len && res == 0; i++) { - ofs = i; - res = match(r, 0, buf, len, &ofs, caps); - } } return res; diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index 2a7a4d286c0..411ae6189f2 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -141,7 +141,7 @@ static void ip4_addr_string(struct printf_info *info, u8 *addr) string(info, ip4_addr); } -#endif +#endif /* CONFIG_SPL_NET */ /* * Show a '%p' thing. A kernel extension is that the '%p' is followed @@ -157,18 +157,14 @@ static void ip4_addr_string(struct printf_info *info, u8 *addr) * decimal). */ -static void __maybe_unused pointer(struct printf_info *info, const char *fmt, - void *ptr) +#if defined(CONFIG_SPL_USE_TINY_PRINTF_POINTER_SUPPORT) || defined(DEBUG) +static void pointer(struct printf_info *info, const char *fmt, void *ptr) { -#ifdef DEBUG unsigned long num = (uintptr_t)ptr; unsigned long div; -#endif switch (*fmt) { -#ifdef DEBUG case 'a': - switch (fmt[1]) { case 'p': default: @@ -176,7 +172,6 @@ static void __maybe_unused pointer(struct printf_info *info, const char *fmt, break; } break; -#endif #ifdef CONFIG_SPL_NET case 'm': return mac_address_string(info, ptr, false); @@ -185,16 +180,22 @@ static void __maybe_unused pointer(struct printf_info *info, const char *fmt, case 'I': if (fmt[1] == '4') return ip4_addr_string(info, ptr); +#else + case 'm': + case 'M': + case 'I': + out(info, '?'); + return; #endif default: break; } -#ifdef DEBUG + div = 1UL << (sizeof(long) * 8 - 4); for (; div; div /= 0x10) div_out(info, &num, div); -#endif } +#endif static int _vprintf(struct printf_info *info, const char *fmt, va_list va) { @@ -269,21 +270,18 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) div_out(info, &num, div); } break; +#if defined(CONFIG_SPL_USE_TINY_PRINTF_POINTER_SUPPORT) || defined(DEBUG) case 'p': - if (CONFIG_IS_ENABLED(NET) || - CONFIG_IS_ENABLED(NET_LWIP) || _DEBUG) { - pointer(info, fmt, va_arg(va, void *)); - /* - * Skip this because it pulls in _ctype which is - * 256 bytes, and we don't generally implement - * pointer anyway - */ - while (isalnum(fmt[0])) - fmt++; - break; - } - islong = true; - fallthrough; + pointer(info, fmt, va_arg(va, void *)); + /* + * Skip this because it pulls in _ctype which is + * 256 bytes, and we don't generally implement + * pointer anyway + */ + while (isalnum(fmt[0])) + fmt++; + break; +#endif case 'x': case 'X': if (islong) { @@ -310,7 +308,9 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) break; case '%': out(info, '%'); + break; default: + out(info, '?'); break; } |