[v2,19/49] mkimage: Allow updating the FIT timestamp

Message ID 20200613205717.v2.19.I85f46b7979f359a87659dc8d0eb50d692e7bbf18@changeid
State Accepted
Commit 4c63d21754a2583df1d85d3af6f0a5bf5c300d20
Headers show
Series
  • rockchip: x86: Support building ROM files automatically with binman
Related show

Commit Message

Simon Glass June 14, 2020, 2:56 a.m.
Normally the FIT timestamp is created the first time mkimage is run on a
FIT, when converting the source .its to the binary .fit file. This
corresponds to using the -f flag. But if the original input to mkimage is
a binary file (already compiled) then the timestamp is assumed to have
been set previously.

Add a -t flag to allow setting the timestamp in this case.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 doc/mkimage.1     | 9 +++++++++
 tools/fit_image.c | 2 +-
 tools/imagetool.h | 1 +
 tools/mkimage.c   | 5 ++++-
 4 files changed, 15 insertions(+), 2 deletions(-)

Comments

Bin Meng June 29, 2020, 6:54 a.m. | #1
On Sun, Jun 14, 2020 at 10:57 AM Simon Glass <sjg at chromium.org> wrote:
>
> Normally the FIT timestamp is created the first time mkimage is run on a
> FIT, when converting the source .its to the binary .fit file. This
> corresponds to using the -f flag. But if the original input to mkimage is
> a binary file (already compiled) then the timestamp is assumed to have
> been set previously.
>
> Add a -t flag to allow setting the timestamp in this case.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> (no changes since v1)
>
>  doc/mkimage.1     | 9 +++++++++
>  tools/fit_image.c | 2 +-
>  tools/imagetool.h | 1 +
>  tools/mkimage.c   | 5 ++++-
>  4 files changed, 15 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>

Patch

diff --git a/doc/mkimage.1 b/doc/mkimage.1
index 3dcdcedcef..fea5288784 100644
--- a/doc/mkimage.1
+++ b/doc/mkimage.1
@@ -167,6 +167,15 @@  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 "\-t
+Update the timestamp in the FIT.
+
+Normally the FIT timestamp is created the first time mkimage is run on a FIT,
+when converting the source .its to the binary .fit file. This corresponds to
+using the -f flag. But if the original input to mkimage is a binary file
+(already compiled) then the timestamp is assumed to have been set previously.
+
 .SH EXAMPLES
 
 List image information:
diff --git a/tools/fit_image.c b/tools/fit_image.c
index a082d9386d..df310b53da 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -53,7 +53,7 @@  static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
 	}
 
 	/* for first image creation, add a timestamp at offset 0 i.e., root  */
-	if (params->datafile) {
+	if (params->datafile || params->reset_timestamp) {
 		time_t time = imagetool_get_source_date(params->cmdname,
 							sbuf.st_mtime);
 		ret = fit_set_timestamp(ptr, 0, time);
diff --git a/tools/imagetool.h b/tools/imagetool.h
index f54809cd57..acbc48e9be 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -81,6 +81,7 @@  struct image_tool_params {
 	unsigned int external_offset;	/* Add padding to external data */
 	int bl_len;		/* Block length in byte for external data */
 	const char *engine_id;	/* Engine to use for signing */
+	bool reset_timestamp;	/* Reset the timestamp on an existing image */
 };
 
 /*
diff --git a/tools/mkimage.c b/tools/mkimage.c
index d2cd191787..a7eb4d4360 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -145,7 +145,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:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
+		   "a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qstT:vVx")) != -1) {
 		switch (opt) {
 		case 'a':
 			params.addr = strtoull(optarg, &ptr, 16);
@@ -269,6 +269,9 @@  static void process_args(int argc, char **argv)
 		case 's':
 			params.skipcpy = 1;
 			break;
+		case 't':
+			params.reset_timestamp = 1;
+			break;
 		case 'T':
 			if (strcmp(optarg, "list") == 0) {
 				show_valid_options(IH_TYPE);