Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B11CC07E99 for ; Mon, 12 Jul 2021 15:51:35 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8318261221 for ; Mon, 12 Jul 2021 15:51:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8318261221 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 35FCC82C09; Mon, 12 Jul 2021 17:51:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (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=1626105092; bh=QyO6xr+mG0gEVqgwkcP7pQnE/aki1FIVg8sucnQHr34=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HtqKP+9cNfZlxfq/IWdAX+yPJUD3tSosxhCe0Il+QzXteUN4tcRNTkFA4nrqY2YW+ WjCa/xQukfOQnwfSC3et9FnXXZWf+UZ48jc5JOnA961czTf+nHMNwaqx/AfAELVyK2 1ZOafSA/ybJ25wR5ilfT5ugRy1nwJ61wQzbrZBTQaOeelYErDNS6tBzXiP8mVlafb/ m8UJLObbmH9eESCbk/lcJ0xJsGbVSCFVU3vfGsGSYBulzSDdNEluHZPx5kKVmM8jl7 SDSi91rlpmZ5TLpqzFN1+OJMNP/kUezGKdcZCOw2v8N0k+KJie4PayE2gbm+UNfNBf CH/06Zot8pnlw== Received: from [IPv6:::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 63C9D82C04; Mon, 12 Jul 2021 17:51:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1626105090; bh=QyO6xr+mG0gEVqgwkcP7pQnE/aki1FIVg8sucnQHr34=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=dNdg5cs28J3sr5MFaFmEjG8yiOnMv8Er9PzUrjSJcLfUoPwwZ8dVIlRSaor5MBsL0 7Rpk8i1pIcfylbIs8Vqqhxa81Ah+VnB+tYXrjbg7U07BSPzjTvhPdFzrnd618pZNDT bthLOhHYWZlSzfTTejeOgdaXgtZ8RPnP8Y2Kol7B1GmE32tE9Uwp8CrNBrAWLpsyx2 OaqyQ1QAPR2idKVuq5pgrD/6xoVjUATF5VZ+RYvNxTCoghuR/iI5546+6GeYiFqqeH cchj9gmzaQSSg0TmYsza5BlZzn/QeJFRwQxhk61NyVdMo05oZmGCLqAIK/zjNAMAjK 1kEwrQ6sto3vg== Subject: Re: [PATCH] spl: Align device tree blob address at 8-byte boundary To: Tom Rini Cc: Bin Meng , Reuben Dowle , Simon Glass , "u-boot@lists.denx.de" References: <20210712035231.26475-1-bmeng.cn@gmail.com> <58187afcb4aa481a8302777aca599fa7@4rf.com> <20210712151510.GT9516@bill-the-cat> <1fed7815-de64-27b4-77ed-4e888fb882da@denx.de> <20210712154316.GX9516@bill-the-cat> From: Marek Vasut Message-ID: Date: Mon, 12 Jul 2021 17:51:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210712154316.GX9516@bill-the-cat> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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 On 7/12/21 5:43 PM, Tom Rini wrote: > On Mon, Jul 12, 2021 at 05:38:33PM +0200, Marek Vasut wrote: >> On 7/12/21 5:15 PM, Tom Rini wrote: >>> On Mon, Jul 12, 2021 at 01:36:14PM +0800, Bin Meng wrote: >>>> On Mon, Jul 12, 2021 at 1:21 PM Reuben Dowle wrote: >>>>> >>>>> I submitted an almost identical patch. See https://github.com/u-boot/u-boot/commit/eb39d8ba5f0d1468b01b89a2a464d18612d3ea76 >>>>> >>>>> This patch eventually had to be reverted (https://github.com/u-boot/u-boot/commit/5675ed7cb645f5ec13958726992daeeed16fd114), because it was causing issues on some platforms that had FIT on 32 bit boundary. However I continue to use it in production code, as without it the boot on my platform aborts. >>>>> >>>>> I don't have time to investigate why this was happening, but you need to check this code won't just cause exactly the same faults. >>>> >>>> Thanks for your information. >>>> >>>> +Marek who did the revert >>>> >>>> The revert commit message says: >>>> >>>> "The commit breaks booting of fitImage by SPL, the system simply >>>> hangs. This is because on arm32, the fitImage and all of its content >>>> can be aligned to 4 bytes and U-Boot expects just that." >>>> >>>> I don't understand this. If an address is aligned to 8, it is already >>>> aligned to 4, so how did this commit make the system hang on arm32? >>> >>> I think this had something to do with embedding contents somewhere in >>> the image? There is a thread on the ML from then but I don't know how >>> informative it will end up being. >> >> If I recall this correctly, DT node alignment is 4 byte and that is what DTC >> emits. If you have fitImage with embedded data, you basically end up with >> >> / { >> prop1 = "string1"; >> prop2 = "string2"; >> }; >> >> where the "string2" is aligned to 4 bytes. And that is what U-Boot expects >> when it tries to access those data in-place in SPL. >> >> The problem with the reverted patch was that it made U-Boot assume the >> alignment is 8 bytes, and that actually works only if you use fitImage with >> external data (mkimage -E), but with embedded data (mkimage default) not so >> much. That caused off-by-4 error in some cases and that made the SPL hang. >> >>>> Note, as I indicated in this patch, now with libfdt 1.6.1, the >>>> alignment to 8 byte is a must-have. So we have to do such alignment >>>> anyway. >>>> >>>> @Tom may fill in why libfdt commit commit 5e735860c478 ("libfdt: Check >>>> for 8-byte address alignment in fdt_ro_probe_()") was made to have the >>>> 8-byte alignment requirement. >>> >>> Note that it's not so much since libfdt 1.6.1 but that since always the >>> device tree has required 8 byte alignment. >> >> DT alignment was always 4 byte , no ? > > I'm pretty sure, no, 8 byte base alignment is a pretty much always > thing. I don't have a reference handy but I also know I couldn't have > convinced dgibson to add the check otherwise. DTSpec rev 0.3 says the following and I think you got confused by section 5.6 which talks about alignment of the entire tree, not its nodes: 5.4 Structure Block " Each token in the structure block, and thus the structure block itself, shall be located at a 4-byte aligned offset from the beginning of the devicetree blob (see 5.6). " 5.4.2 Tree structure " For each property of the node: ... – FDT_PROP token ... * [zeroed padding bytes to align to a 4-byte boundary] " 5.5 Strings Block " The strings block contains strings representing all the property names used in the tree. These null terminated strings are simply concatenated together in this section, and referred to from the structure block by an offset into the strings block. The strings block has no alignment constraints and may appear at any offset from the beginning of the devicetree blob. " 5.6 Alignment " As described in the previous sections, the structure and strings blocks shall have aligned offsets from the beginning of the devicetree blob. To ensure the in-memory alignment of the blocks, it is sufficient to ensure that the devicetree as a whole is loaded at an address aligned to the largest alignment of any of the subblocks, that is, to an 8-byte boundary. "