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/mkdhpimg.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/mkdhpimg.c')
-rw-r--r-- | tools/firmware-utils/src/mkdhpimg.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tools/firmware-utils/src/mkdhpimg.c b/tools/firmware-utils/src/mkdhpimg.c new file mode 100644 index 0000000000..e61d042504 --- /dev/null +++ b/tools/firmware-utils/src/mkdhpimg.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016 FUKAUMI Naoki <naobsd@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 <in> <out>\n", progname); + exit(EXIT_FAILURE); +} + +int +main(int argc, char *argv[]) +{ + struct stat in_st; + size_t size; + uint32_t crc; + int in, out; + uint8_t *buf; + + progname = argv[0]; + + if (argc != 3) + usage(); + + if ((in = open(argv[1], O_RDONLY)) == -1) + err(EXIT_FAILURE, "%s", argv[1]); + + if (fstat(in, &in_st) == -1) + err(EXIT_FAILURE, "%s", argv[1]); + + size = DHP_HEADER_SIZE + in_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(in, &buf[DHP_HEADER_SIZE], in_st.st_size); + close(in); + + 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[2], O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) + err(EXIT_FAILURE, "%s", argv[2]); + write(out, buf, size); + close(out); + + free(buf); + + return EXIT_SUCCESS; +} |