[PATCH 1/2] mkimage: Document misc options

Over the years, several options have not made it into the help message. Document them. Do the same for the man page.
Signed-off-by: Sean Anderson sean.anderson@seco.com ---
doc/mkimage.1 | 36 +++++++++++++++++++++++++++++++++++- tools/mkimage.c | 15 +++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 287006279f..c92e133732 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -53,6 +53,10 @@ Parse image file as type. Pass -h as the image to see the list of supported image type. Without this option image type is autodetected.
+.TP +.BI "-q" +Quiet. Don't print the image header on successful verification. + .P .B Create old legacy image:
@@ -91,6 +95,11 @@ List the contents of an image. .BI "-n [" "image name" "]" Set image name to 'image name'.
+.TP +.BI "-R [" "secondary image name" "]" +Some image types support a second image for additional data. For these types, +use -R to specify this second image. + .TP .BI "-d [" "image data file" "]" Use image data from 'image data file'. @@ -99,6 +108,15 @@ Use image data from 'image data file'. .BI "-x" Set XIP (execute in place) flag.
+.TP +.BI "-s" +Create an image with no data. The header will be created, but the image itself +will not contain data (such as U-Boot or any specified kernel). + +.TP +.BI "-v" +Verbose. Print file names as they are added to the image. + .P .B Create FIT image:
@@ -126,6 +144,11 @@ in each image will be replaced with 'data-offset' and 'data-size' properties. A 'data-offset' of 0 indicates that it starts in the first (4-byte aligned) byte after the FIT.
+.TP +.BI "-B [" "alignment" "]" +The alignment, in hexadecimal, that external data will be aligned to. This +option only has an effect when -E is specified. + .TP .BI "-f [" "image tree source file" " | " "auto" "]" Image tree source file that describes the structure and contents of the @@ -161,6 +184,11 @@ the corresponding public key is written into this file for for run-time verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot.
+.TP +.BI "-G [" "key_file" "]" +Specifies the private key file to use when signing. This option may be used +instead of -k. + .TP .BI "-o [" "signing algorithm" "]" Specifies the algorithm to be used for signing a FIT image. The default is @@ -173,11 +201,17 @@ a 'data-offset' property defining the offset from the end of the FIT, -p will use 'data-position' as the absolute position from the base of the FIT.
.TP -.BI "-r +.BI "-r" Specifies that keys used to sign the FIT are required. This means that they must be verified for the image to boot. Without this option, the verification will be optional (useful for testing but not for release).
+.TP +.BI "-N [" "engine" "]" +The openssl engine to use when signing and verifying the image. For a complete list of +available engines, refer to +.BR engine (1). + .TP .BI "-t Update the timestamp in the FIT. diff --git a/tools/mkimage.c b/tools/mkimage.c index 74bd072832..c12d5932fc 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -84,7 +84,8 @@ static void usage(const char *msg) fprintf(stderr, "Error: %s\n", msg); fprintf(stderr, "Usage: %s [-T type] -l image\n" " -l ==> list image header information\n" - " -T ==> parse image file as 'type'\n", + " -T ==> parse image file as 'type'\n" + " -q ==> quiet\n", params.cmdname); fprintf(stderr, " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n" @@ -95,8 +96,11 @@ static void usage(const char *msg) " -a ==> set load address to 'addr' (hex)\n" " -e ==> set entry point to 'ep' (hex)\n" " -n ==> set image name to 'name'\n" + " -R ==> set second image name to 'name'\n" " -d ==> use image data from 'datafile'\n" - " -x ==> set XIP (execute in place)\n", + " -x ==> set XIP (execute in place)\n" + " -s ==> create an image with no data\n" + " -v ==> verbose\n", params.cmdname); fprintf(stderr, " %s [-D dtc_options] [-f fit-image.its|-f auto|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image\n" @@ -107,7 +111,9 @@ static void usage(const char *msg) " -f => input filename for FIT source\n" " -i => input filename for ramdisk file\n" " -E => place data outside of the FIT structure\n" - " -B => align size in hex for FIT structure and header\n"); + " -B => align size in hex for FIT structure and header\n" + " -b => append the device tree binary to the FIT\n" + " -t => update the timestamp in the FIT\n"); #ifdef CONFIG_FIT_SIGNATURE fprintf(stderr, "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n" @@ -118,7 +124,8 @@ static void usage(const char *msg) " -F => re-sign existing FIT image\n" " -p => place external data at a static position\n" " -r => mark keys used as 'required' in dtb\n" - " -N => openssl engine to use for signing\n"); + " -N => openssl engine to use for signing\n" + " -o => algorithm to use for signing\n"); #else fprintf(stderr, "Signing / verified boot not supported (CONFIG_FIT_SIGNATURE undefined)\n");

This adds support for signing images in auto-generated FITs. To do this, we need to add a signature node. The algorithm name property already has its own option, but we need one for the key name hint. We could have gone the -G route and added an explicit name for the public key (like what is done for the private key). However, many places assume the public key can be constructed from the key dir and hint, and I don't want to do the refactoring necessary.
As a consequence of this, it is now easier to add public keys to an existing image without signing something. This could be done all along, but now you don't have to create an its just to do it. Ideally, we wouldn't create a FIT at the end. This could be done by calling fit_image_setup_sig/info.crypto->add_verify_data directly.
Signed-off-by: Sean Anderson sean.anderson@seco.com ---
doc/mkimage.1 | 24 ++++++++++++++++++++++++ tools/fit_image.c | 41 ++++++++++++++++++++++++++++++++++------- tools/imagetool.h | 1 + tools/mkimage.c | 5 ++++- 4 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/doc/mkimage.1 b/doc/mkimage.1 index c92e133732..60853ec3e6 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -184,6 +184,13 @@ the corresponding public key is written into this file for for run-time verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot.
+.TP +.BI "-g [" "key_name_hint" "]" +Sets the key-name-hint property when used with -f auto. This is the <name> +part of the key. The directory part is set by -k. This option also indicates +that the images included in the FIT should be signed. If this option is +specified, -o must be specified as well. + .TP .BI "-G [" "key_file" "]" Specifies the private key file to use when signing. This option may be used @@ -249,6 +256,15 @@ skipping those for which keys cannot be found. Also add a comment. .B -c """Kernel 3.8 image for production devices""" kernel.itb .fi
+.P +Add public keys to u-boot.dtb without needing a FIT to sign. This will also +create a FIT containing an images node with no data named unused.itb. +.nf +.B mkimage -f auto -d /dev/null -k /public/signing-keys -g dev \\ +.br +.B -o sha256,rsa2048 -K u-boot.dtb unused.itb +.fi + .P Update an existing FIT image, signing it with additional keys. Add corresponding public keys into u-boot.dtb. This will resign all images @@ -277,6 +293,14 @@ automatic mode. No .its file is required. .B -c """Kernel 4.4 image for production devices""" -d vmlinuz \\ .B -b /path/to/rk3288-firefly.dtb -b /path/to/rk3288-jerry.dtb kernel.itb .fi +.P +Create a FIT image containing a signed kernel, using automatic mode. No .its +file is required. +.nf +.B mkimage -f auto -A arm -O linux -T kernel -C none -a 43e00000 -e 0 \\ +.br +.B -d vmlinuz -k /secret/signing-keys -g dev -o sha256,rsa2048 kernel.itb +.fi
.SH HOMEPAGE http://www.denx.de/wiki/U-Boot/WebHome diff --git a/tools/fit_image.c b/tools/fit_image.c index 0d5a6a28f9..48fc1f5579 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -199,15 +199,36 @@ static void get_basename(char *str, int size, const char *fname) }
/** - * add_crc_node() - Add a hash node to request a CRC checksum for an image + * add_hash_node() - Add a hash or signature node * + * @params: Image parameters * @fdt: Device tree to add to (in sequential-write mode) + * + * If there is a key name hint, try to sign the images. Otherwise, just add a + * CRC. + * + * Return: 0 on success, or -1 on failure */ -static void add_crc_node(void *fdt) +static int add_hash_node(struct image_tool_params *params, void *fdt) { - fdt_begin_node(fdt, "hash-1"); - fdt_property_string(fdt, FIT_ALGO_PROP, "crc32"); + if (params->keyname) { + if (!params->algo_name) { + fprintf(stderr, + "%s: Algorithm name must be specified\n", + params->cmdname); + return -1; + } + + fdt_begin_node(fdt, "signature-1"); + fdt_property_string(fdt, FIT_ALGO_PROP, params->algo_name); + fdt_property_string(fdt, FIT_KEY_HINT, params->keyname); + } else { + fdt_begin_node(fdt, "hash-1"); + fdt_property_string(fdt, FIT_ALGO_PROP, "crc32"); + } + fdt_end_node(fdt); + return 0; }
/** @@ -248,7 +269,9 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile); if (ret) return ret; - add_crc_node(fdt); + ret = add_hash_node(params, fdt); + if (ret) + return ret; fdt_end_node(fdt);
/* Now the device tree files if available */ @@ -271,7 +294,9 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, FIT_COMP_PROP, genimg_get_comp_short_name(IH_COMP_NONE)); - add_crc_node(fdt); + ret = add_hash_node(params, fdt); + if (ret) + return ret; fdt_end_node(fdt); }
@@ -289,7 +314,9 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) params->fit_ramdisk); if (ret) return ret; - add_crc_node(fdt); + ret = add_hash_node(params, fdt); + if (ret) + return ret; fdt_end_node(fdt); }
diff --git a/tools/imagetool.h b/tools/imagetool.h index 5169b0245d..a022e23389 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -70,6 +70,7 @@ struct image_tool_params { const char *keydir; /* Directory holding private keys */ const char *keydest; /* Destination .dtb for public key */ const char *keyfile; /* Filename of private or public key */ + const char *keyname; /* Key name "hint" */ const char *comment; /* Comment to add to signature node */ /* Algorithm name to use for hashing/signing or NULL to use the one * specified in the its */ diff --git a/tools/mkimage.c b/tools/mkimage.c index c12d5932fc..329e0cf924 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -119,6 +119,7 @@ static void usage(const char *msg) "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n" " -k => set directory containing private keys\n" " -K => write public keys to this .dtb file\n" + " -g => set key name hint\n" " -G => use this signing key (in lieu of -k)\n" " -c => add comment in signature node\n" " -F => re-sign existing FIT image\n" @@ -163,7 +164,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:O:rR:qstT:vVx")) != -1) { + "a:A:b:B:c:C:d:D:e:Ef:Fg:G:k:i:K:ln:N:p:o:O:rR:qstT:vVx")) != -1) { switch (opt) { case 'a': params.addr = strtoull(optarg, &ptr, 16); @@ -238,6 +239,8 @@ static void process_args(int argc, char **argv) params.type = IH_TYPE_FLATDT; params.fflag = 1; break; + case 'g': + params.keyname = optarg; case 'G': params.keyfile = optarg; break;

On 4/8/22 22:08, Sean Anderson wrote:
Over the years, several options have not made it into the help message. Document them. Do the same for the man page.
Signed-off-by: Sean Anderson sean.anderson@seco.com
doc/mkimage.1 | 36 +++++++++++++++++++++++++++++++++++- tools/mkimage.c | 15 +++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 287006279f..c92e133732 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -53,6 +53,10 @@ Parse image file as type. Pass -h as the image to see the list of supported image type. Without this option image type is autodetected.
+.TP +.BI "-q" +Quiet. Don't print the image header on successful verification.
- .P .B Create old legacy image:
@@ -91,6 +95,11 @@ List the contents of an image. .BI "-n [" "image name" "]" Set image name to 'image name'.
+.TP +.BI "-R [" "secondary image name" "]" +Some image types support a second image for additional data. For these types, +use -R to specify this second image.
A user needs to know which image types require or support a second image. We need more text here.
- .TP .BI "-d [" "image data file" "]" Use image data from 'image data file'.
@@ -99,6 +108,15 @@ Use image data from 'image data file'. .BI "-x" Set XIP (execute in place) flag.
+.TP +.BI "-s" +Create an image with no data. The header will be created, but the image itself +will not contain data (such as U-Boot or any specified kernel).
The text in parentheses seems superfluous.
+.TP +.BI "-v" +Verbose. Print file names as they are added to the image.
- .P .B Create FIT image:
@@ -126,6 +144,11 @@ in each image will be replaced with 'data-offset' and 'data-size' properties. A 'data-offset' of 0 indicates that it starts in the first (4-byte aligned) byte after the FIT.
+.TP +.BI "-B [" "alignment" "]" +The alignment, in hexadecimal, that external data will be aligned to. This +option only has an effect when -E is specified.
- .TP .BI "-f [" "image tree source file" " | " "auto" "]" Image tree source file that describes the structure and contents of the
@@ -161,6 +184,11 @@ the corresponding public key is written into this file for for run-time verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot.
+.TP +.BI "-G [" "key_file" "]"
This should directly follow -k as it is related.
+Specifies the private key file to use when signing. This option may be used +instead of -k.
- .TP .BI "-o [" "signing algorithm" "]" Specifies the algorithm to be used for signing a FIT image. The default is
@@ -173,11 +201,17 @@ a 'data-offset' property defining the offset from the end of the FIT, -p will use 'data-position' as the absolute position from the base of the FIT.
.TP -.BI "-r +.BI "-r" Specifies that keys used to sign the FIT are required. This means that they must be verified for the image to boot. Without this option, the verification will be optional (useful for testing but not for release).
+.TP +.BI "-N [" "engine" "]" +The openssl engine to use when signing and verifying the image. For a complete list of +available engines, refer to +.BR engine (1).
I can't find a reference (1) in your patch.
Best regards
Heinrich
- .TP .BI "-t Update the timestamp in the FIT.
diff --git a/tools/mkimage.c b/tools/mkimage.c index 74bd072832..c12d5932fc 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -84,7 +84,8 @@ static void usage(const char *msg) fprintf(stderr, "Error: %s\n", msg); fprintf(stderr, "Usage: %s [-T type] -l image\n" " -l ==> list image header information\n"
" -T ==> parse image file as 'type'\n",
" -T ==> parse image file as 'type'\n"
params.cmdname); fprintf(stderr, " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"" -q ==> quiet\n",
@@ -95,8 +96,11 @@ static void usage(const char *msg) " -a ==> set load address to 'addr' (hex)\n" " -e ==> set entry point to 'ep' (hex)\n" " -n ==> set image name to 'name'\n"
" -d ==> use image data from 'datafile'\n"" -R ==> set second image name to 'name'\n"
" -x ==> set XIP (execute in place)\n",
" -x ==> set XIP (execute in place)\n"
" -s ==> create an image with no data\n"
params.cmdname); fprintf(stderr, " %s [-D dtc_options] [-f fit-image.its|-f auto|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image\n"" -v ==> verbose\n",
@@ -107,7 +111,9 @@ static void usage(const char *msg) " -f => input filename for FIT source\n" " -i => input filename for ramdisk file\n" " -E => place data outside of the FIT structure\n"
" -B => align size in hex for FIT structure and header\n");
" -B => align size in hex for FIT structure and header\n"
" -b => append the device tree binary to the FIT\n"
#ifdef CONFIG_FIT_SIGNATURE fprintf(stderr, "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"" -t => update the timestamp in the FIT\n");
@@ -118,7 +124,8 @@ static void usage(const char *msg) " -F => re-sign existing FIT image\n" " -p => place external data at a static position\n" " -r => mark keys used as 'required' in dtb\n"
" -N => openssl engine to use for signing\n");
" -N => openssl engine to use for signing\n"
#else fprintf(stderr, "Signing / verified boot not supported (CONFIG_FIT_SIGNATURE undefined)\n");" -o => algorithm to use for signing\n");

On 4/8/22 5:59 PM, Heinrich Schuchardt wrote:
On 4/8/22 22:08, Sean Anderson wrote:
Over the years, several options have not made it into the help message. Document them. Do the same for the man page.
Signed-off-by: Sean Anderson sean.anderson@seco.com
doc/mkimage.1 | 36 +++++++++++++++++++++++++++++++++++- tools/mkimage.c | 15 +++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 287006279f..c92e133732 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -53,6 +53,10 @@ Parse image file as type. Pass -h as the image to see the list of supported image type. Without this option image type is autodetected.
+.TP +.BI "-q" +Quiet. Don't print the image header on successful verification.
.P .B Create old legacy image:
@@ -91,6 +95,11 @@ List the contents of an image. .BI "-n [" "image name" "]" Set image name to 'image name'.
+.TP +.BI "-R [" "secondary image name" "]" +Some image types support a second image for additional data. For these types, +use -R to specify this second image.
A user needs to know which image types require or support a second image. We need more text here.
Will update. At the moment it seems to just be pblimage/zynqimage/zynqmpimage.
.TP .BI "-d [" "image data file" "]" Use image data from 'image data file'. @@ -99,6 +108,15 @@ Use image data from 'image data file'. .BI "-x" Set XIP (execute in place) flag.
+.TP +.BI "-s" +Create an image with no data. The header will be created, but the image itself +will not contain data (such as U-Boot or any specified kernel).
The text in parentheses seems superfluous.
Actually, I'm not really sure if the whole thing is correct. It doesn't seem to apply to FITs at the very least.
+.TP +.BI "-v" +Verbose. Print file names as they are added to the image.
.P .B Create FIT image:
@@ -126,6 +144,11 @@ in each image will be replaced with 'data-offset' and 'data-size' properties. A 'data-offset' of 0 indicates that it starts in the first (4-byte aligned) byte after the FIT.
+.TP +.BI "-B [" "alignment" "]" +The alignment, in hexadecimal, that external data will be aligned to. This +option only has an effect when -E is specified.
.TP .BI "-f [" "image tree source file" " | " "auto" "]" Image tree source file that describes the structure and contents of the @@ -161,6 +184,11 @@ the corresponding public key is written into this file for for run-time verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot.
+.TP +.BI "-G [" "key_file" "]"
This should directly follow -k as it is related.
OK.
+Specifies the private key file to use when signing. This option may be used +instead of -k.
.TP .BI "-o [" "signing algorithm" "]" Specifies the algorithm to be used for signing a FIT image. The default is @@ -173,11 +201,17 @@ a 'data-offset' property defining the offset from the end of the FIT, -p will use 'data-position' as the absolute position from the base of the FIT.
.TP -.BI "-r +.BI "-r" Specifies that keys used to sign the FIT are required. This means that they must be verified for the image to boot. Without this option, the verification will be optional (useful for testing but not for release).
+.TP +.BI "-N [" "engine" "]" +The openssl engine to use when signing and verifying the image. For a complete list of +available engines, refer to +.BR engine (1).
I can't find a reference (1) in your patch.
This is a reference to the engine(1) manual page.
--Sean
participants (2)
-
Heinrich Schuchardt
-
Sean Anderson