ulib: Create a test program for the shared library
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>
This commit is contained in:
9
Makefile
9
Makefile
@@ -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
|
||||
|
||||
12
test/ulib/Makefile
Normal file
12
test/ulib/Makefile
Normal file
@@ -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
|
||||
36
test/ulib/ulib_test.c
Normal file
36
test/ulib/ulib_test.c
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user