[OpenWrt-Devel] [PATCH 1/2] firmware-utils: add Gemtek header tool

2014-04-21 Thread Claudio Leite
Generates webflash-compatible images for a few RT2880 routers based
on Gemtek OEM boards.

Signed-off-by: Claudio Leite lei...@staticky.com
---
 tools/firmware-utils/Makefile  |   1 +
 tools/firmware-utils/src/mkheader_gemtek.c | 211 +
 2 files changed, 212 insertions(+)
 create mode 100644 tools/firmware-utils/src/mkheader_gemtek.c

diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile
index 585090e..3be80e7 100644
--- a/tools/firmware-utils/Makefile
+++ b/tools/firmware-utils/Makefile
@@ -66,6 +66,7 @@ define Host/Compile
$(call cc,mkporayfw, -Wall)
#$(call cc,mkhilinkfw, -lcrypto)
$(call cc,mkdcs932, -Wall)
+   $(call cc,mkheader_gemtek,-lz)
 endef
 
 define Host/Install
diff --git a/tools/firmware-utils/src/mkheader_gemtek.c 
b/tools/firmware-utils/src/mkheader_gemtek.c
new file mode 100644
index 000..9e618ef
--- /dev/null
+++ b/tools/firmware-utils/src/mkheader_gemtek.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2014  Claudio Leite lei...@staticky.com
+ *
+ * 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
+ */
+
+/*
+ * Builds a proper flash image for routers using some Gemtek
+ * OEM boards. These include the Airlink101 AR725W, the
+ * Asante SmartHub 600 (AWRT-600N), and Linksys WRT100/110.
+ *
+ * The resulting image is compatible with the factory firmware
+ * web upgrade and TFTP interface.
+ *
+ * To build:
+ *  gcc -O2 -o mkheader_gemtek mkheader_gemtek.c -lz
+ *
+ * Claudio Leite lei...@staticky.com
+ */
+
+#include stdio.h
+#include stdlib.h
+#include stdint.h
+#include string.h
+
+#include zlib.h  /* for crc32() */
+
+/*
+ * The header is in little-endian format. In case
+ * we are on a BE host, we need to swap binary
+ * values.
+ */
+#ifdef __APPLE__
+# include libkern/OSByteOrder.h
+# define le32 OSSwapHostToLittleInt32
+#else
+# if defined(__linux__)
+#  include endian.h
+#  if __BYTE_ORDER == __BIG_ENDIAN
+#   define CPU_BIG_ENDIAN
+#  endif
+# else
+#  include sys/endian.h  /* BSD's should have this */
+#  if _BYTE_ORDER == _BIG_ENDIAN
+#   define CPU_BIG_ENDIAN
+#  endif
+# endif
+# ifdef CPU_BIG_ENDIAN
+#  define le32(x) (((x  0xff00)  24) | \
+   ((x  0x00ff)  8)  | \
+   ((x  0xff00)  8)  | \
+   ((x  0x00ff)  24))
+# else
+#  define le32(x) (x)
+# endif
+#endif
+
+struct gemtek_header {
+   uint8_t magic[4];
+   uint8_t version[4];
+   uint32_tproduct_id;
+   uint32_timagesz;
+   uint32_tchecksum;
+   uint32_tfast_checksum;
+   uint8_t build[4];
+   uint8_t lang[4];
+};
+
+#define HDRLEN sizeof(struct gemtek_header)
+
+struct machines {
+   char   *desc;
+   char   *id;
+   uint32_tmaxsize;
+   struct gemtek_header header;
+};
+
+struct machines mach_def[] = {
+   {Airlink101 AR725W, ar725w, 0x34,
+   {GMTK, 1003, le32(0x0301), 0, 0,
+ 0, 01\0\0, EN\0\0}},
+   {Asante AWRT-600N, awrt600n, 0x34,
+   {A600, 1005, le32(0x0301), 0, 0,
+ 0, 01\0\0, EN\0\0}},
+   {Linksys WRT100, wrt100, 0x32,
+   {GMTK, 1007, le32(0x03040001), 0, 0,
+ 0, 2\0\0\0, EN\0\0}},
+   {Linksys WRT110, wrt110, 0x32,
+   {GMTK, 1007, le32(0x03040001), 0, 0,
+ 0, 2\0\0\0, EN\0\0}},
+   {0}
+};
+
+int
+main(int argc, char *argv[])
+{
+   unsigned long   res, flen;
+   struct gemtek_header my_hdr;
+   FILE   *f, *f_out;
+   int image_type = -1, index;
+   uint8_t*buf;
+   uint32_tcrc;
+
+   if (argc  3) {
+   fprintf(stderr, mkheader_gemtek uImage webflash image 
[machine ID]\n);
+   fprintf(stderr,   where [machine ID] is one of:\n);
+   for (index = 0; mach_def[index].desc != 0; index++) {
+   fprintf(stderr, %-10s  %s, mach_def[index].id, 
mach_def[index].desc);
+   if (index == 0)
+   fprintf(stderr,  (default)\n);
+   else
+   fprintf(stderr, \n);
+   }
+
+   

Re: [OpenWrt-Devel] [PATCH 1/2] firmware-utils: add Gemtek header tool

2014-04-21 Thread John Crispin


On 21/04/2014 17:57, Claudio Leite wrote:
 Generates webflash-compatible images for a few RT2880 routers
 based on Gemtek OEM boards.
 
 Signed-off-by: Claudio Leite lei...@staticky.com

is there a difference between these 2 patches and the 3/3 that was
posted earlier ? i already have the 3/3 in my local queue, wanna make
sure i push the correct patch ...








 --- tools/firmware-utils/Makefile  |   1 + 
 tools/firmware-utils/src/mkheader_gemtek.c | 211
 + 2 files changed, 212 insertions(+) 
 create mode 100644 tools/firmware-utils/src/mkheader_gemtek.c
 
 diff --git a/tools/firmware-utils/Makefile
 b/tools/firmware-utils/Makefile index 585090e..3be80e7 100644 ---
 a/tools/firmware-utils/Makefile +++
 b/tools/firmware-utils/Makefile @@ -66,6 +66,7 @@ define
 Host/Compile $(call cc,mkporayfw, -Wall) #$(call cc,mkhilinkfw,
 -lcrypto) $(call cc,mkdcs932, -Wall) +$(call
 cc,mkheader_gemtek,-lz) endef
 
 define Host/Install diff --git
 a/tools/firmware-utils/src/mkheader_gemtek.c
 b/tools/firmware-utils/src/mkheader_gemtek.c new file mode 100644 
 index 000..9e618ef --- /dev/null +++
 b/tools/firmware-utils/src/mkheader_gemtek.c @@ -0,0 +1,211 @@ +/* 
 + * Copyright (C) 2014  Claudio Leite lei...@staticky.com + * + *
 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 + */ + 
 +/* + * Builds a proper flash image for routers using some Gemtek +
 * OEM boards. These include the Airlink101 AR725W, the + * Asante
 SmartHub 600 (AWRT-600N), and Linksys WRT100/110. + * + * The
 resulting image is compatible with the factory firmware + * web
 upgrade and TFTP interface. + * + * To build: + *  gcc -O2 -o
 mkheader_gemtek mkheader_gemtek.c -lz + * + * Claudio Leite
 lei...@staticky.com + */ + +#include stdio.h +#include
 stdlib.h +#include stdint.h +#include string.h + +#include
 zlib.h  /* for crc32() */ + +/* + * The header is in
 little-endian format. In case + * we are on a BE host, we need to
 swap binary + * values. + */ +#ifdef __APPLE__ +# include
 libkern/OSByteOrder.h +# define le32 OSSwapHostToLittleInt32 
 +#else +# if defined(__linux__) +#  include endian.h +#  if
 __BYTE_ORDER == __BIG_ENDIAN +#   define CPU_BIG_ENDIAN +#  endif 
 +# else +#  include sys/endian.h/* BSD's should have this */ +#
 if _BYTE_ORDER == _BIG_ENDIAN +#   define CPU_BIG_ENDIAN +#  endif 
 +# endif +# ifdef CPU_BIG_ENDIAN +#  define le32(x) (((x 
 0xff00)  24) | \ +   ((x  0x00ff)  8)
 | \ +   ((x  0xff00)  8)  | \ +
 ((x  0x00ff)  24)) +# else +#  define le32(x) (x) +# endif 
 +#endif + +struct gemtek_header { +   uint8_t magic[4]; + uint8_t
 version[4]; + uint32_tproduct_id; +   uint32_timagesz; +  
 uint32_t
 checksum; +   uint32_tfast_checksum; +uint8_t 
 build[4]; + uint8_t
 lang[4]; +}; + +#define HDRLENsizeof(struct gemtek_header) + 
 +struct machines { +  char   *desc; + char   *id; +
 uint32_t  maxsize; +  struct gemtek_header header; +}; + +struct
 machines mach_def[] = { + {Airlink101 AR725W, ar725w,
 0x34, +   {GMTK, 1003, le32(0x0301), 0, 0, +  
   0,
 01\0\0, EN\0\0}}, +   {Asante AWRT-600N, awrt600n, 0x34, 
 + {A600, 1005, le32(0x0301), 0, 0, +0, 
 01\0\0,
 EN\0\0}}, + {Linksys WRT100, wrt100, 0x32, +{GMTK,
 1007, le32(0x03040001), 0, 0, +   0, 2\0\0\0, EN\0\0}}, +
 {Linksys WRT110, wrt110, 0x32, +  {GMTK, 1007,
 le32(0x03040001), 0, 0, +   0, 2\0\0\0, EN\0\0}}, +   {0} +}; 
 + 
 +int +main(int argc, char *argv[]) +{ +   unsigned long   res, flen; +
 struct gemtek_header my_hdr; +FILE   *f, *f_out; +int
 image_type = -1, index; + uint8_t*buf; +  uint32_tcrc; + +
 if (argc  3) { + fprintf(stderr, mkheader_gemtek uImage
 webflash image [machine ID]\n); +  fprintf(stderr,   where
 [machine ID] is one of:\n); +for (index = 0;
 mach_def[index].desc != 0; index++) { +   fprintf(stderr, 
 
 %-10s  %s, mach_def[index].id, mach_def[index].desc); +  
 if
 (index == 0) +   

Re: [OpenWrt-Devel] [PATCH 1/2] firmware-utils: add Gemtek header tool

2014-04-21 Thread Claudio Leite
Hi John,

* John Crispin (j...@phrozen.org) wrote:
 
 is there a difference between these 2 patches and the 3/3 that was
 posted earlier ? i already have the 3/3 in my local queue, wanna make
 sure i push the correct patch ...
 

No difference in the code. I just figured it made more sense to split
them into firmware-utils and ramips bits instead of one blob.

Thank you kindly for merging these.

-Claudio
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel