From mboxrd@z Thu Jan 1 00:00:00 1970 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 57D12C4332F for ; Sun, 18 Dec 2022 14:21:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88E0685390; Sun, 18 Dec 2022 15:21:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=xs4all.nl header.i=@xs4all.nl header.b="OylS8BmG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D94D9851DF; Sun, 18 Dec 2022 15:21:12 +0100 (CET) Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8F90E851DF for ; Sun, 18 Dec 2022 15:21:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mark.kettenis@xs4all.nl X-KPN-MessageId: 1f362137-7edf-11ed-956b-005056aba152 Received: from smtp.kpnmail.nl (unknown [10.31.155.39]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 1f362137-7edf-11ed-956b-005056aba152; Sun, 18 Dec 2022 15:20:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=xs4all01; h=subject:to:from:message-id:date; bh=e8CPjmR/3LnhXs5HYQ3B0QtLjghW1fv24mxGSM8+pic=; b=OylS8BmGithrie1wrKEZdZo/IKZo0Na1AxLi7oPWGWI2TEAX3jLhsSGM2+r6/PYPCyGpnTLGyWkCD YhMvzqXfsYWPuYg3PV/GGwyICM4UJBL/Sg7Mq+yzWW4R2wYafiE11/bsz7CmuwSF1r6l86zcyYPf6w h8i7MtQ+Pipf3z8jzm/LWa74Ya88fFAXP84sZ398wBVzYanysNKwOZ3HGnYjUnuOCoOazvpVoA6USz SAzVLIpEaRkfUcvn9YDu8DMUHgL9DHAnxZiwE8WVSTmfA8Dt+VLeDKZBKPV+BaX4W5Ryr/Uh0CibXY l5yHt03xc2Jx2j/Ti83Y36KuGTstjnA== X-KPN-MID: 33|0aQObLdhd7hH85/3yJmmDYSjboPKCx/YELB/NbzmMFNP6UWEqFZz21LDL3G6R+e Ne7T4UhAUTKIUby6FIYR8sbOcoqB+VK3YSIAEsKURnTc= X-KPN-VerifiedSender: Yes X-CMASSUN: 33|ElMBIUF14hwQIdlKyCSJFEYeXl/EkwxCEmsTS0quFKC9VxU+FLK4+tAjaTbeWno A9cnM+3Loyhsnsid6OmIqTw== X-Originating-IP: 80.61.163.207 Received: from bloch.sibelius.xs4all.nl (80-61-163-207.fixed.kpn.net [80.61.163.207]) by smtp.xs4all.nl (Halon) with ESMTPSA id 36323022-7edf-11ed-ab4b-005056ab7447; Sun, 18 Dec 2022 15:21:07 +0100 (CET) Date: Sun, 18 Dec 2022 15:21:06 +0100 Message-Id: <878rj44wtp.fsf@bloch.sibelius.xs4all.nl> From: Mark Kettenis To: u-boot@lists.denx.de CC: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, sjg@chromium.org, marcan@marcan.st, j@jannau.net Subject: RFC: Handling of multiple EFI System Partitions 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.6 at phobos.denx.de X-Virus-Status: Clean The Asahi installer, which is what most people use to get their Apple Silicon Mac into a state where it is possible to install another OS on the machine, offers the posibility to create multiple OS installs. For each of these it creates a separate APFS partition (which holds among other things, some essential system firmware) and separate EFI System Partitions. This has a few benefits: * It allows control over which version of the system firmware is used by the OS. This is especially important for things like the GPU and DCP (display controller) firmware, where the firmware interface isn't exactly what we'd call "stable". This way system firmware is paired with the OS install (similar to what macOS does for itself) which prevents breaking other OS installs on the same disk. * It allows us to store a 2nd stage bootloader (m1n1+u-boot+dtb) on the EFI System Partition (ESP) such that it can be easily upgraded from within Linux without affecting other OS installs on the same disk. * It allows the use of the "native" boot picker to switch between OSes. The approach the Asahi team has taken is to pair the APFS partition with the ESP by adding a proprty that contains the partition UUID to the device tree. The installer ships u-boot with a patched distro boot script that looks at this device tree property, figures out what the right ESP is and loads the EFI bootloader (efi/boot/bootaarch64.efi) from that partition. This approach has some drawbacks: 1. U-Boot will still consider the first ESP as *the* ESP, which means that the ubootefi.var file is still read from and written from the first ESP. 2. The distro boot script modifications don't work if U-Boot's built-in efibootmgr is used. This probably also affects Simon's bootstd stuff. So my idea is to have U-Boot recognize the device tree property and use it when it determines what partition is *the* ESP. A proof of concept diff is attached below. This probably needs a bit of massaging as reading the device tree property in generic EFI code like this is probably not acceptable. A better approach might be to have a function that can be called from board-specific code that sets the UUID. Thoughts? Would such a feature be useful on other hardware platforms? commit 088f5626d4347cef76ad5a54477944886efb005a Author: Mark Kettenis Date: Sun Sep 25 01:57:24 2022 +0200 HACK: Use designated ESP Signed-off-by: Mark Kettenis diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 7ea0334083..86b867d319 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -523,6 +523,27 @@ static efi_status_t efi_disk_add_dev( desc->devnum, part); } } + + ofnode chosen_node; + const char *uuid = NULL; + chosen_node = ofnode_path("/chosen"); + if (ofnode_valid(chosen_node)) { + uuid = ofnode_read_string(chosen_node, + "asahi,efi-system-partition"); + } + + /* Store designated EFI system partition */ + if (part && uuid && strcmp(uuid, part_info->uuid) == 0) { + if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) { + efi_system_partition.uclass_id = desc->uclass_id; + efi_system_partition.devnum = desc->devnum; + efi_system_partition.part = part; + EFI_PRINT("EFI system partition: %s %x:%x\n", + blk_get_uclass_name(desc->uclass_id), + desc->devnum, part); + } + } + return EFI_SUCCESS; error: efi_delete_handle(&diskobj->header);