[U-Boot-Users] Multi-file image comment in image.h is misleading

I tried using the "How to Add Files to a SELF Ramdisk" (http://www.denx.de/twiki/bin/view/DULG/HowToAddFiles) instructions to extract a ramdisk from an image until I realized that I am dealing with a multi-file image.
# mkimage -l pImage Image Name: Linux-2.4.22 Created: Mon Aug 30 15:56:07 2004 Image Type: PowerPC Linux Multi-File Image (gzip compressed) Data Size: 5406339 Bytes = 5279.63 kB = 5.16 MB Load Address: 0x00000000 Entry Point: 0x00000000 Contents: Image 0: 1147513 Bytes = 1120 kB = 1 MB Image 1: 4258811 Bytes = 4158 kB = 4 MB
My image file is 5406403 bytes but the total size of the files inside the image is 5406324 (1147513+4258811) which is a difference of 79 bytes. Given that the header is 64 bytes, I am left with 15 that must be related to the multi-file image type.
When looking at include/image.h I read the following: * "Multi-File Images" start with a list of image sizes, each * image size (in bytes) specified by an "uint32_t" in network * byte order. This list is terminated by an "(uint32_t)0". * Immediately after the terminating 0 follow the images, one by * one, all aligned on "uint32_t" boundaries (size rounded up to * a multiple of 4 bytes).
So my 15 extra bytes were explained as 4 bytes for the size of the first file 4 bytes for the size of the second file 4 bytes for the terminating 0 3 bytes for the padding on the first file (4 - (1147513 % 4)) = 3
Now for the confusion... The second file should also be padded given the image.h comment above and the fact that (4 - (4258811 % 4)) = 1 So why was there no padding?
As it turns out, the code in mkimage.c responsible for copying the data files does not add the padding to the last file in the multi-file image. The code I am referring to is in main() and is as follows:
for (;;) { char *sep = strchr(file, ':'); if (sep) { *sep = '\0'; copy_file (ifd, file, 1); *sep++ = ':'; file = sep; } else { copy_file (ifd, file, 0); break; }
With copy_file defined as copy_file (int ifd, const char *datafile, int pad)
Clearly the pad flag is only set when there are more files to copy.
My suggestion is a simple update to the comment in image.h to state that the last file will not have any padding applied.
BTW: Anyone know if a tool for extracting files from a multi-file image exists or do I have to write one myself? ;)
Jason
participants (1)
-
Jason Milley