From patchwork Wed Jun 30 23:08:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1499115 X-Patchwork-Delegate: van.freenix@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=A3N/nZWn; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=JPAtaCjD; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GFcTG5ZDnz9sXS for ; Thu, 1 Jul 2021 09:08:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2D7228317B; Thu, 1 Jul 2021 01:08:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1625094494; bh=B0FRK5TB+mROWZPbcze2r/LByV8AZaFL/VgfSySG5vs=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=A3N/nZWnUmH1jp1QGou5npCeUZcoSeMPI5Gm2pUV55Pa4vUEPyxyWk0yiz4xWTQKs SI70Pmig+43xCeOckfAWqfa1OAcK+x2Mua/0/OFMTMSIoHjWvjLrOStW1dxYvGZc1N cLCMn/oRbdeDTRYfXxLy5B4PH8M93jPHbluVHl5jjEatQQpGYq/1//ml42LZZLQ9f9 uSQz5JN7n5iruB0vTle68V4OlmUgX5vBQJDvK2rExKqwyfUjTMCscrgQvIg3ZNnx8n REVDBhIQal7L8UvcGux982dHAz6bnFFFmAhMF/Gq51CWT4GGzZv3ZnvYAckZSegI27 XqZJffu3poN4w== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 25D6A82BF2; Thu, 1 Jul 2021 01:08:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1625094492; bh=B0FRK5TB+mROWZPbcze2r/LByV8AZaFL/VgfSySG5vs=; h=From:To:Cc:Subject:Date:From; b=JPAtaCjDSJGzb38SPf8GraBgMPANpJ5zKGPBPw2v8ygAIwf6LUCnDtyRwOuvQDsRs bySBRSd9RVCB91ZL0HsAM81ySVFvF8tDi6RqT6hByQXgewcMKXsL8AwwMwis6kiEd5 rnymm2hq7ldjZYLg7vBZy1ZaEmXnMArlP0BIHgOADX7m3MZ70sepywAuNv/ftHySAL UTUtVGOzAONKx2cUi3R73viKN0QkurCI+GCKvenanH+fnz7GIoRb61jB0TDxQ++Bav ot27LuQpxcg7XA8v82Wp+PqvdGe+tor4tIUxC/uOtw41VLF69XnBjUTptvn9yKwmGO EZ/qTY+Lf1GGA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Faiz Abbas , Harald Seiler , Lokesh Vutla , Simon Glass , Fabio Estevam , Peng Fan , Stefano Babic , Ye Li Subject: [PATCH 1/2] spl: mmc: Factor out eMMC boot partition selection code Date: Thu, 1 Jul 2021 01:08:00 +0200 Message-Id: <20210630230801.290195-1-marex@denx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Factor out eMMC boot partition selection code into default_spl_mmc_emmc_boot_partition() function and implement weak spl_mmc_emmc_boot_partition(), so that architecture or board code can override the eMMC boot partition selection. Signed-off-by: Marek Vasut Cc: Faiz Abbas Cc: Harald Seiler Cc: Lokesh Vutla Cc: Simon Glass Cc: Fabio Estevam Cc: Peng Fan Cc: Stefano Babic Cc: Ye Li --- common/spl/spl_mmc.c | 37 ++++++++++++++++++++++++------------- include/spl.h | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index add2785b4e3..2377d0937d1 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -324,6 +324,29 @@ unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc, return raw_sect; } +int default_spl_mmc_emmc_boot_partition(struct mmc *mmc) +{ + int part; +#ifdef CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION + part = CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION; +#else + /* + * We need to check what the partition is configured to. + * 1 and 2 match up to boot0 / boot1 and 7 is user data + * which is the first physical partition (0). + */ + part = (mmc->part_config >> 3) & PART_ACCESS_MASK; + if (part == 7) + part = 0; +#endif + return part; +} + +int __weak spl_mmc_emmc_boot_partition(struct mmc *mmc) +{ + return default_spl_mmc_emmc_boot_partition(mmc); +} + int spl_mmc_load(struct spl_image_info *spl_image, struct spl_boot_device *bootdev, const char *filename, @@ -355,19 +378,7 @@ int spl_mmc_load(struct spl_image_info *spl_image, err = -EINVAL; switch (boot_mode) { case MMCSD_MODE_EMMCBOOT: -#ifdef CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION - part = CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION; -#else - /* - * We need to check what the partition is configured to. - * 1 and 2 match up to boot0 / boot1 and 7 is user data - * which is the first physical partition (0). - */ - part = (mmc->part_config >> 3) & PART_ACCESS_MASK; - - if (part == 7) - part = 0; -#endif + part = spl_mmc_emmc_boot_partition(mmc); if (CONFIG_IS_ENABLED(MMC_TINY)) err = mmc_switch_part(mmc, part); diff --git a/include/spl.h b/include/spl.h index cee9a42ddb5..b6698a686a7 100644 --- a/include/spl.h +++ b/include/spl.h @@ -357,6 +357,31 @@ u32 spl_mmc_boot_mode(const u32 boot_device); * If not overridden, it is weakly defined in common/spl/spl_mmc.c. */ int spl_mmc_boot_partition(const u32 boot_device); + +struct mmc; +/** + * default_spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from. + * @boot_device: ID of the device which the MMC driver wants to load + * U-Boot from. + * + * This function should return the eMMC boot partition number which + * the SPL should load U-Boot from (on the given boot_device). + */ +int default_spl_mmc_emmc_boot_partition(struct mmc *mmc); + +/** + * spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from. + * @boot_device: ID of the device which the MMC driver wants to load + * U-Boot from. + * + * This function should return the eMMC boot partition number which + * the SPL should load U-Boot from (on the given boot_device). + * + * If not overridden, it is weakly defined in common/spl/spl_mmc.c + * and calls default_spl_mmc_emmc_boot_partition(); + */ +int spl_mmc_emmc_boot_partition(struct mmc *mmc); + void spl_set_bd(void); /** From patchwork Wed Jun 30 23:08:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1499116 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=pBzjWFT3; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=xk0p9Tby; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GFcTQ597cz9sXS for ; Thu, 1 Jul 2021 09:08:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DAF3F831B9; Thu, 1 Jul 2021 01:08:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1625094496; bh=6KZai2pDxZ0RYTqh/osypYr8scKiQwMSgCUTBm973To=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pBzjWFT37o6T3movw5Zas9QTQDcsyJe/JwUl425CAwLimXGh0OTHzkc3YPpCsZqix hTaTaWs8KbpZNvCN5TwOva7WIaDw2by3B2AKaCBs/OvV2+RG90A0DadnXvsm/N7vW4 ZyIM9Z5kCmnWQ7sKpf8c2s0XC5VkLrqnzq/tNo0H9M6tN0N4qraPIIzDaUus/YMQjt U3y4T3uqvNPO8RG3piQ1/F84be4RN7ez7MNjBIvCQ3JzX1KMy8ZGIumo8huAMpzh0A KUnWBGaLAm1QIGtXCh0awfZx4vMLbP66hzIyyZ0hm4Ir6i+r0W8HqoG3GIydxnsT8s yXIBKxXP6PgVg== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id A0EF283169; Thu, 1 Jul 2021 01:08:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1625094493; bh=6KZai2pDxZ0RYTqh/osypYr8scKiQwMSgCUTBm973To=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xk0p9Tby08H19bxo8E05V+4IitSsXj5bM0pxjBIQZFwRFFP6+L/O25pTtzZDV1B/J FMUmOFYjRzNP0LPO5LiHTpRFlJMZFjb37N45YWNpfHZZsMFLdEX8d6ZcEg4xXadJpu YqrjfiSf7b/NDoqjEQ0JbshJG9x2OnW4pxr8slt8tm4L5Jj4QuAw27EvQ9i0VuOj7V 6z08bihXpCH6uWVjLb0tMOtN/LHza0lNb29HCK3X7EOj4ljsYfaCoptq1vcvVs/GQ6 e6yMTHSis/Oi8wKvVEJOhuBIKhmheuT7ZopffkAFTcmSHEzlODCQ9wthpcCS8MXgpr gSj4QvVX9H3tw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Faiz Abbas , Harald Seiler , Lokesh Vutla , Simon Glass , Fabio Estevam , Peng Fan , Stefano Babic , Ye Li Subject: [PATCH 2/2] ARM: imx: Pick correct eMMC boot partition from ROM log Date: Thu, 1 Jul 2021 01:08:01 +0200 Message-Id: <20210630230801.290195-2-marex@denx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210630230801.290195-1-marex@denx.de> References: <20210630230801.290195-1-marex@denx.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean In case the iMX8M boot from eMMC boot partition and the primary image is corrupted, the BootROM is capable of starting a secondary image in the other eMMC boot partition as a fallback. However, the BootROM leaves the eMMC BOOT_PARTITION_ENABLE setting as it was, i.e. pointing to the boot partition containing the corrupted image, and the BootROM does not provide any indication that this sort of fallback occured. According to AN12853 i.MX ROMs Log Events, Rev. 0, May 2020, it is possible to determine whether fallback event occurred by parsing the ROM event log. In case ROM event ID 0x51 is present, fallback event did occur. This patch implements ROM event log parsing and search for event ID 0x51 for all iMX8M SoCs, and based on that corrects the eMMC boot partition selection. This way, the SPL loads the remaining boot components from the same eMMC boot partition from which it was started, even in case of the fallback. Signed-off-by: Marek Vasut Cc: Faiz Abbas Cc: Harald Seiler Cc: Lokesh Vutla Cc: Simon Glass Cc: Fabio Estevam Cc: Peng Fan Cc: Stefano Babic Cc: Ye Li --- arch/arm/mach-imx/imx8m/soc.c | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c index 0c44022a6dc..92a71b6ba29 100644 --- a/arch/arm/mach-imx/imx8m/soc.c +++ b/arch/arm/mach-imx/imx8m/soc.c @@ -571,6 +571,67 @@ enum boot_device get_boot_device(void) } #endif +#if defined(CONFIG_IMX8M) +#include +int spl_mmc_emmc_boot_partition(struct mmc *mmc) +{ + u32 *rom_log_addr = (u32 *)0x9e0; + u32 *rom_log; + u8 event_id; + int i, part; + + part = default_spl_mmc_emmc_boot_partition(mmc); + + /* If the ROM event log pointer is not valid. */ + if (*rom_log_addr < 0x900000 || *rom_log_addr >= 0xb00000 || + *rom_log_addr & 0x3) + return part; + + /* Parse the ROM event ID version 2 log */ + rom_log = (u32 *)(uintptr_t)(*rom_log_addr); + for (i = 0; i < 128; i++) { + event_id = rom_log[i] >> 24; + switch (event_id) { + case 0x00: /* End of list */ + break; + /* Log entries with 1 parameter, skip 1 */ + case 0x80: /* Start to perform the device initialization */ + case 0x81: /* The boot device initialization completes */ + case 0x8f: /* The boot device initialization fails */ + case 0x90: /* Start to read data from boot device */ + case 0x91: /* Reading data from boot device completes */ + case 0x9f: /* Reading data from boot device fails */ + i += 1; + continue; + /* Log entries with 2 parameters, skip 2 */ + case 0xa0: /* Image authentication result */ + case 0xc0: /* Jump to the boot image soon */ + i += 2; + continue; + /* Boot from the secondary boot image */ + case 0x51: + /* + * Swap the eMMC boot partitions in case there was a + * fallback event (i.e. primary image was corrupted + * and that corruption was recognized by the BootROM), + * so the SPL loads the rest of the U-Boot from the + * correct eMMC boot partition, since the BootROM + * leaves the boot partition set to the corrupted one. + */ + if (part == 1) + part = 2; + else if (part == 2) + part = 1; + continue; + default: + continue; + } + } + + return part; +} +#endif + bool is_usb_boot(void) { return get_boot_device() == USB_BOOT;