summaryrefslogtreecommitdiffstats
path: root/include
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 /include
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 'include')
-rw-r--r--include/image-metadata.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/include/image-metadata.h b/include/image-metadata.h
index 5904d95acd..4ed5448a8c 100644
--- a/include/image-metadata.h
+++ b/include/image-metadata.h
@@ -25,9 +25,12 @@
#define IMD_TYPE_MODEL 0x640c8004 /* The board name this image is for */
#define IMD_TYPE_OF_COMPATIBLE 0x640c8005 /* the device tree compatible string */
#define IMD_TYPE_PARAMETER 0x640c8006 /* A generic parameter. Use key=value as data */
+#define IMD_TYPE_CRC32 0x640c1007 /* the checksum of the barebox images */
#define IMD_TYPE_END 0x640c7fff
#define IMD_TYPE_INVALID 0xffffffff
+#define IMD_CRC32_FLAG_TAG_VALID (1 << 0)
+
/*
* The IMD header. All data is stored in little endian format in the image.
* The next header starts at the next 4 byte boundary after the data.
@@ -51,8 +54,26 @@ static inline int imd_is_string(uint32_t type)
return (type & 0x8000) ? 1 : 0;
}
-static inline int imd_type_valid(uint32_t type)
+/*
+ * A IMD int.
+ */
+struct imd_entry_crc32 {
+ struct imd_header header;
+ uint32_t data;
+ uint32_t flags;
+};
+
+static inline int imd_is_crc32(uint32_t type)
+{
+ return (type & IMD_TYPE_CRC32) ? 1 : 0;
+}
+
+static inline int imd_crc32_is_valid(uint32_t flags)
{
+ return (flags & IMD_CRC32_FLAG_TAG_VALID) ? 1 : 0;
+}
+
+static inline int imd_type_valid(uint32_t type) {
return (type & 0xffff0000) == 0x640c0000;
}
@@ -78,11 +99,18 @@ static inline uint32_t imd_read_length(const struct imd_header *imd)
return imd_read_le32(&imd->datalength);
}
+static inline uint32_t imd_read_flags(const struct imd_entry_crc32 *imd)
+{
+ return imd_read_le32(&imd->flags);
+}
+
const struct imd_header *imd_find_type(const struct imd_header *imd,
uint32_t type);
const struct imd_header *imd_get(const void *buf, int size);
const char *imd_string_data(const struct imd_header *imd, int index);
+const uint32_t *imd_uint32_data(const struct imd_header *imd);
+uint32_t *imd_uint32_flags(const struct imd_header *imd);
const char *imd_type_to_name(uint32_t type);
char *imd_concat_strings(const struct imd_header *imd);
const char *imd_get_param(const struct imd_header *imd, const char *name);
@@ -90,6 +118,7 @@ const char *imd_get_param(const struct imd_header *imd, const char *name);
extern int imd_command_verbose;
int imd_command_setenv(const char *variable_name, const char *value);
int imd_command(int argc, char *argv[]);
+int imd_verify_crc32(void *buf, size_t size);
#ifdef __BAREBOX__
@@ -107,6 +136,13 @@ int imd_command(int argc, char *argv[]);
.data = _string, \
}
+#define BAREBOX_IMD_CRC(_name, _crc, _keep_if_unused) \
+ const struct imd_entry_crc32 __barebox_imd_##__name \
+ __BAREBOX_IMD_SECTION(.barebox_imd_ ## _keep_if_unused ## _ ## _name) = { \
+ .header.type = cpu_to_le32(IMD_TYPE_CRC32), \
+ .header.datalength = cpu_to_le32(sizeof(uint32_t) * 2), \
+ .data = _crc, \
+ }
#ifdef CONFIG_IMD
void imd_used(const void *);