summaryrefslogtreecommitdiff
path: root/tools/fiptool/fiptool.c
diff options
context:
space:
mode:
authordp-arm <dimitris.papastamos@arm.com>2016-08-24 13:21:08 +0100
committerdp-arm <dimitris.papastamos@arm.com>2016-09-12 11:01:25 +0100
commit9df69ba37f3dd3a3f02fc8c0ba41236960b6b771 (patch)
tree869cf3bc21b77356eb83ef2d21c064408af13b21 /tools/fiptool/fiptool.c
parent77b05323921c23e4261ddd8fee5c326a79b0af97 (diff)
fiptool: Add support for printing the sha256 digest with info command
This feature allows one to quickly verify that the expected image is contained in the FIP without extracting the image and running sha256sum(1) on it. The sha256 digest is only shown when the verbose flag is used. This change requires libssl-dev to be installed in order to build Trusted Firmware. Previously, libssl-dev was optionally needed only to support Trusted Board Boot configurations. Fixes ARM-Software/tf-issues#124 Change-Id: Ifb1408d17f483d482bb270a589ee74add25ec5a6
Diffstat (limited to 'tools/fiptool/fiptool.c')
-rw-r--r--tools/fiptool/fiptool.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/fiptool/fiptool.c b/tools/fiptool/fiptool.c
index 68ddcf5a..6a3406e0 100644
--- a/tools/fiptool/fiptool.c
+++ b/tools/fiptool/fiptool.c
@@ -42,6 +42,8 @@
#include <string.h>
#include <unistd.h>
+#include <openssl/sha.h>
+
#include "fiptool.h"
#include "firmware_image_package.h"
#include "tbbr_config.h"
@@ -354,6 +356,14 @@ static void add_opt(struct option *opts, int idx, char *name,
opts[idx].val = val;
}
+static void md_print(unsigned char *md, size_t len)
+{
+ size_t i;
+
+ for (i = 0; i < len; i++)
+ printf("%02x", md[i]);
+}
+
static int info_cmd(int argc, char *argv[])
{
image_t *image;
@@ -391,10 +401,16 @@ static int info_cmd(int argc, char *argv[])
(unsigned long long)image_offset,
(unsigned long long)image_size);
if (image->toc_entry != NULL)
- printf(", cmdline=\"--%s\"\n",
+ printf(", cmdline=\"--%s\"",
image->toc_entry->cmdline_name);
- else
- putchar('\n');
+ if (verbose) {
+ unsigned char md[SHA256_DIGEST_LENGTH];
+
+ SHA256(image->buffer, image_size, md);
+ printf(", sha256=");
+ md_print(md, sizeof(md));
+ }
+ putchar('\n');
image_offset += image_size;
}