From patchwork Fri Oct 19 22:07:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 987080 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 42cL5x52nvz9t0P for ; Sat, 20 Oct 2018 09:23:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 67D68C21DFF; Fri, 19 Oct 2018 22:12:39 +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=none 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 6562CC21D9A; Fri, 19 Oct 2018 22:11:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 30548C21DDC; Fri, 19 Oct 2018 22:11:17 +0000 (UTC) Received: from mail-edgeDD24.fraunhofer.de (mail-edgeDD24.fraunhofer.de [192.102.167.24]) by lists.denx.de (Postfix) with ESMTPS id B8055C21DDC for ; Fri, 19 Oct 2018 22:11:13 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2EGAACcVcpb/xwBYJlkGgEBAQEBAgEBAQEHAgEBAQGBUQUBAQEBCwGCBIFTOowNX4s7mRyBeg2EbAKFCSE0DQ0BAwEBAgEBAgICaSiFPAYnTQUQUT0aBgoEBYMhggEBqEwzihoJAYcihCOBWD+BEAGNagKIbZVUBwKBDYEBBI5PCxeBT4dchn6JI40vgUM5gVUzGiSDO4ImF44cbQGJVwSCSQEB X-IPAS-Result: A2EGAACcVcpb/xwBYJlkGgEBAQEBAgEBAQEHAgEBAQGBUQUBAQEBCwGCBIFTOowNX4s7mRyBeg2EbAKFCSE0DQ0BAwEBAgEBAgICaSiFPAYnTQUQUT0aBgoEBYMhggEBqEwzihoJAYcihCOBWD+BEAGNagKIbZVUBwKBDYEBBI5PCxeBT4dchn6JI40vgUM5gVUzGiSDO4ImF44cbQGJVwSCSQEB X-IronPort-AV: E=Sophos;i="5.54,401,1534802400"; d="scan'208";a="7272595" Received: from mail-mtaka28.fraunhofer.de ([153.96.1.28]) by mail-edgeDD24.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Oct 2018 00:11:13 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AjAAAHVspb/xBhWMBkHAEBAQQBAQcEAQGBUQcBAQsBhBGMDV+kV4F6DYRsAoUpNA0NAQMBAQIBAQJtKIU7BidNBRBRPRoGCgQFgyGCAqhIM4obCQGHIoV7P4EQAY1qAohtlVQHAoENgQEEjk8LF4FPh1yGfokjjS+BQziBVTMaJIM7giYXjhw9MAGJVwSCSQEB X-IronPort-AV: E=Sophos;i="5.54,401,1534802400"; d="scan'208";a="18910120" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP11EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaKA28.fraunhofer.de with ESMTP/TLS/AES256-SHA; 20 Oct 2018 00:11:07 +0200 Received: from localhost.de (10.80.233.50) by FGDEMUCIMP11EXC.ads.fraunhofer.de (10.80.232.42) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sat, 20 Oct 2018 00:12:25 +0200 From: Lukas Auer To: Date: Sat, 20 Oct 2018 00:07:41 +0200 Message-ID: <20181019220743.15020-29-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181019220743.15020-1-lukas.auer@aisec.fraunhofer.de> References: <20181019220743.15020-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24166.002 X-TM-AS-Result: No--3.798300-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: Alexander Graf , Greentime Hu Subject: [U-Boot] [PATCH 28/30] 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 --- arch/riscv/lib/bootm.c | 94 ++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 22 deletions(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index bc1d4b2864..b4e18a768a 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include #include @@ -24,27 +26,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"); @@ -53,17 +69,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); - cleanup_before_linux(); + kernel = (void (*)(ulong, void *))images->ep; + invalidate_icache_all(); + + bootstage_mark(BOOTSTAGE_ID_RUN_OS); + + debug("## Transferring control to Linux (at address %08lx) ...\n", + (ulong)kernel); + + announce_and_cleanup(fake); + + if (!fake) { + if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) + kernel(csr_read(mhartid), images->ft_addr); + } +} - 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; - /* does not return */ + if (flag & BOOTM_STATE_OS_PREP) { + boot_prep_linux(images); + return 0; + } - return 1; + 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; }