diff options
author | Felix Fietkau <nbd@nbd.name> | 2016-11-14 16:02:46 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2016-11-19 11:24:09 +0100 |
commit | 929641fa1fb23942581f64e6fa75ba87ba6111af (patch) | |
tree | 7770a34a417f1cf445e9323fc165260c0ea1a4b6 /package/system/fwtool/src/crc32.h | |
parent | 5e339a48aa95b4c7702829c09a99ccf3b99aad3e (diff) | |
download | upstream-929641fa1fb23942581f64e6fa75ba87ba6111af.tar.gz upstream-929641fa1fb23942581f64e6fa75ba87ba6111af.tar.bz2 upstream-929641fa1fb23942581f64e6fa75ba87ba6111af.zip |
fwtool: add utility for appending and extracting firmware metadata/signatures
This will be used to append extra information to images which allows the
system to verify if an image is compatible with the system.
The extra data is appended to the end of the image, where it will be
ignored when upgrading from systems that do not process this data yet:
If the image is a squashfs or jffs2 image, the extra data will land
after the end-of-filesystem marker, where it will be overwritten once
the system boots for the first timee.
If the image is a sysupgrade tar file, tar will simply ignore the extra
data when unpacking.
The layout of the metadata/signature chunks is constructed in a way
that the last part contains just a magic and size information, so that
the tool can quickly check if any valid data is present without having
to do a pattern search throughout the full image.
Chunks also contain CRC32 information to detect file corruption, even
when the image is not signed.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'package/system/fwtool/src/crc32.h')
-rw-r--r-- | package/system/fwtool/src/crc32.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/package/system/fwtool/src/crc32.h b/package/system/fwtool/src/crc32.h new file mode 100644 index 0000000000..022c69fc7f --- /dev/null +++ b/package/system/fwtool/src/crc32.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> + * + * Based on busybox code: + * CRC32 table fill function + * Copyright (C) 2006 by Rob Sullivan <cogito.ergo.cogito@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#ifndef __BB_CRC32_H +#define __BB_CRC32_H + +static inline void +crc32_filltable(uint32_t *crc_table) +{ + uint32_t polynomial = 0xedb88320; + uint32_t c; + int i, j; + + for (i = 0; i < 256; i++) { + c = i; + for (j = 8; j; j--) + c = (c&1) ? ((c >> 1) ^ polynomial) : (c >> 1); + + *crc_table++ = c; + } +} + +static inline uint32_t +crc32_block(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) +{ + const void *end = (uint8_t*)buf + len; + + while (buf != end) { + val = crc_table[(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); + buf = (uint8_t*)buf + 1; + } + return val; +} + +#endif |