some of Buffalo DHP series use slightly different trx magic, buffalo-tag, and factory image begin with 'bgn'.
this patch adds support for building those images. Signed-off-by: FUKAUMI Naoki <nao...@gmail.com> --- tools/firmware-utils/Makefile | 1 + tools/firmware-utils/src/buffalo-tag.c | 29 ++++++++--- tools/firmware-utils/src/mkdhpimg.c | 94 ++++++++++++++++++++++++++++++++++ tools/firmware-utils/src/trx.c | 13 ++++- 4 files changed, 128 insertions(+), 9 deletions(-) create mode 100644 tools/firmware-utils/src/mkdhpimg.c diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile index 456b7a3..8a0d13f 100644 --- a/tools/firmware-utils/Makefile +++ b/tools/firmware-utils/Makefile @@ -79,6 +79,7 @@ define Host/Compile $(call cc,jcgimage, -lz -Wall) $(call cc,mkbuffaloimg, -Wall) $(call cc,zyimage, -Wall) + $(call cc,mkdhpimg buffalo-lib, -Wall) endef define Host/Install diff --git a/tools/firmware-utils/src/buffalo-tag.c b/tools/firmware-utils/src/buffalo-tag.c index b5db72e..63bc6d3 100644 --- a/tools/firmware-utils/src/buffalo-tag.c +++ b/tools/firmware-utils/src/buffalo-tag.c @@ -7,6 +7,7 @@ * */ +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -48,6 +49,7 @@ static uint32_t base2; static char *region_code; static uint32_t region_mask; static int num_regions; +static int dhp; void usage(int status) { @@ -63,6 +65,7 @@ void usage(int status) " -d <base2>\n" " -f <flag> set flag to <flag>\n" " -i <file> read input from the file <file>\n" +" -I <file> read input from the file <file> for DHP series\n" " -l <language> set language to <language>\n" " -m <version> set minor version to <version>\n" " -o <file> write output to the file <file>\n" @@ -177,11 +180,17 @@ static void fixup_tag(unsigned char *buf, ssize_t buflen) memcpy(tag->region_code, region_code, 2); } - tag->len = htonl(buflen); - tag->data_len = htonl(fsize[0]); - tag->base1 = htonl(base1); - tag->base2 = htonl(base2); - tag->flag = flag; + if (dhp) { + tag->len = htonl(buflen + 200); + tag->base1 = htonl(buflen); + tag->base2 = htonl(0x01000000); + } else { + tag->len = htonl(buflen); + tag->data_len = htonl(fsize[0]); + tag->base1 = htonl(base1); + tag->base2 = htonl(base2); + tag->flag = flag; + } if (hwver) { memcpy(tag->hwv, "hwv", 3); @@ -270,7 +279,10 @@ static int tag_file(void) offset += fsize[i]; } - if (num_files == 1) + if (dhp) { + buflen = offsetof(struct buffalo_tag, data_len); + fixup_tag(buf, fsize[0]); + } else if (num_files == 1) fixup_tag(buf, buflen); else fixup_tag2(buf, buflen); @@ -299,7 +311,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:b:c:d:f:hi:l:m:o:p:r:sv:w:"); + c = getopt(argc, argv, "a:b:c:d:f:hi:l:m:o:p:r:sv:w:I:"); if (c == -1) break; @@ -319,6 +331,9 @@ int main(int argc, char *argv[]) case 'f': flag = strtoul(optarg, NULL, 2); break; + case 'I': + dhp = 1; + /* FALLTHROUGH */ case 'i': err = process_ifname(optarg); if (err) diff --git a/tools/firmware-utils/src/mkdhpimg.c b/tools/firmware-utils/src/mkdhpimg.c new file mode 100644 index 0000000..775e512 --- /dev/null +++ b/tools/firmware-utils/src/mkdhpimg.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2016 FUKAUMI Naoki <nao...@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. + * + */ + +#include <sys/stat.h> +#include <err.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "buffalo-lib.h" + +#define DHP_HEADER_SIZE 20 + +static char *progname; + +static void +usage(void) +{ + + fprintf(stderr, "usage: %s <tag> <trx> <out>\n", progname); + exit(EXIT_FAILURE); +} + +int +main(int argc, char *argv[]) +{ + struct stat tag_st, trx_st; + size_t size; + uint32_t crc; + int tag, trx, out; + uint8_t *buf; + + progname = argv[0]; + + if (argc != 4) + usage(); + + if ((tag = open(argv[1], O_RDONLY)) == -1) + err(EXIT_FAILURE, "%s", argv[1]); + + if (fstat(tag, &tag_st) == -1) + err(EXIT_FAILURE, "%s", argv[1]); + + if ((trx = open(argv[2], O_RDONLY)) == -1) + err(EXIT_FAILURE, "%s", argv[2]); + + if (fstat(trx, &trx_st) == -1) + err(EXIT_FAILURE, "%s", argv[2]); + + size = DHP_HEADER_SIZE + tag_st.st_size + trx_st.st_size; + + if ((buf = malloc(size)) == NULL) + err(EXIT_FAILURE, "malloc"); + + memset(buf, 0, DHP_HEADER_SIZE); + buf[0x0] = 0x62; + buf[0x1] = 0x67; + buf[0x2] = 0x6e; + buf[0xb] = 0xb1; + buf[0xc] = (size >> 24) & 0xff; + buf[0xd] = (size >> 16) & 0xff; + buf[0xe] = (size >> 8) & 0xff; + buf[0xf] = size & 0xff; + + read(tag, &buf[DHP_HEADER_SIZE], tag_st.st_size); + close(tag); + + read(trx, &buf[DHP_HEADER_SIZE + tag_st.st_size], trx_st.st_size); + close(trx); + + crc = buffalo_crc(buf, size); + buf[0x10] = (crc >> 24) & 0xff; + buf[0x11] = (crc >> 16) & 0xff; + buf[0x12] = (crc >> 8) & 0xff; + buf[0x13] = crc & 0xff; + + if ((out = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) + err(EXIT_FAILURE, "%s", argv[3]); + write(out, buf, size); + close(out); + + free(buf); + + return EXIT_SUCCESS; +} diff --git a/tools/firmware-utils/src/trx.c b/tools/firmware-utils/src/trx.c index aa1f5be..dc5bb67 100644 --- a/tools/firmware-utils/src/trx.c +++ b/tools/firmware-utils/src/trx.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) int c, i, append = 0; size_t n; ssize_t n2; - uint32_t cur_len, fsmark=0; + uint32_t cur_len, fsmark=0, magic; unsigned long maxlen = TRX_MAX_LEN; struct trx_header *p; char trx_version = 1; @@ -121,7 +121,7 @@ int main(int argc, char **argv) in = NULL; i = 0; - while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:")) != -1) { + while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:M:")) != -1) { switch (c) { case '2': /* take care that nothing was written to buf so far */ @@ -243,6 +243,15 @@ int main(int argc, char **argv) } break; + case 'M': + errno = 0; + magic = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "illegal numeric string\n"); + usage(); + } + p->magic = STORE32_LE(magic); + break; default: usage(); } -- 2.7.4 _______________________________________________ Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev