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 C3B08C67871 for ; Thu, 27 Oct 2022 06:27:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 510B585078; Thu, 27 Oct 2022 08:27:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="hfTP4d31"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AA36685072; Thu, 27 Oct 2022 08:27:29 +0200 (CEST) Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) (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 E2BD185078 for ; Thu, 27 Oct 2022 08:27:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pbrobinson@gmail.com Received: by mail-lf1-x12a.google.com with SMTP id d6so784762lfs.10 for ; Wed, 26 Oct 2022 23:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PjLVgCl8Hu38h2GcZalNrpEzkjR14yZYKV2HMgWSsjk=; b=hfTP4d31PnrM9Hi6sXAveHfFv3FrtlEBTPFvy+NfSolGRHKssxT/mwnT0eRdY9s3oZ HHTxkRJ44eJClr1FIAdfywliNHd0BWJjdCYE3EesMUSPN5/lW6dV80H/+/RIyDR7C/4o MiqpSfwHJqjAksMubLIcVO5AxDxaDYFJsrqSwYA15HWqX2Y2PHeqDvOC1RDa6wXe43bb /MklW9gP1KcaTwxN8l/6VRtlaU/5vQvD9ulz1ZN4DVB5DaGOP4BmvySU+yYUboZMR/ri TvJbTrMiyWQWLU7XTBTGesW9Gu0mZDyucONYmCVUXu5cpjvp/unRRgvdOeEeuqfVKjrl nJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PjLVgCl8Hu38h2GcZalNrpEzkjR14yZYKV2HMgWSsjk=; b=SZ/plWi//hwA58dA+88LHE+E03TNtwbFC3pt0KViCZZYCGTL9n3qMSOnsNYN9njdxK YQfx76j9klxDbHcmaE1qc7o+nmPdbi6dH/PrGH+eaq+3954aJkxLB6SZZuw2E/2CgIu5 lL7Zs3MGQ9syCCVORipdHyR5CfJPOGISgOj+AgNJ/Uukt5fGqOgxBFXOfrUC4+vOfE1q yVSThEDBbeYSdW5rHHmHhpHiBiHoeBO90Lfbc689pzzSAzQfvtx5WcQTRUjz3wooiNB6 4RUvAzxaHFVeQvCWEV8ZXEWo5QO/xcS1fILyFdElVKvFt11FfI5CikCgDvbPQUqYWs5X 2OvA== X-Gm-Message-State: ACrzQf04FgsLwWXcqvjAr7ohyknCZYSaBWuxHgEY97XdNgzVm15N8jJz DENi8Y6Hrj9je2IfJuEvoGKZJXYEbxKgcGiXooc= X-Google-Smtp-Source: AMsMyM5lpuLV37e6C4kw4e5pplmircbSMBE21MUDMeVnEkG1xmQ/WYmTPwR1fEggx9V/lCGF36vAQm2In0QFht2kBJw= X-Received: by 2002:ac2:54b9:0:b0:4a2:9c69:ab51 with SMTP id w25-20020ac254b9000000b004a29c69ab51mr19461379lfk.297.1666852046061; Wed, 26 Oct 2022 23:27:26 -0700 (PDT) MIME-Version: 1.0 References: <20221026071301.31260-1-jhp@endlessos.org> In-Reply-To: <20221026071301.31260-1-jhp@endlessos.org> From: Peter Robinson Date: Thu, 27 Oct 2022 07:27:14 +0100 Message-ID: Subject: Re: [PATCH] rpi: copy the eMMC controller configuration from firmware-supplied DT To: Jian-Hong Pan , Matthias Brugger Cc: u-boot@lists.denx.de, linux@endlessos.org, Ilya Katsnelson Content-Type: text/plain; charset="UTF-8" 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 Adding Matthias as the RPi maintainer. There was also this patch series which fixed it and a few other things from the firmware DT [1] which is likely a better fix TBH. Either way Matthias can we get one of these upstream as even the RPi4 Model B has moved to the newer rev of the SoCs so it's not a nice experience for users if they're not aware of the differences/problems. Peter [1] https://lists.denx.de/pipermail/u-boot/2022-August/491455.html On Wed, Oct 26, 2022 at 12:23 PM Jian-Hong Pan wrote: > > 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 >