mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Stefan Müller-Klieser" <s.mueller-klieser@phytec.de>
To: barebox@lists.infradead.org
Subject: [RFC 1/1] ARM: bootm: recalculate decompression space
Date: Wed, 22 Jun 2016 16:49:04 +0200	[thread overview]
Message-ID: <1466606944-22735-2-git-send-email-s.mueller-klieser@phytec.de> (raw)
In-Reply-To: <1466606944-22735-1-git-send-email-s.mueller-klieser@phytec.de>

According to the kernel documentation it is recommended to place the
compressed image between 32MiB and 128MiB. We will conform to this if we
have at least 64MiB of RAM. If this is not the case, we fall back to the
old scheme but take the relocated image into account.
This is required because of the ARM default kernel config changes
regarding RODATA layout, which lead to an increased compression factor
of the kernel image.

Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
---
 arch/arm/lib/bootm.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 803aa94..d4fe9a4 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -73,18 +73,24 @@ static int get_kernel_addresses(size_t image_size,
 {
 	unsigned long mem_start, mem_size;
 	int ret;
-	size_t image_decomp_size;
-	unsigned long spacing;
+	unsigned long decomp_space, spacing;
 
 	ret = sdram_start_and_size(&mem_start, &mem_size);
 	if (ret)
 		return ret;
 
 	/*
-	 * We don't know the exact decompressed size so just use a conservative
-	 * default of 4 times the size of the compressed image.
+	 * The kernel documentation "Documentation/arm/Booting" advises
+	 * to place the compressed image outside of the lowest 32MiB to
+	 * avoid relocation. We should do this if we have at least 64MiB
+	 * of ram. If we have less space, we assume a maximum
+	 * compression factor of 4 plus 1. The latter factor is the
+	 * space for the relocated image.
 	 */
-	image_decomp_size = PAGE_ALIGN(image_size * 4);
+	if (mem_size >= SZ_64M)
+		decomp_space = SZ_32M;
+	else
+		decomp_space = PAGE_ALIGN(image_size * 5);
 
 	/*
 	 * By default put oftree/initrd close behind compressed kernel image to
@@ -97,21 +103,21 @@ static int get_kernel_addresses(size_t image_size,
 		 * Place the kernel at an address where it does not need to
 		 * relocate itself before decompression.
 		 */
-		*load_address = mem_start + image_decomp_size;
+		*load_address = mem_start + decomp_space;
 		if (verbose)
 			printf("no OS load address, defaulting to 0x%08lx\n",
 				*load_address);
-	} else if (*load_address <= mem_start + image_decomp_size) {
+	} else if (*load_address <= mem_start + decomp_space) {
 		/*
 		 * If the user/image specified an address where the kernel needs
 		 * to relocate itself before decompression we need to extend the
 		 * spacing to allow this relocation to happen without
 		 * overwriting anything placed behind the kernel.
 		 */
-		spacing += image_decomp_size;
+		spacing += decomp_space;
 	}
 
-	*mem_free = PAGE_ALIGN(*load_address + image_size + spacing);
+	*mem_free = PAGE_ALIGN(*load_address + decomp_space + spacing);
 
 	return 0;
 }
-- 
1.9.1


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

  reply	other threads:[~2016-06-22 14:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-22 14:49 [RFC 0/1] am335x kernel not booting Stefan Müller-Klieser
2016-06-22 14:49 ` Stefan Müller-Klieser [this message]
2016-06-29  8:08   ` [RFC 1/1] ARM: bootm: recalculate decompression space Sascha Hauer
2016-06-23 11:44 ` [RFC 0/1] am335x kernel not booting 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=1466606944-22735-2-git-send-email-s.mueller-klieser@phytec.de \
    --to=s.mueller-klieser@phytec.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