From patchwork Tue Aug 23 14:29:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 1669307 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=fris.de header.i=@fris.de header.a=rsa-sha256 header.s=dkim header.b=cE880MAd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MBs8B2SMxz1ygP for ; Wed, 24 Aug 2022 00:30:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 71B008482F; Tue, 23 Aug 2022 16:29:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=fris.de 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=fris.de header.i=@fris.de header.b="cE880MAd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1D1CF83FA1; Tue, 23 Aug 2022 16:29:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail.fris.de (mail.fris.de [IPv6:2a01:4f8:c2c:390b::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4AF0484803 for ; Tue, 23 Aug 2022 16:29:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=frieder@fris.de Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8699CC0160; Tue, 23 Aug 2022 16:29:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1661264969; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=YjJ4DOV0kurOyqvUHIiQuqQk1cpYX8vl6KoVy/GdcD4=; b=cE880MAdNMSUtMYSr9SBi+68OWnWJOK36CJOqsm7zsBX6YrQybonWNqwTSIsBX3YfLyoOX h2bPJHY8fBa9yHUmV/tT0Zsm+ugW7cBxqRJqN4dm4dEc5PZvwxfRSQvo8rWxyr3Sw/WuHf EcEphv97tzYHS15UUnc4/1DtfJSIuYkn/mdeCAQQTLEzJpjfraAxSX16xzyYX2et59/zev eDzyP5yfs+++m87ihKWtd/+l4g/V7k+VDSpKKQSdEdqxELRvDLLwGiqewESiWosFt1rYhE 18OQWTfE+FsJBJVKcu3Vi6IyWF9kdU2eMRsVK/sEVATzq5ctmBbPmNkji9B+HQ== From: Frieder Schrempf To: Frieder Schrempf , u-boot@lists.denx.de Cc: Marcel Ziswiler , Stefano Babic Subject: [PATCH 4/6] imx: imx6ul: kontron-sl-mx6ul: Select correct boot and env device Date: Tue, 23 Aug 2022 16:29:13 +0200 Message-Id: <20220823142917.306176-5-frieder@fris.de> In-Reply-To: <20220823142917.306176-1-frieder@fris.de> References: <20220823142917.306176-1-frieder@fris.de> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 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.6 at phobos.denx.de X-Virus-Status: Clean From: Frieder Schrempf Instead of checking both, SPI NOR and MMC for loading U-Boot proper and the environment, implement a way to detect the actual boot device even if the BootROM doesn't report it and we can't rely solely on the fuse settings, as by default we use MMC as primary boot device and boot from SPI NOR via the secondary fallback device (EEPROM Recovery Mode). Signed-off-by: Frieder Schrempf --- board/kontron/sl-mx6ul/Makefile | 2 ++ board/kontron/sl-mx6ul/sl-mx6ul-common.c | 24 ++++++++++++++++++++++++ board/kontron/sl-mx6ul/sl-mx6ul-common.h | 11 +++++++++++ board/kontron/sl-mx6ul/sl-mx6ul.c | 15 +++++++++++++++ board/kontron/sl-mx6ul/spl.c | 23 ++++++++++++++--------- 5 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul-common.c create mode 100644 board/kontron/sl-mx6ul/sl-mx6ul-common.h diff --git a/board/kontron/sl-mx6ul/Makefile b/board/kontron/sl-mx6ul/Makefile index cae273c9309..6af5f65450a 100644 --- a/board/kontron/sl-mx6ul/Makefile +++ b/board/kontron/sl-mx6ul/Makefile @@ -6,3 +6,5 @@ obj-y := spl.o else obj-y := sl-mx6ul.o endif + +obj-y += sl-mx6ul-common.o diff --git a/board/kontron/sl-mx6ul/sl-mx6ul-common.c b/board/kontron/sl-mx6ul/sl-mx6ul-common.c new file mode 100644 index 00000000000..1f24acdfa3d --- /dev/null +++ b/board/kontron/sl-mx6ul/sl-mx6ul-common.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Kontron Electronics GmbH + */ + +#include +#include + +#include + +bool sl_mx6ul_is_spi_nor_boot(void) +{ + u32 bmode = imx6_src_get_boot_mode(); + + /* + * Check if "EEPROM Recovery" enabled and ECSPI2_CONREG not 0x0. + * If this is the case and U-Boot didn't initialize the SPI bus + * yet, we can safely assume that we are booting from SPI NOR. + */ + if ((bmode & 0x40000000) && readl(0x0200c008)) + return true; + + return false; +} diff --git a/board/kontron/sl-mx6ul/sl-mx6ul-common.h b/board/kontron/sl-mx6ul/sl-mx6ul-common.h new file mode 100644 index 00000000000..58a0e77a8b0 --- /dev/null +++ b/board/kontron/sl-mx6ul/sl-mx6ul-common.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2022 Kontron Electronics GmbH + */ + +#ifndef __SL_MX6UL_COMMON_H +#define __SL_MX6UL_COMMON_H + +bool sl_mx6ul_is_spi_nor_boot(void); + +#endif // __SL_MX6UL_COMMON_H diff --git a/board/kontron/sl-mx6ul/sl-mx6ul.c b/board/kontron/sl-mx6ul/sl-mx6ul.c index 79d4d8753b0..0f45ea84fc7 100644 --- a/board/kontron/sl-mx6ul/sl-mx6ul.c +++ b/board/kontron/sl-mx6ul/sl-mx6ul.c @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -83,3 +85,16 @@ int board_init(void) return 0; } + +enum env_location env_get_location(enum env_operation op, int prio) +{ + if (prio) + return ENVL_UNKNOWN; + + if (sl_mx6ul_is_spi_nor_boot() && CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) + return ENVL_SPI_FLASH; + else if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC)) + return ENVL_MMC; + + return ENVL_NOWHERE; +} diff --git a/board/kontron/sl-mx6ul/spl.c b/board/kontron/sl-mx6ul/spl.c index 12b0352146f..ba6915c898c 100644 --- a/board/kontron/sl-mx6ul/spl.c +++ b/board/kontron/sl-mx6ul/spl.c @@ -17,6 +17,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -339,26 +340,30 @@ void board_boot_order(u32 *spl_boot_list) /* * The default boot fuse settings use the SD card (MMC1) as primary - * boot device, but allow SPI NOR as a fallback boot device. - * We can't detect the fallback case and spl_boot_device() will return - * BOOT_DEVICE_MMC1 despite the actual boot device being SPI NOR. - * Therefore we try to load U-Boot proper vom SPI NOR after loading - * from MMC has failed. + * boot device, but allow SPI NOR as a fallback boot device. There + * is no proper way to detect if the fallback was used. Therefore + * we read the ECSPI2_CONREG register and see if it differs from the + * reset value 0x0. If that's the case we can assume that the BootROM + * has successfully probed the SPI NOR. */ - spl_boot_list[0] = bootdev; - switch (bootdev) { case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2: - spl_boot_list[1] = BOOT_DEVICE_SPI; + if (sl_mx6ul_is_spi_nor_boot()) { + spl_boot_list[0] = BOOT_DEVICE_SPI; + return; + } break; } + + spl_boot_list[0] = bootdev; } int board_early_init_f(void) { setup_iomux_uart(); - setup_spi(); + if (sl_mx6ul_is_spi_nor_boot()) + setup_spi(); return 0; }