From nobody Mon Dec 23 22:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=flygoat.com ARC-Seal: i=1; a=rsa-sha256; t=1734913927; cv=none; d=zohomail.com; s=zohoarc; b=Lvt390NE5ixNLqe8wx1FW1+/y1TRwPDApAXf6XUcM2OAw78yO/zKyfCNWEDB7G/otAZ4Qpok8Lb8AQJeKxKMmeoDeCDAKpDaTLUHd0nqE7B4x40p7ZaCAhJeU7fHvf0rX8XN/M80LmvUzS2vPwB1CTW3DxXWR16v5MmX/HoysnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734913927; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sFkjPM6Ahyu09h+6QhdmM3ZEQFBsk+iSPjww6+WnRxk=; b=cC0GKHq1Ti94DaByPsLIsxVV/rQwFeOWeDkyGYOXwe5Xwy8pQMqdI7I40/uQuvfi1RAgXg4+iYbiW8N3cJdmBW7r7rkfP/mGE2ujPj5HB7rDK6PhjhWVvAg4QbaAAextLleh1X7mPSLo42mkuCuJsY/cFfxUkNuAM+8bF7vcP8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734913927617926.1322877168329; Sun, 22 Dec 2024 16:32:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPWLl-0007aH-Sv; Sun, 22 Dec 2024 19:31:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPWLj-0007Zj-RE for qemu-devel@nongnu.org; Sun, 22 Dec 2024 19:31:07 -0500 Received: from fout-b4-smtp.messagingengine.com ([202.12.124.147]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPWLe-0003Lm-Od for qemu-devel@nongnu.org; Sun, 22 Dec 2024 19:31:07 -0500 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id CFB5111400E4; Sun, 22 Dec 2024 19:31:00 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Sun, 22 Dec 2024 19:31:00 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 22 Dec 2024 19:30:59 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :subject:subject:to:to; s=fm3; t=1734913860; x=1735000260; bh=sF kjPM6Ahyu09h+6QhdmM3ZEQFBsk+iSPjww6+WnRxk=; b=QOtsVIjlU7D9MHINoN tbIPUK7+7OtAN7wCMfrpu+oWbHW3wNrWiNmiiMzqeibLnWmOqeXz7qJhXOA96yhv QlPP2YkpSzS8y9kWcNSWqaeNr2KGeR3ssOXXAlBqfKj6HPFYgiS8I4U0UohsI4WP mLo6e4D/yNyU4+6PyqhwKjDouYVvjDCB8CxrzMTUyZIWWsf7UoPagF11gCH6vkE0 ONT+/eLt6LP9vU4X8EFFEmtpzO+H/2D57LFs3PiONiAbMp88Lil/+qusgqgQDiyi G6nyZxhEUjsfYpvse+9gZvbVif5aDJuMVEazJ3xNGIOHe96Klspa5cXrDN055MEW mXuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1734913860; x=1735000260; bh=sFkjPM6Ahyu09h+6QhdmM3ZEQFBs k+iSPjww6+WnRxk=; b=xzWyLhWyakjJ4LRpW6BwyIfB6K4mOn2EZsqZaw0ufuq4 JU2ghFzfpyPOxW/FeTGV47McTk8PNOEBVcnSbZMu14w+5Z3wAndd2GjBaVP+KyXC KzjSMv/rmZ+rhgI3x9vZEf0UCk1gxaU0rjP/W5ljBld7rKHJMUzo8hZHO/TId9kc MZNac7dfyr/lRqz6i30X5k4IlJKnlGoWIkvgMdTiWz/G3ZXYU+pivBQgs5pWrdDV BlX0C1DioVhGfRd2/ONMWn2+t1upK4sgy1brhnJA2OR5uXLi21km+FFyvttru2eo wnZCAiSHLwNR6itayz32+krhVRcoOc6BES7Dh/YlDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddtledgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkffvvefosehtjeertdertdejnecu hfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgoh grthdrtghomheqnecuggftrfgrthhtvghrnhepleeigefhveefgeekvdffuddtteegkeek ffevffeigedvjeehffdvffffgfeifedvnecuffhomhgrihhnpegvfhhirdhsuhhpphhorh htpdhkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhnsg gprhgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmrghosghi sghosehlohhonhhgshhonhdrtghnpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnoh hnghhnuhdrohhrghdprhgtphhtthhopehjihgrgihunhdrhigrnhhgsehflhihghhorght rdgtohhmpdhrtghpthhtohepghgrohhsohhngheslhhoohhnghhsohhnrdgtnh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail From: Jiaxun Yang Date: Mon, 23 Dec 2024 00:30:58 +0000 Subject: [PATCH] hw/loongarch/boot: Support Linux raw boot image MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241223-la-direct-kernel-boot-v1-1-a79995d8b15e@flygoat.com> X-B4-Tracking: v=1; b=H4sIAEGvaGcC/x3MQQqDMBBG4avIrB0wg9bqVcSFjX/bQUlkIlIQ7 27o8lu8d1KCKRL1xUmGQ5PGkOHKgvx3Ch+wztkkldRORHideFaD33mBBaz8inFn33RPedStq9B SbjfDW3//7zBe1w2+vD+4ZwAAAA== X-Change-ID: 20241222-la-direct-kernel-boot-c598264710e7 To: qemu-devel@nongnu.org Cc: Song Gao , Bibo Mao , Jiaxun Yang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3980; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=7oK8b7rq/fD2GXyUApOzLkS1TwZEcDUnO5vv8AAlL0g=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhvSM9c6bdimYJ2c1ft4Q+MuNkSHK4WitwqRNpc73eANf6 R9LT/zfUcrCIMbFICumyBIioNS3ofHigusPsv7AzGFlAhnCwMUpABNZ1MjIsC+qpWnDhDwBu8w3 icZ6nkkfjvedeDl/T6lo5/Pl3n0zljEyPL9iz/JuywELmUw/6cM5Uuav5p/xCn9WW6td27fQfsp MXgA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=202.12.124.147; envelope-from=jiaxun.yang@flygoat.com; helo=fout-b4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @flygoat.com) X-ZM-MESSAGEID: 1734913929439116600 Many distros are shipping raw kernel images (i.e. vmlinux.efi). Support booting such image by parsing header as per Linux's specification [1]. [1]: https://docs.kernel.org/arch/loongarch/booting.html Signed-off-by: Jiaxun Yang --- It is based on my previous booting protocol patch --- hw/loongarch/boot.c | 45 +++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/loongarch/boot.h | 17 +++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c index 93847b0eaf8e50ce1a990b91267780e6785e1c2f..5bc889c51fafa9c6d37426b9bee= 9709c12183927 100644 --- a/hw/loongarch/boot.c +++ b/hw/loongarch/boot.c @@ -260,6 +260,43 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaqu= e, uint64_t addr) return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); } =20 +static int64_t get_linux_image_info(struct loongarch_boot_info *info, + uint64_t *kernel_entry, + uint64_t *kernel_low, + uint64_t *kernel_high) +{ + int fd; + struct loongarch_linux_hdr hdr; + int64_t kernel_size =3D -1; + + fd =3D open(info->kernel_filename, O_RDONLY | O_BINARY); + if (fd < 0) { + return -1; + } + + if (read(fd, &hdr, sizeof(hdr)) !=3D sizeof(hdr)) { + close(fd); + return -1; + } + + if ((le32_to_cpu(hdr.mz_magic) & 0xffff) !=3D MZ_MAGIC || + le32_to_cpu(hdr.linux_pe_magic) !=3D LINUX_PE_MAGIC) { + close(fd); + return -1; + } + + *kernel_entry =3D le64_to_cpu(hdr.kernel_entry); + /* Early kernel versions may have those fields in virtual address */ + *kernel_entry &=3D MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); + *kernel_low =3D le64_to_cpu(hdr.load_offset); + *kernel_low &=3D MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); + kernel_size =3D le64_to_cpu(hdr.kernel_size); + *kernel_high =3D *kernel_low + kernel_size; + + close(fd); + return kernel_size; +} + static int64_t load_kernel_info(struct loongarch_boot_info *info) { uint64_t kernel_entry, kernel_low, kernel_high; @@ -270,6 +307,14 @@ static int64_t load_kernel_info(struct loongarch_boot_= info *info) &kernel_entry, &kernel_low, &kernel_high, NULL, 0, EM_LOONGARCH, 1, 0); + if (kernel_size < 0) { + kernel_size =3D get_linux_image_info(info, &kernel_entry, + &kernel_low, &kernel_high); + if (kernel_size >=3D 0) { + kernel_size =3D load_image_targphys(info->kernel_filename, + kernel_low, kernel_size); + } + } =20 if (kernel_size < 0) { error_report("could not load kernel '%s': %s", diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h index 96ec15016a314499acf65c6c47e0c4932aa99d01..5e8bd4dd73bbb27abccfa1fa577= df52aed15b6a2 100644 --- a/include/hw/loongarch/boot.h +++ b/include/hw/loongarch/boot.h @@ -8,6 +8,23 @@ #ifndef HW_LOONGARCH_BOOT_H #define HW_LOONGARCH_BOOT_H =20 +/* Linux Image Format */ +#define LINUX_PE_MAGIC 0x818223cd +#define MZ_MAGIC 0x5a4d /* "MZ" */ + +struct loongarch_linux_hdr { + uint32_t mz_magic; + uint32_t res0; + uint64_t kernel_entry; + uint64_t kernel_size; + uint64_t load_offset; + uint64_t res1; + uint64_t res2; + uint64_t res3; + uint32_t linux_pe_magic; + uint32_t pe_header_offset; +} QEMU_PACKED; + /* UEFI 2.10 */ #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249 #define EFI_2_100_SYSTEM_TABLE_REVISION ((2<<16) | (100)) --- base-commit: c69612063e1844b76ac01e3a781b979548c3585c change-id: 20241222-la-direct-kernel-boot-c598264710e7 Best regards, --=20 Jiaxun Yang