26 (edited by budzulb 2012-11-18 20:38:29)

Re: TP-Link MR3220V2

here after inclusion wifi
Nov 19 02:18:48 OpenWrt kern.info kernel: [  397.180000] ADDRCONF(NETDEV_UP): wlan0: link is not ready
Nov 19 02:18:48 OpenWrt kern.info kernel: [  397.200000] device wlan0 entered promiscuous mode
Nov 19 02:18:48 OpenWrt kern.info kernel: [  397.270000] ADDRCONF(NETDEV_UP): wlan0: link is not ready
Nov 19 02:18:48 OpenWrt kern.info kernel: [  397.300000] br-lan: port 2(wlan0) entered forwarding state
Nov 19 02:18:48 OpenWrt kern.info kernel: [  397.300000] br-lan: port 2(wlan0) entered forwarding state
Nov 19 02:18:48 OpenWrt kern.info kernel: [  397.310000] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Nov 19 02:18:50 OpenWrt kern.info kernel: [  399.300000] br-lan: port 2(wlan0) entered forwarding state
Nov 19 02:19:47 OpenWrt kern.info kernel: [  455.970000] eth0: link down
Nov 19 02:19:47 OpenWrt kern.info kernel: [  455.970000] br-lan: port 1(eth0) entered disabled state
Nov 19 02:19:51 OpenWrt daemon.info hostapd: wlan0: STA e0:b9:a5:2d:01:6b IEEE 802.11: authenticated
Nov 19 02:19:52 OpenWrt daemon.info hostapd: wlan0: STA e0:b9:a5:2d:01:6b IEEE 802.11: associated (aid 1)
Nov 19 02:19:52 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPREQUEST(br-lan) 192.168.1.3 e0:b9:a5:2d:01:6b
Nov 19 02:19:52 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPNAK(br-lan) 192.168.1.3 e0:b9:a5:2d:01:6b address not available
Nov 19 02:19:58 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPDISCOVER(br-lan) e0:b9:a5:2d:01:6b
Nov 19 02:19:58 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPOFFER(br-lan) 192.168.1.201 e0:b9:a5:2d:01:6b
Nov 19 02:19:58 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPREQUEST(br-lan) 192.168.1.201 e0:b9:a5:2d:01:6b
Nov 19 02:19:58 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPACK(br-lan) 192.168.1.201 e0:b9:a5:2d:01:6b
Nov 19 02:20:01 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPINFORM(br-lan) 192.168.1.201 e0:b9:a5:2d:01:6b
Nov 19 02:20:01 OpenWrt daemon.info dnsmasq-dhcp[1584]: DHCPACK(br-lan) 192.168.1.201 e0:b9:a5:2d:01:6b
Nov 19 02:20:30 OpenWrt daemon.info pppd[2061]: No response to 5 echo-requests
Nov 19 02:20:30 OpenWrt daemon.notice pppd[2061]: Serial link appears to be disconnected.
Nov 19 02:20:30 OpenWrt daemon.info pppd[2061]: Connect time 5.1 minutes.
Nov 19 02:20:30 OpenWrt daemon.info pppd[2061]: Sent 66946 bytes, received 120815 bytes.
Nov 19 02:20:31 OpenWrt daemon.notice netifd: Interface '3g' has lost the connection
Nov 19 02:20:31 OpenWrt user.info firewall: removing 3g (3g-3g) from zone wan
Nov 19 02:20:36 OpenWrt daemon.notice pppd[2061]: Connection terminated.
Nov 19 02:20:58 OpenWrt daemon.notice pppd[2061]: Modem hangup

Re: TP-Link MR3220V2

same behaviour also if modem is plugged after enabling wifi?

Re: TP-Link MR3220V2

if wifi is switched off that everything works

Re: TP-Link MR3220V2

But i did not ask that xD

Re: TP-Link MR3220V2

with English not so, probably didn't understand a question

Re: TP-Link MR3220V2

no prob, i meant to ask what happen if you power on the router, enable wifi and use it, and THEN plug in the usb modem and connect to internet..

Re: TP-Link MR3220V2

Addition to issue reported from @budzulb. You pull out modem and put it back the connection is up from next few minutes and again disconnected. Not sure why.

Issue I was trying to fix:
1. Got sealed pack modem got my ZTE AC2726 working but Huawei E173 not working.
2. Upgraded with firmware available on website TP-Link all modem stopped working.
3. Installed build given by @cindy.wijaya.
4. Got router up and running. Configure 3G uid/password.
5. Got connected.
6. Disconnected within a few minutes. Using modem ZTE AC2726. Not sure why. Log is same as what @budzulb has given.
7. Pull modem out, push in back. Click connect in interfaces connection up again but disconnected after a few minutes.
8. Requested TP-Link original firmware shipped with router not available on there website.
9. Restored the recieved firmware. Got it working back.

Re: TP-Link MR3220V2

in any case with included wifi internet to stop,better I will show log before wifi inclusion

Re: TP-Link MR3220V2

I built my own firmware for MR3220 v2, but the WiFi and leds aren't working, can someone help me fix this?

Re: TP-Link MR3220V2

It seems that cindy.wijaya finds time for updates to the binary image, but not for instructions on how to create that image, which would be much more useful. It is also a violation of the GPL to provide binaries only.

Re: TP-Link MR3220V2

She said "9331 profile to build", but I'm not sure what she meant. I mean, MR3220 is already built upon AR9xxx target.

Re: TP-Link MR3220V2

RalfFriedl wrote:

It seems that cindy.wijaya finds time for updates to the binary image, but not for instructions on how to create that image, which would be much more useful. It is also a violation of the GPL to provide binaries only.

Compile 740Nv4 profiles with USB patch , thats all , how to patch the USB find here .

Re: TP-Link MR3220V2

Have you tested it? I wouldn't want to brick my router just yet...

39 (edited by xopal 2012-11-21 19:39:23)

Re: TP-Link MR3220V2

mooop12 wrote:

Have you tested it? I wouldn't want to brick my router just yet...

Of course yes , i use this router too

Open /trunk/target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr741nd-v4.c

paste this code

/*
 *  TP-LINK TL-WR741ND v4 board support
 *
 *  Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
 *
 *  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/gpio.h>

#include <asm/mach-ath79/ath79.h>
#include <asm/mach-ath79/ar71xx_regs.h>

#include "common.h"
#include "dev-eth.h"
#include "dev-gpio-buttons.h"
#include "dev-leds-gpio.h"
#include "dev-m25p80.h"
#include "dev-usb.h"
#include "dev-wmac.h"
#include "machtypes.h"

#define TL_WR741NDV4_GPIO_BTN_RESET    11
#define TL_WR741NDV4_GPIO_BTN_WPS    26

#define TL_WR741NDV4_GPIO_LED_WLAN    0
#define TL_WR741NDV4_GPIO_LED_QSS    1
#define TL_WR741NDV4_GPIO_USB_POWER    8
#define TL_WR741NDV4_GPIO_LED_WAN    13
#define TL_WR741NDV4_GPIO_LED_LAN1    14
#define TL_WR741NDV4_GPIO_LED_LAN2    15
#define TL_WR741NDV4_GPIO_LED_LAN3    16
#define TL_WR741NDV4_GPIO_LED_LAN4    17

#define TL_WR741NDV4_GPIO_LED_SYSTEM    27

#define TL_WR741NDV4_KEYS_POLL_INTERVAL    20    /* msecs */
#define TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR741NDV4_KEYS_POLL_INTERVAL)

static const char *tl_wr741ndv4_part_probes[] = {
    "tp-link",
    NULL,
};

static struct flash_platform_data tl_wr741ndv4_flash_data = {
    .part_probes    = tl_wr741ndv4_part_probes,
};

static struct gpio_led tl_wr741ndv4_leds_gpio[] __initdata = {
    {
        .name        = "tp-link:green:lan1",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN1,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:lan2",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN2,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:lan3",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN3,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:lan4",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN4,
        .active_low    = 1,
    }, {
        .name        = "tp-link:green:qss",
        .gpio        = TL_WR741NDV4_GPIO_LED_QSS,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:system",
        .gpio        = TL_WR741NDV4_GPIO_LED_SYSTEM,
        .active_low    = 1,
    }, {
        .name        = "tp-link:green:wan",
        .gpio        = TL_WR741NDV4_GPIO_LED_WAN,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:wlan",
        .gpio        = TL_WR741NDV4_GPIO_LED_WLAN,
        .active_low    = 0,
    },
};

static struct gpio_keys_button tl_wr741ndv4_gpio_keys[] __initdata = {
    {
        .desc        = "reset",
        .type        = EV_KEY,
        .code        = KEY_RESTART,
        .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
        .gpio        = TL_WR741NDV4_GPIO_BTN_RESET,
        .active_low    = 0,
    }, {
        .desc        = "WPS",
        .type        = EV_KEY,
        .code        = KEY_WPS_BUTTON,
        .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
        .gpio        = TL_WR741NDV4_GPIO_BTN_WPS,
        .active_low    = 0,
    }
};

static void __init tl_wr741ndv4_setup(void)
{
    u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
    u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);

    ath79_setup_ar933x_phy4_switch(true, true);

    ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);

    ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio),
                 tl_wr741ndv4_leds_gpio);

    ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL,
                    ARRAY_SIZE(tl_wr741ndv4_gpio_keys),
                    tl_wr741ndv4_gpio_keys);
                    
    gpio_request_one(TL_WR741NDV4_GPIO_USB_POWER,
             GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
             "USB power");
    ath79_register_usb();

    ath79_register_m25p80(&tl_wr741ndv4_flash_data);
    ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
    ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);

    ath79_register_mdio(0, 0x0);
    ath79_register_eth(1);
    ath79_register_eth(0);

    ath79_register_wmac(ee, mac);
}

MIPS_MACHINE(ATH79_MACH_TL_WR741ND_V4, "TL-WR741ND-v4",
         "TP-LINK TL-WR741ND v4", tl_wr741ndv4_setup);

Re: TP-Link MR3220V2

Thanks, it's working. But it's a dirty hack. It would be nice if a dev could just add this new router. If I can build it with a little help I'm sure a real dev would add support for this device in no time smile

Re: TP-Link MR3220V2

Could someone post his .config as a starting point?
Also some few instructions would be adequate wink

beside editing "/trunk/target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr741nd-v4.c" is there any other modification needed?

Re: TP-Link MR3220V2

Nope, just compile for wr740n and install the binary for version 4 of this router. Make sure it's version 4, because from what I saw it's the only one compatible with MR3200v2. As for .config, just put what you need in it. You'll have to force the installation of this image because sysupgrade performs some basic checking of image so you don't install a wrong one, just add -F option after sysupgrade.

Re: TP-Link MR3220V2

matteo wrote:

@cindy.wijaya
Thank you very much for sharing your builds!

Anyway, can you provide info on how to build the firmware? Maybe you can update the wiki smile

ok, i would prepare for it smile

***
Sorry for my busy days. This is modification needed to build mr3220.v2

/trunk/target/linux/ar71xx/image/makefile

#
# Copyright (C) 2008-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk

JFFS2_BLOCKSIZE = 64k 128k 256k

define imgname
$(BIN_DIR)/$(IMG_PREFIX)-$(2)-$(patsubst jffs2-%,jffs2,$(patsubst squashfs-%,squashfs,$(1)))
endef

define rootfs_align
$(patsubst %-256k,0x40000,$(patsubst %-128k,0x20000,$(patsubst %-64k,0x10000,$(patsubst squashfs-%,0x4,$(1)))))
endef

define sysupname
$(call imgname,$(1),$(2))-sysupgrade.bin
endef

define factoryname
$(call imgname,$(1),$(2))-factory.bin
endef

COMMA:=,

define mkcmdline
$(if $(1),board=$(1) )$(if $(2),console=$(2)$(COMMA)$(3))
endef

SINGLE_PROFILES:=

define SingleProfile
  define Image/Build/Profile/$(3)
    $$(call Image/Build/Template/$(2)/$$(1),$(1),$(4),$$(call mkcmdline,$(5),$(6),$(7)),$(8),$(9),$(10),$(11),$(12))
  endef
  SINGLE_PROFILES += $(3)
endef

define MultiProfile
  define Image/Build/Profile/$(1)
    $(foreach p,$(2),
        $$(call Image/Build/Profile/$p,$$(1))
    )
  endef
endef

LOADER_MAKE := $(NO_TRACE_MAKE) -C lzma-loader KDIR=$(KDIR)

KDIR_TMP:=$(KDIR)/tmp
VMLINUX:=$(BIN_DIR)/$(IMG_PREFIX)-vmlinux
UIMAGE:=$(BIN_DIR)/$(IMG_PREFIX)-uImage
fs_squash:=squashfs-only
fs_64k:=64k
fs_64kraw:=64kraw
fs_128k:=128k
fs_256k:=256k
ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
    fs_squash:=initramfs
    fs_64k:=initramfs
    fs_64kraw:=initramfs
    fs_128k:=initramfs
    fs_256k:=initramfs
    VMLINUX:=$(BIN_DIR)/$(IMG_PREFIX)-vmlinux-initramfs
    UIMAGE:=$(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs
endif

define CompressLzma
  $(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
endef

define PatchKernelLzma
    cp $(KDIR)/vmlinux $(KDIR_TMP)/vmlinux-$(1)
    $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR_TMP)/vmlinux-$(1) "$(strip $(2))"
    $(call CompressLzma,$(KDIR_TMP)/vmlinux-$(1),$(KDIR_TMP)/vmlinux-$(1).bin.lzma)
endef

define PatchKernelGzip
    cp $(KDIR)/vmlinux $(KDIR_TMP)/vmlinux-$(1)
    $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR_TMP)/vmlinux-$(1) "$(strip $(2))"
    gzip -9 -c $(KDIR_TMP)/vmlinux-$(1) > $(KDIR_TMP)/vmlinux-$(1).bin.gz
endef

define MkuImage
    mkimage -A mips -O linux -T kernel -a 0x80060000 -C $(1) $(2) \
        -e 0x80060000 -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
        -d $(3) $(4)
endef

define MkuImageLzma
    $(call PatchKernelLzma,$(1),$(2))
    $(call MkuImage,lzma,,$(KDIR_TMP)/vmlinux-$(1).bin.lzma,$(KDIR_TMP)/vmlinux-$(1).uImage)
endef

define MkuImageLzma/initramfs
    $(call PatchKernelLzma,$(1),$(2))
    $(call MkuImage,lzma,,$(KDIR_TMP)/vmlinux-$(1).bin.lzma,$(call imgname,initramfs,$(1))-uImage.bin)
endef

define MkuImageGzip
    $(call PatchKernelGzip,$(1),$(2))
    $(call MkuImage,gzip,,$(KDIR_TMP)/vmlinux-$(1).bin.gz,$(KDIR_TMP)/vmlinux-$(1).uImage)
endef

define MkuImageGzip/initramfs
    $(call PatchKernelGzip,$(1),$(2))
    $(call MkuImage,gzip,,$(KDIR_TMP)/vmlinux-$(1).bin.gz,$(call imgname,initramfs,$(1))-uImage.bin)
endef

define MkuImageOKLI
    $(call MkuImage,lzma,-M 0x4f4b4c49,$(KDIR)/vmlinux.bin.lzma,$(KDIR_TMP)/vmlinux-$(1).okli)
endef

define CatFiles
    if [ `stat -c%s "$(1)"` -gt $(2) ]; then \
        echo "Warning: $(1) is too big"; \
    else if [ `stat -c%s $(3)` -gt $(4) ]; then \
        echo "Warning: $(3) is too big"; \
    else \
        ( dd if=$(1) bs=$(2) conv=sync; dd if=$(3) ) > $(5); \
    fi; fi
endef

define Sysupgrade/KR
    $(call CatFiles,$(2),$(3),$(KDIR)/root.$(1),$(4),$(call sysupname,$(1),$(5)))
endef

define Sysupgrade/KRuImage
    $(call CatFiles,$(KDIR_TMP)/vmlinux-$(2).uImage,$(3),$(KDIR)/root.$(1),$(4),$(call sysupname,$(1),$(2)))
endef

define Sysupgrade/RKuImage
    $(call CatFiles,$(KDIR)/root.$(1),$(4),$(KDIR_TMP)/vmlinux-$(2).uImage,$(3),$(call sysupname,$(1),$(2)))
endef

define Image/BuildLoader
    -rm -rf $(KDIR)/lzma-loader
    $(LOADER_MAKE) LOADER=loader-$(1).$(2) KERNEL_CMDLINE="$(3)"\
        LZMA_TEXT_START=0x80a00000 LOADADDR=0x80060000 \
        LOADER_DATA="$(KDIR)/vmlinux.bin.lzma" BOARD="$(1)" \
        compile loader.$(2)
endef

define Image/BuildLoaderAlone
    -rm -rf $(KDIR)/lzma-loader
    $(LOADER_MAKE) LOADER=loader-$(1).$(2) KERNEL_CMDLINE="$(3)" \
        LZMA_TEXT_START=0x80a00000 LOADADDR=0x80060000 \
        BOARD="$(1)" FLASH_OFFS=$(4) FLASH_MAX=$(5) \
        compile loader.$(2)
endef

define Build/Clean
    $(LOADER_MAKE) clean
endef


alfa_ap96_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,256k(u-boot-env)ro,13312k(rootfs),2048k(kernel),512k(caldata)ro,15360k@0x80000(firmware)
alfa_mtdlayout_8M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6144k(rootfs),1600k(kernel),64k(nvram),64k(art)ro,7744k@0x50000(firmware)
all0258n_mtdlayout=mtdparts=spi0.0:256k(u-boot),64k(u-boot-env),1024k(kernel),5248k(rootfs),1536k(failsafe),64k(art),6272k@0x50000(firmware)
all0315n_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,256k(u-boot-env),1024k(kernel),12544k(rootfs),2048k(failsafe),256k(art)ro,13568k@0x80000(firmware)
ap96_mtdlayout=mtdparts=spi0.0:192k(u-boot)ro,64k(u-boot-env)ro,6144k(rootfs),1728k(kernel),64k(art)ro,7872k@0x40000(firmware)
ap113_mtd_layout=mtdparts=spi0.0:64k(u-boot),3008k(rootfs),896k(uImage),64k(NVRAM),64k(ART),3904k@0x10000(firmware)
ap121_mtdlayout_2M=mtdparts=spi0.0:64k(u-boot)ro,1216k(rootfs),704k(kernel),64k(art)ro,1920k@0x10000(firmware)
ap121_mtdlayout_4M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,2752k(rootfs),896k(kernel),64k(nvram),64k(art)ro,3648k@0x50000(firmware)
ap136_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6336k(rootfs),1408k(kernel),64k(mib0),64k(art)ro,7744k@0x50000(firmware)
cameo7240_mtdlayout=mtdparts=spi0.0:192k(u-boot)ro,64k(nvram)ro,960k(kernel),2752k(rootfs),64k(mac)ro,64k(art)ro,3712k@0x40000(firmware)
cameo913x_mtdlayout=mtdparts=spi0.0:128k(u-boot)ro,64k(config)ro,960k(kernel),2880k(rootfs),64k(art)ro,3840k@0x30000(firmware)
cameo933x_mtdlayout=mtdparts=spi0.0:64k(u-boot)ro,64k(art)ro,64k(mac)ro,64k(nvram)ro,192k(language)ro,896k(kernel),2752k(rootfs),3648k@0x70000(firmware)
cap4200ag_mtdlayout=mtdparts=spi0.0:256k(u-boot),64k(u-boot-env),320k(custom)ro,1536k(kernel),12096k(rootfs),2048k(failsafe),64k(art),13632k@0xa0000(firmware)
db120_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6336k(rootfs),1408k(kernel),64k(nvram),64k(art)ro,7744k@0x50000(firmware)
dir825b1_mtdlayout=mtdparts=spi0.0:256k(uboot)ro,64k(config)ro,1024k(kernel),5184k(rootfs),64k(caldata)ro,1600k(unknown)ro,6208k@0x50000(firmware),64k@0x7f0000(caldata_copy)
dir825b1_mtdlayout_fat=mtdparts=spi0.0:256k(uboot)ro,64k(config)ro,1024k(kernel),6784k(rootfs),64k(caldata)ro,7808k@0x50000(firmware),64k@0x660000(caldata_orig),6208k@0x50000(firmware_orig)
ew-dorin_mtdlayout_4M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env),1024k(kernel),2688k(rootfs),64k(art),3712k@0x50000(firmware)
dlrtdev_mtdlayout=mtdparts=spi0.0:256k(uboot)ro,64k(config)ro,1024k(kernel),5184k(rootfs),64k(caldata)ro,640k(certs),960k(unknown)ro,6208k@0x50000(firmware),64k@0x7f0000(caldata_copy)
dlrtdev_mtdlayout_fat=mtdparts=spi0.0:256k(uboot)ro,64k(config)ro,1024k(kernel),6544k(rootfs),640k(certs),64k(caldata)ro,7168k@0x50000(firmware),64k@0x660000(caldata_orig),6208k@0x50000(firmware_orig)
pb92_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,2752k(rootfs),896k(kernel),64k(nvram),64k(art)ro,3648k@0x50000(firmware)
planex_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,960k(kernel),6784k(rootfs),128k(art)ro,7744k@0x50000(firmware)
ubntxm_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,1024k(kernel),6528k(rootfs),256k(cfg)ro,64k(EEPROM)ro,7552k@0x50000(firmware)
ubdev_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,1024k(kernel),6464k(rootfs),64k(certs),256k(cfg)ro,64k(EEPROM)ro,7488k@0x50000(firmware)
whrhpg300n_mtdlayout=mtdparts=spi0.0:248k(u-boot)ro,8k(u-boot-env)ro,960k(kernel),2816k(rootfs),64k(art)ro,3712k@0x40000(firmware)
wndr3700_mtdlayout=mtdparts=spi0.0:320k(u-boot)ro,128k(u-boot-env)ro,1024k(kernel),6656k(rootfs),64k(art)ro,7680k@0x70000(firmware)
wndr3700v2_mtdlayout=mtdparts=spi0.0:320k(u-boot)ro,128k(u-boot-env)ro,1024k(kernel),14848k(rootfs),64k(art)ro,15872k@0x70000(firmware)
zcn1523h_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6208k(rootfs),1472k(kernel),64k(configure)ro,64k(mfg)ro,64k(art)ro,7680k@0x50000(firmware)

define Image/BuildKernel
    cp $(KDIR)/vmlinux.elf $(VMLINUX).elf
    cp $(KDIR)/vmlinux $(VMLINUX).bin
    dd if=$(KDIR)/vmlinux.bin.lzma of=$(VMLINUX).lzma bs=65536 conv=sync
    dd if=$(KDIR)/vmlinux.bin.gz of=$(VMLINUX).gz bs=65536 conv=sync
    $(call MkuImage,gzip,,$(KDIR)/vmlinux.bin.gz,$(UIMAGE)-gzip.bin)
    $(call MkuImage,lzma,,$(KDIR)/vmlinux.bin.lzma,$(UIMAGE)-lzma.bin)
    -mkdir -p $(KDIR_TMP)
    $(call Image/Build/Initramfs)
endef

define Image/Build/WRT400N
    $(call MkuImageLzma,$(2),$(3))
    $(call Sysupgrade/KRuImage,$(1),$(2),1310720,6488064)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        wrt400n $(KDIR_TMP)/vmlinux-$(2).uImage $(KDIR)/root.$(1) $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/DIR825B1
    $(call MkuImageLzma,$(2),$(3) $(dir825b1_mtdlayout))
    $(call Sysupgrade/KRuImage,$(1),$(2),1048576,5308416)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        ( \
            dd if=$(call sysupname,$(1),$(2)); \
            echo -n "$(4)"; \
        ) > $(call imgname,$(1),$(2))-backup-loader.bin; \
        if [ `stat -c%s $(call sysupname,$(1),$(2))` -gt 4194304 ]; then \
            echo "Warning: $(call sysupname,$(1),$(2)) is too big"; \
        else \
            ( \
                dd if=$(call sysupname,$(1),$(2)) bs=4096k conv=sync; \
                echo -n "$(5)"; \
            ) > $(call factoryname,$(1),$(2)); \
        fi; \
    fi
    $(call MkuImageLzma,$(2)-fat,$(3) $(dir825b1_mtdlayout_fat))
    $(call CatFiles,$(KDIR_TMP)/vmlinux-$(2)-fat.uImage,1048576,$(KDIR)/root.$(1),6946816,$(KDIR_TMP)/$(2)-fat.bin)
    if [ -e "$(KDIR_TMP)/$(2)-fat.bin" ]; then \
        echo -n "" > $(KDIR_TMP)/$(2)-fat.dummy; \
        sh $(TOPDIR)/scripts/combined-image.sh \
            "$(KDIR_TMP)/$(2)-fat.bin" \
            "$(KDIR_TMP)/$(2)-fat.dummy" \
            $(call sysupname,$(1),$(2)-fat); \
    fi
endef

define Image/Build/DLRTDEV
    $(call MkuImageLzma,$(2),$(3) $(dlrtdev_mtdlayout))
    $(call Sysupgrade/KRuImage,$(1),$(2),1048576,5308416)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        ( \
            dd if=$(call sysupname,$(1),$(2)); \
            echo -n "$(4)"; \
        ) > $(call imgname,$(1),$(2))-backup-loader.bin; \
        if [ `stat -c%s $(call sysupname,$(1),$(2))` -gt 4194304 ]; then \
            echo "Warning: $(call sysupname,$(1),$(2)) is too big"; \
        else \
            ( \
                dd if=$(call sysupname,$(1),$(2)) bs=4096k conv=sync; \
                echo -n "$(5)"; \
            ) > $(call factoryname,$(1),$(2)); \
        fi; \
    fi
    $(call MkuImageLzma,$(2)-fat,$(3) $(dlrtdev_mtdlayout_fat))
    $(call CatFiles,$(KDIR_TMP)/vmlinux-$(2)-fat.uImage,1048576,$(KDIR)/root.$(1),6946816,$(KDIR_TMP)/$(2)-fat.bin)
    if [ -e "$(KDIR_TMP)/$(2)-fat.bin" ]; then \
        echo -n "" > $(KDIR_TMP)/$(2)-fat.dummy; \
        sh $(TOPDIR)/scripts/combined-image.sh \
            "$(KDIR_TMP)/$(2)-fat.bin" \
            "$(KDIR_TMP)/$(2)-fat.dummy" \
            $(call sysupname,$(1),$(2)-fat); \
    fi
endef

define Image/Build/WZRHPG30XNH
    $(call MkuImageLzma,$(2),$(3))
    $(call Sysupgrade/KRuImage,$(1),$(2),1048576,31850496)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        ( \
            dd if=$(call sysupname,$(1),$(2)); \
        ) > $(call imgname,$(1),$(2))-tftp.bin; \
        buffalo-enc -p $(4) -v 1.99 \
            -i $(call sysupname,$(1),$(2)) \
            -o $(KDIR_TMP)/$(2).enc; \
        buffalo-tag -b $(4) -p $(4) -a ath -v 1.99 -m 1.01 -l mlang8 \
            -w 3 -c 0x80041000 -d 0x801e8000 -f 1 -r M_ \
            -i $(KDIR_TMP)/$(2).enc \
            -o $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/WHRHPG300N
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(call Sysupgrade/KRuImage,$(1),$(2),983040,2883584)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        ( \
            dd if=$(call sysupname,$(1),$(2)); \
        ) > $(call imgname,$(1),$(2))-tftp.bin; \
        buffalo-enc -p $(5) -v 1.99 \
            -i $(call sysupname,$(1),$(2)) \
            -o $(KDIR_TMP)/$(2).enc; \
        buffalo-tag -b $(5) -p $(5) -a ath -v 1.99 -m 1.01 -l mlang8 \
            -w 3 -c 0x80041000 -d 0x801e8000 -f 1 -r M_ \
            -i $(KDIR_TMP)/$(2).enc \
            -o $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/WHRHPG300N/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(4))
endef

define Image/Build/Cameo
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(call Sysupgrade/KRuImage,$(1),$(2),$(5),$(6))
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        ( \
            dd if=$(KDIR_TMP)/vmlinux-$(2).uImage bs=$(5) conv=sync; \
            dd if=$(KDIR)/root.$(1) bs=$(6) conv=sync; \
            echo -n $(7); \
        ) > $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/CameoHornet
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(call Sysupgrade/KRuImage,$(1),$(2),$(5),$(6))
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        mkcameofw -M HORNET -R "DEF" -S $(7) -V "1.99" \
            -K $(5) -I $$$$(($(5)+$(6))) \
            -k $(KDIR_TMP)/vmlinux-$(2).uImage \
            -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
            -o $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/Cameo913x
    $(call Image/Build/Cameo,$(1),$(2),$(3),$(cameo913x_mtdlayout),983040,2949120,$(4))
endef

define Image/Build/Cameo913x/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(cameo913x_mtdlayout))
endef

define Image/Build/Cameo7240
    $(call Image/Build/Cameo,$(1),$(2),$(3),$(cameo7240_mtdlayout),983040,2818048,$(4))
endef

define Image/Build/Cameo7240/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(cameo7240_mtdlayout))
endef

define Image/Build/Cameo933x
    $(call Image/Build/CameoHornet,$(1),$(2),$(3),$(cameo933x_mtdlayout),917504,2818048,$(4))
endef

define Image/Build/Cameo933x/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(cameo933x_mtdlayout))
endef

define Image/Build/Ath
    $(call Sysupgrade/$(7),$(1),$(2),$(5),$(6))
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        dd if=$(KDIR_TMP)/vmlinux-$(2).uImage \
            of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync; \
        dd if=$(KDIR)/root.$(1) \
            of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync; \
    fi
endef

define Image/Build/AthGzip
    $(call MkuImageGzip,$(2),$(3) $(4))
    $(call Image/Build/Ath,$(1),$(2),$(3),$(4),$(5),$(6),$(7))
endef

define Image/Build/AthGzip/initramfs
    $(call MkuImageGzip/initramfs,$(2),$(3) $(4))
endef

define Image/Build/AthLzma
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(call Image/Build/Ath,$(1),$(2),$(3),$(4),$(5),$(6),$(7))
endef

define Image/Build/AthLzma/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(4))
endef

define Image/Build/PB4X
    $(call PatchKernelLzma,$(2),$(3))
    dd if=$(KDIR_TMP)/vmlinux-$(2).bin.lzma \
       of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync
    dd if=$(KDIR)/root.$(1) \
       of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync
    -sh $(TOPDIR)/scripts/combined-image.sh \
        "$(call imgname,kernel,$(2)).bin" \
        "$(call imgname,$(1),$(2)-rootfs).bin" \
        $(call sysupname,$(1),$(2))
endef


define Image/Build/MyLoader
    $(call PatchKernelLzma,$(2),$(3))
    -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) -s $(4) \
        -p0x030000:0xe0000:al:0x80060000:kernel:$(KDIR_TMP)/vmlinux-$(2).bin.lzma \
        -p0x110000:0:::rootfs:$(KDIR)/root.$(1) \
        $(call imgname,$(1),$(2))-$(5)-factory.img
endef

define Image/Build/UBNTXM
    $(call MkuImageLzma,$(2),$(3) $(ubntxm_mtdlayout))
    $(call Sysupgrade/KRuImage,$(1),$(2),1048576,6684672)
    dd if=$(KDIR_TMP)/vmlinux-$(2).uImage of=$(KDIR_TMP)/vmlinux-$(2).uImage.bin bs=1024k conv=sync
    -$(STAGING_DIR_HOST)/bin/mkfwimage \
        -B $(4) -v $(5).$(6).v6.0.0-OpenWrt-$(REVISION) \
        -k $(KDIR_TMP)/vmlinux-$(2).uImage.bin \
        -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
        -o $(call factoryname,$(1),$(2))
endef


define Image/Build/UBDEV
    $(call MkuImageLzma,$(2),$(3) $(ubdev_mtdlayout))
    $(call Sysupgrade/KRuImage,$(1),$(2),1048576,6684672)
    dd if=$(KDIR_TMP)/vmlinux-$(2).uImage of=$(KDIR_TMP)/vmlinux-$(2).uImage.bin bs=1024k conv=sync
    -$(STAGING_DIR_HOST)/bin/mkfwimage \
        -B $(4) -v $(5).$(6).v6.0.0-OpenWrt-$(REVISION) \
        -k $(KDIR_TMP)/vmlinux-$(2).uImage.bin \
        -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
        -o $(call factoryname,$(1),$(2))
endef

define Image/Build/UBNT
    $(call PatchKernelLzma,$(2),$(3))
    dd if=$(KDIR_TMP)/vmlinux-$(2).bin.lzma of=$(KDIR_TMP)/vmlinux-$(2).lzma bs=64k conv=sync
    -$(STAGING_DIR_HOST)/bin/mkfwimage \
        -B $(4) -v $(5).$(6).OpenWrt.$(REVISION) \
        -k $(KDIR_TMP)/vmlinux-$(2).lzma \
        -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
        -o $(call factoryname,$(1),$(2))
    -sh $(TOPDIR)/scripts/combined-image.sh \
        "$(KDIR_TMP)/vmlinux-$(2).lzma" \
        "$(BIN_DIR)/$(IMG_PREFIX)-root.$(1)" \
  $(call sysupname,$(1),$(2))
endef

define Image/Build/Planex/loader
    $(call Image/BuildLoaderAlone,$(1),gz,$(2) $(planex_mtdlayout),0x52000,0)
endef

define Image/Build/Planex
    [ -e "$(KDIR)/loader-$(2).gz" ]
    $(call MkuImage,gzip,,$(KDIR)/loader-$(2).gz,$(KDIR_TMP)/vmlinux-$(2).uImage)
    $(call MkuImageOKLI,$(2))
    ( \
        dd if=$(KDIR_TMP)/vmlinux-$(2).uImage bs=8k count=1 conv=sync; \
        dd if=$(KDIR_TMP)/vmlinux-$(2).okli; \
    ) > $(KDIR_TMP)/kernel-$(2).bin
    $(call Sysupgrade/KR,$(1),$(KDIR_TMP)/kernel-$(2).bin,983040,6815744,$(2))
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        $(STAGING_DIR_HOST)/bin/mkplanexfw \
            -B $(2) \
            -v 2.00.00 \
            -i $(call sysupname,$(1),$(2)) \
            -o $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/ALFA
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(call Sysupgrade/RKuImage,$(1),$(2),$(5),$(6))
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        rm -rf $(KDIR)/$(1); \
        mkdir -p $(KDIR)/$(1); \
        cd $(KDIR)/$(1); \
        cp $(KDIR_TMP)/vmlinux-$(2).uImage $(KDIR)/$(1)/$(7); \
        cp $(KDIR)/root.$(1) $(KDIR)/$(1)/$(8); \
        $(TAR) zcf $(call factoryname,$(1),$(2)) -C $(KDIR)/$(1) $(7) $(8); \
        ( \
            echo WRM7222C | dd bs=32 count=1 conv=sync; \
            echo -ne '\xfe'; \
        ) >> $(call factoryname,$(1),$(2)); \
    fi
endef

define Image/Build/ALFA/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(4))
endef

define Image/Build/TPLINKOLD/loader
    $(call Image/BuildLoaderAlone,$(1),gz,$(2),0x22000,0)
endef

define Image/Build/TPLINKOLD
    [ -e "$(KDIR)/loader-$(2).gz" ]
    $(call MkuImageOKLI,$(2))
    ( \
        dd if=$(KDIR)/loader-$(2).gz bs=7680 count=1 conv=sync; \
        dd if=$(KDIR_TMP)/vmlinux-$(2).okli conv=sync; \
    ) > $(KDIR_TMP)/kernel-$(2).bin
    -$(STAGING_DIR_HOST)/bin/mktplinkfw \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION)\
        -k $(KDIR_TMP)/kernel-$(2).bin \
        -r $(KDIR)/root.$(1) \
        -o $(call factoryname,$(1),$(2))
    -$(STAGING_DIR_HOST)/bin/mktplinkfw \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) -s\
        -k $(KDIR_TMP)/kernel-$(2).bin \
        -r $(KDIR)/root.$(1) \
        -o $(call sysupname,$(1),$(2))
endef

define Image/Build/TPLINKOLD/initramfs
    $(call Image/BuildLoader,$(2),gz,$(3),0x80060000)
    -$(STAGING_DIR_HOST)/bin/mktplinkfw -c \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) -s\
        -k $(KDIR)/loader-$(2).gz \
        -o $(call imgname,$(1),$(2))-uImage.bin
endef

define Image/Build/TPLINK/loader
    $(call Image/BuildLoaderAlone,$(1),gz,$(2),0x22000,0)
endef

define Image/Build/TPLINK
    [ -e "$(KDIR)/loader-$(2).gz" ]
    $(call MkuImageOKLI,$(2))
    ( \
        dd if=$(KDIR)/loader-$(2).gz bs=7680 count=1 conv=sync; \
        dd if=$(KDIR_TMP)/vmlinux-$(2).okli conv=sync; \
    ) > $(KDIR_TMP)/kernel-$(2).bin
    -$(STAGING_DIR_HOST)/bin/mktplinkfw \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION)\
        -k $(KDIR_TMP)/kernel-$(2).bin \
        -r $(KDIR)/root.$(1) \
        -a $(call rootfs_align,$(1)) -j \
        -o $(call factoryname,$(1),$(2))
    -$(STAGING_DIR_HOST)/bin/mktplinkfw \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) -s\
        -k $(KDIR_TMP)/kernel-$(2).bin \
        -r $(KDIR)/root.$(1) \
        -a $(call rootfs_align,$(1)) -j \
        -o $(call sysupname,$(1),$(2))
endef

define Image/Build/TPLINK/initramfs
    $(call Image/BuildLoader,$(2),gz,$(3),0x80060000)
    -$(STAGING_DIR_HOST)/bin/mktplinkfw -c \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) -s\
        -k $(KDIR)/loader-$(2).gz \
        -o $(call imgname,$(1),$(2))-uImage.bin
endef

define Image/Build/TPLINK-LZMA
    $(call PatchKernelLzma,$(2),$(3))
    -$(STAGING_DIR_HOST)/bin/mktplinkfw \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) $(7) \
        -k $(KDIR_TMP)/vmlinux-$(2).bin.lzma \
        -r $(KDIR)/root.$(1) \
        -a $(call rootfs_align,$(1)) -j \
        -o $(call factoryname,$(1),$(2))
    -$(STAGING_DIR_HOST)/bin/mktplinkfw \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) $(7) -s \
        -k $(KDIR_TMP)/vmlinux-$(2).bin.lzma \
        -r $(KDIR)/root.$(1) \
        -a $(call rootfs_align,$(1)) -j \
        -o $(call sysupname,$(1),$(2))
endef

define Image/Build/TPLINK-LZMA/initramfs
    $(call PatchKernelLzma,$(2),$(3))
    -$(STAGING_DIR_HOST)/bin/mktplinkfw -c \
        -H $(4) -W $(5) -F $(6) -N OpenWrt -V $(REVISION) $(7) -s \
        -k $(KDIR_TMP)/vmlinux-$(2).bin.lzma \
        -o $(call imgname,$(1),$(2))-uImage.bin
endef

define Image/Build/CyberTAN
    $(call MkuImageGzip,$(2),$(3))
    $(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp -f $(KDIR_TMP)/vmlinux-$(2).uImage \
        -x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
    -$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) \
        -i $(KDIR)/image.tmp \
        -o $(call sysupname,$(1),$(2))
    -$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) -g \
        -i $(KDIR)/image.tmp \
        -o $(call factoryname,$(1),$(2))
    rm $(KDIR)/image.tmp
endef

define Image/Build/Netgear/Build_uImage
    $(call MkuImageLzma,$(1),$(2) $(3))
    -rm -rf $(KDIR)/$(1)
    mkdir -p $(KDIR)/$(1)/image
    $(STAGING_DIR_HOST)/bin/wndr3700 \
        $(KDIR_TMP)/vmlinux-$(1).uImage \
        $(KDIR)/$(1)/image/uImage \
        $(4)
    $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
        $(KDIR)/$(1) $(KDIR_TMP)/vmlinux-$(1).uImage.squashfs.tmp \
        -nopad -noappend -root-owned -be
    -rm -rf $(KDIR)/$(1)
    mkimage -A mips -O linux -T filesystem -C none \
        -a 0xbf070000 -e 0xbf070000 \
        -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
        -d $(KDIR_TMP)/vmlinux-$(1).uImage.squashfs.tmp \
        $(KDIR_TMP)/vmlinux-$(1).uImage.squashfs.tmp2
    $(STAGING_DIR_HOST)/bin/wndr3700 \
        $(KDIR_TMP)/vmlinux-$(1).uImage.squashfs.tmp2 \
        $(KDIR_TMP)/vmlinux-$(1).uImage.squashfs \
        $(4)
    -rm -f $(KDIR_TMP)/vmlinux-$(1).uImage.squashfs.tmp*
endef

define Image/Build/Netgear/Estimate_uImage
    $(call Image/Build/Netgear/Build_uImage,$(1)_est,$(2),$(3),$(4))
    ( \
        set -e; \
        kk=`echo '$(3)' | sed -e 's/.*[:,]\([0-9]*\)k(kernel).*/\1/'`; \
        rk=`echo '$(3)' | sed -e 's/.*[:,]\([0-9]*\)k(rootfs).*/\1/'`; \
        let 'tk = kk + rk'; \
        s=`stat -c'%s' '$(KDIR_TMP)/vmlinux-$(1)_est.uImage.squashfs'`; \
        c=`echo '$(3)' | wc -c`; \
        let 'kk = (((s + c) / (64 * 1024) + 1) * 64)'; \
        let 'rk = tk - kk'; \
        echo '$(3)' | sed -e "s/[0-9]*k(kernel)/$$$${kk}k(kernel)/" \
                  -e "s/[0-9]*k(rootfs)/$$$${rk}k(rootfs)/" > \
            '$(KDIR_TMP)/$(1)_mtdparts'; \
        let 'k = kk * 1024'; \
        echo "$$$${k}" > '$(KDIR_TMP)/$(1)_kernel_maxsize'; \
        let 'r = rk * 1024'; \
        echo "$$$${r}" > '$(KDIR_TMP)/$(1)_rootfs_maxsize'; \
    )
    -rm -f $(KDIR_TMP)/vmlinux-$(1)_est \
           $(KDIR_TMP)/vmlinux-$(1)_est.bin.lzma \
           $(KDIR_TMP)/vmlinux-$(1)_est.uImage \
           $(KDIR_TMP)/vmlinux-$(1)_est.uImage.squashfs
endef

define Image/Build/Netgear
    $(call Image/Build/Netgear/Estimate_uImage,$(2),$(3),$(4),$(5))
    $(call Image/Build/Netgear/Build_uImage,$(2),$(3),`cat $(KDIR_TMP)/$(2)_mtdparts`,$(5))
    if [ `stat -c%s '$(KDIR_TMP)/vmlinux-$(2).uImage.squashfs'` -gt \
         `cat '$(KDIR_TMP)/$(2)_kernel_maxsize'` ]; then \
                echo "$(KDIR_TMP)/vmlinux-$(2).uImage.squashfs is too big" >& 2; \
    else if [ `stat -c%s '$(KDIR)/root.$(1)'` -gt \
         `cat '$(KDIR_TMP)/$(2)_rootfs_maxsize'` ]; then \
                echo "$(KDIR)/root.$(1) is too big" >& 2; \
    else \
        ( \
            set -e; \
            dd if=$(KDIR_TMP)/vmlinux-$(2).uImage.squashfs \
            bs=`cat '$(KDIR_TMP)/$(2)_kernel_maxsize'` conv=sync; \
            dd if=$(KDIR)/root.$(1) bs=64k; \
        ) > $(call sysupname,$(1),$(2)); \
        for r in $(7) ; do \
            [ -n "$$$$r" ] && dashr="-$$$$r" || dashr= ; \
            $(STAGING_DIR_HOST)/bin/mkdniimg \
                -B $(6) -v OpenWrt.$(REVISION) -r "$$$$r" $(8) \
                -i $(call sysupname,$(1),$(2)) \
                -o $(call imgname,$(1),$(2))-factory$$$$dashr.img; \
        done; \
    fi; fi
endef

define Image/Build/Netgear/initramfs
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(STAGING_DIR_HOST)/bin/wndr3700 \
        $(KDIR_TMP)/vmlinux-$(2).uImage \
        $(call imgname,$(1),$(2))-uImage.bin \
        $(5)
endef

ifdef CONFIG_PACKAGE_uboot-ar71xx-nbg460n_550n_550nh
  define Image/Build/ZyXEL
    $(call MkuImageLzma,$(2),$(3))
    $(call Sysupgrade/KRuImage,$(1),$(2),917504,2752512)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        if [ ! -f $(BIN_DIR)/$(IMG_PREFIX)-$(2)-u-boot.bin ]; then \
            echo "Warning: $(IMG_PREFIX)-$(2)-u-boot.bin not found"; \
        else \
            $(STAGING_DIR_HOST)/bin/mkzynfw \
                -B $(4) \
                -b $(BIN_DIR)/$(IMG_PREFIX)-$(2)-u-boot.bin \
                -r $(call sysupname,$(1),$(2)):0x10000 \
                -o $(call factoryname,$(1),$(2)); \
    fi; fi
  endef
endif

define Image/Build/OpenMesh
    $(call MkuImageLzma,$(2))
    -sh $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
        "$(BUILD_DIR)/om2p-fwupgrade.cfg" \
        "$(KDIR_TMP)/vmlinux-$(2).uImage" \
        "$(KDIR)/root.$(1)"
    -sh $(TOPDIR)/scripts/combined-ext-image.sh \
        "$(4)" "$(call factoryname,$(1),$(2))" \
        "$(BUILD_DIR)/om2p-fwupgrade.cfg" "fwupgrade.cfg" \
        "$(KDIR_TMP)/vmlinux-$(2).uImage" "kernel" \
        "$(KDIR)/root.$(1)" "rootfs"
endef

define Image/Build/Zcomax
    $(call MkuImageLzma,$(2),$(3) $(4))
    $(call Sysupgrade/RKuImage,$(1),$(2),1507328,6356992)
    if [ -e "$(call sysupname,$(1),$(2))" ]; then \
        $(STAGING_DIR_HOST)/bin/mkzcfw \
            -B $(2) \
            -k $(KDIR_TMP)/vmlinux-$(2).uImage \
            -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
            -o $(call imgname,$(1),$(2))-factory.img; \
    fi
endef

define Image/Build/Zcomax/initramfs
    $(call MkuImageLzma/initramfs,$(2),$(3) $(4))
endef

define Image/Build/Template/initramfs/initramfs
    $(call Image/Build/$(1)/initramfs,initramfs,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/all/squashfs
    $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/all/jffs2-64k
    $(call Image/Build/$(1),jffs2-64k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/all/jffs2-128k
    $(call Image/Build/$(1),jffs2-128k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/all/jffs2-256k
    $(call Image/Build/$(1),jffs2-256k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/squashfs-only/loader
    $(call Image/Build/$(1)/loader,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/squashfs-only/squashfs
    $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/64k/loader
    $(call Image/Build/$(1)/loader,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/64k/squashfs
    $(call Image/Build/$(1),squashfs-64k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/64k/jffs2-64k
    $(call Image/Build/$(1),jffs2-64k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/64kraw/loader
    $(call Image/Build/$(1)/loader,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/64kraw/squashfs
    $(call Image/Build/$(1),squashfs-raw,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/64kraw/jffs2-64k
    $(call Image/Build/$(1),jffs2-64k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/128k/squashfs
    $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/128k/jffs2-128k
    $(call Image/Build/$(1),jffs2-128k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/256k/squashfs
    $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

define Image/Build/Template/256k/jffs2-256k
    $(call Image/Build/$(1),jffs2-256k,$(2),$(3),$(4),$(5),$(6),$(7),$(8))
endef

$(eval $(call SingleProfile,ALFA,$(fs_64k),ALFANX,alfa-nx,ALFA-NX,ttyS0,115200,$$(alfa_mtdlayout_8M),1638400,6291456,vmlinux.gz.uImage,pb9x-2.6.31-jffs2))
$(eval $(call SingleProfile,ALFA,$(fs_64k),HORNETUB,hornet-ub,HORNET-UB,ttyATH0,115200,$$(alfa_mtdlayout_8M),1638400,6291456,kernel_image,rootfs_image))
$(eval $(call SingleProfile,AthGzip,$(fs_64k),AP81,ap81,AP81,ttyS0,115200,,1310720,6619136,KRuImage))
$(eval $(call SingleProfile,AthGzip,$(fs_64k),AP83,ap83,AP83,ttyS0,115200,,1310720,6619136,KRuImage))
$(eval $(call SingleProfile,AthGzip,$(fs_64k),AP96,ap96,AP96,ttyS0,115200,$$(ap96_mtdlayout),1769472,6291456,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),ALFAAP96,alfa-ap96,ALFA-AP96,ttyS0,115200,$$(alfa_ap96_mtdlayout),2097152,13631488,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),ALL0258N,all0258n,ALL0258N,ttyS0,115200,$$(all0258n_mtdlayout),1048576,5373952,KRuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_256k),ALL0315N,all0315n,ALL0315N,ttyS0,115200,$$(all0315n_mtdlayout),1048576,12845056,KRuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP113,ap113,AP113,ttyS0,115200,$$(ap113_mtd_layout),917504,3080192,RK))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP121_2M,ap121-2M,AP121,ttyATH0,115200,$$(ap121_mtdlayout_2M),720896,1245184,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP121_4M,ap121-4M,AP121,ttyATH0,115200,$$(ap121_mtdlayout_4M),917504,2818048,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP121MINI,ap121-mini,AP121-MINI,ttyATH0,115200,$$(ap121_mtdlayout_4M),917504,2818048,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP136,ap136,AP136,ttyS0,115200,$$(ap136_mtdlayout),1441792,6488064,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),CAP4200AG,cap4200ag,CAP4200AG,ttyS0,115200,$$(cap4200ag_mtdlayout),1572864,12386304,KRuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),DB120,db120,DB120,ttyS0,115200,$$(db120_mtdlayout),1441792,6488064,RKuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),EWDORINAP,ew-dorin,EW-DORIN,ttyATH0,115200,$$(ew-dorin_mtdlayout_4M),1048576,2752512,KRuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),EWDORINRT,ew-dorin-router,EW-DORIN-ROUTER,ttyATH0,115200,$$(ew-dorin_mtdlayout_4M),1048576,2752512,KRuImage))
$(eval $(call SingleProfile,AthLzma,$(fs_64k),PB92,pb92,PB92,ttyS0,115200,$$(pb92_mtdlayout),917504,2818048,KRuImage))
$(eval $(call SingleProfile,Cameo7240,$(fs_64k),DIR600A1,dir-600-a1,DIR-600-A1,ttyS0,115200,"AP91-AR7240-RT-090223-00"))
$(eval $(call SingleProfile,Cameo7240,$(fs_64k),DIR601A1,dir-601-a1,DIR-600-A1,ttyS0,115200,"AP91-AR7240-RT-090223-02"))
$(eval $(call SingleProfile,Cameo7240,$(fs_64k),DIR615E4,dir-615-e4,DIR-615-E4,ttyS0,115200,"AP99-AR7240-RT-091105-05"))
$(eval $(call SingleProfile,Cameo7240,$(fs_64k),FR54RTR,fr-54rtr,DIR-600-A1,ttyS0,115200,"AP91-AR7240-RT-090223-01"))
$(eval $(call SingleProfile,Cameo913x,$(fs_squash),A02RBW300N,a02-rb-w300n,TEW-632BRP,ttyS0,115200,"AP81-AR9130-RT-070614-03"))
$(eval $(call SingleProfile,Cameo913x,$(fs_squash),DIR615C1,dir-615-c1,DIR-615-C1,ttyS0,115200,"AP81-AR9130-RT-070614-02"))
$(eval $(call SingleProfile,Cameo913x,$(fs_squash),TEW632BRP,tew-632brp,TEW-632BRP,ttyS0,115200,"AP81-AR9130-RT-070614-00"))
$(eval $(call SingleProfile,Cameo913x,$(fs_squash),TEW652BRP_FW,tew-652brp,TEW-632BRP,ttyS0,115200,"AP81-AR9130-RT-080609-05"))
$(eval $(call SingleProfile,Cameo913x,$(fs_squash),TEW652BRP_RECOVERY,tew-652brp-recovery,TEW-632BRP,ttyS0,115200,"AP81-AR9130-RT-070614-02"))
$(eval $(call SingleProfile,Cameo933x,$(fs_squash),TEW712BR,tew-712br,TEW-712BR,ttyATH0,115200,"HORNET-RT-TEW712BR-3"))
$(eval $(call SingleProfile,CyberTAN,$(fs_64k),WRT160NL,wrt160nl,WRT160NL,ttyS0,115200,1.00.01))
$(eval $(call SingleProfile,DIR825B1,$(fs_64k),DIR825B1,dir-825-b1,DIR-825-B1,ttyS0,115200,01AP94-AR7161-RT-080619-00,00AP94-AR7161-RT-080619-00))
$(eval $(call SingleProfile,DIR825B1,$(fs_64k),TEW673GRU,tew-673gru,TEW-673GRU,ttyS0,115200,01AP94-AR7161-RT-080619-01,00AP94-AR7161-RT-080619-01))
$(eval $(call SingleProfile,DLRTDEV,$(fs_64k),DLRTDEV01,dlrtdev01,DIR-825-B1,ttyS0,115200,01AP94-AR7161-RT-080619-00,00AP94-AR7161-RT-080619-00))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WP543_2M,wp543,,ttyS0,115200,0x200000,2M))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WP543_4M,wp543,,ttyS0,115200,0x400000,4M))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WP543_8M,wp543,,ttyS0,115200,0x800000,8M))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WP543_16M,wp543,,ttyS0,115200,0x1000000,16M))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WPE72_4M,wpe72,,ttyS0,115200,0x400000,4M))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WPE72_8M,wpe72,,ttyS0,115200,0x800000,8M))
$(eval $(call SingleProfile,MyLoader,$(fs_64k),WPE72_16M,wpe72,,ttyS0,115200,0x1000000,16M))
$(eval $(call SingleProfile,Netgear,$(fs_64k),WNDR3700V1,wndr3700,WNDR3700,ttyS0,115200,$$(wndr3700_mtdlayout),3700,WNDR3700,"" NA,))
$(eval $(call SingleProfile,Netgear,$(fs_64k),WNDR3700V2,wndr3700v2,WNDR3700,ttyS0,115200,$$(wndr3700v2_mtdlayout),3701,WNDR3700v2,"",-H 29763654+16+64))
$(eval $(call SingleProfile,Netgear,$(fs_64k),WNDR3800,wndr3800,WNDR3700,ttyS0,115200,$$(wndr3700v2_mtdlayout),3701,WNDR3800,"",-H 29763654+16+128))
$(eval $(call SingleProfile,Netgear,$(fs_64k),WNDRMAC,wndrmac,WNDR3700,ttyS0,115200,$$(wndr3700v2_mtdlayout),3701,WNDRMAC,"",-H 29763654+16+64))
$(eval $(call SingleProfile,Netgear,$(fs_64k),WNDRMACV2,wndrmacv2,WNDR3700,ttyS0,115200,$$(wndr3700v2_mtdlayout),3701,WNDRMACv2,"",-H 29763654+16+128))
$(eval $(call SingleProfile,OpenMesh,$(fs_squash),OM2P,om2p,,,,OM2P))
$(eval $(call SingleProfile,PB4X,$(fs_128k),ALL0305,all0305,ALL0305,ttyS0,115200))
$(eval $(call SingleProfile,PB4X,$(fs_128k),EAP7660D,eap7660d,EAP7660D,ttyS0,115200))
$(eval $(call SingleProfile,PB4X,$(fs_64k),JA76PF,ja76pf,JA76PF,ttyS0,115200))
$(eval $(call SingleProfile,PB4X,$(fs_64k),JA76PF2,ja76pf2,JA76PF2,ttyS0,115200))
$(eval $(call SingleProfile,PB4X,$(fs_64k),JWAP003,jwap003,JWAP003,ttyS0,115200))
$(eval $(call SingleProfile,PB4X,$(fs_64k),PB42,pb42,PB42,ttyS0,115200))
$(eval $(call SingleProfile,PB4X,$(fs_64k),PB44,pb44,PB44,ttyS0,115200))
$(eval $(call SingleProfile,Planex,$(fs_64k),MZKW04NU,mzk-w04nu,MZK-W04NU,ttyS0,115200))
$(eval $(call SingleProfile,Planex,$(fs_64k),MZKW300NH,mzk-w300nh,MZK-W300NH,ttyS0,115200))
$(eval $(call SingleProfile,TPLINKOLD,$(fs_squash),TLWR841NV15,tl-wr841nd-v1.5,TL-WR841N-v1.5,ttyS0,115200,0x08410002,2,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWA701,tl-wa701n-v1,TL-WA901ND,ttyS0,115200,0x07010001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWA7510NV1,tl-wa7510n,TL-WA7510N,ttyS0,115200,0x75100001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWA901NV1,tl-wa901nd-v1,TL-WA901ND,ttyS0,115200,0x09010001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWA901NV2,tl-wa901nd-v2,TL-WA901ND-v2,ttyS0,115200,0x09010002,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR740NV1,tl-wr740n-v1,TL-WR741ND,ttyS0,115200,0x07400001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR740NV3,tl-wr740n-v3,TL-WR741ND,ttyS0,115200,0x07400003,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR741NV1,tl-wr741nd-v1,TL-WR741ND,ttyS0,115200,0x07410001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR741NV2,tl-wr741nd-v2,TL-WR741ND,ttyS0,115200,0x07410001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR743,tl-wr743nd-v1,TL-WR741ND,ttyS0,115200,0x07430001,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR841NV3,tl-wr841nd-v3,TL-WR941ND,ttyS0,115200,0x08410003,3,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR841NV5,tl-wr841nd-v5,TL-WR741ND,ttyS0,115200,0x08410005,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR841NV7,tl-wr841nd-v7,TL-WR841N-v7,ttyS0,115200,0x08410007,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR842,tl-wr842n-v1,TL-MR3420,ttyS0,115200,0x08420001,1,8M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR941NV2,tl-wr941nd-v2,TL-WR941ND,ttyS0,115200,0x09410002,2,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR941NV3,tl-wr941nd-v3,TL-WR941ND,ttyS0,115200,0x09410002,2,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR941NV4,tl-wr941nd-v4,TL-WR741ND,ttyS0,115200,0x09410004,1,4M))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLWR1043,tl-wr1043nd-v1,TL-WR1043ND,ttyS0,115200,0x10430001,1,8M))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR11U,tl-mr11u-v1,TL-MR11U,ttyATH0,115200,0x00110101,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR3020V1,tl-mr3020-v1,TL-MR3020,ttyATH0,115200,0x30200001,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR3020V2,tl-mr3220-v2,TL-MR3020,ttyATH0,115200,0x32200002,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR3040,tl-mr3040-v1,TL-MR3040,ttyATH0,115200,0x30400001,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR3220V2,tl-mr3220-v2,TL-MR3220,ttyATH0,115200,0x32200002,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR3420V2,tl-mr3420-v2,TL-MR3420,ttyATH0,115200,0x34200002,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLMR3220V1,tl-mr3220-v1,TL-MR3220,ttyS0,115200,0x32200001,1,4M)) 
$(eval $(call SingleProfile,TPLINK,$(fs_64kraw),TLMR3420V1,tl-mr3420-v1,TL-MR3420,ttyS0,115200,0x34200001,1,4M)) 
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWR703,tl-wr703n-v1,TL-WR703N,ttyATH0,115200,0x07030101,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWR740NV4,tl-wr740n-v4,TL-WR741ND-v4,ttyATH0,115200,0x07400004,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLMR3220V2,tl-mr3220-v2,TL-WR741ND-v4,ttyATH0,115200,0x32200002,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWR841NV8,tl-wr841n-v8,TL-WR841N-v8,ttyS0,115200,0x08410008,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWR1041,tl-wr1041n-v2,TL-WR1041N-v2,ttyS0,115200,0x10410002,1,4Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWR2543,tl-wr2543-v1,TL-WR2543N,ttyS0,115200,0x25430001,1,8Mlzma,-v 3.13.99))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWDR3600V1,tl-wdr3600-v1,TL-WDR4300,ttyS0,115200,0x36000001,1,8Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWDR4300V1,tl-wdr4300-v1,TL-WDR4300,ttyS0,115200,0x43000001,1,8Mlzma))
$(eval $(call SingleProfile,TPLINK-LZMA,$(fs_64kraw),TLWDR4310V1,tl-wdr4310-v1,TL-WDR4300,ttyS0,115200,0x43100001,1,8Mlzma))
$(eval $(call SingleProfile,UBDEV,$(fs_64k),UBDEV01,ubdev01,UBNT-UF,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNT,$(fs_64k),UBNTRS,ubnt-rs,UBNT-RS,ttyS0,115200,RS,RSx,ar7100))
$(eval $(call SingleProfile,UBNT,$(fs_64k),UBNTRSPRO,ubnt-rspro,UBNT-RSPRO,ttyS0,115200,RSPRO,RSPRO,ar7100pro))
$(eval $(call SingleProfile,UBNT,$(fs_64k),UBNTLSSR71,ubnt-ls-sr71,UBNT-LS-SR71,ttyS0,115200,LS-SR71,LS-SR71,ar7100))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),RW2458N,rw2458n,RW2458N,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),UBNTAIRROUTER,ubnt-airrouter,UBNT-AR,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),UBNTBULLETM,ubnt-bullet-m,UBNT-BM,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),UBNTROCKETM,ubnt-rocket-m,UBNT-RM,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),UBNTNANOM,ubnt-nano-m,UBNT-NM,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),UBNTUNIFI,ubnt-unifi,UBNT-UF,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,UBNTXM,$(fs_64k),UBNTUNIFIOUTDOOR,ubnt-unifi-outdoor,UBNT-U20,ttyS0,115200,XM,XM,ar7240))
$(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WHRG301N,whr-g301n,WHR-G301N,ttyS0,115200,$$(whrhpg300n_mtdlayout),WHR-G301N))
$(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WHRHPG300N,whr-hp-g300n,WHR-HP-G300N,ttyS0,115200,$$(whrhpg300n_mtdlayout),WHR-HP-G300N))
$(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WHRHPGN,whr-hp-gn,WHR-HP-GN,ttyS0,115200,$$(whrhpg300n_mtdlayout),WHR-HP-GN))
$(eval $(call SingleProfile,WHRHPG300N,$(fs_64k),WLAEAG300N,wlae-ag300n,WLAE-AG300N,ttyS0,115200,$$(whrhpg300n_mtdlayout),WLAE-AG300N))
$(eval $(call SingleProfile,WRT400N,$(fs_64k),WRT400N,wrt400n,WRT400N,ttyS0,115200))
$(eval $(call SingleProfile,WZRHPG30XNH,$(fs_128k),WZRHPG300NH,wzr-hp-g300nh,WZR-HP-G300NH,ttyS0,115200,WZR-HP-G300NH))
$(eval $(call SingleProfile,WZRHPG30XNH,$(fs_64k),WZRHPG300NH2,wzr-hp-g300nh2,WZR-HP-G300NH2,ttyS0,115200,WZR-HP-G300NH2))
$(eval $(call SingleProfile,WZRHPG30XNH,$(fs_64k),WZRHPAG300H,wzr-hp-ag300h,WZR-HP-AG300H,ttyS0,115200,WZR-HP-AG300H))
$(eval $(call SingleProfile,WZRHPG30XNH,$(fs_64k),WZRHPG450H,wzr-hp-g450h,WZR-HP-G450H,ttyS0,115200,WZR-HP-AG450H))
$(eval $(call SingleProfile,Zcomax,$(fs_64k),ZCN1523H28,zcn-1523h-2-8,ZCN-1523H-2,ttyS0,115200,$$(zcn1523h_mtdlayout)))
$(eval $(call SingleProfile,Zcomax,$(fs_64k),ZCN1523H516,zcn-1523h-5-16,ZCN-1523H-5,ttyS0,115200,$$(zcn1523h_mtdlayout)))
$(eval $(call SingleProfile,ZyXEL,$(fs_64k),NBG_460N_550N_550NH,nbg460n_550n_550nh,NBG460N,ttyS0,115200,NBG-460N))
$(eval $(call MultiProfile,AP121,AP121_2M AP121_4M))
$(eval $(call MultiProfile,EWDORIN, EWDORINAP EWDORINRT))
$(eval $(call MultiProfile,TEW652BRP,TEW652BRP_FW TEW652BRP_RECOVERY))
$(eval $(call MultiProfile,TLWA901,TLWA901NV1 TLWA901NV2))
$(eval $(call MultiProfile,TLWA7510,TLWA7510NV1))
$(eval $(call MultiProfile,TLWR740,TLWR740NV1 TLWR740NV3 TLWR740NV4))
$(eval $(call MultiProfile,TLMR3220,TLMR3220V1 TLMR3220V2))
$(eval $(call MultiProfile,TLMR3420,TLMR3420V1 TLMR3420V2))
$(eval $(call MultiProfile,TLMR3020,TLMR3020V1 TLMR3020V2))
$(eval $(call MultiProfile,TLWR741,TLWR741NV1 TLWR741NV2 TLWR741NV4))
$(eval $(call MultiProfile,TLWR841,TLWR841NV15 TLWR841NV3 TLWR841NV5 TLWR841NV7 TLWR841NV8))
$(eval $(call MultiProfile,TLWR941,TLWR941NV2 TLWR941NV3 TLWR941NV4))
$(eval $(call MultiProfile,TLWDR4300,TLWDR3600V1 TLWDR4300V1 TLWDR4310V1))
$(eval $(call MultiProfile,UBNT,UBNTAIRROUTER UBNTRS UBNTRSPRO UBNTLSSR71 UBNTBULLETM UBNTROCKETM UBNTNANOM UBNTUNIFI UBNTUNIFIOUTDOOR))
$(eval $(call MultiProfile,WNDR3700,WNDR3700V1 WNDR3700V2 WNDR3800 WNDRMAC WNDRMACV2))
$(eval $(call MultiProfile,WP543,WP543_2M WP543_4M WP543_8M WP543_16M))
$(eval $(call MultiProfile,WPE72,WPE72_4M WPE72_8M WPE72_16M))
$(eval $(call MultiProfile,Default,$(SINGLE_PROFILES)))
$(eval $(call MultiProfile,Minimal,$(SINGLE_PROFILES)))
$(eval $(call MultiProfile,Madwifi,EAP7660D UBNTRS UBNTRSPRO UBNTLSSR71 WP543))

define Image/Build/squashfs
    cp $(KDIR)/root.squashfs $(KDIR)/root.squashfs-raw
    cp $(KDIR)/root.squashfs $(KDIR)/root.squashfs-64k
    $(STAGING_DIR_HOST)/bin/padjffs2 $(KDIR)/root.squashfs-64k 64
    cp $(KDIR)/root.squashfs-64k $(BIN_DIR)/$(IMG_PREFIX)-root.squashfs-64k
    $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
endef

define Image/Build/Initramfs
    $(call Image/Build/Profile/$(PROFILE),initramfs)
endef

define Image/Prepare
    gzip -9 -c $(KDIR)/vmlinux > $(KDIR)/vmlinux.bin.gz
    $(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
    $(call Image/Build/Profile/$(if $(CONFIG_IB),Default,$(PROFILE)),loader)
endef

define Image/Build
    $(call Image/Build/$(1))
    dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
    $(call Image/Build/Profile/$(PROFILE),$(1))
endef

$(eval $(call BuildImage))
OpenWrt
Wireless Freedom

Re: TP-Link MR3220V2

build_dir/linux-ar71xx_generic/linux-3.3.8/arch/mips/ath79/Kconfig

if ATH79

menu "Atheros AR71XX/AR724X/AR913X machine selection"

config ATH79_MACH_ALFA_AP96
    bool "ALFA Network AP96 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_SPI
    select ATH79_DEV_USB

config ATH79_MACH_HORNET_UB
    bool "ALFA Network Hornet-UB board support"
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_ALFA_NX
    bool "ALFA Network N2/N5 board support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_ALL0258N
    bool "Allnet ALL0258N support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_ALL0315N
    bool "Allnet ALL0315N support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_AP113
    bool "Atheros AP113 board support"
    select SOC_AR724X
    select ATH79_DEV_M25P80
    select ATH79_DEV_PB9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_USB
    select ATH79_DEV_ETH

config ATH79_MACH_AP121
    bool "Atheros AP121 reference board"
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC
    help
      Say 'Y' here if you want your kernel to support the
      Atheros AP121 reference board.

config ATH79_MACH_AP136
    bool "Atheros AP136 reference board"
    select SOC_QCA955X
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_SPI
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC
    help
      Say 'Y' here if you want your kernel to support the
      Atheros AP136 reference board.

config ATH79_MACH_AP81
    bool "Atheros AP81 reference board"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC
    help
      Say 'Y' here if you want your kernel to support the
      Atheros AP81 reference board.

config ATH79_MACH_AP83
    bool "Atheros AP83 board support"
    select SOC_AR913X
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_AP96
    bool "Atheros AP96 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_DB120
    bool "Atheros DB120 reference board"
    select SOC_AR934X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_NFC
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC
    help
      Say 'Y' here if you want your kernel to support the
      Atheros DB120 reference board.

config ATH79_MACH_PB42
    bool "Atheros PB42 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_M25P80

config ATH79_MACH_PB44
    bool "Atheros PB44 reference board"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_SPI
    select ATH79_DEV_USB
    help
      Say 'Y' here if you want your kernel to support the
      Atheros PB44 reference board.

config ATH79_MACH_PB92
    bool "Atheros PB92 board support"
    select SOC_AR724X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_PB9X_PCI if PCI
    select ATH79_DEV_USB

config ATH79_MACH_AW_NR580
    bool "AzureWave AW-NR580 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_WHR_HP_G300N
    bool "Buffalo WHR-HP-G300N board support"
    select SOC_AR724X
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_WLAE_AG300N
    bool "Buffalo WLAE-AG300N board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_WZR_HP_AG300H
    bool "Buffalo WZR-HP-AG300H board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_WZR_HP_G300NH
    bool "Buffalo WZR-HP-G300NH board support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC
    select RTL8366_SMI

config ATH79_MACH_WZR_HP_G300NH2
    bool "Buffalo WZR-HP-G300NH2 board support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_WZR_HP_G450H
    bool "Buffalo WZR-HP-G450H board support"
    select SOC_AR724X
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_WP543
    bool "Compex WP543/WPJ543 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select MYLOADER

config ATH79_MACH_WPE72
    bool "Compex WPE72/WPE72NX board support"
    select SOC_AR724X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select MYLOADER

config ATH79_MACH_DIR_600_A1
    bool "D-Link DIR-600 A1/DIR-615 E4 support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_NVRAM

config ATH79_MACH_DIR_615_C1
    bool "D-Link DIR-615 rev. C1 support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC
    select ATH79_NVRAM

config ATH79_MACH_DIR_825_B1
    bool "D-Link DIR-825 rev. B1 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_EW_DORIN
    bool "embedded wireless Dorin Platform support"
    select SOC_AR933X
    select ATH79_DEV_M25P80
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_WMAC
    select ATH79_DEV_ETH
    help
      Say 'Y' here if you want your kernel to support the
      Dorin Platform from www.80211.de .

config ATH79_MACH_JA76PF
    bool "jjPlus JA76PF board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_JWAP003
    bool "jjPlus JWAP003 board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_WRT160NL
    bool "Linksys WRT160NL board support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC
    select ATH79_NVRAM

config ATH79_MACH_WRT400N
    bool "Linksys WRT400N board support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_RB4XX
    bool "MikroTik RouterBOARD 4xx series support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_USB

config ATH79_MACH_RB750
    bool "MikroTik RouterBOARD 750 support"
    select SOC_AR724X
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_USB
    select ATH79_ROUTERBOOT
    select RLE_DECOMPRESS

config ATH79_MACH_RB2011
    bool "MikroTik RouterBOARD 2011 support"
    select SOC_AR934x
    select ATH79_DEV_ETH
    select ATH79_DEV_NFC
    select ATH79_DEV_WMAC
    select ATH79_ROUTERBOOT

config ATH79_MACH_WNDR3700
    bool "NETGEAR WNDR3700 board support"
    select SOC_AR71XX
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_WNR2000
    bool "NETGEAR WNR2000 board support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_OM2P
    bool "OpenMesh OM2P board support"
    select SOC_AR724X
    select SOC_AR933X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_MZK_W04NU
    bool "Planex MZK-W04NU board support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_MZK_W300NH
    bool "Planex MZK-W300NH board support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_RW2458N
    bool "Redwave RW2458N board support"
    select SOC_AR724X
    select ATH79_DEV_ETH
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_CAP4200AG
    bool "Senao CAP4200AG support"
    select SOC_AR934X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_EAP7660D
    bool "Senao EAP7660D support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_TL_MR11U
    bool "TP-LINK TL-MR11U/TL-MR3040 support"
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_MR3020
    bool "TP-LINK TL-MR3020 support"
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_MR3X20
    bool "TP-LINK TL-MR3220/3420 support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_TL_WA901ND
    bool "TP-LINK TL-WA901ND/TL-WA7510N support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_TL_WA901ND_V2
    bool "TP-LINK TL-WA901ND v2 support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WDR4300
    bool "TP-LINK TL-WDR3600/4300/4310 board support"
    select SOC_AR934X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR703N
    bool "TP-LINK TL-WR703N support"
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR741ND
    bool "TP-LINK TL-WR741ND support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_TL_WR741ND_V4
    bool "TP-LINK TL-WR741ND v4 support"
    select ATH79_DEV_USB
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR841N_V1
    bool "TP-LINK TL-WR841N v1 support"
    select SOC_AR71XX
    select ATH79_DEV_DSA
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_TL_WR841N_V8
    bool "TP-LINK TL-WR841N/ND v8 support"
    select SOC_AR934X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR941ND
    bool "TP-LINK TL-WR941ND support"
    select SOC_AR913X
    select ATH79_DEV_DSA
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR1041N_V2
    bool "TP-LINK TL-WR1041N v2 support"
    select SOC_AR934X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR1043ND
    bool "TP-LINK TL-WR1043ND support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_DEV_WMAC

config ATH79_MACH_TL_WR2543N
    bool "TP-LINK TL-WR2543N/ND support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_TEW_632BRP
    bool "TRENDnet TEW-632BRP support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC
    select ATH79_NVRAM

config ATH79_MACH_TEW_673GRU
    bool "TRENDnet TEW-673GRU support"
    select SOC_AR71XX
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    select ATH79_NVRAM

config ATH79_MACH_TEW_712BR
    bool "TRENDnet TEW-712BR support"
    select SOC_AR933X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC
    select ATH79_NVRAM

config ATH79_MACH_UBNT
    bool "Ubiquiti AR71xx based boards support"
    select SOC_AR71XX
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB

config ATH79_MACH_UBNT_XM
    bool "Ubiquiti Networks XM (rev 1.0) board"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_USB
    help
      Say 'Y' here if you want your kernel to support the
      Ubiquiti Networks XM (rev 1.0) board.

config ATH79_MACH_ZCN_1523H
    bool "Zcomax ZCN-1523H support"
    select SOC_AR724X
    select ATH79_DEV_AP9X_PCI if PCI
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80

config ATH79_MACH_NBG460N
    bool "Zyxel NBG460N/550N/550NH board support"
    select SOC_AR913X
    select ATH79_DEV_ETH
    select ATH79_DEV_GPIO_BUTTONS
    select ATH79_DEV_LEDS_GPIO
    select ATH79_DEV_M25P80
    select ATH79_DEV_WMAC

endmenu

config SOC_AR71XX
    select USB_ARCH_HAS_EHCI
    select USB_ARCH_HAS_OHCI
    select HW_HAS_PCI
    def_bool n

config SOC_AR724X
    select USB_ARCH_HAS_EHCI
    select USB_ARCH_HAS_OHCI
    select HW_HAS_PCI
    select PCI_AR724X if PCI
    def_bool n

config SOC_AR913X
    select USB_ARCH_HAS_EHCI
    def_bool n

config SOC_AR933X
    select USB_ARCH_HAS_EHCI
    def_bool n

config SOC_AR934X
    select USB_ARCH_HAS_EHCI
    select HW_HAS_PCI
    select PCI_AR724X if PCI
    def_bool n

config SOC_QCA955X
    select USB_ARCH_HAS_EHCI
    select HW_HAS_PCI
    select PCI_AR724X if PCI
    def_bool n

config ATH79_DEV_AP9X_PCI
    select ATH79_PCI_ATH9K_FIXUP
    def_bool n

config ATH79_DEV_DSA
    def_bool n

config ATH79_DEV_ETH
    def_bool n

config ATH79_DEV_M25P80
    select ATH79_DEV_SPI
    def_bool n

config ATH79_DEV_DSA
    def_bool n

config ATH79_DEV_ETH
    def_bool n

config ATH79_DEV_GPIO_BUTTONS
    def_bool n

config ATH79_DEV_LEDS_GPIO
    def_bool n

config ATH79_DEV_NFC
    depends on (SOC_AR934X)
    def_bool n

config ATH79_DEV_SPI
    def_bool n

config ATH79_DEV_USB
    def_bool n

config ATH79_DEV_WMAC
    depends on (SOC_AR913X || SOC_AR933X || SOC_AR934X || SOC_QCA955X)
    def_bool n

config ATH79_NVRAM
    def_bool n

config ATH79_PCI_ATH9K_FIXUP
    def_bool n

config ATH79_ROUTERBOOT
    def_bool n

config PCI_AR724X
    def_bool n

endif
OpenWrt
Wireless Freedom

Re: TP-Link MR3220V2

build_dir/linux-ar71xx_generic/linux-3.3.8/arch/mips/ath79/mach-tl-wr741nd-v4.c

/*
 *  TP-LINK TL-WR741ND v4 board support
 *
 *  Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
 *
 *  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 "dev-usb.h"
#include <linux/gpio.h>

#include <asm/mach-ath79/ath79.h>
#include <asm/mach-ath79/ar71xx_regs.h>

#include "common.h"
#include "dev-eth.h"
#include "dev-gpio-buttons.h"
#include "dev-leds-gpio.h"
#include "dev-m25p80.h"
#include "dev-wmac.h"
#include "machtypes.h"

#define TL_WR741NDV4_GPIO_BTN_RESET    11
#define TL_WR741NDV4_GPIO_BTN_WPS    26

#define TL_WR741NDV4_GPIO_LED_WLAN    0
#define TL_WR741NDV4_GPIO_LED_QSS    1
#define TL_WR741NDV4_GPIO_LED_WAN    13
#define TL_WR741NDV4_GPIO_LED_LAN1    14
#define TL_WR741NDV4_GPIO_LED_LAN2    15
#define TL_WR741NDV4_GPIO_LED_LAN3    16
#define TL_WR741NDV4_GPIO_LED_LAN4    17

#define TL_WR741NDV4_GPIO_LED_SYSTEM    27

#define TL_WR741NDV4_KEYS_POLL_INTERVAL    20    /* msecs */
#define TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR741NDV4_KEYS_POLL_INTERVAL)

static const char *tl_wr741ndv4_part_probes[] = {
    "tp-link",
    NULL,
};

static struct flash_platform_data tl_wr741ndv4_flash_data = {
    .part_probes    = tl_wr741ndv4_part_probes,
};

static struct gpio_led tl_wr741ndv4_leds_gpio[] __initdata = {
    {
        .name        = "tp-link:green:lan1",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN1,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:lan2",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN2,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:lan3",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN3,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:lan4",
        .gpio        = TL_WR741NDV4_GPIO_LED_LAN4,
        .active_low    = 1,
    }, {
        .name        = "tp-link:green:qss",
        .gpio        = TL_WR741NDV4_GPIO_LED_QSS,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:system",
        .gpio        = TL_WR741NDV4_GPIO_LED_SYSTEM,
        .active_low    = 1,
    }, {
        .name        = "tp-link:green:wan",
        .gpio        = TL_WR741NDV4_GPIO_LED_WAN,
        .active_low    = 0,
    }, {
        .name        = "tp-link:green:wlan",
        .gpio        = TL_WR741NDV4_GPIO_LED_WLAN,
        .active_low    = 0,
    },
};

static struct gpio_keys_button tl_wr741ndv4_gpio_keys[] __initdata = {
    {
        .desc        = "reset",
        .type        = EV_KEY,
        .code        = KEY_RESTART,
        .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
        .gpio        = TL_WR741NDV4_GPIO_BTN_RESET,
        .active_low    = 0,
    }, {
        .desc        = "WPS",
        .type        = EV_KEY,
        .code        = KEY_WPS_BUTTON,
        .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
        .gpio        = TL_WR741NDV4_GPIO_BTN_WPS,
        .active_low    = 0,
    }
};

static void __init tl_wr741ndv4_setup(void)
{
    u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
    u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);

    ath79_setup_ar933x_phy4_switch(true, true);

    ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
                    AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);

    ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio),
                 tl_wr741ndv4_leds_gpio);

    ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL,
                    ARRAY_SIZE(tl_wr741ndv4_gpio_keys),
                    tl_wr741ndv4_gpio_keys);

    ath79_register_usb();
    ath79_register_m25p80(&tl_wr741ndv4_flash_data);
    ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
    ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);

    ath79_register_mdio(0, 0x0);
    ath79_register_eth(1);
    ath79_register_eth(0);

    ath79_register_wmac(ee, mac);
}

MIPS_MACHINE(ATH79_MACH_TL_WR741ND_V4, "TL-WR741ND-v4",
         "TP-LINK TL-WR741ND v4", tl_wr741ndv4_setup);

/trunk/tools/firmware-utils/src/mktplink.c

/*
 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
 *
 * This tool was based on:
 *   TP-Link WR941 V2 firmware checksum fixing tool.
 *   Copyright (C) 2008,2009 Wang Jian <lark@linux.net.cn>
 *
 * 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 <stdint.h>
#include <string.h>
#include <unistd.h>     /* for unlink() */
#include <libgen.h>
#include <getopt.h>     /* for getopt() */
#include <stdarg.h>
#include <errno.h>
#include <sys/stat.h>

#include <arpa/inet.h>
#include <netinet/in.h>

#include "md5.h"

#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })

#define HEADER_VERSION_V1    0x01000000
#define HWID_TL_MR3020_V1    0x30200001
#define HWID_TL_MR3020_V2    0x30200002
#define HWID_TL_MR3220_V1    0x32200001
#define HWID_TL_MR3420_V1    0x34200001
#define HWID_TL_MR3220_V2    0x32200002
#define HWID_TL_WA701N_V1    0x07010001
#define HWID_TL_WA7510N_V1    0x75100001
#define HWID_TL_WA901ND_V1    0x09010001
#define HWID_TL_WA901ND_V2    0x09010002
#define HWID_TL_WR703N_V1    0x07030101
#define HWID_TL_WR741ND_V1    0x07410001
#define HWID_TL_WR741ND_V4    0x07410004
#define HWID_TL_WR740N_V1    0x07400001
#define HWID_TL_WR740N_V3    0x07400003
#define HWID_TL_WR743ND_V1    0x07430001
#define HWID_TL_WR841N_V1_5    0x08410002
#define HWID_TL_WR841ND_V3    0x08410003
#define HWID_TL_WR841ND_V5    0x08410005
#define HWID_TL_WR841ND_V7    0x08410007
#define HWID_TL_WR941ND_V2    0x09410002
#define HWID_TL_WR941ND_V4    0x09410004
#define HWID_TL_WR1043ND_V1    0x10430001
#define HWID_TL_WR1041N_V2    0x10410002
#define HWID_TL_WR2543N_V1    0x25430001

#define MD5SUM_LEN    16

struct file_info {
    char        *file_name;    /* name of the file */
    uint32_t    file_size;    /* length of the file */
};

struct fw_header {
    uint32_t    version;    /* header version */
    char        vendor_name[24];
    char        fw_version[36];
    uint32_t    hw_id;        /* hardware id */
    uint32_t    hw_rev;        /* hardware revision */
    uint32_t    unk1;
    uint8_t        md5sum1[MD5SUM_LEN];
    uint32_t    unk2;
    uint8_t        md5sum2[MD5SUM_LEN];
    uint32_t    unk3;
    uint32_t    kernel_la;    /* kernel load address */
    uint32_t    kernel_ep;    /* kernel entry point */
    uint32_t    fw_length;    /* total length of the firmware */
    uint32_t    kernel_ofs;    /* kernel data offset */
    uint32_t    kernel_len;    /* kernel data length */
    uint32_t    rootfs_ofs;    /* rootfs data offset */
    uint32_t    rootfs_len;    /* rootfs data length */
    uint32_t    boot_ofs;    /* bootloader data offset */
    uint32_t    boot_len;    /* bootloader data length */
    uint16_t    ver_hi;
    uint16_t    ver_mid;
    uint16_t    ver_lo;
    uint8_t        pad[354];
} __attribute__ ((packed));

struct flash_layout {
    char        *id;
    uint32_t    fw_max_len;
    uint32_t    kernel_la;
    uint32_t    kernel_ep;
    uint32_t    rootfs_ofs;
};

struct board_info {
    char        *id;
    uint32_t    hw_id;
    uint32_t    hw_rev;
    char        *layout_id;
};

/*
 * Globals
 */
static char *ofname;
static char *progname;
static char *vendor = "TP-LINK Technologies";
static char *version = "ver. 1.0";
static char *fw_ver = "0.0.0";

static char *board_id;
static struct board_info *board;
static char *layout_id;
static struct flash_layout *layout;
static char *opt_hw_id;
static uint32_t hw_id;
static char *opt_hw_rev;
static uint32_t hw_rev;
static int fw_ver_lo;
static int fw_ver_mid;
static int fw_ver_hi;
static struct file_info kernel_info;
static uint32_t kernel_la = 0;
static uint32_t kernel_ep = 0;
static uint32_t kernel_len = 0;
static struct file_info rootfs_info;
static uint32_t rootfs_ofs = 0;
static uint32_t rootfs_align;
static struct file_info boot_info;
static int combined;
static int strip_padding;
static int add_jffs2_eof;
static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};

static struct file_info inspect_info;
static int extract = 0;

char md5salt_normal[MD5SUM_LEN] = {
    0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
    0xdd, 0xf9, 0xe7, 0xf4, 0x0e, 0xae, 0x47, 0x38,
};

char md5salt_boot[MD5SUM_LEN] = {
    0x8c, 0xef, 0x33, 0x5b, 0xd5, 0xc5, 0xce, 0xfa,
    0xa7, 0x9c, 0x28, 0xda, 0xb2, 0xe9, 0x0f, 0x42,
};

static struct flash_layout layouts[] = {
    {
        .id        = "4M",
        .fw_max_len    = 0x3c0000,
        .kernel_la    = 0x80060000,
        .kernel_ep    = 0x80060000,
        .rootfs_ofs    = 0x140000,
    }, {
        .id        = "4Mlzma",
        .fw_max_len    = 0x3c0000,
        .kernel_la    = 0x80060000,
        .kernel_ep    = 0x80060000,
        .rootfs_ofs    = 0x100000,
    }, {
        .id        = "8M",
        .fw_max_len    = 0x7c0000,
        .kernel_la    = 0x80060000,
        .kernel_ep    = 0x80060000,
        .rootfs_ofs    = 0x140000,
    }, {
        .id        = "8Mlzma",
        .fw_max_len    = 0x7c0000,
        .kernel_la    = 0x80060000,
        .kernel_ep    = 0x80060000,
        .rootfs_ofs    = 0x100000,
    }, {
        /* terminating entry */
    }
};

static struct board_info boards[] = {
    {
        .id        = "TL-MR3020v1",
        .hw_id        = HWID_TL_MR3020_V1,
        .hw_rev        = 1,
        .layout_id    = "4Mlzma",
    }, {
        .id        = "TL-MR3020v2",
        .hw_id        = HWID_TL_MR3020_V2,
        .hw_rev        = 1,
        .layout_id    = "4Mlzma",
    }, {
        .id        = "TL-MR3220v1",
        .hw_id        = HWID_TL_MR3220_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id             = "TL-MR3220v2",
        .hw_id          = HWID_TL_MR3220_V2,
        .hw_rev         = 1,
        .layout_id      = "4Mlzma",
    }, {
        .id        = "TL-MR3420v1",
        .hw_id        = HWID_TL_MR3420_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WA701Nv1",
        .hw_id        = HWID_TL_WA701N_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WA7510N",
        .hw_id        = HWID_TL_WA7510N_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WA901NDv1",
        .hw_id        = HWID_TL_WA901ND_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id             = "TL-WA901NDv2",
        .hw_id          = HWID_TL_WA901ND_V2,
        .hw_rev         = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR741NDv1",
        .hw_id        = HWID_TL_WR741ND_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR741NDv4",
        .hw_id        = HWID_TL_WR741ND_V4,
        .hw_rev        = 1,
        .layout_id    = "4Mlzma",
    }, {
        .id        = "TL-WR740Nv1",
        .hw_id        = HWID_TL_WR740N_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR740Nv3",
        .hw_id        = HWID_TL_WR740N_V3,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR743NDv1",
        .hw_id        = HWID_TL_WR743ND_V1,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR841Nv1.5",
        .hw_id        = HWID_TL_WR841N_V1_5,
        .hw_rev        = 2,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR841NDv3",
        .hw_id        = HWID_TL_WR841ND_V3,
        .hw_rev        = 3,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR841NDv5",
        .hw_id        = HWID_TL_WR841ND_V5,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR841NDv7",
        .hw_id        = HWID_TL_WR841ND_V7,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR941NDv2",
        .hw_id        = HWID_TL_WR941ND_V2,
        .hw_rev        = 2,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR941NDv4",
        .hw_id        = HWID_TL_WR941ND_V4,
        .hw_rev        = 1,
        .layout_id    = "4M",
    }, {
        .id        = "TL-WR1041Nv2",
        .hw_id        = HWID_TL_WR1041N_V2,
        .hw_rev        = 1,
        .layout_id    = "4Mlzma",
    }, {
        .id        = "TL-WR1043NDv1",
        .hw_id        = HWID_TL_WR1043ND_V1,
        .hw_rev        = 1,
        .layout_id    = "8M",
    }, {
        .id        = "TL-WR2543Nv1",
        .hw_id        = HWID_TL_WR2543N_V1,
        .hw_rev        = 1,
        .layout_id    = "8Mlzma",
    }, {
        .id        = "TL-WR703Nv1",
        .hw_id        = HWID_TL_WR703N_V1,
        .hw_rev        = 1,
        .layout_id    = "4Mlzma",
    }, {
        /* terminating entry */
    }
};

/*
 * Message macros
 */
#define ERR(fmt, ...) do { \
    fflush(0); \
    fprintf(stderr, "[%s] *** error: " fmt "\n", \
            progname, ## __VA_ARGS__ ); \
} while (0)

#define ERRS(fmt, ...) do { \
    int save = errno; \
    fflush(0); \
    fprintf(stderr, "[%s] *** error: " fmt "\n", \
            progname, ## __VA_ARGS__, strerror(save)); \
} while (0)

#define DBG(fmt, ...) do { \
    fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
} while (0)

static struct board_info *find_board(char *id)
{
    struct board_info *ret;
    struct board_info *board;

    ret = NULL;
    for (board = boards; board->id != NULL; board++){
        if (strcasecmp(id, board->id) == 0) {
            ret = board;
            break;
        }
    };

    return ret;
}

static struct board_info *find_board_by_hwid(uint32_t hw_id)
{
    struct board_info *board;

    for (board = boards; board->id != NULL; board++) {
        if (hw_id == board->hw_id)
            return board;
    };

    return NULL;
}

static struct flash_layout *find_layout(char *id)
{
    struct flash_layout *ret;
    struct flash_layout *l;

    ret = NULL;
    for (l = layouts; l->id != NULL; l++){
        if (strcasecmp(id, l->id) == 0) {
            ret = l;
            break;
        }
    };

    return ret;
}

static void usage(int status)
{
    FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
    struct board_info *board;

    fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
    fprintf(stream,
"\n"
"Options:\n"
"  -B <board>      create image for the board specified with <board>\n"
"  -c              use combined kernel image\n"
"  -E <ep>         overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
"  -L <la>         overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
"  -H <hwid>       use hardware id specified with <hwid>\n"
"  -F <id>         use flash layout specified with <id>\n"
"  -k <file>       read kernel image from the file <file>\n"
"  -r <file>       read rootfs image from the file <file>\n"
"  -a <align>      align the rootfs start on an <align> bytes boundary\n"
"  -R <offset>     overwrite rootfs offset with <offset> (hexval prefixed with 0x)\n"
"  -o <file>       write output to the file <file>\n"
"  -s              strip padding from the end of the image\n"
"  -j              add jffs2 end-of-filesystem markers\n"
"  -N <vendor>     set image vendor to <vendor>\n"
"  -V <version>    set image version to <version>\n"
"  -v <version>    set firmware version to <version>\n"
"  -i <file>       inspect given firmware file <file>\n"
"  -x              extract kernel and rootfs while inspecting (requires -i)\n"
"  -h              show this screen\n"
    );

    exit(status);
}

static int get_md5(char *data, int size, char *md5)
{
    MD5_CTX ctx;

    MD5_Init(&ctx);
    MD5_Update(&ctx, data, size);
    MD5_Final(md5, &ctx);
}

static int get_file_stat(struct file_info *fdata)
{
    struct stat st;
    int res;

    if (fdata->file_name == NULL)
        return 0;

    res = stat(fdata->file_name, &st);
    if (res){
        ERRS("stat failed on %s", fdata->file_name);
        return res;
    }

    fdata->file_size = st.st_size;
    return 0;
}

static int read_to_buf(struct file_info *fdata, char *buf)
{
    FILE *f;
    int ret = EXIT_FAILURE;

    f = fopen(fdata->file_name, "r");
    if (f == NULL) {
        ERRS("could not open \"%s\" for reading", fdata->file_name);
        goto out;
    }

    errno = 0;
    fread(buf, fdata->file_size, 1, f);
    if (errno != 0) {
        ERRS("unable to read from file \"%s\"", fdata->file_name);
        goto out_close;
    }

    ret = EXIT_SUCCESS;

 out_close:
    fclose(f);
 out:
    return ret;
}

static int check_options(void)
{
    int ret;

    if (inspect_info.file_name) {
        ret = get_file_stat(&inspect_info);
        if (ret)
            return ret;

        return 0;
    } else if (extract) {
        ERR("no firmware for inspection specified");
        return -1;
    }

    if (board_id == NULL && opt_hw_id == NULL) {
        ERR("either board or hardware id must be specified");
        return -1;
    }

    if (board_id) {
        board = find_board(board_id);
        if (board == NULL) {
            ERR("unknown/unsupported board id \"%s\"", board_id);
            return -1;
        }
        if (layout_id == NULL)
            layout_id = board->layout_id;

        hw_id = board->hw_id;
        hw_rev = board->hw_rev;
    } else {
        if (layout_id == NULL) {
            ERR("flash layout is not specified");
            return -1;
        }
        hw_id = strtoul(opt_hw_id, NULL, 0);

        if (opt_hw_rev)
            hw_rev = strtoul(opt_hw_rev, NULL, 0);
        else
            hw_rev = 1;
    }

    layout = find_layout(layout_id);
    if (layout == NULL) {
        ERR("unknown flash layout \"%s\"", layout_id);
        return -1;
    }

    if (!kernel_la)
        kernel_la = layout->kernel_la;
    if (!kernel_ep)
        kernel_ep = layout->kernel_ep;
    if (!rootfs_ofs)
        rootfs_ofs = layout->rootfs_ofs;

    if (kernel_info.file_name == NULL) {
        ERR("no kernel image specified");
        return -1;
    }

    ret = get_file_stat(&kernel_info);
    if (ret)
        return ret;

    kernel_len = kernel_info.file_size;

    if (combined) {
        if (kernel_info.file_size >
            layout->fw_max_len - sizeof(struct fw_header)) {
            ERR("kernel image is too big");
            return -1;
        }
    } else {
        if (rootfs_info.file_name == NULL) {
            ERR("no rootfs image specified");
            return -1;
        }

        ret = get_file_stat(&rootfs_info);
        if (ret)
            return ret;

        if (rootfs_align) {
            kernel_len += sizeof(struct fw_header);
            kernel_len = ALIGN(kernel_len, rootfs_align);
            kernel_len -= sizeof(struct fw_header);

            DBG("kernel length aligned to %u", kernel_len);

            if (kernel_len + rootfs_info.file_size >
                layout->fw_max_len - sizeof(struct fw_header)) {
                ERR("images are too big");
                return -1;
            }
        } else {
            if (kernel_info.file_size >
                rootfs_ofs - sizeof(struct fw_header)) {
                ERR("kernel image is too big");
                return -1;
            }

            if (rootfs_info.file_size >
                (layout->fw_max_len - rootfs_ofs)) {
                ERR("rootfs image is too big");
                return -1;
            }
        }
    }

    if (ofname == NULL) {
        ERR("no output file specified");
        return -1;
    }

    ret = sscanf(fw_ver, "%d.%d.%d", &fw_ver_hi, &fw_ver_mid, &fw_ver_lo);
    if (ret != 3) {
        ERR("invalid firmware version '%s'", fw_ver);
        return -1;
    }

    return 0;
}

static void fill_header(char *buf, int len)
{
    struct fw_header *hdr = (struct fw_header *)buf;

    memset(hdr, 0, sizeof(struct fw_header));

    hdr->version = htonl(HEADER_VERSION_V1);
    strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name));
    strncpy(hdr->fw_version, version, sizeof(hdr->fw_version));
    hdr->hw_id = htonl(hw_id);
    hdr->hw_rev = htonl(hw_rev);

    if (boot_info.file_size == 0)
        memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1));
    else
        memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1));

    hdr->kernel_la = htonl(kernel_la);
    hdr->kernel_ep = htonl(kernel_ep);
    hdr->fw_length = htonl(layout->fw_max_len);
    hdr->kernel_ofs = htonl(sizeof(struct fw_header));
    hdr->kernel_len = htonl(kernel_len);
    if (!combined) {
        hdr->rootfs_ofs = htonl(rootfs_ofs);
        hdr->rootfs_len = htonl(rootfs_info.file_size);
    }

    hdr->ver_hi = htons(fw_ver_hi);
    hdr->ver_mid = htons(fw_ver_mid);
    hdr->ver_lo = htons(fw_ver_lo);

    get_md5(buf, len, hdr->md5sum1);
}

static int pad_jffs2(char *buf, int currlen)
{
    int len;
    uint32_t pad_mask;

    len = currlen;
    pad_mask = (64 * 1024);
    while ((len < layout->fw_max_len) && (pad_mask != 0)) {
        uint32_t mask;
        int i;

        for (i = 10; i < 32; i++) {
            mask = 1 << i;
            if (pad_mask & mask)
                break;
        }

        len = ALIGN(len, mask);

        for (i = 10; i < 32; i++) {
            mask = 1 << i;
            if ((len & (mask - 1)) == 0)
                pad_mask &= ~mask;
        }

        for (i = 0; i < sizeof(jffs2_eof_mark); i++)
            buf[len + i] = jffs2_eof_mark[i];

        len += sizeof(jffs2_eof_mark);
    }

    return len;
}

static int write_fw(char *data, int len)
{
    FILE *f;
    int ret = EXIT_FAILURE;

    f = fopen(ofname, "w");
    if (f == NULL) {
        ERRS("could not open \"%s\" for writing", ofname);
        goto out;
    }

    errno = 0;
    fwrite(data, len, 1, f);
    if (errno) {
        ERRS("unable to write output file");
        goto out_flush;
    }

    DBG("firmware file \"%s\" completed", ofname);

    ret = EXIT_SUCCESS;

 out_flush:
    fflush(f);
    fclose(f);
    if (ret != EXIT_SUCCESS) {
        unlink(ofname);
    }
 out:
    return ret;
}

static int build_fw(void)
{
    int buflen;
    char *buf;
    char *p;
    int ret = EXIT_FAILURE;
    int writelen = 0;

    buflen = layout->fw_max_len;

    buf = malloc(buflen);
    if (!buf) {
        ERR("no memory for buffer\n");
        goto out;
    }

    memset(buf, 0xff, buflen);
    p = buf + sizeof(struct fw_header);
    ret = read_to_buf(&kernel_info, p);
    if (ret)
        goto out_free_buf;

    writelen = sizeof(struct fw_header) + kernel_len;

    if (!combined) {
        if (rootfs_align)
            p = buf + writelen;
        else
            p = buf + rootfs_ofs;

        ret = read_to_buf(&rootfs_info, p);
        if (ret)
            goto out_free_buf;

        if (rootfs_align)
            writelen += rootfs_info.file_size;
        else
            writelen = rootfs_ofs + rootfs_info.file_size;

        if (add_jffs2_eof)
            writelen = pad_jffs2(buf, writelen);
    }

    if (!strip_padding)
        writelen = buflen;

    fill_header(buf, writelen);
    ret = write_fw(buf, writelen);
    if (ret)
        goto out_free_buf;

    ret = EXIT_SUCCESS;

 out_free_buf:
    free(buf);
 out:
    return ret;
}

/* Helper functions to inspect_fw() representing different output formats */
static inline void inspect_fw_pstr(char *label, char *str)
{
    printf("%-23s: %s\n", label, str);
}

static inline void inspect_fw_phex(char *label, uint32_t val)
{
    printf("%-23s: 0x%08x\n", label, val);
}

static inline void inspect_fw_phexpost(char *label,
                                       uint32_t val, char *post)
{
    printf("%-23s: 0x%08x (%s)\n", label, val, post);
}

static inline void inspect_fw_phexdef(char *label,
                                      uint32_t val, uint32_t defval)
{
    printf("%-23s: 0x%08x                  ", label, val);

    if (val == defval)
        printf("(== OpenWrt default)\n");
    else
        printf("(OpenWrt default: 0x%08x)\n", defval);
}

static inline void inspect_fw_phexexp(char *label,
                                      uint32_t val, uint32_t expval)
{
    printf("%-23s: 0x%08x ", label, val);

    if (val == expval)
        printf("(ok)\n");
    else
        printf("(expected: 0x%08x)\n", expval);
}

static inline void inspect_fw_phexdec(char *label, uint32_t val)
{
    printf("%-23s: 0x%08x / %8u bytes\n", label, val, val);
}

static inline void inspect_fw_phexdecdef(char *label,
                                         uint32_t val, uint32_t defval)
{
    printf("%-23s: 0x%08x / %8u bytes ", label, val, val);

    if (val == defval)
        printf("(== OpenWrt default)\n");
    else
        printf("(OpenWrt default: 0x%08x)\n", defval);
}

static inline void inspect_fw_pmd5sum(char *label, uint8_t *val, char *text)
{
    int i;

    printf("%-23s:", label);
    for (i=0; i<MD5SUM_LEN; i++)
        printf(" %02x", val[i]);
    printf(" %s\n", text);
}

static int inspect_fw(void)
{
    char *buf;
    struct fw_header *hdr;
    uint8_t md5sum[MD5SUM_LEN];
    struct board_info *board;
    int ret = EXIT_FAILURE;

    buf = malloc(inspect_info.file_size);
    if (!buf) {
        ERR("no memory for buffer!\n");
        goto out;
    }

    ret = read_to_buf(&inspect_info, buf);
    if (ret)
        goto out_free_buf;
    hdr = (struct fw_header *)buf;

    inspect_fw_pstr("File name", inspect_info.file_name);
    inspect_fw_phexdec("File size", inspect_info.file_size);

    if (ntohl(hdr->version) != HEADER_VERSION_V1) {
        ERR("file does not seem to have V1 header!\n");
        goto out_free_buf;
    }

    inspect_fw_phexdec("Version 1 Header size", sizeof(struct fw_header));

    if (ntohl(hdr->unk1) != 0)
        inspect_fw_phexdec("Unknown value 1", hdr->unk1);

    memcpy(md5sum, hdr->md5sum1, sizeof(md5sum));
    if (ntohl(hdr->boot_len) == 0)
        memcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum));
    else
        memcpy(hdr->md5sum1, md5salt_boot, sizeof(md5sum));
    get_md5(buf, inspect_info.file_size, hdr->md5sum1);

    if (memcmp(md5sum, hdr->md5sum1, sizeof(md5sum))) {
        inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(*ERROR*)");
        inspect_fw_pmd5sum("          --> expected", hdr->md5sum1, "");
    } else {
        inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(ok)");
    }
    if (ntohl(hdr->unk2) != 0)
        inspect_fw_phexdec("Unknown value 2", hdr->unk2);
    inspect_fw_pmd5sum("Header MD5Sum2", hdr->md5sum2,
                       "(purpose yet unknown, unchecked here)");
    if (ntohl(hdr->unk3) != 0)
        inspect_fw_phexdec("Unknown value 3", hdr->unk3);

    printf("\n");

    inspect_fw_pstr("Vendor name", hdr->vendor_name);
    inspect_fw_pstr("Firmware version", hdr->fw_version);
    board = find_board_by_hwid(ntohl(hdr->hw_id));
    if (board) {
        layout = find_layout(board->layout_id);
        inspect_fw_phexpost("Hardware ID",
                            ntohl(hdr->hw_id), board->id);
        inspect_fw_phexexp("Hardware Revision",
                           ntohl(hdr->hw_rev), board->hw_rev);
    } else {
        inspect_fw_phexpost("Hardware ID",
                            ntohl(hdr->hw_id), "unknown");
        inspect_fw_phex("Hardware Revision",
                        ntohl(hdr->hw_rev));
    }

    printf("\n");

    inspect_fw_phexdec("Kernel data offset",
                       ntohl(hdr->kernel_ofs));
    inspect_fw_phexdec("Kernel data length",
                       ntohl(hdr->kernel_len));
    if (board) {
        inspect_fw_phexdef("Kernel load address",
                           ntohl(hdr->kernel_la),
                           layout ? layout->kernel_la : 0xffffffff);
        inspect_fw_phexdef("Kernel entry point",
                           ntohl(hdr->kernel_ep),
                           layout ? layout->kernel_ep : 0xffffffff);
        inspect_fw_phexdecdef("Rootfs data offset",
                              ntohl(hdr->rootfs_ofs),
                              layout ? layout->rootfs_ofs : 0xffffffff);
    } else {
        inspect_fw_phex("Kernel load address",
                        ntohl(hdr->kernel_la));
        inspect_fw_phex("Kernel entry point",
                        ntohl(hdr->kernel_ep));
        inspect_fw_phexdec("Rootfs data offset",
                           ntohl(hdr->rootfs_ofs));
    }
    inspect_fw_phexdec("Rootfs data length",
                       ntohl(hdr->rootfs_len));
    inspect_fw_phexdec("Boot loader data offset",
                       ntohl(hdr->boot_ofs));
    inspect_fw_phexdec("Boot loader data length",
                       ntohl(hdr->boot_len));
    inspect_fw_phexdec("Total firmware length",
                       ntohl(hdr->fw_length));

    if (extract) {
        FILE *fp;
        char *filename;

        printf("\n");

        filename = malloc(strlen(inspect_info.file_name) + 8);
        sprintf(filename, "%s-kernel", inspect_info.file_name);
        printf("Extracting kernel to \"%s\"...\n", filename);
        fp = fopen(filename, "w");
        if (fp)    {
            if (!fwrite(buf + ntohl(hdr->kernel_ofs),
                        ntohl(hdr->kernel_len), 1, fp)) {
                ERR("error in fwrite(): %s", strerror(errno));
            }
            fclose(fp);
        } else {
            ERR("error in fopen(): %s", strerror(errno));
        }
        free(filename);

        filename = malloc(strlen(inspect_info.file_name) + 8);
        sprintf(filename, "%s-rootfs", inspect_info.file_name);
        printf("Extracting rootfs to \"%s\"...\n", filename);
        fp = fopen(filename, "w");
        if (fp)    {
            if (!fwrite(buf + ntohl(hdr->rootfs_ofs),
                        ntohl(hdr->rootfs_len), 1, fp)) {
                ERR("error in fwrite(): %s", strerror(errno));
            }
            fclose(fp);
        } else {
            ERR("error in fopen(): %s", strerror(errno));
        }
        free(filename);
    }

 out_free_buf:
    free(buf);
 out:
    return ret;
}

int main(int argc, char *argv[])
{
    int ret = EXIT_FAILURE;
    int err;

    FILE *outfile;

    progname = basename(argv[0]);

    while ( 1 ) {
        int c;

        c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsjv:");
        if (c == -1)
            break;

        switch (c) {
        case 'a':
            sscanf(optarg, "0x%x", &rootfs_align);
            break;
        case 'B':
            board_id = optarg;
            break;
        case 'H':
            opt_hw_id = optarg;
            break;
        case 'E':
            sscanf(optarg, "0x%x", &kernel_ep);
            break;
        case 'F':
            layout_id = optarg;
            break;
        case 'W':
            opt_hw_rev = optarg;
            break;
        case 'L':
            sscanf(optarg, "0x%x", &kernel_la);
            break;
        case 'V':
            version = optarg;
            break;
        case 'v':
            fw_ver = optarg;
            break;
        case 'N':
            vendor = optarg;
            break;
        case 'c':
            combined++;
            break;
        case 'k':
            kernel_info.file_name = optarg;
            break;
        case 'r':
            rootfs_info.file_name = optarg;
            break;
        case 'R':
            sscanf(optarg, "0x%x", &rootfs_ofs);
            break;
        case 'o':
            ofname = optarg;
            break;
        case 's':
            strip_padding = 1;
            break;
        case 'i':
            inspect_info.file_name = optarg;
            break;
        case 'j':
            add_jffs2_eof = 1;
            break;
        case 'x':
            extract = 1;
            break;
        case 'h':
            usage(EXIT_SUCCESS);
            break;
        default:
            usage(EXIT_FAILURE);
            break;
        }
    }

    ret = check_options();
    if (ret)
        goto out;

    if (!inspect_info.file_name)
        ret = build_fw();
    else
        ret = inspect_fw();

 out:
    return ret;
}

/trunk/target/linux/ar7xx/base-files/etc/uci-defaults/network

#!/bin/sh
#
# Copyright (C) 2011 OpenWrt.org
#

[ -e /etc/config/network ] && exit 0

touch /etc/config/network

. /lib/functions/uci-defaults.sh
. /lib/ar71xx.sh

ucidef_set_interface_loopback

board=$(ar71xx_board_name)

case "$board" in
all0315n |\
all0258n |\
ja76pf2|\
ubnt-unifi-outdoor)
    ucidef_set_interface_lan "eth0 eth1"
    ;;

db120 |\
rb-2011l | \
rb-2011uas-2hnd)
    ucidef_set_interfaces_lan_wan "eth0.1 eth1" "eth0.2"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0t 2 3 4 5"
    ucidef_add_switch_vlan "eth0" "2" "0t 1"
    ucidef_add_switch "eth1" "1" "1"
    ucidef_add_switch_vlan "eth1" "1" "0 1 2 3 4 5"
    ;;

dir-825-b1|\
tew-673gru)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
    ucidef_add_switch "rtl8366s" "1" "1"
    ucidef_add_switch_vlan "rtl8366s" "1" "0 1 2 3 5t"
    ;;

nbg460n_550n_550nh)
    ucidef_set_interfaces_lan_wan "eth0" "eth1"
    ucidef_add_switch "rtl8366s" "1" "1"
    ucidef_add_switch_vlan "rtl8366s" "0" "0 1 2 3 5"
    ;;

rb-433 |\
rb-433u)
    ucidef_set_interfaces_lan_wan "eth1" "eth0"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "1 2 5"
    ;;

rb-450)
    ucidef_set_interfaces_lan_wan "eth1" "eth0"
    ucidef_add_switch "eth1" "1" "1"
    ucidef_add_switch_vlan "eth1" "1" "0 1 2 3 5"
    ;;

rb-450g |\
routerstation-pro)
    ucidef_set_interfaces_lan_wan "eth1" "eth0"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4"
    ;;

ap136 |\
rb-750gl |\
rb-751g |\
wzr-hp-g450h)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "0t 2 3 4 5"
    ucidef_add_switch_vlan "switch0" "2" "0t 1"
    ;;

rb-493g)
    ucidef_set_interfaces_lan_wan "eth0 eth1.1" "eth1.2"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4"
    ucidef_add_switch "switch1" "1" "1"
    ucidef_add_switch_vlan "switch1" "1" "0t 1 2 3 4"
    ucidef_add_switch_vlan "switch1" "2" "0t 5"
    ;;

wzr-hp-g300nh2 |\
pb92 |\
ap113)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0t 1 3 4 5"
    ucidef_add_switch_vlan "eth0" "2" "0t 2"
    ;;

tl-wdr4300|\
tl-wr1041n-v2)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0t 2 3 4 5"
    ucidef_add_switch_vlan "eth0" "2" "0t 1"
    ;;

tl-wr1043nd)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
    ucidef_add_switch "rtl8366rb" "1" "1"
    ucidef_add_switch_vlan "rtl8366rb" "1" "1 2 3 4 5t"
    ucidef_add_switch_vlan "rtl8366rb" "2" "0 5t"
    ;;

tl-wr2543n)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
    ucidef_add_switch_vlan "switch0" "2" "0 9t"
    ;;

tl-wr841n-v1|\
tl-wr941nd)
    ucidef_set_interface_raw "eth" "eth0"
    ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
    ;;

tl-wr841n-v8)
    ucidef_set_interfaces_lan_wan "eth1" "eth0"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4"
    ;;

wrt160nl)
    ucidef_set_interfaces_lan_wan "eth0" "eth1"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0 1 2 3 4 5"
    ;;

wzr-hp-g300nh)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
    ucidef_add_switch "switch0" "1" "1"
    ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
    ;;

all0305 |\
aw-nr580 |\
bullet-m |\
cap4200ag |\
eap7660d |\
rb-411 |\
tl-mr11u |\
tl-mr3020 |\
tl-mr3040 |\
tl-wa901nd |\
tl-wa901nd-v2 |\
tl-wr703n |\
wp543)
    ucidef_set_interface_lan "eth0"
    ;;

alfa-ap96 |\
alfa-nx |\
ap83 |\
jwap003 |\
pb42 |\
pb44 |\
routerstation|\
wpe72)
    ucidef_set_interfaces_lan_wan "eth1" "eth0"
    ;;

ap121 |\
ap121-mini |\
ap96 |\
airrouter |\
dir-600-a1 |\
dir-615-c1 |\
dir-615-e4 |\
ja76pf |\
rb-750 |\
rb-751 |\
tew-632brp |\
tew-712br |\
tl-mr3220 |\
tl-mr3220-v2 |\
tl-mr3420 |\
tl-wr741nd |\
tl-wr741nd-v4 |\
tl-wr841n-v7 |\
whr-g301n |\
whr-hp-g300n |\
whr-hp-gn |\
wzr-hp-ag300h)
    ucidef_set_interfaces_lan_wan "eth0" "eth1"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0 1 2 3 4"
    ;;

wzr-hp-g450h)
    ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0t 2 3 4 5"
    ucidef_add_switch_vlan "eth0" "2" "0t 1"
    ;;

ew-dorin)
    ucidef_set_interface_lan "eth0"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0 1 2 3"
    ;;

ew-dorin-router)
    ucidef_set_interfaces_lan_wan "eth0" "eth1"
    ucidef_add_switch "eth0" "1" "1"
    ucidef_add_switch_vlan "eth0" "1" "0 2 3"
    ;;

*)
    ucidef_set_interfaces_lan_wan "eth0" "eth1"
    ;;
esac

uci commit network

exit 0
OpenWrt
Wireless Freedom

Re: TP-Link MR3220V2

openwrt_user wrote:

Could someone post his .config as a starting point?
Also some few instructions would be adequate wink

beside editing "/trunk/target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr741nd-v4.c" is there any other modification needed?

just select profile mr3220 at menu config.


***
if needed you can download this:

mr3220-v2.config
https://www.box.com/s/x6mozis7kw5b9h86xhy4

OpenWrt
Wireless Freedom

Re: TP-Link MR3220V2

cindy it will be awesome if you prepare those files in "patch" form, so they could be committed by openwrt trunk itself...

48 (edited by GaDs 2012-11-25 12:14:47)

Re: TP-Link MR3220V2

Replaced the files as indicated, an error:

>make V=99 -j 3
Makefile:934: *** missing separator.  Stop.
make[5]: *** [image-prereq] Error 2
make[4]: *** [prereq] Error 2
make[3]: *** [target/linux/prereq] Error 2
make[2]: *** [/home/davn/OpenWrt/mr3220/trunk/staging_dir/target-mips_r2_uClibc-0.9.33.2/stamp/.target_prereq] Error 2
make[1]: *** [prereq] Error 2
make: *** [world] Error 2

Used mr3220-v2.config
Trunk 34325.

Re: TP-Link MR3220V2

I also have GaDs error even with trunk 34200. It fails at prereq.

the file is /trunk/tools/firmware-utils/src/mktplinkfw.c ?
minor typo?

Thanks Cindy for everything

Re: TP-Link MR3220V2

i have mr3220 and already patch openwrt mr3220 v2 (SUCCESS) but i have problem, i can't install kmod-video-core  kmod-video-uvc. please any one help me. thx