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 2ACD2C433EF for ; Fri, 15 Apr 2022 17:28:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 59D198390C; Fri, 15 Apr 2022 19:28:34 +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="FrQ/9MIk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A2FBC83894; Fri, 15 Apr 2022 19:28:32 +0200 (CEST) Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (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 90AE38390C for ; Fri, 15 Apr 2022 19:28:28 +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=macroalpha82@gmail.com Received: by mail-oi1-x235.google.com with SMTP id z2so4542995oic.6 for ; Fri, 15 Apr 2022 10:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=81EVLHIcX9JHcO4/r6FpDYf5BOnvm6rhnSyyxj5tzKM=; b=FrQ/9MIkZU/FM0LzkPi2vsrNlpgkS7zB132BRJbVi6nceE+Dtes6QQBWho/cAmbPoI opbLwPW0Ca9bVvdhg2x1QkqrwEDCygvTMGxvG8lI5uBkH5AU969P7ROCrocnslhw2YOm /v6XUMwSAArH5acTJs3DPBf2MgjQ1W3aLcoXE/XppmQ58z/lpvMs075ljwLg3P3vx+fu sK6G17zl0PfKpY3bxlDZySVdFuAj/9YFn+SKJe3/QNaywLpaxt0BkxgAGUS/MckWCmS9 pz3QXtnReC+T3wuhsGU/nOPgDgJV30NTdRiF66jbkgRFQK8T+hF4ogmV8WSlcK2prU56 M6LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=81EVLHIcX9JHcO4/r6FpDYf5BOnvm6rhnSyyxj5tzKM=; b=LB6f7kXs0NmjYCQLtNrE3/FDBO91twizimPZrTcKkIQqbL4ejAMHP+if/eCVnQ6qj/ AJrFEDb0sSGibPooXTEesdPZZsJwrw+zOwabTzLfaxdv6+zKrrMSdfy5nY3lV/X5d4zp pUu4rOn28G7SUOKPu7LdN3y9wcM3OMlH62DC28vQ7yrjtQT/4OpaiKpXPYLUNn8Am3Hu ax3hifZ7ndyncMBXdCI/zT5/MSoA5Hvfl5RvXiJ9dn1f3ID8rOiat6Lr7EtmbeHazUkd r4DGHq27fNJZX3nMSR9qySYHsb5urTzT/NeQaM/42FmkdlkjB+Id8jr9RGc12EdQzKOt nt6g== X-Gm-Message-State: AOAM532dvIilYgYzexp6PO/TsxVBZ64A9tlx6xuQtj5zT/XZ9OzVk6WX 2ufft/7BwJlNXdGlPL3cp/o= X-Google-Smtp-Source: ABdhPJx72opyynYhwAaxANjaHpJdfrYsyqVvXNEZ2H9dRdDxP/El3TAKY1q3MdRipnHj9WxwmFBrbQ== X-Received: by 2002:a05:6808:1451:b0:2ec:cfe4:21e with SMTP id x17-20020a056808145100b002eccfe4021emr2144578oiv.147.1650043707282; Fri, 15 Apr 2022 10:28:27 -0700 (PDT) Received: from wintermute.localdomain (cpe-76-183-134-35.tx.res.rr.com. [76.183.134.35]) by smtp.gmail.com with ESMTPSA id v17-20020a9d69d1000000b005b2319a08c4sm1239664oto.18.2022.04.15.10.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 10:28:26 -0700 (PDT) Date: Fri, 15 Apr 2022 12:28:22 -0500 From: Chris Morgan To: Andre Przywara Cc: Jagan Teki , Simon Glass , Tom Rini , Chen-Yu Tsai , Hauke Mehrtens , Jernej Skrabec , Samuel Holland , Icenowy Zheng , Joe Hershberger , Wolfgang Denk , Daniel Wagenknecht , u-boot@lists.denx.de Subject: Re: [PATCH 4/7] sunxi: use boot source for determining environment location Message-ID: <20220415172822.GA1010@wintermute.localdomain> References: <20220111124607.863952-1-andre.przywara@arm.com> <20220111124607.863952-5-andre.przywara@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220111124607.863952-5-andre.przywara@arm.com> 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.5 at phobos.denx.de X-Virus-Status: Clean On Tue, Jan 11, 2022 at 12:46:04PM +0000, Andre Przywara wrote: > Currently we only support to load the environment from raw MMC or FAT > locations on Allwinner boards. With the advent of SPI flash we probably > also want to support using the environment there, so we need to become > a bit more flexible. > > Change the environment priority function to take the boot source into > account. When booted from eMMC or SD card, we use FAT or MMC, if > configured, as before. > If we are booted from SPI flash, we try to use the environment from > there, if possible. The same is true for NAND flash booting, although > this is somewhat theoretical right now (as untested). > > This way we can use the same image for SD and SPI flash booting, which > allows us to simply copy a booted image from SD card to the SPI flash, > for instance. Unfortunately after a git-bisect I can confirm this patch breaks booting in FEL mode whenever the environment is set to CONFIG_ENV_IS_NOWHERE. Tested and reproducible on an NTC CHIP or a Source Parts Popcorn (both Allwinner R8 chips). The curious thing though is that I could never see env_get_location called, but whenever I either set the environment to something like FAT or comment out this change (which I believe causes the non-board specific version of env_get_location to be used) it would boot again. So while I can confirm this patch breaks booting FEL when the env is set to nowhere, I was not able to figure out why that is. Thank you. > > Signed-off-by: Andre Przywara > --- > board/sunxi/board.c | 51 ++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 43 insertions(+), 8 deletions(-) > > diff --git a/board/sunxi/board.c b/board/sunxi/board.c > index 2790a0f9e8..2472343d00 100644 > --- a/board/sunxi/board.c > +++ b/board/sunxi/board.c > @@ -170,21 +170,56 @@ void i2c_init_board(void) > #endif > } > > -#if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT) > +/* > + * Try to use the environment from the boot source first. > + * For MMC, this means a FAT partition on the boot device (SD or eMMC). > + * If the raw MMC environment is also enabled, this is tried next. > + * SPI flash falls back to FAT (on SD card). > + */ > enum env_location env_get_location(enum env_operation op, int prio) > { > - switch (prio) { > - case 0: > - return ENVL_FAT; > + enum env_location boot_loc = ENVL_FAT; > > - case 1: > - return ENVL_MMC; > + gd->env_load_prio = prio; > > + switch (sunxi_get_boot_device()) { > + case BOOT_DEVICE_MMC1: > + case BOOT_DEVICE_MMC2: > + boot_loc = ENVL_FAT; > + break; > + case BOOT_DEVICE_NAND: > + if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND)) > + boot_loc = ENVL_NAND; > + break; > + case BOOT_DEVICE_SPI: > + if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) > + boot_loc = ENVL_SPI_FLASH; > + break; > + case BOOT_DEVICE_BOARD: > + break; > default: > - return ENVL_UNKNOWN; > + break; > + } > + > + /* Always try to access the environment on the boot device first. */ > + if (prio == 0) > + return boot_loc; > + > + if (prio == 1) { > + switch (boot_loc) { > + case ENVL_SPI_FLASH: > + return ENVL_FAT; > + case ENVL_FAT: > + if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC)) > + return ENVL_MMC; > + break; > + default: > + break; > + } > } > + > + return ENVL_UNKNOWN; > } > -#endif > > #ifdef CONFIG_DM_MMC > static void mmc_pinmux_setup(int sdc);