Advertisement
S-trace

[OpenWrt-Devel] ramips: add ZyXEL Keenetic series to build s

Feb 26th, 2014
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.83 KB | None | 0 0
  1. Index: target/linux/ramips/image/Makefile
  2. ===================================================================
  3. --- target/linux/ramips/image/Makefile  (revision 39752)
  4. +++ target/linux/ramips/image/Makefile  (working copy)
  5. @@ -422,6 +422,20 @@
  6.  Image/Build/Profile/DIR-300-B7=$(call BuildFirmware/Default4M/$(1),$(1),dir-300-b7,DIR-300-B7)
  7.  Image/Build/Profile/DIR-320-B1=$(call BuildFirmware/Default8M/$(1),$(1),dir-320-b1,DIR-320-B1)
  8.  
  9. +define BuildFirmware/ZyXEL_Keenetic_series/squashfs
  10. +   $(call BuildFirmware/Default8M/$(1),$(1),$(2),$(3))
  11. +   # SquashFS must begin exactly at defined offset $(5)+64 bytes!
  12. +   dd if=$(KDIR)/vmlinux-$(2).bin.lzma of=$(KDIR)/vmlinux-$(2).bin.lzma.padded bs=$(5) conv=sync
  13. +   mv $(KDIR)/vmlinux-$(2).bin.lzma.padded $(KDIR)/vmlinux-$(2).bin.lzma
  14. +   $(call MkImage,lzma,$(KDIR)/vmlinux-$(2).bin.lzma,$(KDIR)/vmlinux-$(2).uImage,$(3))
  15. +   $(call MkImageSysupgrade/squashfs,$(1),$(2),$(4),factory)
  16. +   $(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-factory)
  17. +   # ZyXEL signature must be aligned at 64K
  18. +   dd if=$(BIN_DIR)/$(output_name).bin of=$(BIN_DIR)/$(output_name).padded bs=65536 conv=sync
  19. +   mv $(BIN_DIR)/$(output_name).padded $(BIN_DIR)/$(output_name).bin
  20. +   $(STAGING_DIR_HOST)/bin/zyimage -v "$(output_name)" -d $(6) $(BIN_DIR)/$(output_name).bin
  21. +endef
  22. +
  23.  Image/Build/Profile/NBG-419N=$(call BuildFirmware/Default4M/$(1),$(1),nbg-419n,NBG-419N)
  24.  
  25.  Image/Build/Profile/MZKW300NH2=$(call BuildFirmware/Edimax/$(1),$(1),mzk-w300nh2,MZK-W300NH2,$(mzkw300nh2_mtd_size),CSYS,RN52,0x50000,0xc0000)
  26. Index: target/linux/ramips/rt305x/profiles/zyxel.mk
  27. ===================================================================
  28. --- target/linux/ramips/rt305x/profiles/zyxel.mk    (revision 0)
  29. +++ target/linux/ramips/rt305x/profiles/zyxel.mk    (working copy)
  30. @@ -0,0 +1,7 @@
  31. +#
  32. +# Copyright (C) 2014 OpenWrt.org
  33. +#
  34. +# This is free software, licensed under the GNU General Public License v2.
  35. +# See /LICENSE for more information.
  36. +#
  37. +
  38. Index: tools/Makefile
  39. ===================================================================
  40. --- tools/Makefile  (revision 39752)
  41. +++ tools/Makefile  (working copy)
  42. @@ -17,7 +17,7 @@
  43.  tools-y += sstrip ipkg-utils genext2fs e2fsprogs mtd-utils mkimage
  44.  tools-y += firmware-utils patch-image patch quilt yaffs2 flock padjffs2
  45.  tools-y += mm-macros xorg-macros xfce-macros missing-macros xz cmake scons bc
  46. -tools-y += findutils
  47. +tools-y += findutils zyimage
  48.  tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2
  49.  tools-$(CONFIG_powerpc) += upx
  50.  tools-$(CONFIG_TARGET_x86) += qemu
  51. @@ -68,6 +68,7 @@
  52.  $(curdir)/sdcc/compile := $(curdir)/bison/install
  53.  $(curdir)/b43-tools/compile := $(curdir)/bison/install
  54.  $(curdir)/padjffs2/compile := $(curdir)/findutils/install
  55. +$(curdir)/zyimage/compile := $(curdir)/findutils/install
  56.  
  57.  ifneq ($(CONFIG_CCACHE),)
  58.  $(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/install))
  59. Index: tools/zyimage/Makefile
  60. ===================================================================
  61. --- tools/zyimage/Makefile  (revision 0)
  62. +++ tools/zyimage/Makefile  (working copy)
  63. @@ -0,0 +1,36 @@
  64. +#
  65. +# Copyright (C) 2014 OpenWrt.org
  66. +#
  67. +# This is free software, licensed under the GNU General Public License v2.
  68. +# See /LICENSE for more information.
  69. +#
  70. +
  71. +include $(TOPDIR)/rules.mk
  72. +
  73. +PKG_NAME:=zyimage
  74. +PKG_VERSION:=1
  75. +
  76. +include $(INCLUDE_DIR)/host-build.mk
  77. +
  78. +define Host/Prepare
  79. +   mkdir -p $(HOST_BUILD_DIR)
  80. +   $(CP) ./src/* $(HOST_BUILD_DIR)/
  81. +   find $(HOST_BUILD_DIR) -name .svn | $(XARGS) rm -rf
  82. +endef
  83. +
  84. +define Host/Compile
  85. +   $(MAKE) -C $(HOST_BUILD_DIR) LDFLAGS="$(HOST_STATIC_LINKING)"
  86. +endef
  87. +
  88. +define Host/Configure
  89. +endef
  90. +
  91. +define Host/Install
  92. +   $(CP) $(HOST_BUILD_DIR)/zyimage $(STAGING_DIR_HOST)/bin/
  93. +endef
  94. +
  95. +define Host/Clean
  96. +   rm -f $(STAGING_DIR_HOST)/bin/zyimage
  97. +endef
  98. +
  99. +$(eval $(call HostBuild))
  100. Index: tools/zyimage/src/Makefile
  101. ===================================================================
  102. --- tools/zyimage/src/Makefile  (revision 0)
  103. +++ tools/zyimage/src/Makefile  (working copy)
  104. @@ -0,0 +1,15 @@
  105. +CC = gcc
  106. +CFLAGS =
  107. +WFLAGS = -Wall -Werror
  108. +zyimage-objs = zyimage.o
  109. +
  110. +all: zyimage
  111. +
  112. +%.o: %.c
  113. +   $(CC) $(CFLAGS) $(WFLAGS) -c -o $@ $<
  114. +
  115. +zyimage: $(zyimage-objs)
  116. +   $(CC) $(LDFLAGS) -o $@ $(zyimage-objs)
  117. +
  118. +clean:
  119. +   rm -f zyimage *.o
  120. Index: tools/zyimage/src/zyimage.c
  121. ===================================================================
  122. --- tools/zyimage/src/zyimage.c (revision 0)
  123. +++ tools/zyimage/src/zyimage.c (working copy)
  124. @@ -0,0 +1,141 @@
  125. +/*
  126. + * Copyright (C) 2014 Soul Trace <[email protected]>
  127. + *
  128. + * This program is free software; you can redistribute it and/or modify it
  129. + * under the terms of the GNU General Public License version 2 as published
  130. + * by the Free Software Foundation.
  131. + *
  132. + */
  133. +
  134. +#include <stdio.h>
  135. +#include <stdlib.h>
  136. +#include <sys/types.h>
  137. +#include <string.h>
  138. +#include <unistd.h>
  139. +
  140. +#define szbuf 32768
  141. +
  142. +u_int32_t crc_tab[256];
  143. +
  144. +u_int32_t chksum_crc32 (FILE *f)
  145. +{
  146. +  register unsigned long crc;
  147. +  unsigned long i, j;
  148. +  char *buffer = malloc(szbuf);
  149. +  char *buf;
  150. +  
  151. +  crc = 0xFFFFFFFF;
  152. +  while (!feof(f))
  153. +  {
  154. +    j = fread(buffer, 1, szbuf, f);
  155. +    buf = buffer;
  156. +    for (i = 0; i < j; i++)
  157. +      crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *buf++) & 0xFF];
  158. +  }
  159. +  free(buffer);
  160. +  return crc;
  161. +}
  162. +
  163. +void chksum_crc32gentab ()
  164. +{
  165. +  unsigned long crc, poly;
  166. +  int i, j;
  167. +  
  168. +  poly = 0xEDB88320L;
  169. +  for (i = 0; i < 256; i++)
  170. +  {
  171. +    crc = i;
  172. +    for (j = 8; j > 0; j--)
  173. +    {
  174. +      if (crc & 1)
  175. +        crc = (crc >> 1) ^ poly;
  176. +      else
  177. +        crc >>= 1;
  178. +    }
  179. +    crc_tab[i] = crc;
  180. +  }
  181. +}
  182. +
  183. +void usage(char *progname)
  184. +{
  185. +  printf("Usage: %s [ -v Version ] [ -d Device_ID ] <input file>\n", progname);
  186. +  exit(1);
  187. +}
  188. +
  189. +int main(int argc, char *argv[]) {
  190. +  struct signature
  191. +  {
  192. +    const char magic[4];
  193. +    unsigned int device_id;
  194. +    char firmware_version[48];
  195. +    unsigned int crc32;
  196. +  }
  197. +  sign =
  198. +  {
  199. +    { 'Z', 'N', 'B', 'G' },
  200. +    1,
  201. +    { "V.1.0.0(1.0.0)" },
  202. +    0
  203. +  };
  204. +  FILE *f;
  205. +  
  206. +  if (argc < 1)
  207. +    usage(argv[0]);
  208. +  
  209. +  static const char *optString = "v:d:h";
  210. +  int opt = getopt( argc, argv, optString );
  211. +  while( opt != -1 ) {
  212. +    switch( opt ) {
  213. +      case 'v':
  214. +        if (optarg == NULL)
  215. +          usage(argv[0]);
  216. +        strncpy(sign.firmware_version, optarg, sizeof(sign.firmware_version)-1);
  217. +       sign.firmware_version[sizeof(sign.firmware_version)-1]='\0'; // Make sure that string is terminated correctly
  218. +        break;
  219. +        
  220. +      case 'd':
  221. +        sign.device_id = atoi(optarg);
  222. +        if (sign.device_id == 0)
  223. +          sign.device_id = (int)strtol(optarg, NULL, 16);
  224. +        break;
  225. +        
  226. +      case '?':
  227. +      case 'h':
  228. +        usage(argv[0]);
  229. +        break;
  230. +        
  231. +      default:
  232. +        break;
  233. +    }
  234. +    
  235. +    opt = getopt( argc, argv, optString );
  236. +  }
  237. +  
  238. +  chksum_crc32gentab();
  239. +  char *filename=argv[optind];
  240. +  if (access(filename, W_OK) || access(filename, R_OK))
  241. +  {
  242. +    printf("Not open input file %s\n", filename);
  243. +    exit(1);
  244. +  }
  245. +  f = fopen(argv[optind], "r+");
  246. +  if (f != NULL)
  247. +  {
  248. +    fseek(f, sizeof(sign)*-1, SEEK_END);
  249. +    struct signature oldsign;
  250. +    fread(&oldsign, sizeof(oldsign), 1, f);
  251. +    if (strncmp(oldsign.magic,"ZNBG", sizeof(oldsign.magic)) == 0 )
  252. +    {
  253. +      printf("Image is already signed as:\nDevice ID: 0x%08x\nFirmware version: %s\nImage CRC32: 0x%x\n", oldsign.device_id, oldsign.firmware_version, oldsign.crc32);
  254. +      exit(0);
  255. +    }
  256. +    
  257. +    fseek(f, 0, SEEK_SET);
  258. +    sign.crc32 = chksum_crc32(f);
  259. +    fwrite(&sign, sizeof(sign), 1, f);
  260. +    fclose(f);
  261. +    printf("Image signed as:\nDevice ID: 0x%08x\nFirmware version: %s\nImage CRC32: 0x%x\n", sign.device_id, sign.firmware_version, sign.crc32);
  262. +  }
  263. +  return 0;
  264. +}
  265. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement