Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80457C6FA99 for ; Fri, 10 Mar 2023 20:52:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1F44685FC9; Fri, 10 Mar 2023 21:49:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="aufKgekQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9B98885FA5; Fri, 10 Mar 2023 21:49:25 +0100 (CET) Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A3BED85F94 for ; Fri, 10 Mar 2023 21:49:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12b.google.com with SMTP id k9so3642344ilu.13 for ; Fri, 10 Mar 2023 12:49:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678481356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZgReCh8ajl0zeHYgGX/Q7Vdr6V/572D9dmvcS1Vzzs0=; b=aufKgekQYJMr6P/EgmPv94WnMUdZQPjyWQ0hOv1cBEc1NGZh5I/c6LaEWc9Rnlie7+ ZK1ETmYMoQkO9UN5YNcG2Z+ntcira3ZGrgBt1J9eL5XMsZF+e4aiEqS/ITa56V0h2ddQ NkdtnTTmLQZ2VXK5ZzSQQ1S6VohWiNbFFqHVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678481356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZgReCh8ajl0zeHYgGX/Q7Vdr6V/572D9dmvcS1Vzzs0=; b=jNFC6CZWEe4dQawh6Z1wp/jsM0o9i3uHn/3rhSEGEE+G5voMaC5mfbWQJG4jFRKF3y p2/cYL5GnEgp0J7aoN+nK4mPWtLXZx8HjS+znIdekpWY64ssMyjcFcyJsUHd+raKJJ+g lxipZ6cw/fRpVPiAPOurp8XhWjNeebXFCqs4Yn1gvkHWS38ZxEbfo1Cm3zvfiz70B/S7 ci94kKe+V78mrio1lFcgs0kdcKK0GFH7aYabR/A6ZUAEKKtWaHBRmfZFO3F2Jyrrh4wP 2RMS3YHxVAGScGGtQRECXDdP4QOqIGel+WjdxVV4z+YaOu5y+MeZVLYoDup/7w1A1L9D 0Zhg== X-Gm-Message-State: AO0yUKXNaapcaSDAeYwkr3LNmIziOZzeM8FKZUI0U7R5NW9ZW5G1X6Bt i/dGKX59uKwxV/C8XW5waqa52VjIKX7vHMECLfE= X-Google-Smtp-Source: AK7set9IVaM7yNcS7hhg2K1Ysj1TswhezA+vIhcoqtpGp4M7uRZfJU2NhOl3+UcsmAlVKMVgkHfuVw== X-Received: by 2002:a92:5207:0:b0:316:e453:537c with SMTP id g7-20020a925207000000b00316e453537cmr7085785ilb.11.1678481356030; Fri, 10 Mar 2023 12:49:16 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id a7-20020a056e020e0700b00315785bfabfsm273817ilk.47.2023.03.10.12.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 12:49:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Simon Glass , Bin Meng Subject: [PATCH v2 04/12] x86: Support booting a 64-bit kernel from 64-bit U-Boot Date: Fri, 10 Mar 2023 12:48:54 -0800 Message-Id: <20230310204903.416969-5-sjg@chromium.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230310204903.416969-1-sjg@chromium.org> References: <20230310204903.416969-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add the missing code to handle this. For a 64-bit kernel the entry address is 0x200 bytes after the normal entry. Rename the parameter to boot_linux_kernel() accordingly. Update the comments to indicate that these are addresses, not pointers. Signed-off-by: Simon Glass --- (no changes since v1) arch/x86/include/asm/bootm.h | 12 ++++++------ arch/x86/lib/bootm.c | 25 +++++++++++++++++-------- arch/x86/lib/zimage.c | 15 +++++++++++++-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/bootm.h b/arch/x86/include/asm/bootm.h index 109f686f740..3b641783b9c 100644 --- a/arch/x86/include/asm/bootm.h +++ b/arch/x86/include/asm/bootm.h @@ -14,14 +14,14 @@ void bootm_announce_and_cleanup(void); * This boots a kernel image, either 32-bit or 64-bit. It will also work with * a self-extracting kernel, if you set @image_64bit to false. * - * @setup_base: Pointer to the setup.bin information for the kernel - * @load_address: Pointer to the start of the kernel image - * @image_64bit: true if the image is a raw 64-bit kernel, false if it - * is raw 32-bit or any type of self-extracting kernel - * such as a bzImage. + * @setup_base: Address of the setup.bin information for the kernel + * @entry: Address of the kernel entry point + * @image_64bit: true if the image is a raw 64-bit kernel, or a kernel + * which supports booting in 64-bit mode; false if it is raw 32-bit or any type + * of self-extracting kernel such as a bzImage. * Return: -ve error code. This function does not return if the kernel was * booted successfully. */ -int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit); +int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit); #endif diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index 873e2bc176f..9beb376bb9c 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -149,7 +149,7 @@ error: return 1; } -int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit) +int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit) { bootm_announce_and_cleanup(); @@ -161,14 +161,23 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit) puts("Cannot boot 64-bit kernel on 32-bit machine\n"); return -EFAULT; } - /* At present 64-bit U-Boot does not support booting a + /* + * At present 64-bit U-Boot only supports booting a 64-bit * kernel. - * TODO(sjg@chromium.org): Support booting both 32-bit and - * 64-bit kernels from 64-bit U-Boot. + * + * TODO(sjg@chromium.org): Support booting 32-bit kernels from + * 64-bit U-Boot */ -#if !CONFIG_IS_ENABLED(X86_64) - return cpu_jump_to_64bit(setup_base, load_address); -#endif + if (CONFIG_IS_ENABLED(X86_64)) { + typedef void (*h_func)(ulong zero, ulong setup); + h_func func; + + /* jump to Linux with rdi=0, rsi=setup_base */ + func = (h_func)entry; + func(0, setup_base); + } else { + return cpu_jump_to_64bit(setup_base, entry); + } } else { /* * Set %ebx, %ebp, and %edi to 0, %esi to point to the @@ -190,7 +199,7 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit) "movl $0, %%ebp\n" "cli\n" "jmp *%[kernel_entry]\n" - :: [kernel_entry]"a"(load_address), + :: [kernel_entry]"a"(entry), [boot_params] "S"(setup_base), "b"(0), "D"(0) ); diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index a6d9151c324..e5ea5129c1e 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -504,13 +504,24 @@ static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc, static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + struct boot_params *params = state.base_ptr; + struct setup_header *hdr = ¶ms->hdr; + bool image_64bit; + ulong entry; int ret; disable_interrupts(); + entry = state.load_address; + image_64bit = false; + if (IS_ENABLED(CONFIG_X86_RUN_64BIT) && + (hdr->xloadflags & XLF_KERNEL_64)) { + entry += 0x200; + image_64bit = true; + } + /* we assume that the kernel is in place */ - ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address, - false); + ret = boot_linux_kernel((ulong)state.base_ptr, entry, image_64bit); printf("Kernel returned! (err=%d)\n", ret); return CMD_RET_FAILURE; -- 2.40.0.rc1.284.g88254d51c5-goog