Hello, 2014-02-26 10:28 GMT-08:00 Soul Trace <[email protected]>: > Hello. > > This patch adds ZyXEL Keenetic series profile and neccesary for creating > Factory images for this routers tool to build system. > This patch also available at pastebin: http://pastebin.com/raw.php?i=Su918N9r > > I will send patches adding particular devices which need this functionality > later.
Please send a properly submitted patch according to the guidelines here: https://dev.openwrt.org/wiki/SubmittingPatches > > Thank You. > > Index: target/linux/ramips/image/Makefile > =================================================================== > --- target/linux/ramips/image/Makefile (revision 39752) > +++ target/linux/ramips/image/Makefile (working copy) > @@ -422,6 +422,20 @@ > Image/Build/Profile/DIR-300-B7=$(call > BuildFirmware/Default4M/$(1),$(1),dir-300-b7,DIR-300-B7) > Image/Build/Profile/DIR-320-B1=$(call > BuildFirmware/Default8M/$(1),$(1),dir-320-b1,DIR-320-B1) > > +define BuildFirmware/ZyXEL_Keenetic_series/squashfs > + $(call BuildFirmware/Default8M/$(1),$(1),$(2),$(3)) > + # SquashFS must begin exactly at defined offset $(5)+64 bytes! > + dd if=$(KDIR)/vmlinux-$(2).bin.lzma > of=$(KDIR)/vmlinux-$(2).bin.lzma.padded bs=$(5) conv=sync > + mv $(KDIR)/vmlinux-$(2).bin.lzma.padded $(KDIR)/vmlinux-$(2).bin.lzma > + $(call > MkImage,lzma,$(KDIR)/vmlinux-$(2).bin.lzma,$(KDIR)/vmlinux-$(2).uImage,$(3)) > + $(call MkImageSysupgrade/squashfs,$(1),$(2),$(4),factory) > + $(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-factory) > + # ZyXEL signature must be aligned at 64K > + dd if=$(BIN_DIR)/$(output_name).bin > of=$(BIN_DIR)/$(output_name).padded bs=65536 conv=sync > + mv $(BIN_DIR)/$(output_name).padded $(BIN_DIR)/$(output_name).bin > + $(STAGING_DIR_HOST)/bin/zyimage -v "$(output_name)" -d $(6) > $(BIN_DIR)/$(output_name).bin > +endef > + > Image/Build/Profile/NBG-419N=$(call > BuildFirmware/Default4M/$(1),$(1),nbg-419n,NBG-419N) > > Image/Build/Profile/MZKW300NH2=$(call > BuildFirmware/Edimax/$(1),$(1),mzk-w300nh2,MZK-W300NH2,$(mzkw300nh2_mtd_size),CSYS,RN52,0x50000,0xc0000) > Index: target/linux/ramips/rt305x/profiles/zyxel.mk > =================================================================== > --- target/linux/ramips/rt305x/profiles/zyxel.mk (revision 0) > +++ target/linux/ramips/rt305x/profiles/zyxel.mk (working copy) > @@ -0,0 +1,7 @@ > +# > +# Copyright (C) 2014 OpenWrt.org > +# > +# This is free software, licensed under the GNU General Public License v2. > +# See /LICENSE for more information. > +# > + > Index: tools/Makefile > =================================================================== > --- tools/Makefile (revision 39752) > +++ tools/Makefile (working copy) > @@ -17,7 +17,7 @@ > tools-y += sstrip ipkg-utils genext2fs e2fsprogs mtd-utils mkimage > tools-y += firmware-utils patch-image patch quilt yaffs2 flock padjffs2 > tools-y += mm-macros xorg-macros xfce-macros missing-macros xz cmake scons bc > -tools-y += findutils > +tools-y += findutils zyimage > tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2 > tools-$(CONFIG_powerpc) += upx > tools-$(CONFIG_TARGET_x86) += qemu > @@ -68,6 +68,7 @@ > $(curdir)/sdcc/compile := $(curdir)/bison/install > $(curdir)/b43-tools/compile := $(curdir)/bison/install > $(curdir)/padjffs2/compile := $(curdir)/findutils/install > +$(curdir)/zyimage/compile := $(curdir)/findutils/install > > ifneq ($(CONFIG_CCACHE),) > $(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += > $(curdir)/ccache/install)) > Index: tools/zyimage/Makefile > =================================================================== > --- tools/zyimage/Makefile (revision 0) > +++ tools/zyimage/Makefile (working copy) > @@ -0,0 +1,36 @@ > +# > +# Copyright (C) 2014 OpenWrt.org > +# > +# This is free software, licensed under the GNU General Public License v2. > +# See /LICENSE for more information. > +# > + > +include $(TOPDIR)/rules.mk > + > +PKG_NAME:=zyimage > +PKG_VERSION:=1 > + > +include $(INCLUDE_DIR)/host-build.mk > + > +define Host/Prepare > + mkdir -p $(HOST_BUILD_DIR) > + $(CP) ./src/* $(HOST_BUILD_DIR)/ > + find $(HOST_BUILD_DIR) -name .svn | $(XARGS) rm -rf > +endef > + > +define Host/Compile > + $(MAKE) -C $(HOST_BUILD_DIR) LDFLAGS="$(HOST_STATIC_LINKING)" > +endef > + > +define Host/Configure > +endef > + > +define Host/Install > + $(CP) $(HOST_BUILD_DIR)/zyimage $(STAGING_DIR_HOST)/bin/ > +endef > + > +define Host/Clean > + rm -f $(STAGING_DIR_HOST)/bin/zyimage > +endef > + > +$(eval $(call HostBuild)) > Index: tools/zyimage/src/Makefile > =================================================================== > --- tools/zyimage/src/Makefile (revision 0) > +++ tools/zyimage/src/Makefile (working copy) > @@ -0,0 +1,15 @@ > +CC = gcc > +CFLAGS = > +WFLAGS = -Wall -Werror > +zyimage-objs = zyimage.o > + > +all: zyimage > + > +%.o: %.c > + $(CC) $(CFLAGS) $(WFLAGS) -c -o $@ $< > + > +zyimage: $(zyimage-objs) > + $(CC) $(LDFLAGS) -o $@ $(zyimage-objs) > + > +clean: > + rm -f zyimage *.o > Index: tools/zyimage/src/zyimage.c > =================================================================== > --- tools/zyimage/src/zyimage.c (revision 0) > +++ tools/zyimage/src/zyimage.c (working copy) > @@ -0,0 +1,141 @@ > +/* > + * Copyright (C) 2014 Soul Trace <[email protected]> > + * > + * 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 <stdio.h> > +#include <stdlib.h> > +#include <sys/types.h> > +#include <string.h> > +#include <unistd.h> > + > +#define szbuf 32768 > + > +u_int32_t crc_tab[256]; > + > +u_int32_t chksum_crc32 (FILE *f) > +{ > + register unsigned long crc; > + unsigned long i, j; > + char *buffer = malloc(szbuf); > + char *buf; > + > + crc = 0xFFFFFFFF; > + while (!feof(f)) > + { > + j = fread(buffer, 1, szbuf, f); > + buf = buffer; > + for (i = 0; i < j; i++) > + crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *buf++) & 0xFF]; > + } > + free(buffer); > + return crc; > +} > + > +void chksum_crc32gentab () > +{ > + unsigned long crc, poly; > + int i, j; > + > + poly = 0xEDB88320L; > + for (i = 0; i < 256; i++) > + { > + crc = i; > + for (j = 8; j > 0; j--) > + { > + if (crc & 1) > + crc = (crc >> 1) ^ poly; > + else > + crc >>= 1; > + } > + crc_tab[i] = crc; > + } > +} > + > +void usage(char *progname) > +{ > + printf("Usage: %s [ -v Version ] [ -d Device_ID ] <input file>\n", > progname); > + exit(1); > +} > + > +int main(int argc, char *argv[]) { > + struct signature > + { > + const char magic[4]; > + unsigned int device_id; > + char firmware_version[48]; > + unsigned int crc32; > + } > + sign = > + { > + { 'Z', 'N', 'B', 'G' }, > + 1, > + { "V.1.0.0(1.0.0)" }, > + 0 > + }; > + FILE *f; > + > + if (argc < 1) > + usage(argv[0]); > + > + static const char *optString = "v:d:h"; > + int opt = getopt( argc, argv, optString ); > + while( opt != -1 ) { > + switch( opt ) { > + case 'v': > + if (optarg == NULL) > + usage(argv[0]); > + strncpy(sign.firmware_version, optarg, > sizeof(sign.firmware_version)-1); > + sign.firmware_version[sizeof(sign.firmware_version)-1]='\0'; // Make > sure that string is terminated correctly > + break; > + > + case 'd': > + sign.device_id = atoi(optarg); > + if (sign.device_id == 0) > + sign.device_id = (int)strtol(optarg, NULL, 16); > + break; > + > + case '?': > + case 'h': > + usage(argv[0]); > + break; > + > + default: > + break; > + } > + > + opt = getopt( argc, argv, optString ); > + } > + > + chksum_crc32gentab(); > + char *filename=argv[optind]; > + if (access(filename, W_OK) || access(filename, R_OK)) > + { > + printf("Not open input file %s\n", filename); > + exit(1); > + } > + f = fopen(argv[optind], "r+"); > + if (f != NULL) > + { > + fseek(f, sizeof(sign)*-1, SEEK_END); > + struct signature oldsign; > + fread(&oldsign, sizeof(oldsign), 1, f); > + if (strncmp(oldsign.magic,"ZNBG", sizeof(oldsign.magic)) == 0 ) > + { > + 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); > + exit(0); > + } > + > + fseek(f, 0, SEEK_SET); > + sign.crc32 = chksum_crc32(f); > + fwrite(&sign, sizeof(sign), 1, f); > + fclose(f); > + printf("Image signed as:\nDevice ID: 0x%08x\nFirmware version: %s\nImage > CRC32: 0x%x\n", sign.device_id, sign.firmware_version, sign.crc32); > + } > + return 0; > +} > + > _______________________________________________ > openwrt-devel mailing list > [email protected] > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel -- Florian _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
