Package: uboot-mkimage
Version: 0.4
Severity: normal
Tags: patch

Some versions of U-Boot (especially the one in the OpenMoko Freerunner NOR) are
broken and don't handle multi-file images the right way.
Multi-file images are U-Boot images with a table of sizes (size of the several
files), then the abovementionned files, aligned to multiples of 4 bytes.
Some broken versions of U-Boot expect a 4-byte padding for already aligned
files.

This patch adds a switch to add one zero byte at the end of a file whose size
is a multiple of 4.
This permits readability by both broken and non-broken versions of U-Boot,
while being safe.



-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (990, 'testing'), (120, 'unstable'), (105, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.34-rc5 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages uboot-mkimage depends on:
ii  libc6                         2.10.2-9   Embedded GNU C Library: Shared lib

uboot-mkimage recommends no packages.

uboot-mkimage suggests no packages.

-- no debconf information
diff -r 4281db2bcda6 mkimage.c
--- a/mkimage.c	Tue Jun 01 22:46:18 2010 +0200
+++ b/mkimage.c	Wed Jun 02 00:00:12 2010 +0200
@@ -170,6 +170,7 @@
 int lflag    = 0;
 int vflag    = 0;
 int xflag    = 0;
+int pflag    = 0;
 int opt_os   = IH_OS_LINUX;
 int opt_arch = IH_CPU_PPC;
 int opt_type = IH_TYPE_KERNEL;
@@ -254,6 +255,9 @@
 					usage ();
 				name = *++argv;
 				goto NXTARG;
+			case 'p':
+				pflag++;
+				break;
 			case 'v':
 				vflag++;
 				break;
@@ -408,6 +412,8 @@
 						cmdname, file, strerror(errno));
 					exit (EXIT_FAILURE);
 				}
+				if (pflag && (sbuf.st_size % 4) == 0)
+					sbuf.st_size += 1;
 				size = htonl(sbuf.st_size);
 			} else {
 				size = 0;
@@ -584,7 +590,8 @@
 		exit (EXIT_FAILURE);
 	}
 
-	if (pad && ((tail = size % 4) != 0)) {
+	tail = size % 4;
+	if (pad && (pflag || tail != 0)) {
 
 		if (write(ifd, (char *)&zero, 4-tail) != 4-tail) {
 			fprintf (stderr, "%s: Write error on %s: %s\n",
@@ -613,6 +620,7 @@
 			 "          -e ==> set entry point to 'ep' (hex)\n"
 			 "          -n ==> set image name to 'name'\n"
 			 "          -d ==> use image data from 'datafile'\n"
+			 "          -p ==> force padding in multi-file images (work around a bug in u-boot)\n"
 			 "          -x ==> set XIP (execute in place)\n"
 		);
 	exit (EXIT_FAILURE);

Reply via email to