mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH v3 2/2] uimage: disable zero page when loading to SDRAM at address 0x0
Date: Wed, 21 Oct 2020 16:51:40 +0200	[thread overview]
Message-ID: <20201021145140.597728-2-m.tretter@pengutronix.de> (raw)
In-Reply-To: <20201021145140.597728-1-m.tretter@pengutronix.de>

If the SDRAM is mapped to address 0x0 and an image should be loaded to
to the SDRAM without offset, Barebox would normally trap the access as a
null pointer.

However, since Linux kernel commit cfa7ede20f13 ("arm64: set TEXT_OFFSET
to 0x0 in preparation for removing it entirely") no offset is the
default for arm64. Therefore, copying the image to 0x0 of the SDRAM is
necessary.

Disable the zero page trap for copying an image to address 0x0.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
v3:
- none

v2:
- switch to zero_page_memcpy helper function
- read file to temporary buffer before copying to page 0
---
 common/uimage.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index a84b8fddc4e7..9abfbcf3bac9 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -27,6 +27,7 @@
 #include <rtc.h>
 #include <filetype.h>
 #include <memory.h>
+#include <zero_page.h>
 
 static inline int uimage_is_multi_image(struct uimage_handle *handle)
 {
@@ -359,7 +360,10 @@ static int uimage_sdram_flush(void *buf, unsigned int len)
 		}
 	}
 
-	memcpy(uimage_buf + uimage_size, buf, len);
+	if (zero_page_contains((unsigned long)uimage_buf + uimage_size))
+		zero_page_memcpy(uimage_buf + uimage_size, buf, len);
+	else
+		memcpy(uimage_buf + uimage_size, buf, len);
 
 	uimage_size += len;
 
@@ -388,7 +392,20 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr)
 			goto out;
 		}
 
-		now = read_full(fd, (void *)(res->start + ofs), BUFSIZ);
+		if (zero_page_contains(res->start + ofs)) {
+			void *tmp = malloc(BUFSIZ);
+			if (!tmp)
+				now = -ENOMEM;
+			else
+				now = read_full(fd, tmp, BUFSIZ);
+
+			if (now > 0)
+				zero_page_memcpy((void *)(res->start + ofs), tmp, now);
+			free(tmp);
+		} else {
+			now = read_full(fd, (void *)(res->start + ofs), BUFSIZ);
+		}
+
 		if (now < 0) {
 			release_sdram_region(res);
 			res = NULL;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-10-21 14:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-21 14:51 [PATCH v3 1/2] ARM: mmu64: allow to disable null pointer trap on zero page Michael Tretter
2020-10-21 14:51 ` Michael Tretter [this message]
2020-10-22  7:31 ` 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=20201021145140.597728-2-m.tretter@pengutronix.de \
    --to=m.tretter@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