From patchwork Fri Sep 5 17:01:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 246 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=1757091742; bh=5qHNwVxCCuFIppmFmO1nLzdu3yn6STf4lb9Qi1zLsGY=; 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=sfGoVyVfIjy5HoCSABVjtNIhUAMjHHZOWzSjLLuMpJDlxdgq1FQo04wn5egbk2qKq afiscNmWjLgO03lFKSrfs3GYeJCziMfjZ+uEl7bPB4qgh2f7zSeBWXFg4y3X7jBkE6 LCXpRNxM3PjE9RLwQTPu8lBpFe8BpkiLg8gAccmaSY5yDX95bqzJzLpYRSlxTLzCLl P9hfaExfzAIuWQjwbjbFxNNuSpqX+vs8ja2gXmlUB+jKBvP/vMgs3bVlhqGMOzokQ6 AYP7eUsuxkz+6Fe0/inEOOg8YiBVLPnJ2FlxBplmkyKWe55v0z8LPPgsMjb+HErK3E KfUIHiSXk/jzw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F3B5F679A8 for ; 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 10024) with ESMTP id rPhjI7gSstq7 for ; 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=1757091742; bh=5qHNwVxCCuFIppmFmO1nLzdu3yn6STf4lb9Qi1zLsGY=; 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=sfGoVyVfIjy5HoCSABVjtNIhUAMjHHZOWzSjLLuMpJDlxdgq1FQo04wn5egbk2qKq afiscNmWjLgO03lFKSrfs3GYeJCziMfjZ+uEl7bPB4qgh2f7zSeBWXFg4y3X7jBkE6 LCXpRNxM3PjE9RLwQTPu8lBpFe8BpkiLg8gAccmaSY5yDX95bqzJzLpYRSlxTLzCLl P9hfaExfzAIuWQjwbjbFxNNuSpqX+vs8ja2gXmlUB+jKBvP/vMgs3bVlhqGMOzokQ6 AYP7eUsuxkz+6Fe0/inEOOg8YiBVLPnJ2FlxBplmkyKWe55v0z8LPPgsMjb+HErK3E KfUIHiSXk/jzw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E43CE67980 for ; 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=/LupZRUhu+4Wtl6WxVDatGoaZmbNiv6t8SRb78XR6YM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BwmudXfI8BPvnVyBiHn/httmrvou8ymRcCDvyx4OGO4y7Tps6x7LKt5ibeCD1SMGu y+De6ghL0M69sM79Ex+VKa1ICmz4Gt/L89c7xFV4/qtd7AE3RRDOOUwn13YMK5oRSr lrQZMXDKqL4rckrDU3u53l4YqBLnhP1/2QjQU1093J1lHW1tu/MuvfjcMl6WuFgue3 xbh/1UuRxn0lLPUI4fK+0m9Ke5uwT5QfDDQZIWjS8Wm04Ck7xy2cgV91iAxSOHpFwG qLuFrjhpRIKrAoG6G02Bkl7Qo2a496U7pJfhNvw2H6R81K7UNnpHiGDptYFgFOWIjd HKV6Nt7eHcuKA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E089F6790F; Fri, 5 Sep 2025 11:02:18 -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 9FmAU6hj64_E; Fri, 5 Sep 2025 11:02:18 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091733; bh=4AJpxLAsMxueEq/tVtvsGUEj9uT1ulLtt+q3YMvvVAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iO7XiK6nksXeJS26mFjWQcBgEMS3G23y6o70ZrffJmbLmi34Zc5aQ+2hym0vPbmYm hq6nYtTycOXCZihmKwvaO6PXQ1RN7zOmtTMO+1IgJZRejuRDHu3ajLSrZx48VFqkCd bzlnNS11oJEkfoCpyCeqyVJe8UzbMfyiESHLAqMX3vDcTJKkV/I5vJjaoqlBQwPqu9 MdPgn6iNLETARxc6CZflBMkDu+YKJW6x9LfPdx4Twa3AClplazbyMW1U9svId1srra zkfhF/7nFyJsiubLUXufY7SKYWREjTdjj43gwu3S1fXqLaaFzW8Rhj0byygKKzzDnb GCDQxtgVOjTKg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9300167980; Fri, 5 Sep 2025 11:02:13 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 5 Sep 2025 11:01:20 -0600 Message-ID: <20250905170132.182249-10-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: USKT7N4IXIATIBYVBJXJDHBI3IF7M2BZ X-Message-ID-Hash: USKT7N4IXIATIBYVBJXJDHBI3IF7M2BZ 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 09/15] ulib: Provide an init function for sandbox 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 a simple function to set up the library, to avoid having to worry about the details. This requires the caller to know about global_data Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c | 30 +++++++++++++++++++---- arch/sandbox/include/asm/u-boot-sandbox.h | 9 +++++++ test/ulib/ulib_test.c | 12 +++------ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 59682b039e5..556d1985ccc 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -693,13 +693,14 @@ int sandbox_init(int argc, char *argv[], struct global_data *data) return 0; } -int sandbox_main(int argc, char *argv[]) +static int sandbox_flow(int argc, char *argv[], struct global_data *data, + uint flags) { - gd_t data; int ret; - memset(&data, '\0', sizeof(data)); - ret = sandbox_init(argc, argv, &data); + memset(data, '\0', sizeof(struct global_data)); + data->flags = flags; + ret = sandbox_init(argc, argv, data); if (ret) goto err; @@ -708,10 +709,29 @@ int sandbox_main(int argc, char *argv[]) board_init_r(gd->new_gd, 0); - /* NOTREACHED - board_init_r() does not return */ return 0; err: printf("Error %d\n", ret); return 1; } + +int sandbox_main(int argc, char *argv[]) +{ + gd_t data; + + sandbox_flow(argc, argv, &data, 0); + + /* NOTREACHED - board_init_r() does not return */ + return 1; +} + +int ulib_init_with_data(char *progname, struct global_data *data) +{ + char *argv[] = {progname, NULL}; + int ret; + + ret = sandbox_flow(1, argv, data, GD_FLG_ULIB); + + return ret; +} diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h index 941f35f9e69..859c2f08b4c 100644 --- a/arch/sandbox/include/asm/u-boot-sandbox.h +++ b/arch/sandbox/include/asm/u-boot-sandbox.h @@ -75,4 +75,13 @@ int sandbox_init(int argc, char *argv[], struct global_data *data); */ int sandbox_main(int argc, char *argv[]); +/** + * ulib_init_with_data() - set up the U-Boot library + * + * @progname: Program name to use, 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_with_data(char *progname, struct global_data *data); + #endif /* _U_BOOT_SANDBOX_H_ */ diff --git a/test/ulib/ulib_test.c b/test/ulib/ulib_test.c index 621bcd49be9..e1e863712a8 100644 --- a/test/ulib/ulib_test.c +++ b/test/ulib/ulib_test.c @@ -23,15 +23,9 @@ int main(int argc, char *argv[]) printf("Calling U-Boot initialization via shared library...\n"); - /* init global data */ - memset(&data, '\0', sizeof(data)); - data.flags = GD_FLG_ULIB; - - ret = sandbox_init(argc, argv, &data); - - /* Do pre- and post-relocation init */ - board_init_f(gd->flags); - board_init_r(data.new_gd, 0); + ret = ulib_init_with_data(argv[0], &data); + if (ret) + return 1; return ret; }