diff options
| author | Tom Rini <[email protected]> | 2022-01-24 10:39:28 -0500 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2022-01-24 10:39:28 -0500 |
| commit | 21a1439d986a889cefbc2ed785c3f592fc9266de (patch) | |
| tree | 3ff70c21854c4a1bdbf60414d6fead53c0982049 /tools | |
| parent | ae35c59389b9b67e1e553bc9ed3e6fd93cfdb86f (diff) | |
| parent | 480245cf273dfd14536dc2b30aff0a733b71a1ed (diff) | |
Merge branch '2022-01-24-assorted-fixes-and-updates'
- Assorted dumpimage/mkimage fixes, allow setting the signature
algorithm on the command line with mkimage
- Bugfix to the misc uclass, CONFIG_MP / CMD_MP Kconfig logic improved,
updated Xen platform MAINTAINERS entry and fixed vexpress_aemv8a_semi
booting.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/fit_common.c | 12 | ||||
| -rw-r--r-- | tools/fit_image.c | 8 | ||||
| -rw-r--r-- | tools/image-host.c | 50 | ||||
| -rw-r--r-- | tools/imagetool.h | 1 | ||||
| -rw-r--r-- | tools/mkimage.c | 13 |
5 files changed, 50 insertions, 34 deletions
diff --git a/tools/fit_common.c b/tools/fit_common.c index 52b63296f89..5c8920de547 100644 --- a/tools/fit_common.c +++ b/tools/fit_common.c @@ -26,10 +26,18 @@ int fit_verify_header(unsigned char *ptr, int image_size, struct image_tool_params *params) { - if (fdt_check_header(ptr) != EXIT_SUCCESS || - fit_check_format(ptr, IMAGE_SIZE_INVAL)) + int ret; + + if (fdt_check_header(ptr) != EXIT_SUCCESS) return EXIT_FAILURE; + ret = fit_check_format(ptr, IMAGE_SIZE_INVAL); + if (ret) { + if (ret != -EADDRNOTAVAIL) + return EXIT_FAILURE; + fprintf(stderr, "Image contains unit addresses @, this will break signing\n"); + } + return EXIT_SUCCESS; } diff --git a/tools/fit_image.c b/tools/fit_image.c index f4f372ba62f..8df95c40d20 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -73,7 +73,8 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, params->comment, params->require_keys, params->engine_id, - params->cmdname); + params->cmdname, + params->algo_name); } if (dest_blob) { @@ -884,11 +885,6 @@ static int fit_extract_contents(void *ptr, struct image_tool_params *params) /* Indent string is defined in header image.h */ p = IMAGE_INDENT_STRING; - if (fit_check_format(fit, IMAGE_SIZE_INVAL)) { - printf("Bad FIT image format\n"); - return -1; - } - /* Find images parent node offset */ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); if (images_noffset < 0) { diff --git a/tools/image-host.c b/tools/image-host.c index 945571f584d..f86e1fbb1b9 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -63,7 +63,7 @@ static int fit_image_process_hash(void *fit, const char *image_name, uint8_t value[FIT_MAX_HASH_LEN]; const char *node_name; int value_len; - char *algo; + const char *algo; int ret; node_name = fit_get_name(fit, noffset, NULL); @@ -107,7 +107,7 @@ static int fit_image_process_hash(void *fit, const char *image_name, */ static int fit_image_write_sig(void *fit, int noffset, uint8_t *value, int value_len, const char *comment, const char *region_prop, - int region_proplen, const char *cmdname) + int region_proplen, const char *cmdname, const char *algo_name) { int string_size; int ret; @@ -150,6 +150,8 @@ static int fit_image_write_sig(void *fit, int noffset, uint8_t *value, strdata, sizeof(strdata)); } } + if (algo_name && !ret) + ret = fdt_setprop_string(fit, noffset, "algo", algo_name); return ret; } @@ -157,17 +159,18 @@ static int fit_image_write_sig(void *fit, int noffset, uint8_t *value, static int fit_image_setup_sig(struct image_sign_info *info, const char *keydir, const char *keyfile, void *fit, const char *image_name, int noffset, const char *require_keys, - const char *engine_id) + const char *engine_id, const char *algo_name) { const char *node_name; - char *algo_name; const char *padding_name; node_name = fit_get_name(fit, noffset, NULL); - if (fit_image_hash_get_algo(fit, noffset, &algo_name)) { - printf("Can't get algo property for '%s' signature node in '%s' image node\n", - node_name, image_name); - return -1; + if (!algo_name) { + if (fit_image_hash_get_algo(fit, noffset, &algo_name)) { + printf("Can't get algo property for '%s' signature node in '%s' image node\n", + node_name, image_name); + return -1; + } } padding_name = fdt_getprop(fit, noffset, "padding", NULL); @@ -215,7 +218,7 @@ static int fit_image_process_sig(const char *keydir, const char *keyfile, void *keydest, void *fit, const char *image_name, int noffset, const void *data, size_t size, const char *comment, int require_keys, const char *engine_id, - const char *cmdname) + const char *cmdname, const char *algo_name) { struct image_sign_info info; struct image_region region; @@ -226,7 +229,7 @@ static int fit_image_process_sig(const char *keydir, const char *keyfile, if (fit_image_setup_sig(&info, keydir, keyfile, fit, image_name, noffset, require_keys ? "image" : NULL, - engine_id)) + engine_id, algo_name)) return -1; node_name = fit_get_name(fit, noffset, NULL); @@ -244,7 +247,7 @@ static int fit_image_process_sig(const char *keydir, const char *keyfile, } ret = fit_image_write_sig(fit, noffset, value, value_len, comment, - NULL, 0, cmdname); + NULL, 0, cmdname, algo_name); if (ret) { if (ret == -FDT_ERR_NOSPACE) return -ENOSPC; @@ -606,7 +609,7 @@ int fit_image_cipher_data(const char *keydir, void *keydest, int fit_image_add_verification_data(const char *keydir, const char *keyfile, void *keydest, void *fit, int image_noffset, const char *comment, int require_keys, const char *engine_id, - const char *cmdname) + const char *cmdname, const char* algo_name) { const char *image_name; const void *data; @@ -643,7 +646,8 @@ int fit_image_add_verification_data(const char *keydir, const char *keyfile, strlen(FIT_SIG_NODENAME))) { ret = fit_image_process_sig(keydir, keyfile, keydest, fit, image_name, noffset, data, size, - comment, require_keys, engine_id, cmdname); + comment, require_keys, engine_id, cmdname, + algo_name); } if (ret) return ret; @@ -927,7 +931,8 @@ static int fit_config_get_data(void *fit, int conf_noffset, int noffset, static int fit_config_process_sig(const char *keydir, const char *keyfile, void *keydest, void *fit, const char *conf_name, int conf_noffset, int noffset, const char *comment, - int require_keys, const char *engine_id, const char *cmdname) + int require_keys, const char *engine_id, const char *cmdname, + const char *algo_name) { struct image_sign_info info; const char *node_name; @@ -945,7 +950,8 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile, return -1; if (fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset, - require_keys ? "conf" : NULL, engine_id)) + require_keys ? "conf" : NULL, engine_id, + algo_name)) return -1; ret = info.crypto->sign(&info, region, region_count, &value, @@ -962,7 +968,8 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile, } ret = fit_image_write_sig(fit, noffset, value, value_len, comment, - region_prop, region_proplen, cmdname); + region_prop, region_proplen, cmdname, + algo_name); if (ret) { if (ret == -FDT_ERR_NOSPACE) return -ENOSPC; @@ -992,7 +999,7 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile, static int fit_config_add_verification_data(const char *keydir, const char *keyfile, void *keydest, void *fit, int conf_noffset, const char *comment, int require_keys, const char *engine_id, - const char *cmdname) + const char *cmdname, const char *algo_name) { const char *conf_name; int noffset; @@ -1011,7 +1018,7 @@ static int fit_config_add_verification_data(const char *keydir, strlen(FIT_SIG_NODENAME))) { ret = fit_config_process_sig(keydir, keyfile, keydest, fit, conf_name, conf_noffset, noffset, comment, - require_keys, engine_id, cmdname); + require_keys, engine_id, cmdname, algo_name); } if (ret) return ret; @@ -1058,7 +1065,7 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit, int fit_add_verification_data(const char *keydir, const char *keyfile, void *keydest, void *fit, const char *comment, int require_keys, const char *engine_id, - const char *cmdname) + const char *cmdname, const char *algo_name) { int images_noffset, confs_noffset; int noffset; @@ -1082,7 +1089,7 @@ int fit_add_verification_data(const char *keydir, const char *keyfile, */ ret = fit_image_add_verification_data(keydir, keyfile, keydest, fit, noffset, comment, require_keys, engine_id, - cmdname); + cmdname, algo_name); if (ret) return ret; } @@ -1106,7 +1113,8 @@ int fit_add_verification_data(const char *keydir, const char *keyfile, ret = fit_config_add_verification_data(keydir, keyfile, keydest, fit, noffset, comment, require_keys, - engine_id, cmdname); + engine_id, cmdname, + algo_name); if (ret) return ret; } diff --git a/tools/imagetool.h b/tools/imagetool.h index 3546f7a6711..b7ac3a23d0f 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -69,6 +69,7 @@ struct image_tool_params { const char *keydest; /* Destination .dtb for public key */ const char *keyfile; /* Filename of private or public key */ const char *comment; /* Comment to add to signature node */ + const char *algo_name; /* Algorithm name to use hashing/signing */ int require_keys; /* 1 to mark signing keys as 'required' */ int file_size; /* Total size of output file */ int orig_file_size; /* Original size for file before padding */ diff --git a/tools/mkimage.c b/tools/mkimage.c index fbe883ce362..0ec28da33cb 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -146,7 +146,6 @@ static int add_content(int type, const char *fname) return 0; } -#define OPT_STRING "a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qstT:vVx" static void process_args(int argc, char **argv) { char *ptr; @@ -155,7 +154,7 @@ static void process_args(int argc, char **argv) int opt; while ((opt = getopt(argc, argv, - "a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:O:rR:qstT:vVx")) != -1) { + "a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:o:O:rR:qstT:vVx")) != -1) { switch (opt) { case 'a': params.addr = strtoull(optarg, &ptr, 16); @@ -251,6 +250,9 @@ static void process_args(int argc, char **argv) case 'N': params.engine_id = optarg; break; + case 'o': + params.algo_name = optarg; + break; case 'O': params.os = genimg_get_os_id(optarg); if (params.os < 0) { @@ -433,11 +435,12 @@ int main(int argc, char **argv) params.cmdname, params.imagefile); exit (EXIT_FAILURE); #endif - } else if ((unsigned)sbuf.st_size < tparams->header_size) { + } else if (sbuf.st_size < (off_t)tparams->header_size) { fprintf (stderr, - "%s: Bad size: \"%s\" is not valid image: size %ld < %u\n", + "%s: Bad size: \"%s\" is not valid image: size %llu < %u\n", params.cmdname, params.imagefile, - sbuf.st_size, tparams->header_size); + (unsigned long long) sbuf.st_size, + tparams->header_size); exit (EXIT_FAILURE); } else { size = sbuf.st_size; |
