diff options
author | FUKAUMI Naoki <naobsd@gmail.com> | 2017-01-29 01:05:54 +0900 |
---|---|---|
committer | Rafał Miłecki <rafal@milecki.pl> | 2017-01-31 10:55:02 +0100 |
commit | 7faee1bc9f9ede0e23de19d6156dc8d769431bb3 (patch) | |
tree | 1a29ef2ce5644eaf7d569b6073603cb23ac3793a /tools/firmware-utils/src/buffalo-enc.c | |
parent | bc32f7deb57706e6235ec82ed0e2637c63deadff (diff) | |
download | upstream-7faee1bc9f9ede0e23de19d6156dc8d769431bb3.tar.gz upstream-7faee1bc9f9ede0e23de19d6156dc8d769431bb3.tar.bz2 upstream-7faee1bc9f9ede0e23de19d6156dc8d769431bb3.zip |
firmware-utils: improve tools for Buffalo DHP series
some of Buffalo DHP series use slightly different trx magic, buffalo-enc,
buffalo-tag, and factory image begin with 'bgn'.
this patch adds support for building those images.
Signed-off-by: FUKAUMI Naoki <naobsd@gmail.com>
Diffstat (limited to 'tools/firmware-utils/src/buffalo-enc.c')
-rw-r--r-- | tools/firmware-utils/src/buffalo-enc.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tools/firmware-utils/src/buffalo-enc.c b/tools/firmware-utils/src/buffalo-enc.c index 794659eb41..08fad4ee61 100644 --- a/tools/firmware-utils/src/buffalo-enc.c +++ b/tools/firmware-utils/src/buffalo-enc.c @@ -35,6 +35,7 @@ static char *product; static char *version; static int do_decrypt; static int offset; +static int size; void usage(int status) { @@ -54,6 +55,7 @@ void usage(int status) " -v <version> set version to <version>\n" " -h show this screen\n" " -O Offset of encrypted data in file (decryption)\n" +" -S Size of unencrypted data in file (encryption)\n" ); exit(status); @@ -118,7 +120,7 @@ out: static int encrypt_file(void) { struct enc_param ep; - ssize_t src_len; + ssize_t src_len, tail_dst, tail_len, tail_src; unsigned char *buf; uint32_t hdrlen; ssize_t totlen = 0; @@ -131,8 +133,12 @@ static int encrypt_file(void) goto out; } - totlen = enc_compute_buf_len(product, version, src_len); - hdrlen = enc_compute_header_len(product, version); + if (size) { + tail_dst = enc_compute_buf_len(product, version, size); + tail_len = src_len - size; + totlen = tail_dst + tail_len; + } else + totlen = enc_compute_buf_len(product, version, src_len); buf = malloc(totlen); if (buf == NULL) { @@ -140,12 +146,21 @@ static int encrypt_file(void) goto out; } + hdrlen = enc_compute_header_len(product, version); + err = read_file_to_buf(ifname, &buf[hdrlen], src_len); if (err) { ERR("unable to read from file '%s'", ofname); goto free_buf; } + if (size) { + tail_src = hdrlen + size; + memmove(&buf[tail_dst], &buf[tail_src], tail_len); + memset(&buf[tail_src], 0, tail_dst - tail_src); + src_len = size; + } + memset(&ep, '\0', sizeof(ep)); ep.key = (unsigned char *) crypt_key; ep.seed = seed; @@ -241,7 +256,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "adi:m:o:hlp:v:k:O:r:s:"); + c = getopt(argc, argv, "adi:m:o:hlp:v:k:O:r:s:S:"); if (c == -1) break; @@ -276,6 +291,9 @@ int main(int argc, char *argv[]) case 'O': offset = strtoul(optarg, NULL, 0); break; + case 'S': + size = strtoul(optarg, NULL, 0); + break; case 'h': usage(EXIT_SUCCESS); break; |