From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1okruJ-0007Mo-LT for mharc-grub-devel@gnu.org; Tue, 18 Oct 2022 15:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okruF-0007MZ-03 for grub-devel@gnu.org; Tue, 18 Oct 2022 15:05:40 -0400 Received: from ams.source.kernel.org ([145.40.68.75]:54176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okru8-0000XZ-Il for grub-devel@gnu.org; Tue, 18 Oct 2022 15:05:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 73512B82034; Tue, 18 Oct 2022 19:05:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3593C433C1; Tue, 18 Oct 2022 19:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666119920; bh=KXWEF0l8DM/hTYmC2LP7+scoTgaz9LbambAg/iWN3Yk=; h=From:To:Cc:Subject:Date:From; b=oENutfp6qFlXN/NpdwEtJgB4WP80PWneLky2cga3v6qpYWuHKUSbk0ZNj1QanIS0M wSAmZCLCgUFYnTtsvMR3FMQED8VXY0Orm1wfV/AgVmIWUsDl0XytApk8t/Fv3xgLA6 8J5QGhPSEwCpWhTnZ6juVdZx3Gtjmn/FBFsFesgb7NbNQDD2hlArXWDehIzfks8EOZ dOLyMyJUhjX1PS4vxJ94eJ37zlDWuR03c/5hRGGdlC3b23AI+q6vfHPcZQO1TqeW28 iPA3V6ayfJBiCqYZV6BHTQLtfv5MT3YdswBXTgpidD9/qVPD34jgqSl1S61V1DXFYa tIESVp9iv/DoQ== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: Ard Biesheuvel , Daniel Kiper , Leif Lindholm , Nikita Ermakov , Atish Patra , Huacai Chen , Heinrich Schuchardt , dann frazier , Julian Andres Klode , Ilias Apalodimas Subject: [PATCH v5 0/6] linux: implement LoadFile2 initrd loading Date: Tue, 18 Oct 2022 21:05:01 +0200 Message-Id: <20221018190508.177568-1-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3473; i=ardb@kernel.org; h=from:subject; bh=KXWEF0l8DM/hTYmC2LP7+scoTgaz9LbambAg/iWN3Yk=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjTvjYhHOOXPX2aphDPlmC+fWj0mxmohDtl6a1Pg8/ evEFsFCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY0742AAKCRDDTyI5ktmPJMTyC/ 9dfdQL9SJMHBOVhmFqigjtNxMXpSVa65/P7mkM82GFnSSjYPXBnaEvFtjBbtCllHMbr9iWjMbRSfuD JIpD9ddvxP9JcdAL2WysQY3WIK4LagbysI7D59q5Ovp3S1I8eNjP74a33FEYvD4N0Nre0JzB2aNQQb j7v+khRm/0yxsK7y4gob/7b+QNaIz3xUxVhdEMkKY1U8/nYxentTSQd+/WnFHgtE3t8/SpF1Qm9oF6 nJoQ3kgQs2PYz847ut+5V8kAid4af9+P0EdJLgJw/n0uHXXX70lwN/MhTstGBtuxQ7AGbUCCxJ68kA 8Jk5mGR4eoThCPjg0iFJheBRPSVBFb6aFLQi1bGi0m6dzXuyWJojhBupKQHFCFakBL2g5ZzE7yFjJ+ haN9X4ZmL6a2BCMNa+e5FbTwnPo1cwcSUomTucj0NaV92J2VpqIFYyNU6QbNRGepqm1+zYayGfhF27 i5/95qqu5LC+XwNi+ZRDHLmRs1xOYzE6PiumVeJSsfZXc= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=145.40.68.75; envelope-from=ardb@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -72 X-Spam_score: -7.3 X-Spam_bar: ------- X-Spam_report: (-7.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.256, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Oct 2022 19:05:41 -0000 This implements the LoadFile2 initrd loading protocol, which is essentially a callback interface into the bootloader to load the initrd data into a caller provided buffer. This means the bootloader no longer has to contain any policy regarding where to load the initrd (which differs between architectures and kernel versions) and no longer has to manipulate arch specific data structures such as DT or struct bootparams to inform the OS where the initrd resides in memory. This is especially relevant for the upcoming LoongArch support, which does not use either DT or struct bootparams, and would have to rely on the initrd= command line interface, which is deprecated and of limited utility [0]. Sample output from booting a recent Linux/arm64 kernel: grub> insmod part_msdos grub> linux (hd0,msdos1)/Image grub> initrd (hd0,msdos1)/initrd.img grub> boot EFI stub: Booting Linux Kernel... EFI stub: EFI_RNG_PROTOCOL unavailable EFI stub: Generating empty DTB EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path EFI stub: Exiting boot services... [ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070] Changes since v4: - incorporate review feedback from Daniel regarding whitespace and other minor style deviations Changes since v3: - drop a couple of patches that have been merged independently in the meantime - update patch #1 to read the PE image header offset from the file instead of using the harcoded offset - add acks from Heinrich and Ilias Changes since v2: - incorporate some ancient feedback from Daniel that I never saw until today. (this is why I am sending two versions of the same series on the same day - apologies for the spam) [0] The initrd= command line loader can only access files that reside on the same volume as the loaded image, which means GRUB would have to present this volume abstraction in order to serve the initrd file. Cc: Daniel Kiper Cc: Leif Lindholm Cc: Nikita Ermakov Cc: Atish Patra Cc: Huacai Chen Cc: Heinrich Schuchardt Cc: dann frazier Cc: Julian Andres Klode Cc: Ilias Apalodimas Ard Biesheuvel (6): efi: move MS-DOS stub out of generic PE header definition linux/arm: unify ARM/arm64 vs Xen PE/COFF header handling linux/arm: account for COFF headers appearing at unexpected offsets efi/efinet: Don't close connections at fini_hw() time efi: implement LoadFile2 initrd loading protocol for Linux linux: ignore FDT unless we need to modify it grub-core/commands/efi/lsefi.c | 1 + grub-core/kern/efi/efi.c | 8 +- grub-core/loader/arm64/linux.c | 173 ++++++++++++++++++-- grub-core/loader/arm64/xen_boot.c | 23 +-- grub-core/loader/efi/fdt.c | 7 +- grub-core/net/drivers/efi/efinet.c | 10 +- grub-core/net/net.c | 2 +- include/grub/arm/linux.h | 5 + include/grub/arm64/linux.h | 2 + include/grub/efi/api.h | 40 +++++ include/grub/efi/efi.h | 4 +- include/grub/efi/pe32.h | 16 +- include/grub/net.h | 3 +- 13 files changed, 246 insertions(+), 48 deletions(-) -- 2.35.1