Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DCFBC11F64 for ; Thu, 1 Jul 2021 11:22:36 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4777061461 for ; Thu, 1 Jul 2021 11:22:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4777061461 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4F8608327A; Thu, 1 Jul 2021 13:22:33 +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=1625138553; bh=wrj2FkwqkB7CJFMLzLJJ2+9QN2/bVvl58h4PT3P/SNs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=zwZaQBf3BYqq7OdkzVij1vgf5jU/PFoZbM+Y6EKbkPCAxqHOjZsJj4YyFYSuzZ/YI ahemLlYhGi6ANdJlvkdPjjFPS+b6a6Fps8f+dAjxwyHspbpn5s1J966r0noVmE7z1Y dSW9JzdJN3ZNq1mXtOCMhow1Csb7T28/wsnBvlj98tARRNrOzdie3BJMsKCvU5ESOF u7npjPMR9xvs2DQwe4Obq5tBbwRL07dhwDEbGu1fQtt75kdtfmO0lyMt4mxuX25DGs tUNzfYef7xAj7chs1op29EFKtFyY0hTLR/P7jkVkNy3wEqPrAm9dVyH8PGUrnRtv57 Fu8z8vXG7eAQw== Received: from [10.0.40.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: hws@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 708D983236; Thu, 1 Jul 2021 13:22:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1625138550; bh=wrj2FkwqkB7CJFMLzLJJ2+9QN2/bVvl58h4PT3P/SNs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XxluIGKdNsMeaqNXwFvACeHts51rvSEFGWdPCg9zuCKYG7u48ObHHzsMhm8QZa0Id Y9XcEOPVCkDnqtJAinJ8w5EEU7cYXWqzbrlZwFFIcW0v76OYPRllhkwehu5/Y5ag/w SX+QCR9/Yx3rFdfNc50Hs9JwjtbBkJdLQQ/toyvZvr5g6TVgGDkH7McpDNGsCVPLXO s8Jml2KZfq34fF/0Tzx07B3D0qUMI5UefFnKQbi38NKF5Z4IoLTW53cc6US1Bv6HeH eat9Afsy2e67xGlnnzK+hqTF0Xxj2HW84yNsKDGhLwIrc+mjQzP/SI4vcyMgNANor+ pSgxHaUTeeCwA== Message-ID: Subject: Re: [PATCH 2/2] ARM: imx: Pick correct eMMC boot partition from ROM log From: Harald Seiler To: Marek Vasut , u-boot@lists.denx.de Cc: Faiz Abbas , Lokesh Vutla , Simon Glass , Fabio Estevam , Peng Fan , Stefano Babic , Ye Li Date: Thu, 01 Jul 2021 13:22:30 +0200 In-Reply-To: <20210630230801.290195-2-marex@denx.de> References: <20210630230801.290195-1-marex@denx.de> <20210630230801.290195-2-marex@denx.de> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Hi, On Thu, 2021-07-01 at 01:08 +0200, Marek Vasut wrote: > 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; I assume your intention here is to break from the for loop? This `break` will only exit the switch statement, so the loop will continue running on the data following the "End of list". Or is this behavior intentional? In that case I'd find the use of `continue` in the other branches a bit odd, as `continue` and `break` do the same thing in this situation. -- Harald > + /* 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;