From patchwork Tue Oct 30 12:55:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 990842 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42ksRZ16lmz9s3l for ; Wed, 31 Oct 2018 00:16:09 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 9A602C220E1; Tue, 30 Oct 2018 13:04:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B134BC2211E; Tue, 30 Oct 2018 12:58:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E1106C2215E; Tue, 30 Oct 2018 12:57:31 +0000 (UTC) Received: from mail-edgeKA24.fraunhofer.de (mail-edgeka24.fraunhofer.de [153.96.1.24]) by lists.denx.de (Postfix) with ESMTPS id 45B9CC22135 for ; Tue, 30 Oct 2018 12:57:27 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2EcAAC/VNhb/xoBYJlkGwEBAQEDAQEBBwMBAQGBUwQBAQELAYIEgg2MbZZGjiCBeg2EbAKDJSI2Cw0BAwEBAgEBAgICaRwMhTwGJ00FEFEhNgYKBAWDIYFqAxQBqXoziAENghgJAYc3hCaBWD+BEAGFaIgDAoh9gWqTey4HAoEOgQQEi0mDHQsYgVKHaIcOiTmEPokvgUoCMIFVMxokgzuCJhcSgy+KWm4BiSoEgkkBAQ X-IPAS-Result: A2EcAAC/VNhb/xoBYJlkGwEBAQEDAQEBBwMBAQGBUwQBAQELAYIEgg2MbZZGjiCBeg2EbAKDJSI2Cw0BAwEBAgEBAgICaRwMhTwGJ00FEFEhNgYKBAWDIYFqAxQBqXoziAENghgJAYc3hCaBWD+BEAGFaIgDAoh9gWqTey4HAoEOgQQEi0mDHQsYgVKHaIcOiTmEPokvgUoCMIFVMxokgzuCJhcSgy+KWm4BiSoEgkkBAQ X-IronPort-AV: E=Sophos;i="5.54,444,1534802400"; d="scan'208";a="10904653" Received: from mail-mtaka26.fraunhofer.de ([153.96.1.26]) by mail-edgeKA24.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2018 13:57:27 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BRAACMVNhb/xBhWMBkHAEBAQQBAQcEAQGBUwUBAQsBg1c6jG2WRo4ggXoNhGwCg0Y2Cw0BAwEBAgEBAm0cDIU7BidNBRBRITYGCgQFgyGBagMVqXsziAENghgJAYc3hX4/gRABhWiIAwKIfYFqk3suBwKBDoEEBItJgx0LGIFSh2iHDok5hD6JL4FKAi+BVTMaJIM7giYXEoMvilo+MAGJKgSCSQEB X-IronPort-AV: E=Sophos;i="5.54,444,1534802400"; d="scan'208";a="16525694" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP12EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaKA26.fraunhofer.de with ESMTP/TLS/AES256-SHA; 30 Oct 2018 13:57:26 +0100 Received: from muc-nb-035.aisec.fraunhofer.de (10.80.233.51) by FGDEMUCIMP12EXC.ads.fraunhofer.de (10.80.232.43) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 30 Oct 2018 13:57:26 +0100 From: Lukas Auer To: Date: Tue, 30 Oct 2018 13:55:49 +0100 Message-ID: <20181030125553.5230-27-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181030125553.5230-1-lukas.auer@aisec.fraunhofer.de> References: <20181030125553.5230-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24188.007 X-TM-AS-Result: No--3.343800-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: Alexander Graf Subject: [U-Boot] [PATCH v2 26/29] riscv: align bootm implementation with that of other architectures X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The bootm implementation of RISC-V diverges from that of other architectures. Update it to match the implementation of other architectures. The ARM implementation is used as a reference. This adds the following features and changes to RISC-V. * Add support for the BOOTM_STATE_OS_FAKE_GO command * Call the remove function on devices with the removal flag set before booting Linux * Force disconnect USB devices from the host before booting Linux * Print and add bootstage information to the device tree before booting Linux Signed-off-by: Lukas Auer Reviewed-by: Bin Meng --- Changes in v2: - Rebase onto u-boot-dm/next arch/riscv/lib/bootm.c | 99 ++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index c1cf618806..4e349f5614 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include #include @@ -26,27 +28,41 @@ int arch_fixup_fdt(void *blob) return 0; } -int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) +/** + * announce_and_cleanup() - Print message and prepare for kernel boot + * + * @fake: non-zero to do everything except actually boot + */ +static void announce_and_cleanup(int fake) { - void (*kernel)(ulong hart, void *dtb); - - /* - * allow the PREP bootm subcommand, it is required for bootm to work - */ - if (flag & BOOTM_STATE_OS_PREP) - return 0; + printf("\nStarting kernel ...%s\n\n", fake ? + "(fake run for tracing)" : ""); + bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); +#ifdef CONFIG_BOOTSTAGE_FDT + bootstage_fdt_add_report(); +#endif +#ifdef CONFIG_BOOTSTAGE_REPORT + bootstage_report(); +#endif - if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) - return 1; +#ifdef CONFIG_USB_DEVICE + udc_disconnect(); +#endif - kernel = (void (*)(ulong, void *))images->ep; - invalidate_icache_all(); + board_quiesce_devices(); - bootstage_mark(BOOTSTAGE_ID_RUN_OS); + /* + * Call remove function of all devices with a removal flag set. + * This may be useful for last-stage operations, like cancelling + * of DMA operation or releasing device internal buffers. + */ + dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); - debug("## Transferring control to Linux (at address %08lx) ...\n", - (ulong)kernel); + cleanup_before_linux(); +} +static void boot_prep_linux(bootm_headers_t *images) +{ if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { #ifdef CONFIG_OF_LIBFDT debug("using: FDT\n"); @@ -55,24 +71,51 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) hang(); } #endif + } else { + printf("Device tree not found or missing FDT support\n"); + hang(); } +} - /* we assume that the kernel is in place */ - printf("\nStarting kernel ...\n\n"); +static void boot_jump_linux(bootm_headers_t *images, int flag) +{ + void (*kernel)(ulong hart, void *dtb); + int fake = (flag & BOOTM_STATE_OS_FAKE_GO); - /* - * Call remove function of all devices with a removal flag set. - * This may be useful for last-stage operations, like cancelling - * of DMA operation or releasing device internal buffers. - */ - dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); + kernel = (void (*)(ulong, void *))images->ep; + invalidate_icache_all(); - cleanup_before_linux(); + bootstage_mark(BOOTSTAGE_ID_RUN_OS); - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) - kernel(csr_read(mhartid), images->ft_addr); + debug("## Transferring control to Linux (at address %08lx) ...\n", + (ulong)kernel); - /* does not return */ + announce_and_cleanup(fake); - return 1; + if (!fake) { + if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) + kernel(csr_read(mhartid), images->ft_addr); + } +} + +int do_bootm_linux(int flag, int argc, char * const argv[], + bootm_headers_t *images) +{ + /* No need for those on RISC-V */ + if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) + return -1; + + if (flag & BOOTM_STATE_OS_PREP) { + boot_prep_linux(images); + return 0; + } + + if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { + boot_jump_linux(images, flag); + return 0; + } + + boot_prep_linux(images); + boot_jump_linux(images, flag); + return 0; }