From f77b88d124ea1c900f9cf5e04046939aad48bbe1 Mon Sep 17 00:00:00 2001 From: mbm Date: Sun, 6 Mar 2005 03:34:52 +0000 Subject: nbd's makefile/menuconfig rewrite git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@307 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- target/utils/src/motorola-bin.c | 109 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 target/utils/src/motorola-bin.c (limited to 'target/utils/src/motorola-bin.c') diff --git a/target/utils/src/motorola-bin.c b/target/utils/src/motorola-bin.c new file mode 100644 index 0000000000..476afe32f2 --- /dev/null +++ b/target/utils/src/motorola-bin.c @@ -0,0 +1,109 @@ +/* + * motorola-bin.c + * + * Copyright (C) 2005 Mike Baker + * Openwrt.org + * + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +unsigned long *crc32; + +void init_crc32() +{ + unsigned long crc; + unsigned long poly = ntohl(0x2083b8ed); + int n, bit; + if ((crc32 = (unsigned long *) malloc(256 * sizeof(unsigned long))) == (void *)-1) { + perror("malloc"); + exit(1); + } + for (n = 0; n < 256; n++) { + crc = (unsigned long) n; + for (bit = 0; bit < 8; bit++) + crc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1); + crc32[n] = crc; + } +} + +unsigned int crc32buf(char *buf, size_t len) +{ + unsigned int crc = 0xFFFFFFFF; + for (; len; len--, buf++) + crc = crc32[(crc ^ *buf) & 0xff] ^ (crc >> 8); + return crc; +} + +struct motorola { + unsigned int crc; // crc32 of the remainder + unsigned int flags; // unknown, 10577050 + char *trx; // standard trx +}; + +int main(int argc, char **argv) +{ + unsigned int len; + int fd; + void *trx; + struct motorola *firmware; + + if (argc<3) { + printf("%s \n",argv[0]); + exit(0); + } + + // mmap trx file + if (((fd = open(argv[1], O_RDONLY)) < 0) + || ((len = lseek(fd, 0, SEEK_END)) < 0) + || ((trx = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)) + || (close(fd) < 0)) { + perror("open/malloc"); + exit(-1); + } + + // create a firmware image in memory + // and copy the trx to it + firmware = malloc(len+8); + memcpy(&firmware->trx,trx,len); + munmap(trx,len); + + // setup the motorola headers + init_crc32(); + firmware->flags = ntohl(0x10577050); + firmware->crc = htonl(crc32buf((char *)&firmware->flags,len+4)); + + // write the firmware + if (((fd = open(argv[2], O_CREAT|O_WRONLY,0644)) < 0) + || (write(fd,firmware,len+8) != len+8) + || (close(fd) < 0)) { + perror("write"); + exit(-1); + } + + free(firmware); + + return 0; +} -- cgit v1.2.3 From f1dba241d895bf8b640e8b4ee655b48001350076 Mon Sep 17 00:00:00 2001 From: kaloz Date: Mon, 6 Feb 2006 00:07:27 +0000 Subject: port the changes from [3155] to Kamikaze git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@3156 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- target/linux/image/brcm/Makefile | 20 +++++++++---- target/linux/package/diag/diag_led.c | 5 ++++ target/utils/src/motorola-bin.c | 57 +++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 16 deletions(-) (limited to 'target/utils/src/motorola-bin.c') diff --git a/target/linux/image/brcm/Makefile b/target/linux/image/brcm/Makefile index 494450f247..0fe3ceeac7 100644 --- a/target/linux/image/brcm/Makefile +++ b/target/linux/image/brcm/Makefile @@ -89,7 +89,16 @@ $(BIN_DIR)/openwrt-wrt54g-$(KERNEL)-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$ $(BIN_DIR)/openwrt-wrt54gs_v4-$(KERNEL)-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx $(STAGING_DIR)/bin/addpattern -4 -p W54s -v v1.05.2 -i $< -o $@ -g -install: $(BIN_DIR)/openwrt-wrt54g-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wrt54gs_v4-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wrt54g3g-$(KERNEL)-$(FSNAME).bin +$(BIN_DIR)/openwrt-wr850g-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx + $(STAGING_DIR)/bin/motorola-bin -1 $< $@ + +$(BIN_DIR)/openwrt-wa840g-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx + $(STAGING_DIR)/bin/motorola-bin -2 $< $@ + +$(BIN_DIR)/openwrt-we800g-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx + $(STAGING_DIR)/bin/motorola-bin -3 $< $@ + +install: $(BIN_DIR)/openwrt-wrt54g-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wrt54gs_v4-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wrt54g3g-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wr850g-$(FSNAME).bin $(BIN_DIR)/openwrt-wa840g-$(FSNAME).bin $(BIN_DIR)/openwrt-we800g-$(FSNAME).bin endif ifneq ($(FS),jffs2-4MB) @@ -100,12 +109,11 @@ $(BIN_DIR)/openwrt-wgt634u-$(KERNEL)-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)- $(BIN_DIR)/openwrt-wrt54gs-$(KERNEL)-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx $(STAGING_DIR)/bin/addpattern -4 -p W54S -v v4.70.6 -i $< -o $@ -g -install: $(BIN_DIR)/openwrt-wrt54gs-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wgt634u-$(KERNEL)-$(FSNAME).bin -endif +$(BIN_DIR)/openwrt-wrtsl54gs-$(FSNAME).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx + $(STAGING_DIR)/bin/addpattern -4 -p W54U -v v2.00.0 -i $< -o $@ -g -$(BIN_DIR)/openwrt-motorola-$(KERNEL)-$(FS).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).trx - $(STAGING_DIR)/bin/motorola-bin $< $@ -install: $(BIN_DIR)/openwrt-motorola-$(KERNEL)-$(FS).bin +install: $(BIN_DIR)/openwrt-wrt54gs-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wgt634u-$(KERNEL)-$(FSNAME).bin $(BIN_DIR)/openwrt-wrtsl54gs-$(FSNAME).bin +endif endif ifeq ($(IB),) diff --git a/target/linux/package/diag/diag_led.c b/target/linux/package/diag/diag_led.c index 9864988257..e4dc391117 100644 --- a/target/linux/package/diag/diag_led.c +++ b/target/linux/package/diag/diag_led.c @@ -28,6 +28,7 @@ * 2005/03/14 asus wl-500g deluxe and buffalo v2 support added * 2005/04/13 added licensing informations * 2005/04/18 base reset polarity off initial readings + * 2006/02/07 motorola wa840g/we800g support added */ #include @@ -186,6 +187,10 @@ static int __init diag_init() //asus wl-500g reset_gpio=(1<<6); } + if (!strcmp(buf,"2")) { + //wa840g v1 / we800g v1 + reset_gpio=(1<<0); + } } if (!strcmp(buf,"bcm94710ap")) { buf=nvram_get("boardnum")?:""; diff --git a/target/utils/src/motorola-bin.c b/target/utils/src/motorola-bin.c index 476afe32f2..acf856dde6 100644 --- a/target/utils/src/motorola-bin.c +++ b/target/utils/src/motorola-bin.c @@ -1,8 +1,9 @@ /* * motorola-bin.c * - * Copyright (C) 2005 Mike Baker - * Openwrt.org + * Copyright (C) 2005-2006 Mike Baker, + * Imre Kaloz + * OpenWrt.org * * $Id$ * @@ -22,6 +23,12 @@ * */ +/* + * February 1, 2006 + * + * Add support for for creating WA840G and WE800G images + */ + #include #include #include @@ -59,29 +66,41 @@ unsigned int crc32buf(char *buf, size_t len) struct motorola { unsigned int crc; // crc32 of the remainder - unsigned int flags; // unknown, 10577050 + unsigned int flags; // unknown, 105770* char *trx; // standard trx }; +void usage(void) __attribute__ (( __noreturn__ )); + +void usage(void) +{ + printf("Usage: motorola-bin [-device] [trxfile] [binfile]\n\n"); + printf("Known devices: 1 - WR850G | 2 - WA840G | 3 - WE800G\n"); + exit(1); +} + int main(int argc, char **argv) { unsigned int len; int fd; + int c; void *trx; struct motorola *firmware; - if (argc<3) { - printf("%s \n",argv[0]); - exit(0); + // verify parameters + + if (argc!=4) + { + usage(); } // mmap trx file - if (((fd = open(argv[1], O_RDONLY)) < 0) + if (((fd = open(argv[2], O_RDONLY)) < 0) || ((len = lseek(fd, 0, SEEK_END)) < 0) || ((trx = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)) || (close(fd) < 0)) { perror("open/malloc"); - exit(-1); + exit(1); } // create a firmware image in memory @@ -92,11 +111,29 @@ int main(int argc, char **argv) // setup the motorola headers init_crc32(); - firmware->flags = ntohl(0x10577050); + + // setup the firmware magic + + while ((c = getopt(argc, argv, "123")) !=-1) { + switch (c) { + case '1': + firmware->flags = ntohl(0x10577050); // Motorola WR850G + break; + case '2': + firmware->flags = ntohl(0x10577040); // Motorola WA840G + break; + case '3': + firmware->flags = ntohl(0x10577000); // Motorola WE800G + break; + default: + usage(); + } + } + firmware->crc = htonl(crc32buf((char *)&firmware->flags,len+4)); // write the firmware - if (((fd = open(argv[2], O_CREAT|O_WRONLY,0644)) < 0) + if (((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0) || (write(fd,firmware,len+8) != len+8) || (close(fd) < 0)) { perror("write"); -- cgit v1.2.3