aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2011-01-14 10:37:04 +0000
committerGabor Juhos <juhosg@openwrt.org>2011-01-14 10:37:04 +0000
commit1222152a82d823b152bc196e62a988558cddb055 (patch)
treed099df1995a8cf93df4027cbe7a9ffcaa8a6f17d /tools/firmware-utils/src
parentfd1cf86bac35a42a067856ef36fb1a67929723ca (diff)
downloadmaster-187ad058-1222152a82d823b152bc196e62a988558cddb055.tar.gz
master-187ad058-1222152a82d823b152bc196e62a988558cddb055.tar.bz2
master-187ad058-1222152a82d823b152bc196e62a988558cddb055.zip
firmware-utils/wndr3700: allow to specify image magic via command line
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@24980 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'tools/firmware-utils/src')
-rw-r--r--tools/firmware-utils/src/wndr3700.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/tools/firmware-utils/src/wndr3700.c b/tools/firmware-utils/src/wndr3700.c
index 51e5352cb0..97b5f1d455 100644
--- a/tools/firmware-utils/src/wndr3700.c
+++ b/tools/firmware-utils/src/wndr3700.c
@@ -37,7 +37,10 @@
#define BPB 8 /* bits/byte */
+#define WNDR3700_MAGIC_LEN 4
+
static uint32_t crc32[1<<BPB];
+static char *magic = "3700";
static void init_crc32()
{
@@ -64,7 +67,7 @@ static uint32_t crc32buf(unsigned char *buf, size_t len)
}
struct header {
- uint32_t magic;
+ unsigned char magic[WNDR3700_MAGIC_LEN];
uint32_t crc;
unsigned char stuff[56];
};
@@ -74,7 +77,7 @@ static void usage(const char *) __attribute__ (( __noreturn__ ));
static void usage(const char *mess)
{
fprintf(stderr, "Error: %s\n", mess);
- fprintf(stderr, "Usage: wndr3700 input_file output_file\n");
+ fprintf(stderr, "Usage: wndr3700 input_file output_file [magic]\n");
fprintf(stderr, "\n");
exit(1);
}
@@ -90,9 +93,17 @@ int main(int argc, char **argv)
// verify parameters
- if (argc != 3)
+ if (argc < 3)
usage("wrong number of arguments");
+ if (argc > 3)
+ magic = argv[3];
+
+ if (strlen(magic) != WNDR3700_MAGIC_LEN) {
+ fprintf(stderr, "Invalid magic: '%s'\n", magic);
+ exit(1);
+ }
+
// mmap input_file
if ((fd = open(argv[1], O_RDONLY)) < 0
|| (len = lseek(fd, 0, SEEK_END)) < 0
@@ -110,7 +121,7 @@ int main(int argc, char **argv)
// preload header
memcpy(&header, input_file, sizeof(header));
- header.magic = htonl(0x33373030); /* 3700 in ascii */
+ memcpy(header.magic, magic, WNDR3700_MAGIC_LEN);
header.crc = 0;
// create a firmware image in memory and copy the input_file to it