summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSteffen Trumtrar <s.trumtrar@pengutronix.de>2020-01-27 15:51:50 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-02-10 09:18:12 +0100
commit9d12256bfcc69d7ec7c20bd0e5205c54cefea700 (patch)
treedb576eb92d01c083d9655052f453888012ad547b /scripts
parent3b27a6eecb5bb6089b490258a54e7873aacf6573 (diff)
downloadbarebox-9d12256bfcc69d7ec7c20bd0e5205c54cefea700.tar.gz
barebox-9d12256bfcc69d7ec7c20bd0e5205c54cefea700.tar.xz
imd: add support for checksum generation/verification
Add a new imd type "checksum". This type consists of the CRC32 checksum of the whole barebox image minus the checksum itself. The checksum can be written to the imd field with the bareboximd host-tool. It can be verified with said tool or with "imd" on the target. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bareboximd.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index 5ef91831c4..cf1b8f693a 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <stdarg.h>
#include <linux/err.h>
+#include <linux/kernel.h>
#include "../include/image-metadata.h"
@@ -57,6 +58,35 @@ int imd_command_setenv(const char *variable_name, const char *value)
return -EINVAL;
}
+static int write_file(const char *filename, const void *buf, size_t size)
+{
+ int fd, ret;
+ int now;
+
+ fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT);
+ if (fd < 0)
+ return fd;
+
+ while (size) {
+ now = write(fd, buf, size);
+ if (now == 0) {
+ errno = ENOSPC;
+ return -1;
+ }
+ if (now < 0)
+ return now;
+ size -= now;
+ buf += now;
+ }
+
+ close(fd);
+
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_size)
{
off_t fsize;
@@ -129,6 +159,8 @@ static unsigned long simple_strtoul(const char *cp, char **endp, unsigned int ba
return strtoul(cp, endp, base);
}
+#include "../include/xfuncs.h"
+#include "../crypto/crc32.c"
#include "../common/imd.c"
static void usage(const char *prgname)
@@ -140,6 +172,8 @@ static void usage(const char *prgname)
"Options:\n"
"-t <type> only show information of <type>\n"
"-n <no> for tags with multiple strings only show string <no>\n"
+"-V Verify checksum of FILE\n"
+"-c Create checksum for FILE and write it to the crc32 tag\n"
"\n"
"Without options all information available is printed. Valid types are:\n"
"release, build, model, of_compatible\n",