From patchwork Sat Feb 14 02:13:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1867 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=1771035246; bh=qt9b860Hi7uFF8Sgh/qajV54AdEtU6rOJ7hab4n66nc=; 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=cP6x61T6bKimotIDOiU3+g6KS6SYbBRUceawsNfw0y96cPhbjytMmIaZ1R9gh3xIs vQKcSxAURVeoa0hVCsgte7J39sw09l0WhG1+SwJDU81UCsIuID22JSigmaI4B3Fntl eEaUCb0X2D8q+D6VJdW/zZp5OQqIeC0V6qidhDK5bJk+s7kYF4aPfKYoVV4qNrMe9p vv9X0MScGPPz/O8MbNTkoAavchqYOui+kR1FqjMO4DRtIyQxRnoW/Jd/vZIJsd2XUX YYHFyB7J/ucG30kA0VdbGrYy5E4yic3MYT5rLJYWNQ8GAKcnxgT3gyUFlfY5Yaolqh WGlWcPoWWqIkw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CC10169B58 for ; Fri, 13 Feb 2026 19:14:06 -0700 (MST) 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 7rRQDvPRQSHO for ; Fri, 13 Feb 2026 19:14:06 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771035245; bh=qt9b860Hi7uFF8Sgh/qajV54AdEtU6rOJ7hab4n66nc=; 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=u7/vms0wVis2a/smba0rR5oqd9ATN5S83abpdjK0LdQBAx4KLWdON72VxtkOhfzBq 3hKjRzFFnr/I0g2tsf0w1D/nAlsnBwvmg3AsOu1yyFpXFx6N16VorE5xISN+pmO1mT T3NOotsrkObsMd1QjxUo13e4QLcX5TJ8HJt1xuSuEMKq0UgirGlmTPFY781fT43IZ1 lYfKIBKMZAdAK1iPA71PYp39SPsrUq3AtRO+52mv+esB1XiVrNP9YXOr3QnZt/lC3t qxv8ZkzjQPFCoOURJv8QEig3g9bml5G8dy1ukcQPsunV95DhEmQhEYHEZW81F/qaeI TO7qo5P/KVqLA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4067069B5B for ; Fri, 13 Feb 2026 19:14:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771035242; bh=VaipgS5H73k9blM5yZZ55j1k1IbdKdaiDOnbPJiUmz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BZFs5QP6SotW1/fLkllTYhYH62BqPdtWzd5LkdIaofDHBAaIoMUFGu0UzqMXS4oAn 7K7348oUSehNEpJIUeDxfBpp6m4uM2vTIFht/JVU3GO/VnuTUHbNj1DgelZ9IG1x4+ 8NlY0sNC+CnqPZGEQygNsUEGPi6l8yGH9bIwbwSYn93Pj6Z0SLku/8EHGnbxhdcipH IexGJzxqCwFY2y+DQjSGOe2wq6uEduZ4/BcxFwHGp1fQoiXAxyObdYQ3k7SKs9R7pU c4zXI5yFh4k/zetbQi7RDBKBR3Hpqe3hTCGqQaawJiK5XZbklgfhMcQrWaJjXoJx7i TnzyQzKS5tajw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C397F69B5A; Fri, 13 Feb 2026 19:14:02 -0700 (MST) 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 ZPSyOArVIKrT; Fri, 13 Feb 2026 19:14:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771035242; bh=Npn3vQrKzLXrdEfJv4runrcMCQn/TctwXzRN7vdQf/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pbcvi/zkGvkO3uXltJxsSh5Fyrg95HvinHiiTM3kwD1ieWjGTxl638+OxABys5NK8 YHPs3wJkrv0q4OfBStT4tzL7gmryzlYdvGcPe6zhckzTRunCvAz46vvTzekXgdAEVv SXlwJlp0bCTYCww3BXDTFsZYIwPFd08XlY48o6/3ZpxlJo2pgpFPmhaCtpAHD/wGXK ZyiFnbxdZyKJiJWvn4b4Ky50R3fskNG5DBDjx2b7stVfDHqOtatedFUpYKsRTzZMD3 nq900cu4Bz2AG+SBliALEfEgy6YBrLT0TPVEirFR83r0tzZgnxtetkbQYtkfxNxNdo Lm6IVzm0nOYsw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2E63869B56; Fri, 13 Feb 2026 19:14:02 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 13 Feb 2026 19:13:01 -0700 Message-ID: <20260214021317.816170-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260214021317.816170-1-sjg@u-boot.org> References: <20260214021317.816170-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OW6M4YGQ43S4IYNVK37W476YUT2TWZY6 X-Message-ID-Hash: OW6M4YGQ43S4IYNVK37W476YUT2TWZY6 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 , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/13] ulib: Replace CONFIG_ULIB_JUMP_TO_MAIN with runtime ulib_has_main() 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 The Kconfig option CONFIG_ULIB_JUMP_TO_MAIN is a build-time switch that cannot vary per-binary when multiple images share the same config. Replace it with a weak ulib_has_main() function that returns false by default. Example programs override it to return true, so the decision to set GD_FLG_ULIB and jump to main() is made at link time rather than build time. Add a weak main() fallback that enters the normal command loop. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- Kconfig | 9 --------- common/board_f.c | 2 +- common/board_r.c | 18 +++++++++++++++++- include/init.h | 11 +++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Kconfig b/Kconfig index 011f248ba03..ccd62220f0e 100644 --- a/Kconfig +++ b/Kconfig @@ -129,15 +129,6 @@ config ULIB_SHARED_LIB available for SANDBOX builds since shared libraries are not meaningful for bare-metal targets. -config ULIB_JUMP_TO_MAIN - bool "Set GD_FLG_ULIB flag in early boot" - depends on ULIB - help - Enable this to set the GD_FLG_ULIB flag in the global data structure - during early boot (in start.S before calling board_init_f). This allows - U-Boot code to detect that it's running as a library from the very - beginning of initialization. - config OPTIMIZE_INLINING bool "Allow compiler to uninline functions marked 'inline' in full U-Boot" help diff --git a/common/board_f.c b/common/board_f.c index 448cf2e319a..4558fdf297a 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -1031,7 +1031,7 @@ void board_init_f(ulong boot_flags) gd->flags = boot_flags; gd->flags &= ~GD_FLG_HAVE_CONSOLE; - if (IS_ENABLED(CONFIG_ULIB_JUMP_TO_MAIN)) + if (ulib_has_main()) gd->flags |= GD_FLG_ULIB; gd->boardf = &boardf; diff --git a/common/board_r.c b/common/board_r.c index 53851504c8f..ce5aa28b1e5 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -771,6 +771,22 @@ static void initcall_run_r(void) INITCALL(run_main_loop); } +__weak bool ulib_has_main(void) +{ + return false; +} + +#ifdef CONFIG_ULIB +__weak int main(void) +{ + /* No example linked -- fall through to normal command loop */ + for (;;) + main_loop(); + + return 0; +} +#endif + void board_init_r(gd_t *new_gd, ulong dest_addr) { /* @@ -803,7 +819,7 @@ void board_init_r(gd_t *new_gd, ulong dest_addr) if (gd_ulib()) { #ifdef CONFIG_ULIB /* handle __noreturn attribute */ - if (!IS_ENABLED(CONFIG_ULIB_JUMP_TO_MAIN)) + if (!ulib_has_main()) return; #endif main(); diff --git a/include/init.h b/include/init.h index 4e2155abb22..8a4e23403cc 100644 --- a/include/init.h +++ b/include/init.h @@ -392,6 +392,17 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); */ int ulib_init_with_data(char *progname, struct global_data *data); +/** + * ulib_has_main() - check whether an example main() is linked + * + * This weak function returns false by default. Example programs override it + * to return true so that U-Boot can set GD_FLG_ULIB and jump to main() after + * initialisation. + * + * Return: true if an example main() is present, false otherwise + */ +bool ulib_has_main(void); + /** * main() - main program called from ulib *