From patchwork Thu Sep 4 13:04:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 221 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=1756991142; bh=SsDelqBcEWKkpzzZtb5pcRt80zpTpPM4yLz9vJBwkP4=; 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=fwzSEeH5CmzyqU6toSxYbMG8WaPN7TU+pvoA/YMPWT3QJ7gV6lv7qfQPSSGrRl4u3 4LKP0WeJM8rn3D+TjQLze/lxgUW5cGp2gM2TuHbTUfevjvmUNwCNyVSgAyec322Ey7 ACnT3pjzz7q9hIjrcQb4+VLlt3oVTDToB6RqTpfiQtnM3DBbF3Bd8dqRIIrSW9CPtN /lp6dcM82Tf/yiAHpoqYp2d+a7xQEtbSbCRPrcw8FCWlgHv0XpO+4HMyKfJNLvLA8+ mGuK9XC5rDpJs2v9KjmtXMlFy8IRcWdrg6CVJ9zzgD3Lrdd15jX2eyO1X9Uzyzczlk Ce18pY8BQkO+Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 51EA567961 for ; Thu, 4 Sep 2025 07:05:42 -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 qCc5G1kxkGfd for ; Thu, 4 Sep 2025 07:05:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991142; bh=SsDelqBcEWKkpzzZtb5pcRt80zpTpPM4yLz9vJBwkP4=; 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=fwzSEeH5CmzyqU6toSxYbMG8WaPN7TU+pvoA/YMPWT3QJ7gV6lv7qfQPSSGrRl4u3 4LKP0WeJM8rn3D+TjQLze/lxgUW5cGp2gM2TuHbTUfevjvmUNwCNyVSgAyec322Ey7 ACnT3pjzz7q9hIjrcQb4+VLlt3oVTDToB6RqTpfiQtnM3DBbF3Bd8dqRIIrSW9CPtN /lp6dcM82Tf/yiAHpoqYp2d+a7xQEtbSbCRPrcw8FCWlgHv0XpO+4HMyKfJNLvLA8+ mGuK9XC5rDpJs2v9KjmtXMlFy8IRcWdrg6CVJ9zzgD3Lrdd15jX2eyO1X9Uzyzczlk Ce18pY8BQkO+Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4147A678BF for ; Thu, 4 Sep 2025 07:05:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991140; bh=QSrWlNteS5Us4aEMIOVpbNxnl0uzxkdQMZPOoOHEftY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQfnYaR5z5rJQz5fRqIj0cNyDGEALQqkWg9bDzw4xIUegU2TLXbJEZM8PfVmw2GG5 vBmGTVN/fN+Bujd3Ny2TNqTNpBx3hGeRICbWfoblEHYVh9zgCLMUakb40lUY3QWzxl TXoq6qJjiavpALgCqNzHpQnrz4rCO9mv9gJfV97nDX2ZaYXGlws7oV43VCf/YGFdOG HTpIctfaQZAdF7IpqN6D61F+gtVoEHdwGD6L0zLhWKwltlFY7Jf2SbSwMjvF/pc17W qX17JQKic77TScu8qnR63dAEoV7XYV/v5R4KEQTSAVYR822EwalRqRDxZyTx/IzX3s VOuMhJH2A52Pw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4649C678BF; Thu, 4 Sep 2025 07:05: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 0uMpbBuTPD2p; Thu, 4 Sep 2025 07:05:40 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756991137; bh=PHnZunHayGZmr2oKXzjvWSmKYqNVSS+JpEyFiOMMLPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+cYd2WzBoGXLO7Y+aOtrBvznJzp58Ai3i2b1KAvSQ0Q78GM9YgPj6o/Ua7UballI /FeH14+MQlPAzOOLIa0gIuRWrJvtQcRjNSggkiu7BIxTIHgGWLp6TMkx+KP41SuQIh s2FrN6tfr39rZWSI6HOAogDm3G5xr0uyCC8msfo/D9qq49POC76azU/Sh39PZVwbp8 MYalS1ppHiSgZcDLvJXGode5s6xIgVdv5mP4bRqOOnOKNxlv55Ybqd04jkEpxKK8P9 XMnlk0TzTx391gGRohxgBtu0LH+KRgRMNeQ5x1WDisFMB0FdCQCYc965CJ4orGqzl4 4G8OhN+xaZp+Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E46D9678AB; Thu, 4 Sep 2025 07:05:36 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 4 Sep 2025 07:04:40 -0600 Message-ID: <20250904130459.848794-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250904130459.848794-1-sjg@u-boot.org> References: <20250904130459.848794-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: DCLVXBBEI4C3L4BUKBQON4ONSK3VZSNT X-Message-ID-Hash: DCLVXBBEI4C3L4BUKBQON4ONSK3VZSNT 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 , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/18] sandbox: Extract init code into sandbox_init() 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 Split the init code from sandbox_main() into a separate sandbox_init() function that handles all setup up to the call to board_init_f(). This allows the init to be called independently of the main execution flow. Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c | 25 ++++++++++++++++------- arch/sandbox/include/asm/u-boot-sandbox.h | 21 +++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 40a3559d244..59682b039e5 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -601,18 +601,16 @@ static int last_stage_init(void) } EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); -int sandbox_main(int argc, char *argv[]) +int sandbox_init(int argc, char *argv[], struct global_data *data) { struct sandbox_state *state; void * text_base; - gd_t data; int size; int ret; text_base = os_find_text_base(); - memset(&data, '\0', sizeof(data)); - gd = &data; + gd = data; /* * This must be the first invocation of os_malloc() to have @@ -620,7 +618,7 @@ int sandbox_main(int argc, char *argv[]) */ ret = state_init(); if (ret) - goto err; + return ret; /* * Copy argv[] so that we can pass the arguments in the original @@ -663,13 +661,13 @@ int sandbox_main(int argc, char *argv[]) if (state->read_state && state->state_fname) { ret = sandbox_read_state(state, state->state_fname); if (ret) - goto err; + return ret; } if (state->handle_signals) { ret = os_setup_signal_handlers(); if (ret) - goto err; + return ret; } if (state->upl) @@ -692,6 +690,19 @@ int sandbox_main(int argc, char *argv[]) /* sandbox test: log functions called before log_init in board_init_f */ log_debug("debug: %s\n", __func__); + return 0; +} + +int sandbox_main(int argc, char *argv[]) +{ + gd_t data; + int ret; + + memset(&data, '\0', sizeof(data)); + ret = sandbox_init(argc, argv, &data); + if (ret) + goto err; + /* Do pre- and post-relocation init */ board_init_f(gd->flags); diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h index 001b00fe41e..941f35f9e69 100644 --- a/arch/sandbox/include/asm/u-boot-sandbox.h +++ b/arch/sandbox/include/asm/u-boot-sandbox.h @@ -16,6 +16,8 @@ #include +struct global_data; + /* board/.../... */ int board_init(void); @@ -41,6 +43,22 @@ void sandbox_reset(void); /* Exit sandbox (quit U-Boot) */ void __noreturn sandbox_exit(void); +/** + * sandbox_init() - init sandbox + * + * This function initialises sandbox state, parses arguments, and sets up the + * global data structure, but does not call board_init_f(). + * + * The caller must zero @data before calling this function. This function sets + * gd to point to @data so it must remain valid for the life of sandbox. + * + * @argc: the number of arguments passed to the program + * @argv: array of argc pointers, plus a NULL terminator + * @data: pointer to global data structure to init + * Return: 0 if OK, -ve on error + */ +int sandbox_init(int argc, char *argv[], struct global_data *data); + /** * sandbox_main() - main entrypoint for sandbox * @@ -50,6 +68,9 @@ void __noreturn sandbox_exit(void); * This calls sandbox_init(), then board_init_f/r(). It does not return unless * something goes wrong. * + * @argc: the number of arguments passed to the program + * @argv: array of argc pointers, plus a NULL terminator + * * Return: 1 on error */ int sandbox_main(int argc, char *argv[]);