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 C40BEC433F5 for ; Thu, 10 Feb 2022 04:35:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6107F8141E; Thu, 10 Feb 2022 05:34:52 +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="Je9EnZAg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 485B88169D; Thu, 10 Feb 2022 05:34:49 +0100 (CET) Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (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 6AD4C815D1 for ; Thu, 10 Feb 2022 05:34:43 +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-qt1-x82a.google.com with SMTP id j12so4013580qtr.2 for ; Wed, 09 Feb 2022 20:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H5OktHczZishWGAoGAFBmROmOuSkPIePn5e7VYqr7nI=; b=Je9EnZAg0jZabIfaeNSS+BjE38rhTKGnYmQIMpwonaWG/Nc9JiNJNh/Tec6ww7Vncc XXVm+6Nr0YGkGA9b5v+r/dJMZKdEsuklqdwDcNlh2E3VkA0EQNKuT07x9dyIZ/BlXUm7 FX9W+QizQcxLinPBkFU7y4HruoVZpSRdRuMiosWOh+/9qIXWm6c3fFD/h7BgzpHQ5L/h CbKETI9gnjr1R4TJP46g8jJtuvIK42sgUdlJbnom4oUPYnTxZJ2iGF+fb3MD3+Omc909 fubvrCEuCDbUz9BuCbhVuwi+xWevtYsDH0MItGtTPG4jhEFkb6pazmZtYTdcCGXwix41 mqDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H5OktHczZishWGAoGAFBmROmOuSkPIePn5e7VYqr7nI=; b=jtIrz8i0bQYNG7HvKxuldVyrAt1g4TPnGViVW17S8vN3eKak+e1hvOZdTNmvtLM7IE tNSbcXEnUlh2v7We7sGC3SqbNAUCWKh8dB4uP3inDuXMDVXR3dRwXCJS4S2XgagUd46Y eT55+dl00MSgRkCXi0W2OMUo13piPGoBxy+Ly9Jcs8EkcM/2gWP89iLs4EfSHM6qYBD8 AudyX2M2M6usiYYFmSN//X0mqQEvtuV0w0vgZcqPGzgPiTTasINIz4IQ/A/TKttYTC1E Tfg+LZMb+TtYl91/gY4iU5JTGWjcf2gGJ6dYRUZk9Be+dIOMhu+6Sacg2g7gLwqd2tb4 MUvA== X-Gm-Message-State: AOAM530pznYgZRmtOUrfy0lOO6c64naWKuwkiEr0Q7XBr1rmcjNYxNdw UAP+695BLbx9LYRVw166zN3dISDq8no= X-Google-Smtp-Source: ABdhPJwV4w5XByVcywd/jc+Yfu4tL0W2X7HaBk8fxygBmhWkHm3mkxYhWzcHHR2dNeuQOYkf9Q+Mng== X-Received: by 2002:ac8:5f13:: with SMTP id x19mr3709742qta.344.1644467682017; Wed, 09 Feb 2022 20:34:42 -0800 (PST) Received: from jesse-desktop.jtp-bos.lab (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 p15sm10399512qtk.56.2022.02.09.20.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 20:34:41 -0800 (PST) From: Jesse Taube X-Google-Original-From: Jesse Taube 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, Mr.Bossman075@gmail.com, thirtythreeforty@gmail.com Subject: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV Date: Wed, 9 Feb 2022 23:34:36 -0500 Message-Id: <20220210043438.1706939-2-Mr.Bossman075@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220210043438.1706939-1-Mr.Bossman075@gmail.com> References: <20220210043438.1706939-1-Mr.Bossman075@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Use Samuel's suggestion of looking at the BootRom's stack to determine the boot device. 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 + */ + +#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) +{ + /* 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; + } + + 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) { -- 2.34.1