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 6EA71C433FE for ; Wed, 26 Oct 2022 11:23:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5843085037; Wed, 26 Oct 2022 13:22:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=endlessos.org 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; unprotected) header.d=endlessos.org header.i=@endlessos.org header.b="H4lPt/sX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 70CF684EB6; Wed, 26 Oct 2022 09:14:18 +0200 (CEST) Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7CF4684E0E for ; Wed, 26 Oct 2022 09:14:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=endlessos.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jhp@endlessos.org Received: by mail-pg1-x535.google.com with SMTP id 20so13983125pgc.5 for ; Wed, 26 Oct 2022 00:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=endlessos.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nsHVmbnh5OgrxKHzrFyQ6VDdqQYambsg47doVGTc3OA=; b=H4lPt/sXNt3WIGB612DUa7r2pvKqvlxSVV1M73i55pnTC9+cPd5yObgwdezmF2JNX4 TkoMZu/dE1NSZsjlfB/JMnkkQXGziFsqEM0ksWyC0V3KlUrebHkYkULP1LuHIPQY7p1O Y6T3mWXRUajOlbfYYetIAVw3ZkTu53prmk6dtUnx1fhNX6Ql3g3lfdesAJ5BzRoTcdUV 82Lh+Y8tfdg5qRfJU+GtWVU2urpH2u1In9Kn8BU+HiwpnHDBinWifw/825R1kPXTbSpK zz1X6+J+WFdANKuy/nanhFzzKkpnYExUUR/0+yMnUnURtkthBlzdtyTMJsgK0bQMk/NC TYPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nsHVmbnh5OgrxKHzrFyQ6VDdqQYambsg47doVGTc3OA=; b=TfNPgVQOK2AmQ5FLsrUPxyVnlr3IzIKaxr2tR/edWNrNsqRmm01oXnUlw9wm9KOxS0 xyeeXVw6E1j87DLbehxosjpK11DZoMHGNWwsdeeGLU2UYpG120btk2KVdrgVYLYiNlMu ay7WWkrGodmUS+eLqVe1sPzyC0ShuM62GwxmvJ7eujaGcCbrx5I85gQ0rYapL7Kr2xDJ nAwS3Jqxkp1IMTI4q4qSQa2JvY6sySmFKpsCBlyos0E6/S6+IibtxRMp53jJ0V+m1uEl ZHJWV5QV8z1xnG5q8GTuJAK//SVpPJyjKcPSpQikcN2Jh4aH5k/TPh6VSY1erOjC/B+i A+uA== X-Gm-Message-State: ACrzQf0lcjhQHBHBmmmfztA/fAZHG1OIT832AfC6gg+LZgOPx1Q01tJt WNcHin5P0DJ43HkcNyEOiKZ3NUrYRPcYVMtnH47CDPScCRXwA5yK9bwpw/RYkS5noeNHpEVsHTz OpKM1pcbrwrg/EyCVWJTaZ1bdPDSRa7n1T7Ir/yxnXIUw01W/AkOAaw4qe1CdJm58 X-Google-Smtp-Source: AMsMyM64Jss+5CqgXa/YSQwT16KKrYnAWAktYPx+6npBzfFsGEz9JUjBCtyF1O9KLIZZpvtTr+ifag== X-Received: by 2002:a05:6a00:999:b0:56c:3d0d:96fe with SMTP id u25-20020a056a00099900b0056c3d0d96femr4647599pfg.12.1666768451264; Wed, 26 Oct 2022 00:14:11 -0700 (PDT) Received: from localhost.localdomain (112-104-91-247.adsl.dynamic.seed.net.tw. [112.104.91.247]) by smtp.googlemail.com with ESMTPSA id w10-20020a63af0a000000b0046ae818b626sm2274447pge.30.2022.10.26.00.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 00:14:10 -0700 (PDT) From: Jian-Hong Pan To: u-boot@lists.denx.de Cc: linux@endlessos.org, Ilya Katsnelson , Jian-Hong Pan Subject: [PATCH] rpi: copy the eMMC controller configuration from firmware-supplied DT Date: Wed, 26 Oct 2022 15:13:02 +0800 Message-Id: <20221026071301.31260-1-jhp@endlessos.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Wed, 26 Oct 2022 13:22:26 +0200 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 From: Ilya Katsnelson The RPi firmware adjusts the onboard eMMC controller's DMA mapping ranges of the FDT for each BCM2711 SoC revisions on the Pi 4 and RPi 400 automatically. If the following kernel does not boot with the correct eMMC controller's DMA mapping ranges, the system on the SD card will boot failed and show these error messages: mmc1: invalid bus width mmc1: error -22 whilst initialising SD card This patch carries the adjustment from RPi firmware to the new loaded FDT for the following kernel. Link: https://lists.denx.de/pipermail/u-boot/2021-September/462006.html Fixed: https://bugzilla.kernel.org/show_bug.cgi?id=213753 Signed-off-by: Ilya Katsnelson Signed-off-by: Jian-Hong Pan --- The code of this patch comes from "[RFC PATCH] rpi: copy the EMMC controller configuration from firmware-supplied DT" [1] basically. I only add the message and some modifcation: * Fix the build failed error: board/raspberrypi/rpi/rpi.c: In function 'copy_emmc_config': board/raspberrypi/rpi/rpi.c:553:9: warning: dereferencing 'void *' pointer 553 | *fw_value = fdt_getprop(fw_fdt, fw_emmc_node, "dma-ranges", &length); | ^~~~~~~~~ board/raspberrypi/rpi/rpi.c:553:19: error: invalid use of void expression 553 | *fw_value = fdt_getprop(fw_fdt, fw_emmc_node, "dma-ranges", &length); | ^ make[1]: *** [scripts/Makefile.build:258: board/raspberrypi/rpi/rpi.o] Error 1 * Replace "EMMC" to "eMMC". * Replace the printf with log_[levels]. So, I keep "Ilya Katsnelson " as the author. [1]: https://lists.denx.de/pipermail/u-boot/2021-September/462006.html 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 00afb352bd..d7ff8e269e 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -504,6 +504,67 @@ void *board_fdt_blob_setup(int *err) 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. + */ + 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) { + log_info("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) { + log_info("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) { + log_info("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) { + log_warning("RPi: Failed to set eMMC DMA ranges property in our DT: %d\n", result); + return; + } + + log_debug("RPi: successfully copied FW DT eMMC configuration to our DT!\n"); +} + int ft_board_setup(void *blob, struct bd_info *bd) { int node; @@ -518,5 +579,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) EFI_RESERVED_MEMORY_TYPE); #endif + copy_emmc_config(blob); + return 0; } -- 2.38.1