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 1487DC001DE for ; Fri, 14 Jul 2023 21:38:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6CC3D857D5; Fri, 14 Jul 2023 23:38:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1689370711; bh=1pTRZkP6Bkb9ny+YLHPlBuREsaEGw5OBXzXwG1vhrJ4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JWdTePQeO/bFdIDLrttbMzhqPaRD3EZrPt4S34Dw7Wf3MsZZxGT3bxP4KsLtHHGBy ltRcaH3jURiFvSr62gjk7JjrxprrcOGXkvtlvDFcCQILpkvHt/GUqZDpJfFm/PxNKb ZJqxClg+V0zSBi46VXgxSx3VbI2lr+MyCLBGiR/IZmmgaE/VuD+g/SsTuEBuU2wCJ1 T3gZezH+SqQftYp8rBFYipwDNo4CZDoYtXsxXTfwH9Df6MWmAE93/49rvl1vF6k/NX odkT4I4VuGFEU+Mln+GdrScbaRGq6nbJ2GIlNyNLWZFshEdjrGAC1qFTNJoVSOV5hU b82cHCDPjEpmQ== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 1394184F74; Fri, 14 Jul 2023 23:38:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1689370707; bh=1pTRZkP6Bkb9ny+YLHPlBuREsaEGw5OBXzXwG1vhrJ4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Ua0mKDvI+/hp2qw+HAIe8tHpTc7T7l15ruGQPWv9d0Y5j7I2FxOEae2RSuUMuhaaV +1rak0fzLOhckptmyVwvLeL1Scm9wz65rnmhC8F8BceFrnvwk6BpWRUV5NusInR/Y4 OpxdG+L8kSspXep0Ma3OMuzln9jKy6nG43SINrg57GCK8pRrCEF8w1+ck97WIbkAbf 7AQ0I1HlzIWK7gjEDf8Iutf8pFMua7iMwQoI3V0q15SDis7J80Y9cDYwwjLdJU/kP8 lXGvOo2kKFG1gh/Ou4GE9fBfIgNwrUI9NWCDY0y+/AErQYwzbevRHp++9IELE19utQ pQUBzvzVNi9Mw== Message-ID: Date: Fri, 14 Jul 2023 23:27:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 1/3] apple: Set up file system firmware loader Content-Language: en-US To: Mark Kettenis , u-boot@lists.denx.de Cc: bmeng.cn@gmail.com References: <20230714204323.27220-1-kettenis@openbsd.org> <20230714204323.27220-2-kettenis@openbsd.org> From: Marek Vasut In-Reply-To: <20230714204323.27220-2-kettenis@openbsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 7/14/23 22:43, Mark Kettenis wrote: > Find the appropriate EFI system partition on the internal NVMe > storage and set the U-Boot environment variables such that > the file system firmware loader can load firmware from it. > > Signed-off-by: Mark Kettenis > --- > arch/arm/mach-apple/board.c | 60 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 60 insertions(+) > > diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c > index d501948118..7799a0f916 100644 > --- a/arch/arm/mach-apple/board.c > +++ b/arch/arm/mach-apple/board.c > @@ -8,6 +8,8 @@ > #include > #include > #include > +#include > +#include > > #include > #include > @@ -539,6 +541,60 @@ u64 get_page_table_size(void) > return SZ_256K; > } > > +static char *asahi_esp_devpart(void) > +{ > + struct disk_partition info; > + struct blk_desc *nvme_blk; > + const char *uuid = NULL; > + int devnum, len, p, part, ret; > + static char devpart[64]; > + struct udevice *dev; > + ofnode node; > + > + if (devpart[0]) > + return devpart; > + > + node = ofnode_path("/chosen"); > + if (ofnode_valid(node)) { > + uuid = ofnode_get_property(node, "asahi,efi-system-partition", > + &len); > + } > + > + nvme_scan_namespace(); > + for (devnum = 0, part = 0;; devnum++) { > + nvme_blk = blk_get_devnum_by_uclass_id(UCLASS_NVME, devnum); > + if (nvme_blk == NULL) > + break; > + > + dev = dev_get_parent(nvme_blk->bdev); > + if (!device_is_compatible(dev, "apple,nvme-ans2")) Can we somehow use ofnode_for_each_compatible_node() here ? That might simplify this code. > + continue; > + > + for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { > + ret = part_get_info(nvme_blk, p, &info); > + if (ret < 0) > + break; > + > + if (info.bootable & PART_EFI_SYSTEM_PARTITION) { > + if (uuid && strcasecmp(uuid, info.uuid) == 0) { > + part = p; > + break; > + } > + if (part == 0) > + part = p; > + } > + } > + > + if (part > 0) > + break; > + } > + > + if (part > 0) > + snprintf(devpart, sizeof(devpart), "%d:%d", devnum, part); > + > + return devpart; > +} > + > #define KERNEL_COMP_SIZE SZ_128M > > int board_late_init(void) > @@ -546,6 +602,10 @@ int board_late_init(void) > struct lmb lmb; > u32 status = 0; > > + status |= env_set("storage_interface", > + blk_get_uclass_name(UCLASS_NVME)); > + status |= env_set("fw_dev_part", asahi_esp_devpart()); I think env_set() returns integer (and this could be negative too), so you might want to check the return value instead of casting it to unsigned integer.