All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 01/10] sunxi: mksunxiboot: Fix loading of files with a size which is not a multiple of 4
Date: Mon,  9 Jun 2014 11:36:53 +0200	[thread overview]
Message-ID: <1402306622-18485-2-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1402306622-18485-1-git-send-email-hdegoede@redhat.com>

We should not be aligning the amount of bytes which we try to read from the
disk, this leads to trying to read more bytes then there are which fails.

file_size is already aligned to BLOCK_SIZE before being stored in
img.header.length, so there is no need for load_size at all.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
---
 tools/mksunxiboot.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tools/mksunxiboot.c b/tools/mksunxiboot.c
index da7c9f0..1f0fbae 100644
--- a/tools/mksunxiboot.c
+++ b/tools/mksunxiboot.c
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
 {
 	int fd_in, fd_out;
 	struct boot_img img;
-	unsigned file_size, load_size;
+	unsigned file_size;
 	int count;
 
 	if (argc < 2) {
@@ -101,8 +101,6 @@ int main(int argc, char *argv[])
 	if (file_size > SRAM_LOAD_MAX_SIZE) {
 		fprintf(stderr, "ERROR: File too large!\n");
 		return EXIT_FAILURE;
-	} else {
-		load_size = ALIGN(file_size, sizeof(int));
 	}
 
 	fd_out = open(argv[2], O_WRONLY | O_CREAT, 0666);
@@ -113,8 +111,8 @@ int main(int argc, char *argv[])
 
 	/* read file to buffer to calculate checksum */
 	lseek(fd_in, 0, SEEK_SET);
-	count = read(fd_in, img.code, load_size);
-	if (count != load_size) {
+	count = read(fd_in, img.code, file_size);
+	if (count != file_size) {
 		perror("Reading input image");
 		return EXIT_FAILURE;
 	}
@@ -126,7 +124,7 @@ int main(int argc, char *argv[])
 		 & 0x00FFFFFF);
 	memcpy(img.header.magic, BOOT0_MAGIC, 8);	/* no '0' termination */
 	img.header.length =
-		ALIGN(load_size + sizeof(struct boot_file_head), BLOCK_SIZE);
+		ALIGN(file_size + sizeof(struct boot_file_head), BLOCK_SIZE);
 	gen_check_sum(&img.header);
 
 	count = write(fd_out, &img, img.header.length);
-- 
2.0.0

  reply	other threads:[~2014-06-09  9:36 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09  9:36 [U-Boot] [PATCH v3 00/10] sunxi: Bug fixes, sun4i and sun5i support and network improvements Hans de Goede
2014-06-09  9:36 ` Hans de Goede [this message]
2014-06-09  9:36 ` [U-Boot] [PATCH v3 02/10] sunxi: Fix u-boot-spl.lds to refer to .vectors Hans de Goede
2014-06-09  9:36 ` [U-Boot] [PATCH v3 03/10] sunxi: Remove mmc DMA support Hans de Goede
2014-07-23 17:35   ` Siarhei Siamashka
2014-07-26 13:07     ` Hans de Goede
2014-06-09  9:36 ` [U-Boot] [PATCH v3 04/10] sunxi: Implement reset_cpu Hans de Goede
2014-07-23 17:45   ` Siarhei Siamashka
2014-07-26 13:09     ` Hans de Goede
2014-06-09  9:36 ` [U-Boot] [PATCH v3 05/10] sunxi: Add sun4i support Hans de Goede
2014-07-23 17:53   ` Siarhei Siamashka
2014-06-09  9:36 ` [U-Boot] [PATCH v3 06/10] sunxi: Add sun5i support Hans de Goede
2014-07-23 18:02   ` Siarhei Siamashka
2014-07-26 13:11     ` Hans de Goede
2014-06-09  9:36 ` [U-Boot] [PATCH v3 07/10] net: Rename and cleanup sunxi (Allwinner) emac driver Hans de Goede
2014-07-23 18:12   ` Siarhei Siamashka
2014-07-26 13:21     ` Hans de Goede
2014-07-26 13:31       ` Stefan Roese
2014-06-09  9:37 ` [U-Boot] [PATCH v3 08/10] sunxi: Add emac glue, enable emac on the cubieboard Hans de Goede
2014-07-23 18:18   ` Siarhei Siamashka
2014-06-09  9:37 ` [U-Boot] [PATCH v3 09/10] sunxi: Add support for using MII phy-s with the GMAC nic Hans de Goede
2014-07-23 18:20   ` Siarhei Siamashka
2014-06-09  9:37 ` [U-Boot] [PATCH v3 10/10] sunxi: Add Ian Campbell and Hans de Goede as cubietruck board-maintainers Hans de Goede
2014-06-25 19:57 ` [U-Boot] [PATCH v3 00/10] sunxi: Bug fixes, sun4i and sun5i support and network improvements Ian Campbell
2014-06-26  7:38   ` Ian Campbell
2014-06-27  8:20     ` Stefan Roese
2014-07-06 19:12 ` Ian Campbell
2014-07-06 19:18   ` Albert ARIBAUD
2014-07-06 19:22     ` Ian Campbell
2014-07-06 20:54       ` Albert ARIBAUD
2014-07-06 21:28         ` Ian Campbell
2014-07-07  4:41           ` Wolfgang Denk
2014-07-07 12:50   ` Hans de Goede
2014-07-07 15:10     ` Ian Campbell
2014-07-07 16:47       ` Tom Rini
2014-07-07 20:23         ` Ian Campbell
2014-07-07 20:45           ` Tom Rini
2014-07-08  7:23             ` Ian Campbell
2014-07-08 13:48               ` Tom Rini
2014-07-08  7:48           ` Hans de Goede
2014-07-06 19:26 ` Ian Campbell
2014-07-07 12:53   ` Hans de Goede
2014-07-07 13:06     ` Tom Rini
2014-07-07 15:13     ` Ian Campbell
2014-07-08  7:47       ` Hans de Goede
2014-07-09  8:00         ` Ian Campbell
2014-07-09  8:44           ` Hans de Goede
2014-07-09 13:03           ` Henrik Nordström
2014-07-09 13:56             ` Hans de Goede

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=1402306622-18485-2-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.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.