summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/abuf.c58
-rw-r--r--lib/efi/efi_stub.c2
-rw-r--r--lib/efi_loader/Kconfig7
-rw-r--r--lib/efi_loader/efi_device_path.c1
-rw-r--r--lib/fwu_updates/fwu_v1.c1
-rw-r--r--lib/fwu_updates/fwu_v2.c1
-rw-r--r--lib/of_live.c3
7 files changed, 66 insertions, 7 deletions
diff --git a/lib/abuf.c b/lib/abuf.c
index 61adf7fc6b1..3a2fd1782e9 100644
--- a/lib/abuf.c
+++ b/lib/abuf.c
@@ -10,8 +10,11 @@
#include <malloc.h>
#include <mapmem.h>
#include <string.h>
+#include <vsprintf.h>
#endif
+#include <errno.h>
+#include <stdarg.h>
#include <abuf.h>
void abuf_set(struct abuf *abuf, void *data, size_t size)
@@ -119,6 +122,61 @@ void abuf_init_set(struct abuf *abuf, void *data, size_t size)
abuf_set(abuf, data, size);
}
+bool abuf_init_size(struct abuf *buf, size_t size)
+{
+ abuf_init(buf);
+ if (!abuf_realloc(buf, size))
+ return false;
+
+ return true;
+}
+
+bool abuf_copy(const struct abuf *old, struct abuf *copy)
+{
+ char *data;
+
+ data = malloc(old->size);
+ if (!data)
+ return false;
+ memcpy(data, old->data, old->size);
+ abuf_init_set(copy, data, old->size);
+ copy->alloced = true;
+
+ return true;
+}
+
+int abuf_printf(struct abuf *buf, const char *fmt, ...)
+{
+ int maxlen = buf->size;
+ va_list args;
+ int len;
+
+ va_start(args, fmt);
+ len = vsnprintf(buf->data, buf->size, fmt, args);
+ va_end(args);
+
+ /* add the terminator */
+ len++;
+
+ if (len > 4096)
+ return -E2BIG;
+ if (len > maxlen) {
+ /* make more space and try again */
+ maxlen = len;
+ if (!abuf_realloc(buf, maxlen))
+ return -ENOMEM;
+ va_start(args, fmt);
+ len = vsnprintf(buf->data, maxlen, fmt, args);
+ va_end(args);
+
+ /* check there isn't anything strange going on */
+ if (len > maxlen)
+ return -EFAULT;
+ }
+
+ return len;
+}
+
void abuf_init_const(struct abuf *abuf, const void *data, size_t size)
{
/* for now there is no flag indicating that the abuf data is constant */
diff --git a/lib/efi/efi_stub.c b/lib/efi/efi_stub.c
index 40fc29d9adf..a083c7f1e9b 100644
--- a/lib/efi/efi_stub.c
+++ b/lib/efi/efi_stub.c
@@ -83,7 +83,7 @@ void puts(const char *str)
putc(*str++);
}
-static void _debug_uart_putc(int ch)
+static inline void _debug_uart_putc(int ch)
{
putc(ch);
}
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 7f02a83e2a2..3dadbc54b58 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -443,10 +443,9 @@ config EFI_TCG2_PROTOCOL_MEASURE_DTB
help
When enabled, the DTB image passed to the booted EFI image is
measured using the EFI TCG2 protocol. Do not enable this feature if
- the passed DTB contains data that change across platform reboots
- and cannot be used has a predictable measurement. Otherwise
- this feature allows better measurement of the system boot
- sequence.
+ the passed DTB contains data that changes across platform reboots
+ and cannot be used for a predictable measurement. Otherwise, this
+ feature allows for better measurement of the system boot sequence.
config EFI_LOAD_FILE2_INITRD
bool "EFI_FILE_LOAD2_PROTOCOL for Linux initial ramdisk"
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index 7316a76f462..b3fb20b2501 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -11,6 +11,7 @@
#include <dm.h>
#include <dm/root.h>
#include <efi_device_path.h>
+#include <ide.h>
#include <log.h>
#include <net.h>
#include <usb.h>
diff --git a/lib/fwu_updates/fwu_v1.c b/lib/fwu_updates/fwu_v1.c
index c311a8857a6..974abf216f6 100644
--- a/lib/fwu_updates/fwu_v1.c
+++ b/lib/fwu_updates/fwu_v1.c
@@ -3,6 +3,7 @@
* Copyright (c) 2024, Linaro Limited
*/
+#include <errno.h>
#include <fwu.h>
#include <fwu_mdata.h>
diff --git a/lib/fwu_updates/fwu_v2.c b/lib/fwu_updates/fwu_v2.c
index ce46904ff2e..159315b45b9 100644
--- a/lib/fwu_updates/fwu_v2.c
+++ b/lib/fwu_updates/fwu_v2.c
@@ -3,6 +3,7 @@
* Copyright (c) 2024, Linaro Limited
*/
+#include <errno.h>
#include <fwu.h>
#include <fwu_mdata.h>
#include <log.h>
diff --git a/lib/of_live.c b/lib/of_live.c
index c1620616513..24200b948a6 100644
--- a/lib/of_live.c
+++ b/lib/of_live.c
@@ -448,8 +448,7 @@ int of_live_flatten(const struct device_node *root, struct abuf *buf)
{
int ret;
- abuf_init(buf);
- if (!abuf_realloc(buf, BUF_STEP))
+ if (!abuf_init_size(buf, BUF_STEP))
return log_msg_ret("ini", -ENOMEM);
ret = fdt_create(abuf_data(buf), abuf_size(buf));