[Concept,10/18] ulib: Create a test program for the shared library
Commit Message
From: Simon Glass <sjg@chromium.org>
Provide a host program which can use the shared library. For now this
operates similarly to sandbox itself, but future work will make it more
flexible.
Leave it out of the build, since there are a few other pieces needed.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
Makefile | 9 +++++++++
test/ulib/Makefile | 12 ++++++++++++
test/ulib/ulib_test.c | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+)
create mode 100644 test/ulib/Makefile
create mode 100644 test/ulib/ulib_test.c
@@ -1863,6 +1863,15 @@ quiet_cmd_libu-boot.so = LD $@
libu-boot.so: $(u-boot-init) $(u-boot-main) $(u-boot-keep-syms-lto) FORCE
$(call if_changed,libu-boot.so)
+# Build ulib_test that links with shared library
+quiet_cmd_ulib_test = HOSTCC $@
+ cmd_ulib_test = $(HOSTCC) $(HOSTCFLAGS) \
+ -I$(srctree)/arch/sandbox/include -o $@ $< -L$(obj) -lu-boot \
+ -Wl,-rpath,$(obj)
+
+test/ulib/ulib_test: test/ulib/ulib_test.o libu-boot.so FORCE
+ $(call if_changed,ulib_test)
+
quiet_cmd_sym ?= SYM $@
cmd_sym ?= $(OBJDUMP) -t $< > $@
u-boot.sym: u-boot FORCE
new file mode 100644
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright 2025 Simon Glass <sjg@chromium.org>
+
+obj-y += ulib_test.o
+
+# Link with the shared library
+HOSTCFLAGS_ulib_test.o += -I$(srctree)/arch/sandbox/include
+HOSTLDLIBS_ulib_test += -L$(obj)/../.. -lu-boot -Wl,-rpath,$(obj)/../..
+
+# Ensure shared library is built first
+$(obj)/ulib_test: $(obj)/../../libu-boot.so
new file mode 100644
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test application for U-Boot shared library
+ *
+ * This demonstrates linking against libu-boot.so
+ *
+ * Copyright 2025 Canonical
+ * Written by Simon Glass <simon.glass@canonical.com>
+ */
+
+/* Use system headers, not U-Boot headers */
+#include <stdio.h>
+#include <string.h>
+#include <init.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int main(int argc, char *argv[])
+{
+ struct global_data data;
+ int ret;
+
+ printf("Calling U-Boot initialization via shared library...\n");
+
+ /* init global data */
+ memset(&data, '\0', sizeof(data));
+
+ ret = sandbox_init(argc, argv, &data);
+
+ /* Do pre- and post-relocation init */
+ board_init_f(gd->flags);
+ board_init_r(data.new_gd, 0);
+
+ return ret;
+}