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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A13C8C433F5 for ; Thu, 30 Sep 2021 03:12:17 +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 CB73861452 for ; Thu, 30 Sep 2021 03:12:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CB73861452 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 51EF680F9D; Thu, 30 Sep 2021 05:12:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com 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; unprotected) header.d=suse.com header.i=@suse.com header.b="GfGjFxNB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 152E480FA5; Thu, 30 Sep 2021 05:12:11 +0200 (CEST) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) (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 F29DF80F5F for ; Thu, 30 Sep 2021 05:12:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mbrugger@suse.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1632971526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xt8CJX5ILXsTkWSPeVTxCT9EpC7E2WSG1TZH9iAwq3E=; b=GfGjFxNBYI++faZGx/unI0cPEEgw3bc+xldU6sCNZZ+7TQlddFvBQH7qNOe4FGtc4C6DjZ AV+eVozfj+FHp1WYBYZkwxxm7YVLrE4r/jXELy442ui48dV9XvSUhwMqvzyTzUtuVwlmuf ScS5RpBSmQMICCq7sYuST35dJ3nQKeo= Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2051.outbound.protection.outlook.com [104.47.4.51]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-14-6DacDDC-PwaZYDkx7isidg-1; Thu, 30 Sep 2021 05:12:05 +0200 X-MC-Unique: 6DacDDC-PwaZYDkx7isidg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I5iiDRKDrjY1163fbR0z3qmkP9eix8YbYuUewq3KmBAm917SO8JsBgXYHxjadKJwr1YaVwVAMC+RNC9KxUk1uy0tUq5pp9oO6yGhqHDBEAKU4eriqdcTdZEcCVRgwrKlt+Sz8SoNy4rEEe5AojRHFxVIQ6gb/olwq5ur5XmY9ipM1jmwNIRQ6O4BIWByLhEJae2atm+XqGo4dTIIMKBmPb3XygbJZWa05Qf2rI1vJQ1O+zOX5lWMqC6lF05o+zbZ2MnF7XprUJGErAbP4KCsc95XtmydMUiyqIxZHMgugSzUZGHhlaIPsZPkHamKJbGxXpiYpuD3Ypi0XZmRRmoltw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Xt8CJX5ILXsTkWSPeVTxCT9EpC7E2WSG1TZH9iAwq3E=; b=Oydi+rr3DFKkY68n/ZMu381VbvycVUd+fdyvudgXBrfgIrXEze/IoNdt+F03Cvh5xqhMsrgup0b1PACqioifv5nB5r4mTMO1NaHRZDWeJZ1rxiXkH2TUs/UnSivK0NAIFe75QKz74nUXybqUTEoEj0BCD4NayateuqKjv8kv2AW54EUyL30Ol63Po1QoFFHBs89Vbjx32knivD/hzB8JBsAHPKfLaR4rJowWwDBM7l/0NhRSAZ+zAegFjgpiTKfK7gzk75T5rovsXX+MrsixsWgr5ato2tIRYZ37THyvtbS3oIT4kLaIaHLLWavu7fMV1MhFSYHjlAJASiyJQEIdbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: foundries.io; dkim=none (message not signed) header.d=none;foundries.io; dmarc=none action=none header.from=suse.com; Received: from VI1PR04MB5375.eurprd04.prod.outlook.com (2603:10a6:803:ca::21) by VI1PR0401MB2255.eurprd04.prod.outlook.com (2603:10a6:800:29::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.18; Thu, 30 Sep 2021 03:12:02 +0000 Received: from VI1PR04MB5375.eurprd04.prod.outlook.com ([fe80::dc09:77f5:d9b6:52b7]) by VI1PR04MB5375.eurprd04.prod.outlook.com ([fe80::dc09:77f5:d9b6:52b7%7]) with mapi id 15.20.4566.015; Thu, 30 Sep 2021 03:12:02 +0000 Message-ID: <7cb7185d-1a2c-3f68-10d1-8d951e31b89b@suse.com> Date: Thu, 30 Sep 2021 05:11:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: Re: [PATCH] rpi: always set fdt_addr with firmware-provided FDT address Content-Language: en-US To: Ricardo Salveti Cc: Mauro Salvini , cschieli@gmail.com, u-boot@lists.denx.de References: <20210512123945.25649-1-m.salvini@koansoftware.com> <24facaf3-f3d1-c847-85c7-97f0b3a96091@koansoftware.com> <60d5991c-6d55-a6b8-5d47-cddebca0e4e1@suse.com> <50458790-5f2b-d551-530f-b6cf2a24d725@koansoftware.com> <220385b9-1ba3-d7aa-30ce-453bb1406f2b@koansoftware.com> From: Matthias Brugger In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6P192CA0106.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::47) To VI1PR04MB5375.eurprd04.prod.outlook.com (2603:10a6:803:ca::21) MIME-Version: 1.0 Received: from [192.168.2.177] (206.204.146.29) by AM6P192CA0106.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Thu, 30 Sep 2021 03:12:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9f5591e-bf27-47d0-54ce-08d983c01284 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2255: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KJLd3X8JaKfohHtgve1V9asqUYKvL+NhJZ54gTbYEIEUst4EcXlj66PULiCagesgA1lRF1+SEEPdYXz5nd/nRpQDfgNqCggIyPMhRQ0IngGbq88WWS1Q+I8LmwrTrI/3qVnlGWbYM7+C10VbcuNxf19Sxv7UCzk7o8FUMYb+fAxFb5SM0CBiWmSQYbC4dDtenwXfIeF0AMVhUDYyfzIuvQZz3apMp70PSdNYdN/ffsLnmB2wYB3iQnx/PS9dkeLEYapTP1mccqlEQiIyUFtNty9CoWRZPZAwcwe8G0iTvcr249mvZjBhLqe53DaEM3IOK+66q5P7W/sASKFZhFIZR+p0pblA//EqL1cwEm3kTJcdzd1QBjIW9EhifQZt5GucI0smQBJYcLTtnLVXW2NkGPVJSyntm1qP4b5AaA0qsIvuwgVgNuZFxUyJRF3K2Pm6aLu83hgY92qCozrii1wuagpDTSu7IeXSYMhQa1QANt1zb8w4G73eHl9Idbkm4Q/ynll0KhIjv4mWeFfJGBnT7Gr4qIrSjchqgO5ZI0tLK7+gG2v92NBh3EkYyOuPkZkyk2COI72vkTl6a0IoloHStOh6vEER97dyCgQIAMEtoYBdAjaaXOVRrc6mPmfX8Auk58jne8khXIx8E+btf5UCRbyQg2GXtKPpKIVfgBXD0r1e15a5h8FZSrpkoTQnIfuK7sCr7fD4DpRjQgB0P8tsB2kLGCguOHdyfDUUpQ4qyuQ+2wHwmOpgeKpzlYfMgrFHApJxOoRb3Jf2i6fup5Uor86rnGm0U7QZwiB1pUVVtVjF8qeARgVvGVDH3wpgI5xr X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5375.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(4326008)(16799955002)(956004)(31686004)(31696002)(6916009)(2616005)(83380400001)(6486002)(966005)(36756003)(2906002)(8936002)(8676002)(86362001)(66556008)(53546011)(316002)(38100700002)(5660300002)(508600001)(186003)(26005)(16576012)(66946007)(66476007)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OWJQWkxRVW9SMjlQdDhhNGZ2YnQ1TWMyb0t6M0F6aDVsT1JvQmdDSk80QU03?= =?utf-8?B?alQrUUFxVmRGdUZuMHNIZFRuWEE2SWxHcm1keHAyU1RKejRkNmJBb2FFUnhY?= =?utf-8?B?TzUrWGlxeVVoNzB6OE9OUmZvZ0p0M2xMczREczU1MVpHQVplTythemN5UWJr?= =?utf-8?B?eU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?utf-8?B?Tll0ZmYxQzVPcE93azd0bEN3YnlXUkpiSWJlZXh0WlJ3QUhOejFndXZUYkZX?= =?utf-8?B?U3F6Q1FDUkFMVktGYXBRWTJVeGYwbUFFa05veGZpNzZULytzZWkyblhQZjhs?= =?utf-8?B?QlpDRUlMRDRhZmhueDNVdmxZUnc0REt2RXNBZGc5Q2V6ME1LdXRVZDR4a3VT?= =?utf-8?B?ckl0b1h5ay8yTmx2Mi8rRkVocWxMUElyYmlabnpTMXBKV1R3a0dXc0lxRmpD?= =?utf-8?B?WDhZTDhEbGJyMnVydGlKdTNIMis2c2tmNVFKZXBuWHlXQlBFc0NVN0RtWGlE?= =?utf-8?B?bWZ3aitpakVqdEloMU9WTENaQ05EdUd1QjVVZ3hVS1hkUGR6eXRkWjNxTVpk?= =?utf-8?B?VDRLSmdxQ3p5dktMakhnVGUzZTVjVUluZVRseGdkTGovMmtobk8yUUtPRlpO?= =?utf-8?B?U3ZuUTQzM0h3MmtTNXdQejByVThVTU95TzVodjE2VUJyTHdITnZla3piY0NN?= =?utf-8?B?ekpvOUFaSy9NZmRhOC83Rk9mR0VGanhGS2V5Vm5QTWM0VzlHa3l4RldRTUty?= =?utf-8?B?UTljMHVXeUFITmNINTNpN0tybi9ZY1BYd3h4Yk1sZXRTLy9TQ2JEdzVTSXdO?= =?utf-8?B?N0ZSU2VoUWdqWWJHYm9EQnkvbHFxNnd0NHJRbnBEVE11UlIyZTk3bXVqVlJH?= =?utf-8?Q?yvPl0b8Qva+1/PdcfkFsHwOKsGbL1fkhuDjX1RJ?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9f5591e-bf27-47d0-54ce-08d983c01284 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5375.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2021 03:12:01.9136 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: D1P2Gbw2BquzeDWScEeccYyqOddhoJERdHqFEP9OAdik5Rfm+UK6asH5C7t7gGT45N5Heso6wqEo1gcigzd97A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2255 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 29/09/2021 23:05, Ricardo Salveti wrote: > On Wed, Sep 29, 2021 at 1:49 PM Matthias Brugger wrote: >> On 29/09/2021 14:19, Mauro Salvini wrote: >>> Hi Matthias, >>> >>> On 29/09/21 13:41, Matthias Brugger wrote: >>>> Hi Mauro, >>>> >>>> On 29/09/2021 12:14, Mauro Salvini wrote: >>>>> Hi Matthias >>>>> >>>>> On 15/09/21 13:16, mbrugger at suse.com (Matthias Brugger) wrote: >>>>>> Hi Mauro, >>>>>> >>>>>> On 07/06/2021 11:27, Mauro Salvini wrote: >>>>>>> On 12/05/21 14:39, Mauro Salvini wrote: >>>>>>>> Raspberry firmware prepares the FDT blob in memory at an address >>>>>>>> that depends on both the memory size and the blob size [1]. >>>>>>>> After commit ade243a211d6 ("rpi: passthrough of the firmware provided FDT >>>>>>>> blob") this FDT is passed to kernel through fdt_addr environment variable, >>>>>>>> handled in set_fdt_addr() function in board file. >>>>>>>> >>>>>>>> When u-boot environment is persistently saved, if a change happens >>>>>>>> in loaded FDT (e.g. for a new overlay applied), firmware produces a FDT >>>>>>>> address different from the saved one, but u-boot still use the saved >>>>>>>> one because set_fdt_addr() function does not overwrite the fdt_addr >>>>>>>> variable. So, for example, if there is a script that uses fdt commands for >>>>>>>> e.g. manipulate the bootargs, boot hangs with error >>>>>>>> >>>>>>>> libfdt fdt_check_header(): FDT_ERR_BADMAGIC >>>>>>>> >>>>>>>> Removing the fdt_addr variable in saved environment allows to boot. >>>>>>>> >>>>>>>> With this patch set_fdt_addr() function always overwrite fdt_addr value. >>>>>>>> >>>>>>>> [1] https://www.raspberrypi.org/forums//viewtopic.php?f=107&t=134018 >>>>>>>> >>>>>> >>>>>> First of all sorry for the very late reply. >>>>>> I'm hesitant to apply this patch, basically because it can break other setups >>>>>> where people load a custom DTB to fdt_addr. >>>>>> >>>>>> I wonder why you can't erase fdt_addr from your persistent storage. There is a >>>>>> command called eraseenv that should to the job. >>>>> >>>>> Sorry me too for the late reply. >>>>> >>>>> So your suggestion is to erase the fdt_addr variable from the environment >>>>> each time one needs to "refresh" it (one example could be the situation that >>>>> I ponted out). >>>>> >>>>> Yes, this could be the solution, but the need to delete the fdt_addr variable >>>>> when e.g. one changes the dtb loaded by rpi firmware should be documented >>>>> somewhere. >>>>> >>>> >>>> Hm, maybe I didn't understand the problem. My understanding is, that when you >>>> save the environment with saveenv, you also save the fdt_addr. And that's a >>>> problem because if you add a overlay later, the fdt_addr changed, which will >>>> not be reflected. So my question was if you couldn't just delete the fdt_addr >>>> variable from you saved environment so that when lateron you load overlays, >>>> you won't hit the problem. > >>>> My understanding was that you are setting a custom environment for your >>>> boards, but later your customers might add a overlay via e.g. config.txt and >>>> that will break booting the system. >>>> >>>> But from your response it seems thats not what you are experiencing. Or do you >>>> change the DTB loaded from FW in the U-Boot shell? >>> >>> >>> Maybe I wasn't too clear in my explanation ;-) >>> >>> At every boot, u-boot executes set_fdt_addr() function. At the very first boot, >>> if nobody has changed the default u-boot environment built in u-boot, adding a >>> custom fdt_addr variable, this function saves the fdt_addr variable in >> >> Which function are we talking about? Adding a custom fdt_addr can be done via >> the CLI or by adding that to the U-Boot sources (include/configs/rpi.h) but not >> through a 'function'. >> >> Do you mean that in some script you made saveenv is called? I used overlays in >> RPi and never had that problem. >> >> Actually I'm a bit puzzled about the problem. Can you give me a step by step >> reproducer, starting with which config I should use to compile U-Boot? > > Yes, this issue only happens if you save the environment at least > once, as then on following boots it won't set the address based on > what the firmware uses, but instead restore the value from the saved > environment, which can be wrong. > So can't we just delete the environment variable before saving the environment? Something like "env delete fdt_addr; saveenv" ? Regards, Matthias > I noticed the same when moving one sdcard between boards, and I was > only able to get it to boot correctly after removing the saved > environment. > > Cheers, >