aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2016-05-09 12:54:42 +0000
committerLuka Perkov <luka@openwrt.org>2016-06-19 19:56:13 +0200
commit8ae10b6d327df1b74f78a2834128b53e2d7b38df (patch)
tree5e280e7b4afee0585bf781d6068fda5496acf72d
parent7a4273314a3ea89f984c65f11c1fb59d4378e755 (diff)
downloadupstream-8ae10b6d327df1b74f78a2834128b53e2d7b38df.tar.gz
upstream-8ae10b6d327df1b74f78a2834128b53e2d7b38df.tar.bz2
upstream-8ae10b6d327df1b74f78a2834128b53e2d7b38df.zip
mtd: seama: add md5 to header struct
This allows us to drop some extra offset calculations and simplifies code a bit. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Backport of r49306 git-svn-id: svn://svn.openwrt.org/openwrt/branches/chaos_calmer@49310 3c298f89-4303-0410-b956-a3cf2f4a3e73
-rw-r--r--package/system/mtd/src/seama.c17
-rw-r--r--package/system/mtd/src/seama.h6
2 files changed, 11 insertions, 12 deletions
diff --git a/package/system/mtd/src/seama.c b/package/system/mtd/src/seama.c
index 8894883c26..42b1e88e08 100644
--- a/package/system/mtd/src/seama.c
+++ b/package/system/mtd/src/seama.c
@@ -53,7 +53,7 @@ ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
int
seama_fix_md5(char *buf, size_t len)
{
- struct seama_hdr *shdr = (struct seama_hdr *) buf;
+ struct seama_entity_header *shdr = (struct seama_entity_header *) buf;
char *data;
size_t msize;
size_t isize;
@@ -61,7 +61,7 @@ seama_fix_md5(char *buf, size_t len)
unsigned char digest[16];
int i;
- if (len < sizeof(struct seama_hdr))
+ if (len < sizeof(struct seama_entity_header))
return -1;
isize = ntohl(shdr->size);
@@ -71,17 +71,17 @@ seama_fix_md5(char *buf, size_t len)
return -1;
}
- len -= sizeof(struct seama_hdr) + sizeof(digest) + msize;
+ len -= sizeof(struct seama_entity_header) + msize;
if (isize > len)
isize = len;
- data = buf + sizeof(struct seama_hdr) + sizeof(digest) + msize;
+ data = buf + sizeof(struct seama_entity_header) + msize;
MD5_Init(&ctx);
MD5_Update(&ctx, data, isize);
MD5_Final(digest, &ctx);
- if (!memcmp(digest, &buf[sizeof(struct seama_hdr)], sizeof(digest))) {
+ if (!memcmp(digest, shdr->md5, sizeof(digest))) {
if (quiet < 2)
fprintf(stderr, "the header is fixed already\n");
return -1;
@@ -99,8 +99,7 @@ seama_fix_md5(char *buf, size_t len)
shdr->size = htonl(isize);
/* update the checksum in the image */
- for (i = 0; i < sizeof(digest); i++)
- buf[sizeof(struct seama_hdr) + i] = digest[i];
+ memcpy(shdr->md5, digest, sizeof(digest));
return 0;
}
@@ -113,7 +112,7 @@ mtd_fixseama(const char *mtd, size_t offset)
char *buf;
ssize_t res;
size_t block_offset;
- struct seama_hdr *shdr;
+ struct seama_entity_header *shdr;
if (quiet < 2)
fprintf(stderr, "Trying to fix SEAMA header in %s at 0x%x...\n",
@@ -146,7 +145,7 @@ mtd_fixseama(const char *mtd, size_t offset)
exit(1);
}
- shdr = (struct seama_hdr *)first_block;
+ shdr = (struct seama_entity_header *)first_block;
if (shdr->magic != htonl(SEAMA_MAGIC)) {
fprintf(stderr, "No SEAMA header found\n");
return -1;
diff --git a/package/system/mtd/src/seama.h b/package/system/mtd/src/seama.h
index 02683b6e98..c6634bd15a 100644
--- a/package/system/mtd/src/seama.h
+++ b/package/system/mtd/src/seama.h
@@ -94,14 +94,14 @@
* | image size |
* +-------------+-------------+
*/
+
/* seama header */
-typedef struct seama_hdr seamahdr_t;
-struct seama_hdr
-{
+struct seama_entity_header {
uint32_t magic; /* should always be SEAMA_MAGIC. */
uint16_t reserved; /* reserved for */
uint16_t metasize; /* size of the META data */
uint32_t size; /* size of the image */
+ uint8_t md5[16];
} __attribute__ ((packed));