U-Boot Library Example
======================
This directory contains example programs showing how to use the U-Boot library
(libu-boot.so) in external C programs.
Building U-Boot Library
-----------------------
First, build U-Boot with library support:
make O=/tmp/b/sandbox -j$(nproc) sandbox_defconfig all
This creates:
- /tmp/b/sandbox/libu-boot.so (shared library)
- /tmp/b/sandbox/libu-boot.a (static library)
Example Programs
----------------
The examples are built automatically as part of the U-Boot build. Each program
demonstrates different aspects of the U-Boot library.
**demo.c** - Demonstrates using U-Boot library functions
- Shows how to init the library with ulib_init()
- Uses U-Boot's OS functions (os_open(), os_fgets(), os_close())
- Reads and displays system information
- Shows the U-Boot version
**boot.c** - Demonstrates booting an OS using U-Boot bootflow
- Shows bootflow scanning and booting functionality
- Uses system headers for main program logic (boot.c)
- Uses U-Boot headers for bootflow internals (bootflow.c)
- Demonstrates attaching disk images and scanning for bootable OS
- Attempts to boot the first discovered bootflow
Building Examples
-----------------
The examples are built automatically when U-Boot has these options enabled::
CONFIG_ULIB=y
CONFIG_EXAMPLES=y
To build manually:
# From this directory examples/ulib
make UBOOT_BUILD=/tmp/b/sandbox/ srctree=../..
Running Examples
----------------
# Run the demo
LD_LIBRARY_PATH=/tmp/b/sandbox ./demo
# Run the demo (static version)
./demo_static
# Run the boot example (requires disk image at /home/sglass/u/mmc1.img)
LD_LIBRARY_PATH=/tmp/b/sandbox ./boot
# Run the boot example (static version)
./boot_static
Key Points
----------
- Files are compiled with U-Boot headers by default, except those listed in
sys-objs which use system headers
- Use ulib_init() to init the library
- Use ulib_uninit() to clean up
- Set LD_LIBRARY_PATH when running dynamically linked programs
- Each program automatically gets both dynamic and static versions built
Copying for External Use
-------------------------
This directory can be copied elsewhere and used independently:
cp -r examples/ulib ~/my-project/
cd ~/my-project/ulib
make UBOOT_BUILD=/path/to/u-boot-build srctree=/path/to/u-boot-source
License
-------
All examples are licensed under GPL-2.0+