All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 05/11] tools: mksunxiboot: allow larger SPL binaries
Date: Fri, 20 Jan 2017 01:53:25 +0000	[thread overview]
Message-ID: <1484877211-19332-6-git-send-email-andre.przywara@arm.com> (raw)
In-Reply-To: <1484877211-19332-1-git-send-email-andre.przywara@arm.com>

mksunxiboot limits the size of the resulting SPL binaries to pretty
conservative values to cover all SoCs and all boot media (NAND).
In preparation for supporting modern SoCs without NAND, which may
require a really large SPL, introduce comamnd line parameters to
push the possible SPL size to the limits.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 tools/mksunxiboot.c | 51 ++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/tools/mksunxiboot.c b/tools/mksunxiboot.c
index 0f0b003..fa54bce 100644
--- a/tools/mksunxiboot.c
+++ b/tools/mksunxiboot.c
@@ -48,37 +48,58 @@ int gen_check_sum(struct boot_file_head *head_p)
 #define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
 #define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
 
-#define SUN4I_SRAM_SIZE 0x7600	/* 0x7748+ is used by BROM */
-#define SRAM_LOAD_MAX_SIZE (SUN4I_SRAM_SIZE - sizeof(struct boot_file_head))
+#define SUN4I_SRAM_SIZE		0x7600	/* 0x7748+ is used by BROM */
+#define SUNXI_MAX_SRAM_SIZE	0x8000
+#define SRAM_LOAD_MAX_SIZE (SUNXI_MAX_SRAM_SIZE - sizeof(struct boot_file_head))
 
 /*
  * BROM (at least on A10 and A20) requires NAND-images to be explicitly aligned
  * to a multiple of 8K, and rejects the image otherwise. MMC-images are fine
- * with 512B blocks. To cater for both, align to the largest of the two.
+ * with 512B blocks.
  */
-#define BLOCK_SIZE 0x2000
+#define BLOCK_SIZE_NAND 0x2000
+#define BLOCK_SIZE_MMC  0x0200
+#define MAX_BLOCK_SIZE	BLOCK_SIZE_NAND
 
 struct boot_img {
 	struct boot_file_head header;
 	char code[SRAM_LOAD_MAX_SIZE];
-	char pad[BLOCK_SIZE];
+	char pad[MAX_BLOCK_SIZE];
 };
 
 int main(int argc, char *argv[])
 {
 	int fd_in, fd_out;
+	int ac = 1;
 	struct boot_img img;
 	unsigned file_size;
+	unsigned size_limit = SUN4I_SRAM_SIZE - sizeof(struct boot_file_head);
+	unsigned block_size = BLOCK_SIZE_NAND;
 	int count;
 
 	if (argc < 2) {
 		printf("\tThis program makes an input bin file to sun4i " \
 		       "bootable image.\n" \
-		       "\tUsage: %s input_file out_putfile\n", argv[0]);
+		       "\tUsage: %s input_file [out_putfile]\n", argv[0]);
 		return EXIT_FAILURE;
 	}
 
-	fd_in = open(argv[1], O_RDONLY);
+	if (!strcmp(argv[ac], "--mmc")) {
+		block_size = BLOCK_SIZE_MMC;
+		ac++;
+	}
+	if (!strcmp(argv[ac], "--nand")) {
+		block_size = BLOCK_SIZE_NAND;
+		ac++;
+	}
+	if (!strcmp(argv[ac], "--max")) {
+		size_limit = SUNXI_MAX_SRAM_SIZE - sizeof(struct boot_file_head);
+		ac++;
+	}
+	if (ac >= argc)
+		return EXIT_FAILURE;
+
+	fd_in = open(argv[ac++], O_RDONLY);
 	if (fd_in < 0) {
 		perror("Open input file");
 		return EXIT_FAILURE;
@@ -89,15 +110,19 @@ int main(int argc, char *argv[])
 	/* get input file size */
 	file_size = lseek(fd_in, 0, SEEK_END);
 
-	if (file_size > SRAM_LOAD_MAX_SIZE) {
+	if (file_size > size_limit) {
 		fprintf(stderr, "ERROR: File too large!\n");
 		return EXIT_FAILURE;
 	}
 
-	fd_out = open(argv[2], O_WRONLY | O_CREAT, 0666);
-	if (fd_out < 0) {
-		perror("Open output file");
-		return EXIT_FAILURE;
+	if (ac >= argc) {
+		fd_out = STDOUT_FILENO;
+	} else {
+		fd_out = open(argv[ac], O_WRONLY | O_CREAT, 0666);
+		if (fd_out < 0) {
+			perror("Open output file");
+			return EXIT_FAILURE;
+		}
 	}
 
 	/* read file to buffer to calculate checksum */
@@ -115,7 +140,7 @@ int main(int argc, char *argv[])
 		 & 0x00FFFFFF);
 	memcpy(img.header.magic, BOOT0_MAGIC, 8);	/* no '0' termination */
 	img.header.length =
-		ALIGN(file_size + sizeof(struct boot_file_head), BLOCK_SIZE);
+		ALIGN(file_size + sizeof(struct boot_file_head), block_size);
 	img.header.b_instruction = cpu_to_le32(img.header.b_instruction);
 	img.header.length = cpu_to_le32(img.header.length);
 
-- 
2.8.2

  parent reply	other threads:[~2017-01-20  1:53 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20  1:53 [U-Boot] [RFC PATCH 00/11] extend FIT loading support (plus Pine64/ATF support) Andre Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 01/11] SPL: FIT: refactor FDT loading Andre Przywara
2017-01-23  8:56   ` Lokesh Vutla
2017-01-27 21:29   ` Simon Glass
2017-01-28  0:38     ` André Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 02/11] SPL: FIT: rework U-Boot image loading Andre Przywara
2017-01-23  8:56   ` Lokesh Vutla
2017-01-27 21:29   ` Simon Glass
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 03/11] SPL: FIT: factor out spl_load_fit_image() Andre Przywara
2017-01-22  7:16   ` Kever Yang
2017-01-22 10:42     ` André Przywara
2017-01-23  2:37       ` Kever Yang
2017-01-23  8:53   ` Lokesh Vutla
2017-01-23 12:58     ` Tom Rini
2017-01-23 13:31       ` Lokesh Vutla
2017-01-23 13:50         ` Tom Rini
2017-01-23 23:07     ` André Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 04/11] SPL: FIT: allow loading multiple images Andre Przywara
2017-01-22  7:08   ` Kever Yang
2017-01-22 10:58     ` André Przywara
2017-01-23  2:49       ` Kever Yang
2017-01-23 12:47         ` Michal Simek
2017-01-23 23:52         ` André Przywara
2017-01-23  8:57   ` Lokesh Vutla
2017-01-20  1:53 ` Andre Przywara [this message]
2017-01-21  4:24   ` [U-Boot] [RFC PATCH 05/11] tools: mksunxiboot: allow larger SPL binaries Siarhei Siamashka
2017-01-21 11:17     ` André Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 06/11] sunxi: A64: SPL: allow large SPL binary Andre Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 07/11] sunxi: A64: move SPL stack to end of SRAM A2 Andre Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 08/11] sunxi: SPL: add FIT config selector for Pine64 boards Andre Przywara
2017-01-20 21:35   ` Maxime Ripard
2017-01-20 21:55     ` André Przywara
2017-01-21  2:16       ` [U-Boot] [linux-sunxi] " Icenowy Zheng
2017-01-21  2:16       ` Icenowy Zheng
2017-01-21  4:05       ` [U-Boot] " Siarhei Siamashka
2017-01-21 15:15         ` André Przywara
2017-01-23 17:29           ` Maxime Ripard
2017-01-23 22:55             ` André Przywara
2017-01-26 10:55               ` Maxime Ripard
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 09/11] sunxi: Pine64: defconfig: enable SPL FIT support Andre Przywara
2017-01-20 21:36   ` Maxime Ripard
2017-01-20 21:55     ` André Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 10/11] sunxi: Pine64: add FIT image source Andre Przywara
2017-01-20  1:53 ` [U-Boot] [RFC PATCH 11/11] SPL: SPI: sunxi: add SPL FIT image support Andre Przywara
2017-01-20 21:37   ` Maxime Ripard
2017-01-20 21:58     ` André Przywara
2017-01-20 17:02 ` [U-Boot] [RFC PATCH 00/11] extend FIT loading support (plus Pine64/ATF support) Andrew F. Davis
2017-01-20 17:17   ` Andre Przywara
2017-01-20 17:35     ` Andrew F. Davis
2017-01-20 17:48       ` Andre Przywara
2017-01-20 19:07         ` [U-Boot] [linux-sunxi] " Icenowy Zheng
2017-01-20 22:21       ` [U-Boot] " André Przywara
2017-01-27 21:29 ` Simon Glass
2017-01-28  1:47   ` André Przywara
2017-02-06 15:33     ` Simon Glass
2017-02-06 16:09       ` Andre Przywara
2017-02-06 16:17       ` Andrew F. Davis
2017-02-06 16:32         ` Andre Przywara
2017-02-06 16:37           ` Andrew F. Davis

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=1484877211-19332-6-git-send-email-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.