From patchwork Wed Sep 29 06:47:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: K900 X-Patchwork-Id: 1534322 X-Patchwork-Delegate: matthias.bgg@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=0upti.me header.i=@0upti.me header.a=rsa-sha256 header.s=mail header.b=LxOtNgdy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKDhb3yxzz9tkD for ; Wed, 29 Sep 2021 21:30:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 19C878281E; Wed, 29 Sep 2021 13:30:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=0upti.me 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; secure) header.d=0upti.me header.i=@0upti.me header.b="LxOtNgdy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B45FE8281E; Wed, 29 Sep 2021 08:48:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F0917805DF for ; Wed, 29 Sep 2021 08:47:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=0upti.me Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=me@0upti.me Received: from sas1-4f6d6a97a84a.qloud-c.yandex.net (sas1-4f6d6a97a84a.qloud-c.yandex.net [IPv6:2a02:6b8:c08:f310:0:640:4f6d:6a97]) by forward106p.mail.yandex.net (Yandex) with ESMTP id 0A2532FC2492; Wed, 29 Sep 2021 09:47:58 +0300 (MSK) Received: from sas2-34ddad429748.qloud-c.yandex.net (2a02:6b8:c08:b787:0:640:34dd:ad42 [2a02:6b8:c08:b787:0:640:34dd:ad42]) by sas1-4f6d6a97a84a.qloud-c.yandex.net (mxback/Yandex) with ESMTP id X1WT7Igtfb-lvDurvnF; Wed, 29 Sep 2021 09:47:57 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0upti.me; s=mail; t=1632898077; bh=W6LAjUl4wWAUTkdEohaQcE6zKKuduCAXFPO+/fGBsXE=; h=Message-Id:Date:Subject:To:From:Cc; b=LxOtNgdyJ+7YgarJTdGqfRnXQ+dr4Z2YZ1oJFMIvvVB4rcMmriToY1Qww+yO4KIql 7WEqAKGe4E8ri9j/E6AAL4GiSQq7Aqy/fRQ85px/ZyigpogoDAVst7Ezn5B6cpo19u mD0bHsDWLb2tpl6JEEYhKOQ+Zt0gGvWHfoW4OQdI= Authentication-Results: sas1-4f6d6a97a84a.qloud-c.yandex.net; dkim=pass header.i=@0upti.me Received: by sas2-34ddad429748.qloud-c.yandex.net (smtp/Yandex) with ESMTPS id GCvHBEfwEL-lvFG76n7; Wed, 29 Sep 2021 09:47:57 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: K900 To: Cc: K900 , Matthias Brugger , Nicolas Saenz Julienne , Peter Robinson , "Ivan T. Ivanov" , Marek Szyprowski , u-boot@lists.denx.de Subject: [RFC PATCH] rpi: copy the EMMC controller configuration from firmware-supplied DT Date: Wed, 29 Sep 2021 09:47:50 +0300 Message-Id: <20210929064750.10188-1-me@0upti.me> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 29 Sep 2021 13:30:47 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean We need this to boot with a custom DTB on BCM2711C0-based Pi 4s Signed-off-by: Ilya Katsnelson --- board/raspberrypi/rpi/rpi.c | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 372b26b6f2..f074540091 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -495,6 +495,67 @@ void *board_fdt_blob_setup(void) return (void *)fw_dtb_pointer; } +void copy_emmc_config(void *our_fdt) +{ + /* + * As of 2021-09-28, the Pi 4 has two different revisions, one using a + * B0 stepping of the BCM2711 SoC, and one using a C0 stepping. + * + * The two SoC versions have different, incompatible DMA mappings for + * the on-board eMMC controller, which would normally make them require + * two different DTs. + * + * Unfortunately for us, the different revisions don't actually _use_ + * different DTs - instead, the proprietary stage0 bootloader reads the DT, + * patches it in-memory, then passes the corrected DT to the OS. + * + * In our case, the OS is actually U-Boot, and U-Boot can choose to + * completely disregard the firmware-supplied DT and load a custom one + * instead, which is used by, e.g., NixOS. + * + * When that happens, the DT patches applied by the firmware are also + * thrown out, which leads to BCM2711C0 boards being unable to boot + * due to them trying to use the hardcoded DMA mappings in the DT + * (which are for the B0 revision). + * + * Work around that by manually copying the DMA region setup from the + * firmware-provided DT into whatever DT we're actually being asked + * to load. + A*/ + void *fw_fdt = (void *)fw_dtb_pointer; + int fw_emmc_node; + int our_emmc_node; + int length; + const void *fw_value; + int result; + + fw_emmc_node = fdt_path_offset(fw_fdt, "emmc2bus"); + if (fw_emmc_node < 0) { + printf("RPi: Failed to find EMMC config in FW DT: %d\n", fw_emmc_node); + return; + } + + our_emmc_node = fdt_path_offset(our_fdt, "emmc2bus"); + if (our_emmc_node < 0) { + printf("RPi: Failed to find EMMC config in our DT: %d\n", our_emmc_node); + return; + } + + *fw_value = fdt_getprop(fw_fdt, fw_emmc_node, "dma-ranges", &length); + if (!fw_value) { + printf("RPi: Failed to get EMMC DMA ranges property from FW DT: %d\n", length); + return; + } + + result = fdt_setprop(our_fdt, our_emmc_node, "dma-ranges", fw_value, length); + if (result != 0) { + printf("RPi: Failed to set EMMC DMA ranges property in our DT: %d\n", result); + return; + } + + printf("RPi: successfully copied FW DT EMMC configuration to our DT!\n"); +} + int ft_board_setup(void *blob, struct bd_info *bd) { int node; @@ -509,5 +570,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) EFI_RESERVED_MEMORY_TYPE); #endif + copy_emmc_config(blob); + return 0; }