This is an automated email from Gerrit. "Sergi Granell Escalfet <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9602
-- gerrit commit ebefb72d7675ff7585dbb7d5194819edd8a64be6 Author: Sergi Granell Escalfet <[email protected]> Date: Tue Apr 28 12:03:38 2026 +0900 target: add load_image_info command Add a new load_image_info command that opens an image file, returns a Tcl dict describing it, and closes the file without writing anything to target memory. The dict contains a 'type' key (bin, ihex, elf, s19) and, when present in the image metadata, an 'entry_address' key (ELF e_entry or IHEX record type 05 start linear address). The command is registered as COMMAND_ANY so it can be used in config scripts before a target is initialised. Document the new command in the "Image loading commands" section of the manual. Change-Id: Ie8d9fc0a7f2bd18e105ad675687431f780ddd0e6 Signed-off-by: Sergi Granell Escalfet <[email protected]> diff --git a/doc/openocd.texi b/doc/openocd.texi index ff4bed6f7f..af713aad57 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9971,6 +9971,22 @@ proc load_image_bin @{fname foffset address length @} @{ @end example @end deffn +@deffn {Command} {load_image_info} filename [@option{bin}|@option{ihex}|@option{elf}|@option{s19}] +Returns a Tcl dict describing the image without loading it to target memory. +The dict always contains a @option{type} key with the detected or specified image type +(@option{bin}, @option{ihex}, @option{elf}, or @option{s19}). +If the image carries an entry point (ELF @code{e_entry}, or IHEX record type 05), +an @option{entry_address} key is also present with its value. +@example +set info [load_image_info firmware.elf] +# info => "type elf entry_address 0xfffc0000" +dict get $info type +# => elf +dict get $info entry_address +# => 0xfffc0000 +@end example +@end deffn + @deffn {Command} {test_image} filename [address [@option{bin}|@option{ihex}|@option{elf}]] Displays image section sizes and addresses as if @var{filename} were loaded into target memory diff --git a/src/target/target.c b/src/target/target.c index 7a656383d5..d60ef0fe05 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3649,6 +3649,31 @@ COMMAND_HANDLER(handle_load_image_command) } +COMMAND_HANDLER(handle_load_image_info_command) +{ + if (CMD_ARGC < 1 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct image image; + image.base_address_set = false; + image.base_address = 0; + image.start_address_set = false; + + int retval = image_open(&image, CMD_ARGV[0], (CMD_ARGC == 2) ? CMD_ARGV[1] : NULL); + if (retval != ERROR_OK) + return retval; + + if (image.start_address_set) + command_print(CMD, "type %s entry_address 0x%08" PRIx32, + image_type_name(image.type), image.start_address); + else + command_print(CMD, "type %s", + image_type_name(image.type)); + + image_close(&image); + return ERROR_OK; +} + COMMAND_HANDLER(handle_dump_image_command) { struct fileio *fileio; @@ -6647,6 +6672,13 @@ static const struct command_registration target_exec_command_handlers[] = { .usage = "filename [address ['bin'|'ihex'|'elf'|'s19' " "[min_address [max_length]]]]", }, + { + .name = "load_image_info", + .handler = handle_load_image_info_command, + .mode = COMMAND_ANY, + .help = "Returns a dict with the image type and, if present, entry address.", + .usage = "filename ['bin'|'ihex'|'elf'|'s19']", + }, { .name = "dump_image", .handler = handle_dump_image_command, --
