Message ID | 20250909151824.2327219-1-sjg@u-boot.org |
---|---|
Headers |
Return-Path: <concept-bounces+u-boot-concept=u-boot.org@u-boot.org> X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431127; bh=qLq4khdcRVrI6KVNmvxHqeMrwm5o9nKXdvwtkD+Vcto=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=K5SXXALrD8zibpqNEdaqlekqxIAmDsoZpFN9t3/7aanVwHFLxWSUWhXZT4bhmfqGG 9UOwAwqo2yIF11N4i7in//g7tr5K+ZyAFTEtkTK5+nHhgEvCPFqzNCZ62fAHWyxHKr /kDODFDxkQN0VJTB9V2N3xXLzUbAsATH7kWJRdbrDvb98t5pANWpQyypgsFR8yOf1B aWaLrsChx5hBiNXF/nLy9YOc3gtQxI6RaDrDi6HiA2U9J77rTWQVC4zK8pzvZipw0t gnAfZV3xy9YtO8ZrYkw2YsYOROsF0RpA9EtxUYOqYf8Flfti3xyQrBIBrbTiwI98ql zklgq/740e/Hw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4DAAB67A73 for <u-boot-concept@u-boot.org>; Tue, 9 Sep 2025 09:18:47 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id hyovdrSg_EWy for <u-boot-concept@u-boot.org>; Tue, 9 Sep 2025 09:18:47 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431127; bh=qLq4khdcRVrI6KVNmvxHqeMrwm5o9nKXdvwtkD+Vcto=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=K5SXXALrD8zibpqNEdaqlekqxIAmDsoZpFN9t3/7aanVwHFLxWSUWhXZT4bhmfqGG 9UOwAwqo2yIF11N4i7in//g7tr5K+ZyAFTEtkTK5+nHhgEvCPFqzNCZ62fAHWyxHKr /kDODFDxkQN0VJTB9V2N3xXLzUbAsATH7kWJRdbrDvb98t5pANWpQyypgsFR8yOf1B aWaLrsChx5hBiNXF/nLy9YOc3gtQxI6RaDrDi6HiA2U9J77rTWQVC4zK8pzvZipw0t gnAfZV3xy9YtO8ZrYkw2YsYOROsF0RpA9EtxUYOqYf8Flfti3xyQrBIBrbTiwI98ql zklgq/740e/Hw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3A840679D6 for <u-boot-concept@u-boot.org>; Tue, 9 Sep 2025 09:18:47 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431120; bh=rwmXDLkx6XqMo/6dEO3udplwxo/sj8h8fyixjykBENo=; h=From:To:Cc:Subject:Date:From; b=DXG73Y6lecc2lSRei8zM/QGNxlvjbWuW6TQjbC36pKsWBIEnSeCoASnTsBo4aq8RH 1uELkT7hH6vJJpkU37v/2Orsx76cSDlE/Lz7fmOsNHofiFsMlm1o5a3EDLZqyVSQ/x HSqQQS8d6hK39xhg6kzfNniiUO5ylRee9420yzZDa6RiF2nRcujVrA53hUtAXmWheG hGAYyLuiWQ55yoNDw/q2YouLflI8EMFwZZB3sUiZ1LtIgYakngO8R0DP9AQ0imwrRp Y0IXhnhLWGKKy7O46b5jK6WPHIM7AQTEzPH/mJeuFtnS8P0H4vNcnECMEP9gQiuRam 5gxLEI5JRHvfw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A73AE60026; Tue, 9 Sep 2025 09:18:40 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id EXYxEJOk36FR; Tue, 9 Sep 2025 09:18:40 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431116; bh=Ca9+XKA/JKa6VnujmC8X+gnAfnZGAMs2+/jr2abZitA=; h=From:To:Cc:Subject:Date:From; b=W9n6HKjf5/M0yW5I805DAY4z03prMaO0kYniuhZ94y7QJoPQ181OW+LgV6PkGnpZi FLrVepVyAOOz5j9mQOkyjlwx7Pidlfem3/zW/ldZIU+wJSjJHQeesoXM12oqGuHc74 vIB+/28tS/Px6etu7vIoIosNjdrRuNHh/utnivJq6/CO4jua9IldrPEJtM+hJl6Ets 8JeIbba5ZPgU1+XLfrq+4a2PuxY2kTuCNsTw/4VonfKrMnOD+u2oy7vrYhrBRjNj+V rLSBQWMQvVVZFnZJKrbR5LEYaHobxnFiLkuHrroiEUR3whQQJkAmIRp19Cg+h/8lz2 eZU50Z1u4yEig== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D4582679D6; Tue, 9 Sep 2025 09:18:35 -0600 (MDT) From: Simon Glass <sjg@u-boot.org> To: U-Boot Concept <concept@u-boot.org> Date: Tue, 9 Sep 2025 09:17:57 -0600 Message-ID: <20250909151824.2327219-1-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Message-ID-Hash: 3LB4FCZ2F7JMAQEFTI36MWRC5SA4V7YN X-Message-ID-Hash: 3LB4FCZ2F7JMAQEFTI36MWRC5SA4V7YN X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt <xypron.glpk@gmx.de>, Simon Glass <sjg@chromium.org> X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 00/18] ulib: Complete initial U-Boot library List-Id: Discussion and patches related to U-Boot Concept <concept.u-boot.org> Archived-At: <https://lists.u-boot.org/archives/list/concept@u-boot.org/message/3LB4FCZ2F7JMAQEFTI36MWRC5SA4V7YN/> List-Archive: <https://lists.u-boot.org/archives/list/concept@u-boot.org/> List-Help: <mailto:concept-request@u-boot.org?subject=help> List-Owner: <mailto:concept-owner@u-boot.org> List-Post: <mailto:concept@u-boot.org> List-Subscribe: <mailto:concept-join@u-boot.org> List-Unsubscribe: <mailto:concept-leave@u-boot.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit |
Series |
ulib: Complete initial U-Boot library
|
|
Message
Simon Glass
Sept. 9, 2025, 3:17 p.m. UTC
From: Simon Glass <sjg@chromium.org>
This series completes support for building U-Boot as a shared or static
library, enabling reuse of U-Boot functionality in external programs and
test suites.
The U-Boot library (ulib) allows developers to:
- Link against U-Boot functionality without a full U-Boot image
- Use U-Boot's OS abstraction layer, drivers, and utility functions
- Build test programs that can exercise U-Boot code in isolation
- Create applications that benefit from U-Boot's hardware support
Key features:
- Builds both shared (libu-boot.so) and static (libu-boot.a) libraries
- Preserves U-Boot linker lists for proper driver/subsystem init
- Configurable symbol renaming to avoid conflicts with system libraries
- Generated API headers with renamed function declarations
- Documentation and working examples
- Currently only supports sandbox architecture
The series includes:
- More build-infrastructure and Makefile integration
- Python-based mechanism for symbol renaming and API generation
- Test programs demonstrating basic library usage
- A simple example program showing real-world usage patterns
Symbol renaming ensures that U-Boot functions don't conflict with system
libraries. For example, printf() remains the standard library function
while ub_printf() provides access to U-Boot's printf implementation.
This is handled automatically during the build process.
The library excludes main() to allow external programs to provide their own
entry points while still accessing U-Boot functionality through ulib_init()
and ulib_uninit().
For example:
#include <u-boot-lib.h>
#include <u-boot-api.h>
int main(int argc, char *argv[])
{
if (ulib_init(argv[0]) < 0)
return 1;
ub_printf("Hello from U-Boot library!\n");
ulib_uninit();
return 0;
}
License implications are documented - the GPL-2.0+ license applies to
any programs linked with the library, requiring source code distribution
for compliant usage.
Future work will look at expanding support to other architectures.
Simon Glass (18):
lib: Tidy up comments for vsprintf functions
u_boot_pylib: Correct docs for run_test_coverage() required
os.h: Add standard includes for types used in os.h
sandbox: Enable ULIB just for the sandbox build
test: Move the non-LTO test to sandbox_flattree
test/py: Allow setting the cwd with run_and_log()
ulib: Move ulib into its own directory
ulib: scripts: Add a script to support symbol-renaming
ulib: Use the correct copyright message
ulib: Disable LTO when building the library
ulib: Provide a symbol-rename file
ulib: Makefile: Create a library with renamed symbols
ulib: Makefile: Plumb in renaming symbols for ulib
ulib: Makefile: Plumb in creation of the API header
ulib: Expand the ulib example to have two files
ulib: Adjust the test to check symbol renaming
ulib: doc: Expand the documentation to cover new features
test/py: Add a test for ulib functionality
Kconfig | 3 +-
Makefile | 54 ++-
arch/sandbox/cpu/u-boot-lib.lds | 2 +-
configs/sandbox_defconfig | 1 +
doc/develop/ulib.rst | 179 +++++++-
examples/ulib/.gitignore | 2 +
examples/ulib/Makefile | 60 ++-
examples/ulib/demo.c | 14 +-
examples/ulib/demo_helper.c | 28 ++
examples/ulib/demo_helper.h | 31 ++
include/os.h | 2 +
include/u-boot-lib.h | 2 +-
include/vsprintf.h | 25 +-
lib/Makefile | 2 +-
lib/ulib/Makefile | 6 +
lib/ulib/rename.syms | 30 ++
lib/{ => ulib}/ulib.c | 2 +-
scripts/build_api.py | 714 +++++++++++++++++++++++++++++
test/py/tests/test_sandbox_opts.py | 8 +-
test/py/tests/test_ulib.py | 141 ++++++
test/py/utils.py | 13 +-
test/run | 8 +
test/scripts/test_build_api.py | 704 ++++++++++++++++++++++++++++
test/ulib/ulib_test.c | 12 +-
tools/u_boot_pylib/test_util.py | 2 +-
25 files changed, 1970 insertions(+), 75 deletions(-)
create mode 100644 examples/ulib/.gitignore
create mode 100644 examples/ulib/demo_helper.c
create mode 100644 examples/ulib/demo_helper.h
create mode 100644 lib/ulib/Makefile
create mode 100644 lib/ulib/rename.syms
rename lib/{ => ulib}/ulib.c (95%)
create mode 100755 scripts/build_api.py
create mode 100644 test/py/tests/test_ulib.py
create mode 100644 test/scripts/test_build_api.py