From patchwork Fri Sep 5 17:01:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 247 Return-Path: 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=1757091745; bh=rk1L11TJsKAzAS1Mug4LKYUIv0LzVLdWxwc+TJFCXAM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=On04XcFjr3p0TpKGuC129BeUiNwiiRybKoPq+yZ0kR+DusMLAFDNIrPf2nxpG71Rz TIGvxMzpBXXzUO9HF8o+V3GR91YGdhFjuqAQdhk/234eOimzFiymHB8s+wCYyvaKVa q6xC8nc+VbCFhNwBMY9gRk9qggWN0p37SNTXyFp/Qtz1PQq93E7NgBq6JDBPxU64oD FtzFfu5k8yGzcfAInlVQBcan2OfdljALzWAThk97fdpGqC4HaVYJsiYiPayCZbIhcB nCemTp7kH6wN9uQtjKp3Hpp+IKgU/V6vw3h7Jw2+2c3myJ89wuFEBy9pkV97B/pW+C lzpzmk0ojOv8g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 43DE16794B for ; Fri, 5 Sep 2025 11:02:25 -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 rE3mwYhiMwh7 for ; Fri, 5 Sep 2025 11:02:25 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091744; bh=rk1L11TJsKAzAS1Mug4LKYUIv0LzVLdWxwc+TJFCXAM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=WzwNsuUPrQm/uN3bhUIw4Rc/7Dh+IJwjkEBoURv5pZ5MbyDs8dAX91rLm8+261amf ywYFPv7ZUlsL9NZ0kTYQqkmIq4jTwYzC06PHJnBuEeIxjYemmIJggVWUsg9DYLm2nP ggrKc+/KS6Eu53230Ea2tNs7VtQnCAzKgvA0C70bLe4BFB+dTslW9z3b/rAN30+T4k VJjnXcmwZMGtiVz4T8LPFkGJTtej6WnFHscESIMG7FwPSLSbH2j4h2okq8Z+iRXiqQ NFwBcRkRTf4Ig/DaqYwbLPShXJiIfwEUVNC+GMPhnJLL+ywubml5m1YVJfpxRGc2vr 1odw3aJ4SEqcg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AF2A067980 for ; Fri, 5 Sep 2025 11:02:24 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091742; bh=wrNv2N2Tt9SCggUhsYVUlgvbOLf0ZZXYeLwmshiMRYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kTAttEiE61GWVHB0h2J1glO9VRwgtG7pxz4hx81lu4hLC3ewYcObRWqR6J/rr4izN Rp8CUUPdzp+cdf803CicgnXJZ5AWr+kgnT7wSKkEfOgX6MRyW9veEoO+/K3jmTuxwG y8uqP6vtqDRZuPgw+xypiEEyC650fiaGnvbrjB89aSi+B4VQWN6rB1QHzaMlVNq23l w2OI0j0gLXM8vyh6geQH1UxZZAMxggbTzxxQbgcwBf7a6wnf1pARBzMMXd4cOmqNiL H3cQZ6rZCCJAUJj3EBhvCtkGlT35W27R9BWIdHqvFhlGd3l9oyHMZM4tFkvSzJVHkj 0+QYUlm3JFCSg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 68CBF678E6; Fri, 5 Sep 2025 11:02:22 -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 YjgY7BI9eIUJ; Fri, 5 Sep 2025 11:02:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091738; bh=+HDFxi5JId6MPdkyVjPlBw6DJ/oZusdpaxHzNcoxx2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ndEHLL8yqORwo75Mrk2sfG39AIjaMwK7DVint4UE/bIrQgpES0ZZ8q5dFMPhTw5U7 Ww7YbjMS5n/fNMSd5wCa/Fq9596zIngekwNYozSeJeCzlOlmWHiTovTVaK2gruyi5y eBya8aVC1wXKrbpOMIDm0i6SZLhgTBWKRCX2Onxjc5iHd1FnpGWQtBndzOoMN6cydR wYljovJ3C0zPiD73PQHc6ev1td78xl1zUTjRO9tlk6YksebPtQ4jj8if+g7AxmT/hE ilTGG+GMTCQCr0TivowrlJHnYfBh52/6ozm/1m59nDk0+vJCKCDDleRDhJCnUPoJ9M /ukJi3YpDejKg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 29458678AA; Fri, 5 Sep 2025 11:02:18 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 5 Sep 2025 11:01:21 -0600 Message-ID: <20250905170132.182249-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250905170132.182249-1-sjg@u-boot.org> References: <20250905170132.182249-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: YMDD7MLVWATEAJYBKEKJUKYVC2FONFE2 X-Message-ID-Hash: YMDD7MLVWATEAJYBKEKJUKYVC2FONFE2 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/15] ulib: Provide a generic init function List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Provide an arch-neutral init function that can be used by including a single header file. This declares a static global_data which is used for the initial startup process. Once board_init_r() is called, the global_data is moved into a new place and the static version is not needed. Signed-off-by: Simon Glass --- include/u-boot-lib.h | 34 ++++++++++++++++++++++++++++++++++ lib/Makefile | 2 ++ lib/ulib.c | 36 ++++++++++++++++++++++++++++++++++++ test/ulib/ulib_test.c | 8 ++------ 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 include/u-boot-lib.h create mode 100644 lib/ulib.c diff --git a/include/u-boot-lib.h b/include/u-boot-lib.h new file mode 100644 index 00000000000..7157ef6ba60 --- /dev/null +++ b/include/u-boot-lib.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * U-Boot library interface + * + * This provides basic access to setup of the U-Boot library. + * + * Library functions must be individually accessed via their respective headers. + * + * Copyright 2025 Canonical + * Written by Simon Glass + */ + +#ifndef __U_BOOT_LIB_H +#define __U_BOOT_LIB_H + +struct global_data; + +/** + * ulib_init() - set up the U-Boot library + * + * @progname: Program name to use (must be a writeable string, typically argv[0]) + * @data: Global data (must remain valid until the program exits) + * Return: 0 if OK, -ve error code on error + */ +int ulib_init(char *progname); + +/** + * ulib_uninit() shut down the U-Boot librrary + * + * Call this when your program has finished using the library, before it exits + */ +void ulib_uninit(void); + +#endif diff --git a/lib/Makefile b/lib/Makefile index 1db1e3c9000..eb6da6d63c9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -166,6 +166,8 @@ obj-$(CONFIG_LIB_ELF) += elf.o obj-$(CONFIG_$(PHASE_)SEMIHOSTING) += semihosting.o +obj-$(CONFIG_ULIB) += ulib.o + # # Build a fast OID lookup registry from include/linux/oid_registry.h # diff --git a/lib/ulib.c b/lib/ulib.c new file mode 100644 index 00000000000..03acbe93fd1 --- /dev/null +++ b/lib/ulib.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Simplified U-Boot library interface implementation + * + * Copyright 2025 Canonical + * Written by Simon Glass + */ + +#include +#include +#include +#include + +/* Static storage for global data when using simplified API */ +static struct global_data static_gd; + +int ulib_init(char *progname) +{ + int ret; + + /* Initialize the U-Boot library with our static global data */ + ret = ulib_init_with_data(progname, &static_gd); + if (ret) + return ret; + + return 0; +} + +void ulib_uninit(void) +{ +} + +const char *ulib_get_version(void) +{ + return PLAIN_VERSION; +} diff --git a/test/ulib/ulib_test.c b/test/ulib/ulib_test.c index e1e863712a8..a68290ff484 100644 --- a/test/ulib/ulib_test.c +++ b/test/ulib/ulib_test.c @@ -11,19 +11,15 @@ /* Use system headers, not U-Boot headers */ #include #include -#include -#include - -DECLARE_GLOBAL_DATA_PTR; +#include int main(int argc, char *argv[]) { - struct global_data data; int ret; printf("Calling U-Boot initialization via shared library...\n"); - ret = ulib_init_with_data(argv[0], &data); + ret = ulib_init(argv[0]); if (ret) return 1;