mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: [PATCH 07/14] ARM: arria10: xload: fix __arria10_load_fpga
Date: Mon, 17 Jun 2024 13:36:29 +0200	[thread overview]
Message-ID: <20240617-v2024-05-0-topic-socfpga-arria10-xloader-v1-7-48a6eba4bb5e@pengutronix.de> (raw)
In-Reply-To: <20240617-v2024-05-0-topic-socfpga-arria10-xloader-v1-0-48a6eba4bb5e@pengutronix.de>

If arria10_load_fpga is called with an offset the (count < size)
comparison must handle that; increasing the count variable doesn't make
the bitstream size smaller.
As the function actually works with sectors, rename the variables to
make that clearer and add the offset to the bitstream_size to get the
correct end_sector up until __arria10_load_fpga needs to read.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 arch/arm/mach-socfpga/arria10-xload.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/arm/mach-socfpga/arria10-xload.c b/arch/arm/mach-socfpga/arria10-xload.c
index d4370945a1..e9a12ca9bb 100644
--- a/arch/arm/mach-socfpga/arria10-xload.c
+++ b/arch/arm/mach-socfpga/arria10-xload.c
@@ -353,25 +353,25 @@ int arria10_prepare_mmc(int barebox_part, int rbf_part)
 	return 0;
 }
 
-static inline int __arria10_load_fpga(void *buf, uint32_t count, uint32_t size)
+static inline int __arria10_load_fpga(void *buf, uint32_t sector, uint32_t end)
 {
 	int ret;
 
-	arria10_read_blocks(buf, count + bitstream.first_sec, SZ_16K);
+	arria10_read_blocks(buf, sector + bitstream.first_sec, SZ_16K);
 
-	count += SZ_16K / SECTOR_SIZE;
+	sector += SZ_16K / SECTOR_SIZE;
 
 	ret = a10_fpga_init(buf);
 	if (ret)
 		return -EAGAIN;
 
-	while (count <= size) {
+	while (sector <= end) {
 		ret = a10_fpga_write(buf, SZ_16K);
 		if (ret == -ENOSPC)
 			break;
 
-		count += SZ_16K / SECTOR_SIZE;
-		ret = arria10_read_blocks(buf, count, SZ_16K);
+		sector += SZ_16K / SECTOR_SIZE;
+		ret = arria10_read_blocks(buf, sector, SZ_16K);
 	}
 
 	ret = a10_fpga_write_complete();
@@ -385,8 +385,8 @@ int arria10_load_fpga(int offset, int bitstream_size)
 {
 	int ret;
 	void *buf = (void *)0xffe00000 + SZ_256K - 256 - SZ_16K;
-	uint32_t count;
-	uint32_t size = bitstream_size / SECTOR_SIZE;
+	uint32_t sector_count;
+	uint32_t end_sector = (bitstream_size + offset) / SECTOR_SIZE;
 	uint32_t retryCount;
 
 	if (offset)
@@ -397,9 +397,10 @@ int arria10_load_fpga(int offset, int bitstream_size)
 	 * some margin and try up to 10 times
 	 */
 	for (retryCount = 0; retryCount < 10; ++retryCount) {
-		count = offset;
 
-		ret = __arria10_load_fpga(buf, count, size);
+		sector_count = offset;
+
+		ret = __arria10_load_fpga(buf, sector_count, end_sector);
 		if (!ret)
 			return 0;
 		else if (ret == -EAGAIN)

-- 
2.43.2




  parent reply	other threads:[~2024-06-17 11:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17 11:36 [PATCH 00/14] ARM: SoCFPGA: arria10: clean up early bitstream loading Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 01/14] ARM: arria10: system-manager: add handoff registers Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 02/14] ARM: Arria10: reset manager: document reset source Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 03/14] ARM: socfpga: Arria10: PE1: remove arm_cpu_lowlevel_init Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 04/14] ARM: arria10: reset-manager: don't touch l4 wdog Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 05/14] ARM: Arria10: PE1: disable l4wd0 in bringup Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 06/14] ARM: Arria10: xload: rework __arria10_load_fpga Steffen Trumtrar
2024-06-17 11:36 ` Steffen Trumtrar [this message]
2024-06-17 11:36 ` [PATCH 08/14] ARM: Arria10: xload: kick watchdog Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 09/14] ARM: arria10: mark image in OCRAM as valid Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 10/14] ARM: Arria10: arria10_finish_io: remove unused param Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 11/14] ARM: Arria10: xload: remove useless writel Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 12/14] ARM: Arria10: xload: refactor wait loops Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 13/14] ARM: Arria10: xload: reduce timeout on condone Steffen Trumtrar
2024-06-17 11:36 ` [PATCH 14/14] ARM: arria10-xload: rework broken bitstream handling Steffen Trumtrar
2024-06-18  6:48 ` [PATCH 00/14] ARM: SoCFPGA: arria10: clean up early bitstream loading Sascha Hauer

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=20240617-v2024-05-0-topic-socfpga-arria10-xloader-v1-7-48a6eba4bb5e@pengutronix.de \
    --to=s.trumtrar@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox