summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMichael Tretter <m.tretter@pengutronix.de>2020-10-21 16:51:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-10-22 09:30:49 +0200
commit7e2f6a1ffd64f8099222436362bd0df33b9c7a96 (patch)
tree3ede4c9322fc2f6123455d345bc90cedfcf8bb41 /common
parent92e123a3d66bff3f773f0c2b5eec4463aca34052 (diff)
downloadbarebox-7e2f6a1ffd64f8099222436362bd0df33b9c7a96.tar.gz
barebox-7e2f6a1ffd64f8099222436362bd0df33b9c7a96.tar.xz
uimage: disable zero page when loading to SDRAM at address 0x0
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/uimage.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/common/uimage.c b/common/uimage.c
index a84b8fddc4..9abfbcf3ba 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;