All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Trimarchi <michael@amarulasolutions.com>
To: Ye Li <ye.li@nxp.com>, Stefano Babic <sbabic@denx.de>,
	Fabio Estevam <festevam@gmail.com>
Cc: u-boot@lists.denx.de,
	Ariel D'Alessandro <ariel.dalessandro@collabora.com>,
	linux-amarula@amarulasolutions.com,
	Anthony Brandon <anthony@amarulasolutions.com>
Subject: [PATCH] cmd_nandbcb: Support secondary boot address of imx8mn
Date: Mon, 15 Nov 2021 19:15:52 +0100	[thread overview]
Message-ID: <20211115181553.74830-1-michael@amarulasolutions.com> (raw)

Add support of secondary boot address for imx8mn. The secondary
boot address is hardcoded in the fuse. The value is calculated
from there according to the algo.

The fuse IMG_CNTN_SET1_OFFSET (0x490[22:19]) is defined as follows:
• Secondary boot is disabled if fuse value is bigger than 10, n = fuse value bigger than
10.
• n == 0: Offset = 4MB
• n == 2: Offset = 1MB
• Others & n <= 10 : Offset = 1MB*2^n
• For FlexSPI boot, the valid values are: 0, 1, 2, 3, 4, 5, 6, and 7.

Tested remove the first one image and have the board still booting on
second one. This implementation cover one architecture

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
 arch/arm/mach-imx/cmd_nandbcb.c | 41 +++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c
index 09622c13c9..348f8b626a 100644
--- a/arch/arm/mach-imx/cmd_nandbcb.c
+++ b/arch/arm/mach-imx/cmd_nandbcb.c
@@ -132,6 +132,7 @@ static struct platform_config imx8q_plat_config = {
 
 /* boot search related variables and definitions */
 static int g_boot_search_count = 4;
+static int g_boot_secondary_offset;
 static int g_boot_search_stride;
 static int g_pages_per_stride;
 
@@ -275,9 +276,9 @@ static int nandbcb_set_boot_config(int argc, char * const argv[],
 	boot_stream2_address = ((maxsize - boot_stream1_address) / 2 +
 			       boot_stream1_address);
 
-	if (boot_cfg->secondary_boot_stream_off_in_MB)
+	if (g_boot_secondary_offset)
 		boot_stream2_address =
-			(loff_t)boot_cfg->secondary_boot_stream_off_in_MB * 1024 * 1024;
+			(loff_t)g_boot_secondary_offset * 1024 * 1024;
 
 	max_boot_stream_size = boot_stream2_address - boot_stream1_address;
 
@@ -1269,6 +1270,36 @@ static bool check_fingerprint(void *data, int fingerprint)
 	return (*(int *)(data + off) == fingerprint);
 }
 
+static int fuse_secondary_boot(u32 bank, u32 word, u32 mask, u32 off)
+{
+	int err;
+	u32 val;
+	int ret;
+
+	err = fuse_read(bank, word, &val);
+	if (err)
+		return 0;
+
+	val = (val & mask) >> off;
+
+	if (val > 10)
+		return 0;
+
+	switch (val) {
+	case 0:
+		ret = 4;
+		break;
+	case 1:
+		ret = 1;
+		break;
+	default:
+		ret = 2 << val;
+		break;
+	}
+
+	return ret;
+};
+
 static int fuse_to_search_count(u32 bank, u32 word, u32 mask, u32 off)
 {
 	int err;
@@ -1506,6 +1537,12 @@ static int do_nandbcb(struct cmd_tbl *cmdtp, int flag, int argc,
 		       g_boot_search_count);
 	}
 
+	if ((plat_config.misc_flags) & FIRMWARE_SECONDARY_FIXED_ADDR) {
+		if (is_imx8mn())
+			g_boot_secondary_offset = fuse_secondary_boot(2, 1, 0xff0000, 16);
+
+	}
+
 	cmd = argv[1];
 	--argc;
 	++argv;
-- 
2.25.1


             reply	other threads:[~2021-11-15 18:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 18:15 Michael Trimarchi [this message]
2021-11-15 18:16 [PATCH] cmd_nandbcb: Support secondary boot address of imx8mn Michael Trimarchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211115181553.74830-1-michael@amarulasolutions.com \
    --to=michael@amarulasolutions.com \
    --cc=anthony@amarulasolutions.com \
    --cc=ariel.dalessandro@collabora.com \
    --cc=festevam@gmail.com \
    --cc=linux-amarula@amarulasolutions.com \
    --cc=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=ye.li@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.