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 792BDC433EF for ; Thu, 10 Feb 2022 19:11:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B5D5C83073; Thu, 10 Feb 2022 20:11:24 +0100 (CET) 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="LulSAnEG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2CBF982F5A; Thu, 10 Feb 2022 20:11:23 +0100 (CET) Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) (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 816CA836B4 for ; Thu, 10 Feb 2022 20:11:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.bossman075@gmail.com Received: by mail-qk1-x732.google.com with SMTP id 200so5885487qki.2 for ; Thu, 10 Feb 2022 11:11:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ixdUDq6uInBJd5pOtwicrlycnuBTgxLdOiKAwlhl02g=; b=LulSAnEGgk2PzXtDP6gz5XXfWy2TvLmbwjkD1DeSfcUMRaB3FjRt0bAX5bjjQxIo+P UV5mK9r43fE5f3TSsVuKQ010zGEThd31GIgdcj0fRXI0SN3SgiKVli3hB3QxTY51KXRi nc/GVzYl7BC50Iuc8SgAHXHmDrNvvKJ4yYWOSQGUjM1C/sDoO8TYrCdTKK00WcuRTTG4 aCJFse3huj3MfUyJqLjJKRXhmWhEyn1u5SP0hpQlWb/zqluvZej6QKAFHTPMSr8UCQfz wyj5egEVWwro5fysXSagg68zZhzv/xOTDOhVTGhBA3ra7cVaFIXSb6FqoIuVdvdoZeix w88g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ixdUDq6uInBJd5pOtwicrlycnuBTgxLdOiKAwlhl02g=; b=8AEdXM9wZ0MVew0GOBM4Xf40DZgQDD9EJ9Bp5cJoeY3sz+EFl4ML08Rfv6LCYcZEh6 jEQk1V0PpmFF8HiMxoKw/xOEh8JEdXRTE94hjhn5XXR5e6MIHnMKHyPcz8qn56PZMUIM l4ngvLxHiDPxYNnDiiEcI3oHq+3YBuVhKusWEx1v/y76kao/1w0B8EfCOiSVgNuOCpu2 m9DsJDqup79uc3ZFccqp1unKsRMfnkFZ4Xj5qtGIPn2l8GR6A/op/WFOxsLlqDoy0Fpu pNuvzvtGtU6hwujfqtiB3aaf0FrD51S3CByIVYK6SDXeojXYewCuuJxY/aMSp9s/cAdd YRmw== X-Gm-Message-State: AOAM530LugWvlVl32IMcbwSEqDfOfDtdONLA3xPOKaTGtcAQVo4BcRdg i17Dzu3AlSFXcWIel2Rr6ss= X-Google-Smtp-Source: ABdhPJyTEpBD+m3gdSplRCM8SxwLZT4rfcED3PuRpZuPpagdbf0sFJxlibyGDnBeI6ByHQWFC69QcA== X-Received: by 2002:a05:620a:2589:: with SMTP id x9mr4555889qko.335.1644520266253; Thu, 10 Feb 2022 11:11:06 -0800 (PST) Received: from [10.4.10.38] (146-115-144-188.s4282.c3-0.nwt-cbr1.sbo-nwt.ma.cable.rcncustomer.com. [146.115.144.188]) by smtp.gmail.com with ESMTPSA id u17sm9882726qkj.44.2022.02.10.11.11.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Feb 2022 11:11:05 -0800 (PST) Message-ID: <2435c0ad-e922-2230-4fb4-f9cf0bd76309@gmail.com> Date: Thu, 10 Feb 2022 14:11:04 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV Content-Language: en-US To: Andre Przywara Cc: u-boot@lists.denx.de, jagan@amarulasolutions.com, hdegoede@redhat.com, sjg@chromium.org, icenowy@aosc.io, marek.behun@nic.cz, festevam@denx.de, narmstrong@baylibre.com, tharvey@gateworks.com, christianshewitt@gmail.com, pbrobinson@gmail.com, jernej.skrabec@gmail.com, hs@denx.de, samuel@sholland.org, arnaud.ferraris@gmail.com, giulio.benetti@benettiengineering.com, thirtythreeforty@gmail.com References: <20220210043438.1706939-1-Mr.Bossman075@gmail.com> <20220210043438.1706939-2-Mr.Bossman075@gmail.com> <20220210105746.16f5004a@donnerap.cambridge.arm.com> From: Jesse Taube In-Reply-To: <20220210105746.16f5004a@donnerap.cambridge.arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 2/10/22 05:57, Andre Przywara wrote: > On Wed, 9 Feb 2022 23:34:36 -0500 > Jesse Taube wrote: > > Hi Jesse, > > many thanks for sending this, much appreciated! > >> Use Samuel's suggestion of looking at the BootRom's stack >> to determine the boot device. > > Can you please elaborate here what's going on, for future reference? Like: > ============= > In contrast to other Allwinner SoCs the F1C100s BROM does not store a boot > source indicator in the eGON header in SRAM. This leaves us guessing where > we were exactly booted from, and for instance trying the SD card first, > even though we booted from SPI flash. > By inspecting the BROM code and by experimentation, Samuel found that the > top of the BROM stack contains unique pointers for each of the boot > sources, which we can use as a boot source indicator. > > Remove the existing board_boot_order kludge and replace it with a proper > boot source indication function. > ============= > > >> >> Signed-off-by: Jesse Taube >> Suggested-by: Samuel Holland >> --- >> arch/arm/include/asm/arch-sunxi/spl.h | 15 ++++++++ >> arch/arm/mach-sunxi/board.c | 50 ++++++++++++--------------- >> 2 files changed, 38 insertions(+), 27 deletions(-) >> >> diff --git a/arch/arm/include/asm/arch-sunxi/spl.h b/arch/arm/include/asm/arch-sunxi/spl.h >> index 58cdf806d9..d069091297 100644 >> --- a/arch/arm/include/asm/arch-sunxi/spl.h >> +++ b/arch/arm/include/asm/arch-sunxi/spl.h >> @@ -19,8 +19,23 @@ >> #define SUNXI_BOOTED_FROM_MMC0_HIGH 0x10 >> #define SUNXI_BOOTED_FROM_MMC2_HIGH 0x12 >> >> +/* >> + * Values taken from the Bootrom's stack used >> + * to determine where we booted from. >> + * 0xffff40f8: mmc0 >> + * 0xffff4114: spi0 NAND >> + * 0xffff4130: spi0 NOR >> + * 0xffff4150: mmc1 > > Those last four lines are redundant, as you say exactly that, in code, > down here again. Comments are good, speaking code is better. > >> + */ >> + >> +#define SUNIV_BOOTED_FROM_MMC0 0xffff40f8 >> +#define SUNIV_BOOTED_FROM_NAND 0xffff4114 >> +#define SUNIV_BOOTED_FROM_SPI 0xffff4130 >> +#define SUNIV_BOOTED_FROM_MMC1 0xffff4150 >> + >> #define is_boot0_magic(addr) (memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0) >> >> uint32_t sunxi_get_boot_device(void); >> +uint32_t suniv_get_boot_device(void); >> >> #endif >> diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c >> index 57078f7a7b..b0658d583e 100644 >> --- a/arch/arm/mach-sunxi/board.c >> +++ b/arch/arm/mach-sunxi/board.c >> @@ -241,6 +241,25 @@ uint32_t sunxi_get_boot_device(void) >> return -1; /* Never reached */ >> } >> >> +uint32_t suniv_get_boot_device(void) > > This can be static, right? Yes it can it is not because sunxi_get_boot_device isn'tm, but that is only not static because board/sunxi/board.c:mmc_get_env_dev. I will make it static. > >> +{ >> + /* Get the last function call from BootRom's stack. */ >> + u32 brom_call = *(u32 *)(fel_stash.sp - 4); >> + >> + switch (brom_call) { >> + case SUNIV_BOOTED_FROM_MMC0: >> + return BOOT_DEVICE_MMC1; >> + case SUNIV_BOOTED_FROM_NAND: >> + case SUNIV_BOOTED_FROM_SPI: >> + return BOOT_DEVICE_SPI; >> + case SUNIV_BOOTED_FROM_MMC1: >> + return BOOT_DEVICE_MMC2; >> + } > > Don't you need to handle FEL boot here somehow? > > Cheers, > Andre > >> + >> + printf("Unknown boot source from BROM: 0x%x\n", brom_call); >> + return BOOT_DEVICE_MMC1; >> +} >> + >> #ifdef CONFIG_SPL_BUILD >> static u32 sunxi_get_spl_size(void) >> { >> @@ -276,36 +295,13 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc, >> return sector; >> } >> >> -#ifdef CONFIG_MACH_SUNIV >> -/* >> - * The suniv BROM does not pass the boot media type to SPL, so we try with the >> - * boot sequence in BROM: mmc0->spinor->fail. >> - * TODO: This has the slight chance of being wrong (invalid SPL signature, >> - * but valid U-Boot legacy image on the SD card), but this should be rare. >> - * It looks like we can deduce from some BROM state upon entering the SPL >> - * (registers, SP, or stack itself) where the BROM was coming from and use >> - * that here. >> - */ >> -void board_boot_order(u32 *spl_boot_list) >> -{ >> - /* >> - * See the comments above in sunxi_get_boot_device() for information >> - * about FEL boot. >> - */ >> - if (!is_boot0_magic(SPL_ADDR + 4)) { >> - spl_boot_list[0] = BOOT_DEVICE_BOARD; >> - return; >> - } >> - >> - spl_boot_list[0] = BOOT_DEVICE_MMC1; >> - spl_boot_list[1] = BOOT_DEVICE_SPI; >> -} >> -#else >> u32 spl_boot_device(void) >> { >> - return sunxi_get_boot_device(); >> + if (IS_ENABLED(CONFIG_MACH_SUNIV)) >> + return suniv_get_boot_device(); >> + else >> + return sunxi_get_boot_device(); >> } >> -#endif >> >> __weak void sunxi_sram_init(void) >> { >