Add support for Netgear WNCE2001

This is a small RT3052 device with 4MB spi flash and 32MB ram.
2 built-in antennas, 1x fastE, no USB, reset & wps switch.
On my model the AP/RT switch is unpopulated, but I verified the gpio
mapping for it.
The stock firmware is running an unprotected tftpd which allows you
to read any file from the filesystem.
Serial port is present on testpads (See image on the wiki page).
There are more testpads below the shield near the SoC, which
may have JTAG.
Slight annoyance: The bootloader is checksumming kernel&rootfs, but
can be tricked by zeroing checksum and length fields in the checksum
partition, see
target/linux/ramips/base-files/lib/preinit/04_disable_wnce2001_flash_checksumming

The manufacturer image is very similar to the DAP one, so I slightly
modified mkdapimg to support generating it.

The resulting openwrt-ramips-rt305x-wnce2001-squashfs-factory.bin
can be used to flash from stock to OpenWRT using the stock firmware
upgrade function, without using the serial port.

http://www.netgear.com/landing/wnce2001.aspx
http://wiki.openwrt.org/toh/netgear/wnce2001

Signed-off-by: Tobias Diedrich <ranma+open...@tdiedrich.de>

Index: target/linux/ramips/base-files/etc/diag.sh
===================================================================
--- target/linux/ramips/base-files/etc/diag.sh  (revision 36141)
+++ target/linux/ramips/base-files/etc/diag.sh  (working copy)
@@ -108,6 +108,9 @@
        wr512-3gn)
                status_led="wr512:green:wps"
                ;;
+       wnce2001)
+               status_led="netgear:green:power"
+               ;;
        mzk-w300nh2)
                status_led="mzkw300nh2:green:power"
                ;;
Index: target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
===================================================================
--- target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom      
(revision 36141)
+++ target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom      
(working copy)
@@ -90,6 +90,7 @@
        wl-330n3g | \
        wl-351 | \
        wli-tx4-ag300n | \
+       wnce2001 | \
        wr512-3gn | \
        wr6202 | \
        mzk-w300nh2 | \
Index: target/linux/ramips/base-files/etc/uci-defaults/01_leds
===================================================================
--- target/linux/ramips/base-files/etc/uci-defaults/01_leds     (revision 36141)
+++ target/linux/ramips/base-files/etc/uci-defaults/01_leds     (working copy)
@@ -105,6 +105,9 @@
        wcr-150gn)
                set_usb_led "wcr150gn:amber:user"
                ;;
+       wnce2001)
+               set_wifi_led "netgear:green:wlan"
+               ;;
 esac
 
 ucidef_commit_leds
Index: target/linux/ramips/base-files/etc/uci-defaults/02_network
===================================================================
--- target/linux/ramips/base-files/etc/uci-defaults/02_network  (revision 36141)
+++ target/linux/ramips/base-files/etc/uci-defaults/02_network  (working copy)
@@ -40,7 +40,8 @@
        3g300m | \
        all0256n | \
        all5002 | \
-       broadway)
+       broadway | \
+       wnce2001)
                ucidef_add_switch "switch0" "1" "0"
                ucidef_set_interface_lan "eth0"
                ;;
@@ -238,7 +239,8 @@
 
        all0239-3g | \
        carambola | \
-       w502u)
+       w502u | \
+       wnce2001)
                lan_mac=$(mtd_get_mac_binary factory 40)
                wan_mac=$(mtd_get_mac_binary factory 46)
                ;;
Index: 
target/linux/ramips/base-files/lib/preinit/04_disable_wnce2001_flash_checksumming
===================================================================
--- 
target/linux/ramips/base-files/lib/preinit/04_disable_wnce2001_flash_checksumming
   (revision 0)
+++ 
target/linux/ramips/base-files/lib/preinit/04_disable_wnce2001_flash_checksumming
   (working copy)
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+do_wnce2001_checksumming_disable() {
+       . /lib/ramips.sh
+
+       local board=$(ramips_board_name)
+
+       case "$board" in
+       wnce2001)
+               echo "Board is WNCE2001, updating checksum partition..."
+               local zeroes=/dev/zero
+               local tmpfile=/tmp/wnce2001_checksum
+               local partname=checksum
+               local mtd=$(find_mtd_part $partname)
+               dd if=$mtd of=$tmpfile bs=80 count=1 2>/dev/null
+               signature=$(dd if=$tmpfile bs=1 skip=24 count=20 2>/dev/null)
+               checksum=$(dd if=$tmpfile bs=1 count=4 2>/dev/null | hexdump -v 
-n 4 -e '1/1 "%02x"')
+               if [ "$signature" != "RT3052-AP-WNCE2001-3" ]; then
+                       echo "Signature of checksum partition is wrong, 
bailing."
+                       return 0
+               fi
+               if [ "$checksum" != "00000000" ]; then
+                       echo "Checksum is set, zeroing."
+                       # zero out checksum
+                       dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=0 
count=4 2>/dev/null
+                       # zero out bytecount to be checksummed
+                       dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=60 
count=4 2>/dev/null
+                       mtd write $tmpfile $partname
+               else
+                       echo "Checksum is already zero, nothing to do."
+               fi
+       ;;
+       esac
+
+       return 0
+}
+
+boot_hook_add preinit_main do_wnce2001_checksumming_disable
Index: target/linux/ramips/base-files/lib/preinit/06_set_iface_mac
===================================================================
--- target/linux/ramips/base-files/lib/preinit/06_set_iface_mac (revision 36141)
+++ target/linux/ramips/base-files/lib/preinit/06_set_iface_mac (working copy)
@@ -61,6 +61,7 @@
        w306r-v20 |\
        w502u    |\
        wr6202 |\
+       wnce2001 |\
        xdxrn502j)
                mac=$(mtd_get_mac_binary factory 40)
                ifconfig eth0 hw ether $mac 2>/dev/null
Index: target/linux/ramips/base-files/lib/ramips.sh
===================================================================
--- target/linux/ramips/base-files/lib/ramips.sh        (revision 36141)
+++ target/linux/ramips/base-files/lib/ramips.sh        (working copy)
@@ -114,6 +114,9 @@
        *"NBG-419N")
                name="nbg-419n"
                ;;
+       *"Netgear WNCE2001")
+               name="wnce2001"
+               ;;
        *"NexAira BC2")
                name="bc2"
                ;;
Index: target/linux/ramips/base-files/lib/upgrade/platform.sh
===================================================================
--- target/linux/ramips/base-files/lib/upgrade/platform.sh      (revision 36141)
+++ target/linux/ramips/base-files/lib/upgrade/platform.sh      (working copy)
@@ -56,6 +56,7 @@
        wl341v3 | \
        wl-330n | \
        wl-351 | \
+       wnce2001 | \
        wli-tx4-ag300n | \
        whr-g300n |\
        ur-326n4g |\
Index: target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h
===================================================================
--- target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h       
(revision 36141)
+++ target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h       
(working copy)
@@ -63,6 +63,7 @@
        RAMIPS_MACH_WHR_G300N,          /* Buffalo WHR-G300N */
        RAMIPS_MACH_WL341V3,            /* Sitecom WL-341 v3 */
        RAMIPS_MACH_WL351,              /* Sitecom WL-351 v1 002 */
+       RAMIPS_MACH_WNCE2001,           /* Netgear WNCE2001 */
        RAMIPS_MACH_WR512_3GN,          /* SH-WR512NU/WS-WR512N1-like 3GN*/
        RAMIPS_MACH_WR6202,             /* Accton WR6202 */
        RAMIPS_MACH_MZKW300NH2,         /* Planex MZK-W300NH2 Router */
Index: target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig
===================================================================
--- target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig   (revision 36141)
+++ target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig   (working copy)
@@ -214,6 +214,11 @@
        select RALINK_DEV_GPIO_BUTTONS
        select RALINK_DEV_GPIO_LEDS
 
+config RT305X_MACH_WNCE2001
+       bool "Netgear WNCE2001"
+       select RALINK_DEV_GPIO_BUTTONS
+       select RALINK_DEV_GPIO_LEDS
+
 endmenu
 
 endif
Index: target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile
===================================================================
--- target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile  (revision 36141)
+++ target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile  (working copy)
@@ -51,6 +51,7 @@
 obj-$(CONFIG_RT305X_MACH_WL_330N3G)    += mach-wl-330n3g.o
 obj-$(CONFIG_RT305X_MACH_WL341V3)      += mach-wl341v3.o
 obj-$(CONFIG_RT305X_MACH_WL351)                += mach-wl351.o
+obj-$(CONFIG_RT305X_MACH_WNCE2001)     += mach-wnce2001.o
 obj-$(CONFIG_RT305X_MACH_WR6202)       += mach-wr6202.o
 obj-$(CONFIG_RT305X_MACH_MZKW300NH2)   += mach-mzk-w300nh2.o
 obj-$(CONFIG_RT305X_MACH_XDX_RN502J)    += mach-xdx-rn502j.o
Index: target/linux/ramips/files/arch/mips/ralink/rt305x/mach-wnce2001.c
===================================================================
--- target/linux/ramips/files/arch/mips/ralink/rt305x/mach-wnce2001.c   
(revision 0)
+++ target/linux/ramips/files/arch/mips/ralink/rt305x/mach-wnce2001.c   
(working copy)
@@ -0,0 +1,126 @@
+/*
+ *  Netgear WNCE2001
+ *
+ *  Copyright (C) 2013 Tobias Diedrich <ranma+open...@tdiedrich.de>
+ *
+ *  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 <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/flash.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+
+#include <asm/mach-ralink/machine.h>
+#include <asm/mach-ralink/dev-gpio-buttons.h>
+#include <asm/mach-ralink/dev-gpio-leds.h>
+#include <asm/mach-ralink/rt305x.h>
+#include <asm/mach-ralink/rt305x_regs.h>
+
+#include "devices.h"
+
+#define WNCE2001_GPIO_LED_POWER_GREEN  8  /* active low */
+#define WNCE2001_GPIO_LED_POWER_RED    9  /* active low */
+
+#define WNCE2001_GPIO_LED_WLAN_GREEN   12 /* active low */
+#define WNCE2001_GPIO_LED_WLAN_RED     13 /* active low */
+
+#define WNCE2001_GPIO_BUTTON_RESET     10 /* active low */
+#define WNCE2001_GPIO_BUTTON_WPS       0  /* active low */
+
+#define WNCE2001_GPIO_SWITCH_MODE_AP   7  /* active low */
+#define WNCE2001_GPIO_SWITCH_MODE_RT   11 /* active low */
+
+#define WNCE2001_KEYS_POLL_INTERVAL    20
+#define WNCE2001_KEYS_DEBOUNCE_INTERVAL (3 * WNCE2001_KEYS_POLL_INTERVAL)
+
+static struct gpio_led wnce2001_leds_gpio[] __initdata = {
+       {
+               .name           = "netgear:green:power",
+               .gpio           = WNCE2001_GPIO_LED_POWER_GREEN,
+               .active_low     = 1,
+       }, {
+               .name           = "netgear:red:power",
+               .gpio           = WNCE2001_GPIO_LED_POWER_RED,
+               .active_low     = 1,
+       }, {
+               .name           = "netgear:green:wlan",
+               .gpio           = WNCE2001_GPIO_LED_WLAN_GREEN,
+               .active_low     = 1,
+       }, {
+               .name           = "netgear:red:wlan",
+               .gpio           = WNCE2001_GPIO_LED_WLAN_RED,
+               .active_low     = 1,
+       }
+};
+
+static struct gpio_keys_button wnce2001_gpio_buttons[] __initdata = {
+       {
+               .desc           = "reset",
+               .type           = EV_KEY,
+               .code           = KEY_RESTART,
+               .debounce_interval = WNCE2001_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = WNCE2001_GPIO_BUTTON_RESET,
+               .active_low     = 1,
+       }, {
+               .desc           = "wps",
+               .type           = EV_KEY,
+               .code           = KEY_WPS_BUTTON,
+               .debounce_interval = WNCE2001_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = WNCE2001_GPIO_BUTTON_WPS,
+               .active_low     = 1,
+       }, {
+               .desc           = "rt",
+               .type           = EV_KEY,
+               .code           = BTN_0,
+               .debounce_interval = WNCE2001_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = WNCE2001_GPIO_SWITCH_MODE_RT,
+               .active_low     = 1,
+       }, {
+               .desc           = "ap",
+               .type           = EV_KEY,
+               .code           = BTN_1,
+               .debounce_interval = WNCE2001_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = WNCE2001_GPIO_SWITCH_MODE_AP,
+               .active_low     = 1,
+       }
+};
+
+const struct flash_platform_data wnce2001_flash = {
+       .type           = "mx25l3205d",
+};
+
+struct spi_board_info wnce2001_spi_slave_info[] __initdata = {
+       {
+               .modalias       = "m25p80",
+               .platform_data  = &wnce2001_flash,
+               .irq            = -1,
+               .max_speed_hz   = 10000000,
+               .bus_num        = 0,
+               .chip_select    = 0,
+       },
+};
+
+static void __init wnce2001_init(void)
+{
+       rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
+       rt305x_register_spi(wnce2001_spi_slave_info,
+                           ARRAY_SIZE(wnce2001_spi_slave_info));
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_NONE;
+       rt305x_register_ethernet();
+       ramips_register_gpio_leds(-1, ARRAY_SIZE(wnce2001_leds_gpio),
+                                 wnce2001_leds_gpio);
+       ramips_register_gpio_buttons(-1, WNCE2001_KEYS_POLL_INTERVAL,
+                                    ARRAY_SIZE(wnce2001_gpio_buttons),
+                                    wnce2001_gpio_buttons);
+       rt305x_register_wifi();
+       rt305x_register_wdt();
+}
+
+MIPS_MACHINE(RAMIPS_MACH_WNCE2001, "WNCE2001", "Netgear WNCE2001",
+            wnce2001_init);
Index: target/linux/ramips/image/Makefile
===================================================================
--- target/linux/ramips/image/Makefile  (revision 36141)
+++ target/linux/ramips/image/Makefile  (working copy)
@@ -407,6 +407,17 @@
        $(call BuildFirmware/Buffalo2,$(1),wli-tx4-ag300n,WLI-TX4-AG300N,$(call 
mkmtd/phys,$(mtdlayout_wlitx4ag300n)),917504,2883584)
 endef
 
+mtdlayout_wnce2001=192k(u-boot)ro,64k(factory)ro,128k(config)ro,192k(language)ro,64k(pot)ro,64k(checksum),768k(kernel),2624k(rootfs),3392k@0xb0000(firmware)
+kernel_size_wnce2001=786432
+rootfs_size_wnce2001=2686976
+cmdline_wnce2001=$(call mkcmdline,WNCE2001,ttyS1,115200) $(call 
mkmtd/spi,$(mtdlayout_wnce2001))
+define BuildFirmware/WNCE2001
+       $(call 
BuildFirmware/Generic,$(1),$(2),$(cmdline_wnce2001),$(kernel_size_wnce2001),$(rootfs_size_wnce2001))
+       -mkdapimg -s RT3052-AP-WNCE2001-3 -r WW -v 1.0.0.99 \
+               -i $(call sysupname,$(1),$(2)) \
+               -o $(call imgname,$(1),$(2))-factory.bin
+endef
+
 
mtdlayout_mzkw300nh2=192k(u-boot)ro,64k(u-boot-env)ro,64k(factory)ro,832k(kernel),2816k(rootfs),128k@0x3e0000(cimage)ro,3648k@0x50000(firmware)
 kernel_size_mzkw300nh2=851968
 rootfs_size_mzkw300nh2=2883584
@@ -628,6 +639,10 @@
        $(call 
Image/Build/Template/$(fs_squash)/$(1),GENERIC_4M,wl-351,WL-351,ttyS1,57600,phys)
 endef
 
+define Image/Build/Profile/WNCE2001
+       $(call Image/Build/Template/$(fs_squash)/$(1),WNCE2001,wnce2001)
+endef
+
 define Image/Build/Profile/WR5123GN
        $(call 
Image/Build/Template/$(fs_squash)/$(1),GENERIC_4M,wr512-3gn-4M,WR512-3GN,ttyS1,57600,phys)
        $(call 
Image/Build/Template/$(fs_squash)/$(1),GENERIC_8M,wr512-3gn-8M,WR512-3GN,ttyS1,57600,phys)
@@ -690,6 +705,7 @@
        $(call Image/Build/Profile/WL_330N3G,$(1))
        $(call Image/Build/Profile/WL341V3,$(1))
        $(call Image/Build/Profile/WL351,$(1))
+       $(call Image/Build/Profile/WNCE2001,$(1))
        $(call Image/Build/Profile/WR5123GN,$(1))
        $(call Image/Build/Profile/WR6202,$(1))
        $(call Image/Build/Profile/XDXRN502J,$(1))
Index: target/linux/ramips/rt305x/config-3.7
===================================================================
--- target/linux/ramips/rt305x/config-3.7       (revision 36141)
+++ target/linux/ramips/rt305x/config-3.7       (working copy)
@@ -142,6 +142,7 @@
 CONFIG_RT305X_MACH_WL351=y
 CONFIG_RT305X_MACH_WL_330N=y
 CONFIG_RT305X_MACH_WL_330N3G=y
+CONFIG_RT305X_MACH_WNCE2001=y
 CONFIG_RT305X_MACH_WR512_3GN=y
 CONFIG_RT305X_MACH_WR6202=y
 CONFIG_RT305X_MACH_XDX_RN502J=y
Index: target/linux/ramips/rt305x/config-3.8
===================================================================
--- target/linux/ramips/rt305x/config-3.8       (revision 36141)
+++ target/linux/ramips/rt305x/config-3.8       (working copy)
@@ -141,6 +141,7 @@
 CONFIG_RT305X_MACH_WL351=y
 CONFIG_RT305X_MACH_WL_330N=y
 CONFIG_RT305X_MACH_WL_330N3G=y
+CONFIG_RT305X_MACH_WNCE2001=y
 CONFIG_RT305X_MACH_WR512_3GN=y
 CONFIG_RT305X_MACH_WR6202=y
 CONFIG_RT305X_MACH_XDX_RN502J=y
Index: tools/firmware-utils/src/mkdapimg.c
===================================================================
--- tools/firmware-utils/src/mkdapimg.c (revision 36141)
+++ tools/firmware-utils/src/mkdapimg.c (working copy)
@@ -27,6 +27,8 @@
 
 #define MAX_MODEL_NAME_LEN     20
 #define MAX_SIG_LEN            30
+#define MAX_REGION_LEN         4
+#define MAX_VERSION_LEN                12
 
 struct img_hdr_struct {
        uint32_t checksum;
@@ -51,7 +53,7 @@
 void
 usage()
 {
-       fprintf(stderr, "usage: %s [-p] [-m model] -s signature -i input -o 
output\n", progname);
+       fprintf(stderr, "usage: %s [-p] [-m model] [-r region] [-v version] -s 
signature -i input -o output\n", progname);
        exit(1);
 }
 
@@ -60,8 +62,11 @@
 {
        char model[MAX_MODEL_NAME_LEN+1];
        char signature[MAX_SIG_LEN+1];
+       char region[MAX_REGION_LEN+1];
+       char version[MAX_VERSION_LEN+1];
        int patchmode = 0;
        int fixmode = 0;
+       int have_regionversion = 0;
 
        FILE *ifile, *ofile;
        int c;
@@ -71,11 +76,13 @@
        progname = basename(av[0]);
        memset(model, 0, sizeof(model));
        memset(signature, 0, sizeof(signature));
+       memset(region, 0, sizeof(region));
+       memset(version, 0, sizeof(version));
 
        while ( 1 ) {
                int c;
 
-               c = getopt(ac, av, "pxm:s:i:o:");
+               c = getopt(ac, av, "pxm:r:v:s:i:o:");
                if (c == -1)
                        break;
 
@@ -94,6 +101,24 @@
                        }
                        strcpy(model, optarg);
                        break;
+               case 'r':
+                       if (strlen(optarg) > MAX_REGION_LEN) {
+                               fprintf(stderr, "%s: region exceeds %d chars\n",
+                                       progname, MAX_REGION_LEN);
+                               exit(1);
+                       }
+                       have_regionversion = 1;
+                       strcpy(region, optarg);
+                       break;
+               case 'v':
+                       if (strlen(optarg) > MAX_VERSION_LEN) {
+                               fprintf(stderr, "%s: version exceeds %d 
chars\n",
+                                       progname, MAX_VERSION_LEN);
+                               exit(1);
+                       }
+                       have_regionversion = 1;
+                       strcpy(version, optarg);
+                       break;
                case 's':
                        if (strlen(optarg) > MAX_SIG_LEN) {
                                fprintf(stderr, "%s: signature exceeds %d 
chars\n",
@@ -150,6 +175,10 @@
                imghdr.checksum = htonl(cksum);
                imghdr.partition = 0 ; // don't care?
                imghdr.hdr_len = sizeof(imghdr);
+               if (have_regionversion) {
+                       imghdr.hdr_len += MAX_REGION_LEN;
+                       imghdr.hdr_len += MAX_VERSION_LEN;
+               }
                imghdr.flash_byte_cnt = htonl(bcnt);
        } else {
                if (ntohl(imghdr.checksum) != cksum) {
@@ -176,6 +205,12 @@
 
        if (fwrite(&imghdr, sizeof(imghdr), 1, ofile) < 0)
                perrexit(2, "fwrite header on output");
+       if (have_regionversion) {
+               if (fwrite(&region, MAX_REGION_LEN, 1, ofile) < 0)
+                       perrexit(2, "fwrite header on output");
+               if (fwrite(&version, MAX_VERSION_LEN, 1, ofile) < 0)
+                       perrexit(2, "fwrite header on output");
+       }
 
        while ((c = fgetc(ifile)) != EOF) {
                if (fputc(c, ofile) == EOF)

-- 
Tobias                                          PGP: http://8ef7ddba.uguu.de
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to