dumpimage: add 'T' option to explicitly set the image type
PATCH 1/4 dumpimage: add 'T' option to explicitly set the image type
From: Guilherme Maciel Ferreira <[email protected]>
Some image types, like "KeyStone GP", do not have magic numbers to distinguish them from other image types. Thus, the automatic image type discovery does not work correctly.
This patch also fix some integer type mismatches.
--- README | 7 ++-- test/image/test-imagetools.sh | 48 +++++++++++++++------------- tools/dumpimage.c | 70 ++++++++++++++++++++-------------------- tools/gpimage-common.c | 3 +- tools/mkimage.c | 3 -- 5 files changed, 67 insertions(+), 64 deletions(-)
README +4 -3
@@ -5900,9 +5900,10 @@ option performs the converse operation of the mkimage's second form (the "-d" option). Given an image built by mkimage, the dumpimage extracts a "data file" from the image: - tools/dumpimage -i image -p position data_file - -i ==> extract from the 'image' a specific 'data_file', \ - indexed by 'position' + tools/dumpimage -i image -T type -p position data_file + -i ==> extract from the 'image' a specific 'data_file' + -T ==> set image type to 'type' + -p ==> 'position' (starting at 0) of the 'data_file' inside the 'image' Installing a Linux Image:
test/image/test-imagetools.sh +26 -22
100 lines not on this page · raw message
tools/dumpimage.c +35 -35
126 lines not on this page · raw message
tools/gpimage-common.c +2 -1
@@ -32,7 +32,8 @@ void to_be32(uint32_t *gph_size, uint32_t *gph_load_addr)int gph_verify_header (struct gp_header *gph,int be) { -uint32_t gph_size = gph->size, gph_load_addr = gph->load_addr; +uint32_t gph_size = gph->size; +uint32_t gph_load_addr = gph->load_addr;if (be)to_be32 (&gph_size, &gph_load_addr);
tools/mkimage.c +0 -3
@@ -15,9 +15,6 @@static void copy_file (int ,const char *,int );static void usage (void ); -/* image_type_params link list to maintain registered image type supports */ -struct image_type_params *mkimage_tparams =NULL ; -/* parameters initialized by core will be used by the image type code */ struct image_tool_params params = { .os =IH_OS_LINUX ,
Signature · 1 line
1.7.0.4
PATCH 2/4 dumpimage: replace the term "datafile" by "subimage"
--- tools/default_image.c | 6 +++--- tools/dumpimage.c | 12 ++++++------ tools/imagetool.c | 2 +- tools/imagetool.h | 17 +++++++++-------- 4 files changed, 19 insertions(+), 18 deletions(-)
tools/default_image.c +3 -3
@@ -117,7 +117,7 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd,image_set_hcrc (hdr, checksum); } -static int image_extract_datafile (void *ptr,struct image_tool_params *params) +static int image_extract_subimage (void *ptr,struct image_tool_params *params) {const image_header_t *hdr = (const image_header_t *)ptr;ulong file_data;
@@ -144,7 +144,7 @@ static int image_extract_datafile(void *ptr, struct image_tool_params *params) }/* save the "data file" into the file system */ -return imagetool_save_datafile (params->outfile, file_data, file_len); +return imagetool_save_subimage (params->outfile, file_data, file_len); }/*
@@ -159,7 +159,7 @@ U_BOOT_IMAGE_TYPE( image_verify_header, image_print_contents, image_set_header, - image_extract_datafile, + image_extract_subimage, image_check_image_types,NULL ,NULL
tools/dumpimage.c +6 -6
@@ -18,7 +18,7 @@ static struct image_tool_params params = { };/* -* dumpimage_extract_datafile - +* dumpimage_extract_subimage - * * It scans all registered image types, * verifies image_header for each supported image type
@@ -28,7 +28,7 @@ static struct image_tool_params params = {* returns negative if input image format does not match with any of * supported image types */ -static int dumpimage_extract_datafile (struct image_type_params *tparams, +static int dumpimage_extract_subimage (struct image_type_params *tparams,void *ptr,struct stat *sbuf) {int retval =-1 ;
@@ -42,11 +42,11 @@ static int dumpimage_extract_datafile(struct image_type_params *tparams,* Extract the file from the image * if verify is successful */ -if (tparams->extract_datafile) { - retval = tparams->extract_datafile (ptr, ¶ms); +if (tparams->extract_subimage) { + retval = tparams->extract_subimage (ptr, ¶ms); }else {fprintf (stderr, -"%s: extract_datafile undefined for %s\n" , +"%s: extract_subimage undefined for %s\n" , params.cmdname, tparams->name);return -2 ; }
@@ -170,7 +170,7 @@ int main(int argc, char **argv)* Extract the data files from within the matched * image type. Returns the error code if not matched */ - retval =dumpimage_extract_datafile (tparams, ptr, + retval =dumpimage_extract_subimage (tparams, ptr, &sbuf); }else {/*
tools/imagetool.c +1 -1
@@ -66,7 +66,7 @@ int imagetool_verify_print_header(return retval; } -int imagetool_save_datafile ( +int imagetool_save_subimage (const char *file_name,ulong file_data,ulong file_len)
tools/imagetool.h +9 -8
@@ -110,14 +110,15 @@ struct image_type_params {void (*set_header) (void *,struct stat *,int ,struct image_tool_params *);/* -* This function is used by the command to retrieve a data file from -* the image (i.e. dumpimage -i <image> -p <position> <data_file>). +* This function is used by the command to retrieve a component +* (sub-image) from the image (i.e. dumpimage -i <image> -p <position> +* <sub-image-name>). * Thus the code to extract a file from an image must be put here. * * Returns 0 if the file was successfully retrieved from the image, * or a negative value on error. */ -int (*extract_datafile) (void *,struct image_tool_params *); +int (*extract_subimage)(void *,struct image_tool_params *);/* * Some image generation support for ex (default image type) supports * more than one type_ids, this callback function is used to check
@@ -169,18 +170,18 @@ int imagetool_verify_print_header( struct image_tool_params *params);/** -* imagetool_save_datafile - store data into a file +* imagetool_save_subimage - store data into a file * @file_name: name of the destination file * @file_data: data to be written * @file_len: the amount of data to store * -* imagetool_save_datafile() store file_len bytes of data pointed by file_data +* imagetool_save_subimage() store file_len bytes of data pointed by file_data * into the file name by file_name. * * returns: * zero in case of success or a negative value if fail. */ -int imagetool_save_datafile ( +int imagetool_save_subimage (const char *file_name,ulong file_data,ulong file_len);
@@ -202,7 +203,7 @@ void pbl_load_uboot(int fd, struct image_tool_params *mparams); _verify_header, \ _print_header, \ _set_header, \ - _extract_datafile, \ + _extract_subimage, \ _check_image_type, \ _fflag_handle, \ _vrec_header \
@@ -215,7 +216,7 @@ void pbl_load_uboot(int fd, struct image_tool_params *mparams); .verify_header = _verify_header, \ .print_header = _print_header, \ .set_header = _set_header, \ - .extract_datafile = _extract_datafile, \ + .extract_subimage = _extract_subimage, \ .check_image_type = _check_image_type, \ .fflag_handle = _fflag_handle, \ .vrec_header = _vrec_header \
Signature · 1 line
1.7.0.4
PATCH 2/4 dumpimage: replace the term "datafile" by "subimage"
Quoted 1 line · Guilherme Maciel Ferreira
Signed-off-by Guilherme Maciel Ferreira <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150202/6d158734/attachment.sig>
PATCH 3/4 dumpimage: fit: extract FIT images
In reply to Guilherme Maciel FerreiraThe dumpimage is able to extract components contained in a FIT image:
$ ./dumpimage -T flat_dt -i CONTAINER.ITB -p INDEX FILE
The CONTAINER.ITB is a regular FIT container file. The INDEX is the poisition of the sub-image to be retrieved, and FILE is the file (path+name) to save the extracted sub-image.
For example, given the following kernel.its to build a kernel.itb:
/dts-v1/;
/ {
...
images {
kernel at 1 {
description = "Kernel 2.6.32-34";
data = /incbin/("/boot/vmlinuz-2.6.32-34-generic");
type = "kernel";
arch = "ppc";
os = "linux";
compression = "gzip";
load = <00000000>;
entry = <00000000>;
hash at 1 {
algo = "md5";
};
};
...
};
...
};The dumpimage can extract the 'kernel at 1' node through the following command:
$ ./dumpimage -T flat_dt -i kernel.itb -p 0 kernel
Extracted:
Image 0 (kernel at 1)
Description: Kernel 2.6.32-34
Created: Wed Oct 22 15:50:26 2014
Type: Kernel Image
Compression: gzip compressed
Data Size: 4040128 Bytes = 3945.44 kB = 3.85 MB
Architecture: PowerPC
OS: Linux
Load Address: 0x00000000
Entry Point: 0x00000000
Hash algo: md5
Hash value: 22352ad39bdc03e2e50f9cc28c1c3652Which results in the file 'kernel' being exactly the same as '/boot/vmlinuz-2.6.32-34-generic'.
--- common/image-fit.c | 30 +++++++++++++- include/image.h | 1 + test/image/test-imagetools.sh | 83 ++++++++++++++++++++++++++++++++++++- tools/fit_image.c | 93 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 204 insertions(+), 3 deletions(-)
common/image-fit.c +29 -1
@@ -112,6 +112,33 @@ static void fit_get_debug(const void *fit, int noffset, fdt_strerror(err)); } +/** +* fit_get_subimage_count - get component (sub-image) count +* @fit: pointer to the FIT format image header +* @images_noffset: offset of images node +* +* returns: +* number of image components +*/ +int fit_get_subimage_count (const void *fit,int images_noffset) +{ +int noffset; +int ndepth; +int count =0 ; + +/* Process its subnodes, print out component images details */ +for (ndepth =0 , count =0 , + noffset =fdt_next_node (fit, images_noffset, &ndepth); + (noffset >=0 ) && (ndepth >0 ); + noffset =fdt_next_node (fit, noffset, &ndepth)) { +if (ndepth ==1 ) { + count++; + } + } + +return count; +} +#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_FIT_SPL_PRINT )/** * fit_print_contents - prints out the contents of the FIT format image
@@ -423,7 +450,8 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) } } } -#endif + +#endif /* !defined(CONFIG_SPL_BUILD) || defined(CONFIG_FIT_SPL_PRINT) */ /** * fit_get_desc - get node description property
include/image.h +1 -0
@@ -750,6 +750,7 @@ int fit_parse_conf(const char *spec, ulong addr_curr,int fit_parse_subimage (const char *spec,ulong addr_curr,ulong *addr,const char **image_name); +int fit_get_subimage_count (const void *fit,int images_noffset);void fit_print_contents (const void *fit);void fit_image_print (const void *fit,int noffset,const char *p);
test/image/test-imagetools.sh +82 -1
107 lines not on this page · raw message
tools/fit_image.c +92 -1
105 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 3/4 dumpimage: fit: extract FIT images
Quoted 49 lines · Guilherme Maciel Ferreira
The dumpimage is able to extract components contained in a FIT image:
$ ./dumpimage -T flat_dt -i CONTAINER.ITB -p INDEX FILEThe CONTAINER.ITB is a regular FIT container file. The INDEX is the poisition of the sub-image to be retrieved, and FILE is the file (path+name) to save the extracted sub-image.
For example, given the following kernel.its to build a kernel.itb:
/dts-v1/; / { ... images { kernel at 1 { description = "Kernel 2.6.32-34"; data = /incbin/("/boot/vmlinuz-2.6.32-34-generic"); type = "kernel"; arch = "ppc"; os = "linux"; compression = "gzip"; load = <00000000>; entry = <00000000>; hash at 1 { algo = "md5"; }; }; ... }; ... };The dumpimage can extract the 'kernel at 1' node through the following command:
$ ./dumpimage -T flat_dt -i kernel.itb -p 0 kernel Extracted: Image 0 (kernel at 1) Description: Kernel 2.6.32-34 Created: Wed Oct 22 15:50:26 2014 Type: Kernel Image Compression: gzip compressed Data Size: 4040128 Bytes = 3945.44 kB = 3.85 MB Architecture: PowerPC OS: Linux Load Address: 0x00000000 Entry Point: 0x00000000 Hash algo: md5 Hash value: 22352ad39bdc03e2e50f9cc28c1c3652
Quoted 3 lines
Which results in the file 'kernel' being exactly the same as '
/boot/vmlinuz-2.6.32-34-generic'.Signed-off-by Guilherme Maciel Ferreira <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150202/5391ea26/attachment.sig>
PATCH 4/4 tools: do not print error messages in verify_header() functions
In reply to Guilherme Maciel Ferreiradefault_image.c and socfpgaimage.c are the only image modules that print error messages during header verification. The verify_header() is used to query if a given image file is processed by the image format. Thus, if the image format can't handle the file, it must simply return an error. Otherwise we pollute the screen with errors messages until we find the image format that handle a given image file.
--- tools/default_image.c | 17 ++++++++--------- tools/socfpgaimage.c | 6 ++++-- 2 files changed, 12 insertions(+), 11 deletions(-)
tools/default_image.c +8 -9
@@ -15,6 +15,8 @@*/ #include "imagetool.h" +#include "mkimage.h" +#include <image.h> #include <u-boot/crc.h>
@@ -53,9 +55,8 @@ static int image_verify_header(unsigned char *ptr, int image_size,memcpy (hdr, ptr,sizeof (image_header_t));if (be32_to_cpu (hdr->ih_magic) !=IH_MAGIC ) { -fprintf (stderr, -"%s: Bad Magic Number: \"%s\" is no valid image\n" , - params->cmdname, params->imagefile); +debug ("%s: Bad Magic Number: \"%s\" is no valid image\n" , + params->cmdname, params->imagefile);return -FDT_ERR_BADMAGIC ; }
@@ -66,9 +67,8 @@ static int image_verify_header(unsigned char *ptr, int image_size, hdr->ih_hcrc =cpu_to_be32 (0 );/* clear for re-calculation */ if (crc32 (0 , data, len) != checksum) { -fprintf (stderr, -"%s: ERROR: \"%s\" has bad header checksum!\n" , - params->cmdname, params->imagefile); +debug ("%s: ERROR: \"%s\" has bad header checksum!\n" , + params->cmdname, params->imagefile);return -FDT_ERR_BADSTATE ; }
@@ -77,9 +77,8 @@ static int image_verify_header(unsigned char *ptr, int image_size, checksum =be32_to_cpu (hdr->ih_dcrc);if (crc32 (0 , data, len) != checksum) { -fprintf (stderr, -"%s: ERROR: \"%s\" has corrupted data!\n" , - params->cmdname, params->imagefile); +debug ("%s: ERROR: \"%s\" has corrupted data!\n" , + params->cmdname, params->imagefile);return -FDT_ERR_BADSTRUCTURE ; }return 0 ;
tools/socfpgaimage.c +4 -2
@@ -33,6 +33,8 @@#include "pbl_crc32.h" #include "imagetool.h" +#include "mkimage.h" +#include <image.h> #define HEADER_OFFSET 0x40
@@ -133,12 +135,12 @@ static int verify_buffer(const uint8_t *buf) len =verify_header (buf +HEADER_OFFSET );if (len <0 ) { -fprintf (stderr,"Invalid header\n" ); +debug ("Invalid header\n" );return -1 ; }if (len <HEADER_OFFSET || len >PADDED_SIZE ) { -fprintf (stderr,"Invalid header length (%i)\n" , len); +debug ("Invalid header length (%i)\n" , len);return -1 ; }
Signature · 1 line
1.7.0.4
PATCH 4/4 tools: do not print error messages in verify_header() functions
Quoted 8 lines · Guilherme Maciel Ferreira
default_image.candsocfpgaimage.care the only image modules that print error messages during header verification. Theverify_header()is used to query if a given image file is processed by the image format. Thus, if the image format can't handle the file, it must simply return an error. Otherwise we pollute the screen with errors messages until we find the image format that handle a given image file.Signed-off-by Guilherme Maciel Ferreira <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150202/7023cdd6/attachment.sig>
PATCH 1/4 dumpimage: add 'T' option to explicitly set the image type
In reply to Guilherme Maciel FerreiraQuoted 9 lines · Guilherme Maciel Ferreira
From: Guilherme Maciel Ferreira <[email protected]>
Some image types, like "KeyStone GP", do not have magic numbers to distinguish them from other image types. Thus, the automatic image type discovery does not work correctly.
This patch also fix some integer type mismatches.
Signed-off-by Guilherme Maciel Ferreira <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150202/e5ac1a2c/attachment.sig>