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 2E49CC0015E for ; Sat, 29 Jul 2023 15:10:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E7E3786810; Sat, 29 Jul 2023 17:10:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (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=1690643422; bh=6h1DPKTK9al4facwu9YVSQpy04loRac+cfG8xzFx1N4=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=TPe8QWK9pO58F+25w4McLFVG3Llx1AXowSs78tZbfY4WDf93o8seo8/qipqLpIh/A En2bvFLDD8deqmKXbdda/OvayBQuNrl+rBmLa9codpsMjvctI/AKWij3ZXxHR6UXi5 C92eBAp8WdwbFOGPI60P6y8/zoNiSMnnJqiDY1VNSRYniDi2FRSQKuaZ/Q6FlwUNhT dcQSQI/MKhiJsFblgPn0SKbL34kEhz3f7qwqSgo4PIF13flBggsj4msbItrftip8Se YkHpcI2iqlbJJUlzBTVeOqrgL2792Ezn1GDQS/54Sxvz2G1QAvbyM/rGnmWdJa3GF8 c8jvcD4J4bUvg== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (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 556D7866AA; Sat, 29 Jul 2023 17:10:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1690643420; bh=6h1DPKTK9al4facwu9YVSQpy04loRac+cfG8xzFx1N4=; h=From:To:Cc:Subject:Date:From; b=JjpNBUjMIxTb7DHIWX9upP5oZjdOfeTageG5i/Y518pO5m+gEk5P/Ezh8TPLAl+BW gRgFSYm3sttIXe1F94ZQgUMaXtpNNqKygroPAxsJdfsPyHxdDJN8nh+DQAisYo+6sM lo2gXRppbU3RHEJCEr83zHbFpRucInNH6+8UJ0ll/PkiRcvTdr1XAaleBK2T6nRV0y GgyK602fBnUVfcvnleQdG1eTJz91D6nT63F2TwcP/jvn3/G1+H88zwdoMkAImurIa2 leY+vFXAiI2uL3wREIV3yTQ3yO+knD/SUHNT9AOtbBXGr2v9dSj1NDVrSjBat2+GcX HDt/+hGX/oPNw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Fedor Ross , Marek Vasut , Fabio Estevam , Peng Fan , Stefano Babic Subject: [PATCH 1/3] ARM: imx: Factor out parsing of ROM log Date: Sat, 29 Jul 2023 17:09:44 +0200 Message-Id: <20230729150946.214878-1-marex@denx.de> X-Mailer: git-send-email 2.40.1 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.8 at phobos.denx.de X-Virus-Status: Clean From: Fedor Ross Factor out parsing of ROM log in function spl_mmc_emmc_boot_partition(). This can be helpful to detect a secondary image boot without fiddling around with MMC partitions. This way for example, U-Boot is able to detect a secondary image boot and can enter some fallback scenario like starting a recovery mode. Signed-off-by: Fedor Ross Signed-off-by: Marek Vasut --- Cc: Fabio Estevam Cc: Peng Fan Cc: Stefano Babic --- arch/arm/mach-imx/imx8m/soc.c | 55 +++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c index d5254886bed..b8d7a050dc9 100644 --- a/arch/arm/mach-imx/imx8m/soc.c +++ b/arch/arm/mach-imx/imx8m/soc.c @@ -647,19 +647,17 @@ struct rom_api *g_rom_api = (struct rom_api *)0x980; #if defined(CONFIG_IMX8M) #include -int spl_mmc_emmc_boot_partition(struct mmc *mmc) +int imx8m_detect_secondary_image_boot(void) { u32 *rom_log_addr = (u32 *)0x9e0; u32 *rom_log; u8 event_id; - int i, part; - - part = default_spl_mmc_emmc_boot_partition(mmc); + int i, boot_secondary = 0; /* If the ROM event log pointer is not valid. */ if (*rom_log_addr < 0x900000 || *rom_log_addr >= 0xb00000 || *rom_log_addr & 0x3) - return part; + return -EINVAL; /* Parse the ROM event ID version 2 log */ rom_log = (u32 *)(uintptr_t)(*rom_log_addr); @@ -667,7 +665,7 @@ int spl_mmc_emmc_boot_partition(struct mmc *mmc) event_id = rom_log[i] >> 24; switch (event_id) { case 0x00: /* End of list */ - return part; + return boot_secondary; /* Log entries with 1 parameter, skip 1 */ case 0x80: /* Start to perform the device initialization */ case 0x81: /* The boot device initialization completes */ @@ -685,24 +683,45 @@ int spl_mmc_emmc_boot_partition(struct mmc *mmc) 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; + boot_secondary = 1; continue; default: continue; } } + return boot_secondary; +} + +int spl_mmc_emmc_boot_partition(struct mmc *mmc) +{ + int part, ret; + + part = default_spl_mmc_emmc_boot_partition(mmc); + if (part == 0) + return part; + + ret = imx8m_detect_secondary_image_boot(); + if (ret < 0) { + printf("Could not get boot partition! Using %d\n", part); + return part; + } + + if (ret == 1) { + /* + * 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; + } + return part; } #endif -- 2.40.1