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 85EEBC433F5 for ; Sat, 12 Feb 2022 00:36:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6D38B8381D; Sat, 12 Feb 2022 01:36:26 +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="S0zgSeuv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA5AF80FE2; Sat, 12 Feb 2022 01:36:24 +0100 (CET) Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) (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 BF7B283BAE for ; Sat, 12 Feb 2022 01:36:21 +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-x736.google.com with SMTP id o10so9711390qkg.0 for ; Fri, 11 Feb 2022 16:36:21 -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=0Crdt7jbFeZK6jPmEyb60YMNxnpQsZAuDWEQanH3yj0=; b=S0zgSeuv7C6Z+kwP5ZZw8P9i93PuquClwW25y6R5wPbDf548bY3uQroqWZxN63pug6 JbwF/+VQfhwrA6hMVWAf8GAyZKgmhuPnYN7AChZVV+bhWhgxgFIR+yfILo02lgwZgOpr fbkhq2U2iZAkDBRyYc71mQrfDba941WFRMN7J91MeMbBe1j/LMJ1LJgKxvTYVe86xWSc LlO6cchp0ShjfD49o876oj3y/Knptana3BHn7VCVbKcJ+swDfUxD0S+1fESs0Jk7hnFj n+B5Mrj0TwT6dTFQ63vyFCoBlM9A6JsxGgph2y8Iyr6LsRE9WyHC8AQJDAsqX7Zfy+CL ccJw== 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=0Crdt7jbFeZK6jPmEyb60YMNxnpQsZAuDWEQanH3yj0=; b=BfmoTAouYpjrYlEolPBHm5pipZ71cmQMea5u63awkEfBsxmlkezABaMEue2g9xSrQV 6LkpJ+IA+yyiNH7c7hyjvuJfPky/KaDpoo2t84qVlUddW+A3iSIftKZ+uMQrnoHwYHbj bmeVAicILX2Vlpa+F3FbdEsg7jKcswBC/iYfHcY8Mw6/WmZ8VGaJxmzPv52siqQz3+7l CJgAo1/msHqPt4K9aAO/jILGFARbW6q3pVMHBT8oZIQCqfojfQ31upNXaesq4jEbdera 7duKgHGTh8qmFHCZ+L1P42YKFTGXBapp+lP4Q52db7rzGom3A1DmhOREmEd5yxmkoRPk BsIg== X-Gm-Message-State: AOAM530JRhlj00SuCfr/g6oKkioohvjWyENiOuqCNirvIF49qv0YI3xV ZYExM7OofUizuB3rCBfpzbk9XBg2k3w= X-Google-Smtp-Source: ABdhPJyXPJ16ZF6a+VMc6kAnaUm0zTBRhWkFcylXbYMG5kR887eiNhLZ+EBbQLXnFpajw5o+ppjJFQ== X-Received: by 2002:a05:620a:d82:: with SMTP id q2mr2170464qkl.356.1644626180218; Fri, 11 Feb 2022 16:36:20 -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 p24sm156343qtq.36.2022.02.11.16.36.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Feb 2022 16:36:19 -0800 (PST) Message-ID: <887ecc12-a7db-e3ec-b591-8be1e57e4920@gmail.com> Date: Fri, 11 Feb 2022 19:36:18 -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 v2 1/3] mach-sunxi: Add boot device detection for SUNIV/F1C100s Content-Language: en-US To: u-boot@lists.denx.de Cc: jagan@amarulasolutions.com, andre.przywara@arm.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: <20220212003235.2162334-1-Mr.Bossman075@gmail.com> <20220212003235.2162334-2-Mr.Bossman075@gmail.com> From: Jesse Taube In-Reply-To: <20220212003235.2162334-2-Mr.Bossman075@gmail.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/11/22 19:32, Jesse Taube wrote: > In contrast to other Allwinner SoCs the F1C100s BROM does not store a > boot source indicator in the eGON header in SRAM. This leaves the SPL > 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. > > This patch removes the existing board_boot_order bodge and replace it > with a proper boot source indication function. > > Signed-off-by: Jesse Taube > Suggested-by: Samuel Holland > --- > V1 -> V2: > * Bail on NAND > * Change commit description > * Change sunxi_get_boot_source to u32 > * Fix FEL boot by next change > * Move suniv_get_boot_device call into sunxi_get_boot_source > * Rename suniv_get_boot_device > * Remove redundant comments > --- > arch/arm/include/asm/arch-sunxi/spl.h | 10 +++++ > arch/arm/mach-sunxi/board.c | 57 +++++++++++++-------------- > 2 files changed, 38 insertions(+), 29 deletions(-) > > diff --git a/arch/arm/include/asm/arch-sunxi/spl.h b/arch/arm/include/asm/arch-sunxi/spl.h > index 58cdf806d9..9a6e8da8e1 100644 > --- a/arch/arm/include/asm/arch-sunxi/spl.h > +++ b/arch/arm/include/asm/arch-sunxi/spl.h > @@ -19,6 +19,16 @@ > #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. > + */ > + > +#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); > diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c > index 57078f7a7b..27aee1e445 100644 > --- a/arch/arm/mach-sunxi/board.c > +++ b/arch/arm/mach-sunxi/board.c > @@ -191,12 +191,37 @@ SPL_LOAD_IMAGE_METHOD("FEL", 0, BOOT_DEVICE_BOARD, spl_board_load_image); > > #define SUNXI_INVALID_BOOT_SOURCE -1 > > -static int sunxi_get_boot_source(void) Didn't like the implicit cast on the return statement. > +static uint32_t suniv_get_boot_source(void) > +{ > + /* Get the last function call from BootRom's stack. */ > + u32 brom_call = *(u32 *)(fel_stash.sp - 4); > + > + /* translate SUNIV Bootrom stack to standard SUNXI boot sources */ > + switch (brom_call) { > + case SUNIV_BOOTED_FROM_MMC0: > + return SUNXI_BOOTED_FROM_MMC0; > + case SUNIV_BOOTED_FROM_SPI: > + return SUNXI_BOOTED_FROM_SPI; > + case SUNIV_BOOTED_FROM_MMC1: > + return SUNXI_BOOTED_FROM_MMC2; > + /* SPI nand is invalid try to boot from FEL*/ > + case SUNIV_BOOTED_FROM_NAND: > + return SUNXI_INVALID_BOOT_SOURCE; > + } > + /* If we get here something went wrong try to boot from FEL.*/ > + printf("Unknown boot source from BROM: 0x%x\n", brom_call); > + return SUNXI_INVALID_BOOT_SOURCE; This just trys to boot from FEL doesn't hang. > +} > + > +static uint32_t sunxi_get_boot_source(void) > { > if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */ > return SUNXI_INVALID_BOOT_SOURCE; This will return when booting from FEL. > > - return readb(SPL_ADDR + 0x28); > + if (IS_ENABLED(CONFIG_MACH_SUNIV)) > + return suniv_get_boot_source(); > + else > + return readb(SPL_ADDR + 0x28); > } > > /* The sunxi internal brom will try to loader external bootloader > @@ -204,7 +229,7 @@ static int sunxi_get_boot_source(void) > */ > uint32_t sunxi_get_boot_device(void) > { > - int boot_source = sunxi_get_boot_source(); > + uint32_t boot_source = sunxi_get_boot_source(); > > /* > * When booting from the SD card or NAND memory, the "eGON.BT0" > @@ -276,36 +301,10 @@ 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(); > } > -#endif > > __weak void sunxi_sram_init(void) > {