summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_device_path_to_text.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-02-05 16:16:38 -0500
committerTom Rini <trini@konsulko.com>2022-02-05 16:16:38 -0500
commitb5c5b9a0bee56030f9f05ece52334b5207b72673 (patch)
tree7d4f13a4800ffdf132344be5ee10510fac33766d /lib/efi_loader/efi_device_path_to_text.c
parent3aaabfe9ff4bbcd11096513b1b28d1fb0a40800f (diff)
parent6bbe12f61c4f7208b428cc038170dc286c872a91 (diff)
Merge tag 'efi-2022-04-rc2-2' of https://source.denx.de/u-boot/custodians/u-boot-efi
Pull request for efi-2022-04-rc2-2 UEFI * add unit test for RISCV_EFI_BOOT_PROTOCOL * disable UEFI for Colibri VF610 * add handle for UART * fix printing of Unicode strings * simplify enumeration of block devices
Diffstat (limited to 'lib/efi_loader/efi_device_path_to_text.c')
-rw-r--r--lib/efi_loader/efi_device_path_to_text.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c
index d8a83c88493..4d73954ef89 100644
--- a/lib/efi_loader/efi_device_path_to_text.c
+++ b/lib/efi_loader/efi_device_path_to_text.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <blk.h>
#include <efi_loader.h>
+#include <malloc.h>
#define MAC_OUTPUT_LEN 22
#define UNKNOWN_OUTPUT_LEN 23
@@ -121,16 +122,26 @@ static char *dp_msging(char *s, struct efi_device_path *dp)
case DEVICE_PATH_SUB_TYPE_MSG_UART: {
struct efi_device_path_uart *uart =
(struct efi_device_path_uart *)dp;
- s += sprintf(s, "Uart(%lld,%d,%d,", uart->baud_rate,
- uart->data_bits, uart->parity);
- switch (uart->stop_bits) {
- case 2:
- s += sprintf(s, "1.5)");
- break;
- default:
+ const char parity_str[6] = {'D', 'N', 'E', 'O', 'M', 'S'};
+ const char *stop_bits_str[4] = { "D", "1", "1.5", "2" };
+
+ s += sprintf(s, "Uart(%lld,%d,", uart->baud_rate,
+ uart->data_bits);
+
+ /*
+ * Parity and stop bits can either both use keywords or both use
+ * numbers but numbers and keywords should not be mixed. Let's
+ * go for keywords as this is what EDK II does. For illegal
+ * values fall back to numbers.
+ */
+ if (uart->parity < 6)
+ s += sprintf(s, "%c,", parity_str[uart->parity]);
+ else
+ s += sprintf(s, "%d,", uart->parity);
+ if (uart->stop_bits < 4)
+ s += sprintf(s, "%s)", stop_bits_str[uart->stop_bits]);
+ else
s += sprintf(s, "%d)", uart->stop_bits);
- break;
- }
break;
}
case DEVICE_PATH_SUB_TYPE_MSG_USB: {
@@ -292,10 +303,18 @@ static char *dp_media(char *s, struct efi_device_path *dp)
case DEVICE_PATH_SUB_TYPE_FILE_PATH: {
struct efi_device_path_file_path *fp =
(struct efi_device_path_file_path *)dp;
- int slen = (dp->length - sizeof(*dp)) / 2;
- if (slen > MAX_NODE_LEN - 2)
- slen = MAX_NODE_LEN - 2;
- s += sprintf(s, "%-.*ls", slen, fp->str);
+ u16 *buffer;
+ int slen = dp->length - sizeof(*dp);
+
+ /* two bytes for \0, extra byte if dp->length is odd */
+ buffer = calloc(1, slen + 3);
+ if (!buffer) {
+ log_err("Out of memory\n");
+ return s;
+ }
+ memcpy(buffer, fp->str, dp->length - sizeof(*dp));
+ s += snprintf(s, MAX_NODE_LEN - 1, "%ls", buffer);
+ free(buffer);
break;
}
default: