* [PATCH 1/2] ARM: bootm: be more clever while deciding where to put zImage
@ 2014-05-01 21:42 Lucas Stach
2014-05-01 21:42 ` [PATCH 2/2] ARM: bootm: fix default uImage placement Lucas Stach
0 siblings, 1 reply; 2+ messages in thread
From: Lucas Stach @ 2014-05-01 21:42 UTC (permalink / raw)
To: barebox
For small systems we would put the zImage at 8MiB after
the start of memory, and put the DT a bit after the zImage.
When we encounter an image which is bigger than 8MiB
uncompressed, the kernel would try to relocate itself
and overwrite the DT.
Try to be more clever at zImage placement to avoid
triggering the kernel relocation.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
arch/arm/lib/bootm.c | 57 ++++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index c63cbc02e35f..dc7d2d9dfbae 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -237,7 +237,8 @@ static int do_bootz_linux(struct image_data *data)
int fd, ret, swap = 0;
struct zimage_header __header, *header;
void *zimage;
- u32 end;
+ u32 end, start;
+ size_t image_size;
unsigned long load_address = data->os_address;
unsigned long mem_start, mem_size, mem_free;
@@ -245,23 +246,6 @@ static int do_bootz_linux(struct image_data *data)
if (ret)
return ret;
- if (load_address == UIMAGE_INVALID_ADDRESS) {
- /*
- * The kernel should stay in the first 128MiB of RAM, recommended
- * is 32MiB into RAM so that relocation prior to decompression
- * can be avoided.
- */
- if (mem_size > SZ_64M)
- data->os_address = mem_start + SZ_32M;
- else
- data->os_address = mem_start + SZ_8M;
-
- load_address = data->os_address;
- if (bootm_verbose(data))
- printf("no os load address, defaulting to 0x%08lx\n",
- load_address);
- }
-
fd = open(data->os_file, O_RDONLY);
if (fd < 0) {
perror("open");
@@ -288,14 +272,33 @@ static int do_bootz_linux(struct image_data *data)
}
end = header->end;
+ start = header->start;
- if (swap)
+ if (swap) {
end = swab32(end);
+ start = swab32(start);
+ }
+
+ image_size = end - start;
+
+ if (load_address == UIMAGE_INVALID_ADDRESS) {
+ /*
+ * Just use a conservative default of 4 times the size of the
+ * compressed image, to avoid the need for the kernel to
+ * relocate itself before decompression.
+ */
+ data->os_address = mem_start + PAGE_ALIGN(image_size * 4);
- data->os_res = request_sdram_region("zimage", load_address, end);
+ load_address = data->os_address;
+ if (bootm_verbose(data))
+ printf("no os load address, defaulting to 0x%08lx\n",
+ load_address);
+ }
+
+ data->os_res = request_sdram_region("zimage", load_address, image_size);
if (!data->os_res) {
pr_err("bootm/zImage: failed to request memory at 0x%lx to 0x%lx (%d).\n",
- load_address, load_address + end, end);
+ load_address, load_address + image_size, image_size);
ret = -ENOMEM;
goto err_out;
}
@@ -304,7 +307,8 @@ static int do_bootz_linux(struct image_data *data)
memcpy(zimage, header, sizeof(*header));
- ret = read_full(fd, zimage + sizeof(*header), end - sizeof(*header));
+ ret = read_full(fd, zimage + sizeof(*header),
+ image_size - sizeof(*header));
if (ret < 0)
goto err_out;
if (ret < end - sizeof(*header)) {
@@ -326,13 +330,10 @@ static int do_bootz_linux(struct image_data *data)
close(fd);
/*
- * Put devicetree/initrd at maximum to 128MiB into RAM to not
- * risk to put it outside of lowmem.
+ * put oftree/initrd close behind compressed kernel image to avoid
+ * placing it outside of the kernels lowmem.
*/
- if (mem_size > SZ_256M)
- mem_free = mem_start + SZ_128M;
- else
- mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
+ mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
return __do_bootm_linux(data, mem_free, swap);
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] ARM: bootm: fix default uImage placement
2014-05-01 21:42 [PATCH 1/2] ARM: bootm: be more clever while deciding where to put zImage Lucas Stach
@ 2014-05-01 21:42 ` Lucas Stach
0 siblings, 0 replies; 2+ messages in thread
From: Lucas Stach @ 2014-05-01 21:42 UTC (permalink / raw)
To: barebox
For small systems we would put the zImage at 32KiB after
the start of memory, and put the DT a bit after the uImage.
The kernel will always try to relocate itself and overwrite
the DT.
Try to be more clever at uImage placement to avoid
triggering the kernel relocation.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
arch/arm/lib/bootm.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index dc7d2d9dfbae..803546827945 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -127,7 +127,13 @@ static int do_bootm_linux(struct image_data *data)
load_address = data->os_address;
if (load_address == UIMAGE_INVALID_ADDRESS) {
- load_address = mem_start + SZ_32K;
+ /*
+ * Just use a conservative default of 4 times the size of the
+ * compressed image, to avoid the need for the kernel to
+ * relocate itself before decompression.
+ */
+ load_address = mem_start + PAGE_ALIGN(
+ uimage_get_size(data->os, data->os_num) * 4);
if (bootm_verbose(data))
printf("no os load address, defaulting to 0x%08lx\n",
load_address);
@@ -138,13 +144,10 @@ static int do_bootm_linux(struct image_data *data)
return ret;
/*
- * Put devicetree/initrd at maximum to 128MiB into RAM to not
- * risk to put it outside of lowmem.
+ * put oftree/initrd close behind compressed kernel image to avoid
+ * placing it outside of the kernels lowmem.
*/
- if (mem_size > SZ_256M)
- mem_free = mem_start + SZ_128M;
- else
- mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
+ mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);
return __do_bootm_linux(data, mem_free, 0);
}
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-01 21:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-01 21:42 [PATCH 1/2] ARM: bootm: be more clever while deciding where to put zImage Lucas Stach
2014-05-01 21:42 ` [PATCH 2/2] ARM: bootm: fix default uImage placement Lucas Stach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox