OpenWrt Forum Archive

Topic: WNDR3700 U-boot with USB Support?

The content of this topic has been archived on 26 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I am just wondering if anyone have sucessfully built an uboot image that have support of booting from usb devices on the WNDR3700?
My idea would be to direcly boot from the usb device like this.

# setenv bootargs_usb 'console=ttyS0,115200 ro root=/dev/sda1 init=/etc/preinit rootwait'
# setenv bootcmd_usb 'bootargs $(bootargs_usb); usb start; ext2load usb 0 0x800000 /image/uImage; bootm 0x800000'
# setenv bootcmd 'run bootcmd_usb'
# saveenv

But U-boot that comes with the WNDR3700 does not have usb support, so "usb start" is not there nor ext2load either.
NetGear have provided us the sources for the bootloader that can be found here ftp://downloads.netgear.com/files/GPL/W … ar.bz2.zip

It's indeed a very old version of uboot that have very limited support of USB controllers,
the only supported is PIP405, MIP405, MPC5200 i don't know what controller the WNDR3700 is using
but if it's one of the supported maybe it would be possible to enable CONFIG_USB_UHCI & CONFIG_USB_STORAGE during compilation?

I have not been able to compile the bootloader, i guess i am using too new version of mipsel-linux-gnu-binutils & mipsel-linux-gnu-gcc. Anyhow i were just wondering if anyone here have sucessfully built a uboot image with usb support, and if so i would really love if you could share it with me big_smile

(Last edited by Insecure on 18 Feb 2011, 14:25)

Finally after alot of work i managed to build u-boot, i installed Debian 6 netinstall (minimal) in a separate installation.
And in the Debian system i did the following...

Download Embedded Linux Development Kit 4.0
contains all the needed tools to setup a mips-cross compiler

# wget ftp://ftp.denx.de/pub/eldk/4.0/mips-lin … -01-17.iso
# mkdir /eldk
# mkdir /mnt/eldk
# mount -o loop mips-2006-01-17.iso /mnt/eldk
# /mnt/eldk/install -d /eldk

Replace mips-linux-gcc-4.0.0 with mips-linux-gcc-3.4.6 or else uboot won't build

# cd /eldk
# wget http://www.linux-mips.org/pub/linux/mip … 1.i386.rpm
# rpm2cpio gcc-mips-linux-3.4.6-1.i386.rpm | cpio -vid

Remove unnecessary files

# rm gcc-mips-linux-3.4.6-1.i386.rpm
# rm version
# rm -r /eldk/mips_4KC*

Now let's copy everything to /

# cp -r /eldk/* /

We do also need to install gcc-3.4 unless uboot won't build, we are chaning the repository to lenny since the repository bu default does not have gcc-3.4

# nano /etc/apt/sources.lst
deb http://ftp.debian.org/debian lenny main
deb-src http://ftp.debian.org/debian lenny main

# apt-get update
# apt-get install make gcc-3.4 bzip2

Download & extract uboot
ftp://downloads.netgear.com/files/GPL/W … ar.bz2.zip
# cd WNDR3700-U-boot-GPL
# make wndr3700u_config
# make

This will sucessfully build u-boot and will provide us with u-boot.bin to update our bootloader we do this.

1) Start a tftp server on the PC connected to the router & place u-boot.bin in the tftp-server root
#ifconfig eth0 192.168.1.100

2) Connect you'r serial interface to the router and start the router
ar7100> set serverip 192.168.1.100
ar7100> tftp 0x80010000 u-boot.bin
ar7100> erase 0xbf000000 +0x70000
ar7100> cp.b 0x80010000 0xbf000000 0x50000
ar7100> reset

---------------------------------------

Well now we can compile u-boot let's see if we can get USB & EXT2 support.
I have also created an tar.gz file containing the following changes over here http://unlogical.net/files/misc/wndr370 … xt2.tar.gz

# nano include/config.h

#define CONFIG_USB_UHCI 1
#define CONFIG_USB_STORAGE 1
#define CONFIG_DOS_PARTITION 1 /* Needed or else CFG_CMD_EXT2 won't work */

# nano include/configs/wndr3700u.h
* Change Line 194 to this *

#define CONFIG_COMMANDS (( CONFIG_CMD_DFL   | CFG_CMD_MII     | CFG_CMD_PING  \
   | CFG_CMD_NET | CFG_CMD_PCI     | CFG_CMD_ENV | CFG_CMD_FLASH | CFG_CMD_LOADS \
   | CFG_CMD_RUN | CFG_CMD_LOADB   | CFG_CMD_ELF | CFG_CMD_BSP | CFG_CMD_JFFS2 \
   | CFG_CMD_EXT2 | CFG_CMD_USB ))

#make

---------

However the compilation will fail with the following errors http://pastebin.com/HnKZmBGY

(Last edited by Insecure on 19 Feb 2011, 22:11)

Is there enough space to include all the code needed for this, on 128KiB Flash:

http://wiki.openwrt.org/toh/tp-link/tl- … ash.layout

But the dockstar comes with USB-Support! Check http://jeff.doozan.com/debian/
There some scripts, one is linking to binaries on his homepage. So he did this for the Dockstar, but I do not know if from scratch or if the original bootloader already had that kind of functionality.
You need to address devices connected with the USB, and also files on a ext2 or ext3 filesystem.
Look at the source-code for the dockstar, you should be able to understand it and then apply the same for ar71xx. No more extroot ;-)

The reason the compile fails is because there's no lowlevel USB driver for the ar7100 board/cpu
So here's where i would need help, i don't know if it would be worth a shot asking NetGear if they could provide us with some code.
Or could we port it from OpenWRT? linux/ar71xx/files/drivers/usb/host/

(Last edited by Insecure on 19 Feb 2011, 20:05)

That's funny, I was also trying to build wndr3700 u-boot today. For a different reason though, I am planning to use it for a DIR-825 with the 128MB RAM mod. After some failed attempts with crosstool(-ng) I found that it is possible to use a vanilla ELDK (I used http://ftp.denx.de/pub/eldk/4.1/mips-li … 01-21.iso)

You have to fix up some minor problems, though:

diff -r -u WNDR3700-U-boot-GPL/board/ar7100/wndr3700u/wndr3700u_pci.c WNDR3700-U-boot-GPL_mod/board/ar7100/wndr3700u/wndr3700u_pci.c
--- WNDR3700-U-boot-GPL/board/ar7100/wndr3700u/wndr3700u_pci.c    2009-08-04 06:07:39.000000000 +0200
+++ WNDR3700-U-boot-GPL_mod/board/ar7100/wndr3700u/wndr3700u_pci.c    2011-02-19 20:43:31.000000000 +0100
@@ -49,6 +49,8 @@
 static int  ar7100_local_read_config(int where, int size, uint32_t *value);
 static int  ar7100_local_write_config(int where, int size, uint32_t value);
 
+static int ar7100_pci_write_config(struct pci_controller *hose, pci_dev_t dev, int offset, u32 value);
+
 /*
 ** This is where the merlin devices in slot 0 and 1 are initialized.
 ** Note that for other boards derived from AP-94 this should be customized
diff -r -u WNDR3700-U-boot-GPL/net/nmrp.c WNDR3700-U-boot-GPL_mod/net/nmrp.c
--- WNDR3700-U-boot-GPL/net/nmrp.c    2009-08-04 06:07:43.000000000 +0200
+++ WNDR3700-U-boot-GPL_mod/net/nmrp.c    2011-02-19 20:51:06.000000000 +0100
@@ -134,10 +134,10 @@
     switch (NmrpState) {
     case STATE_LISTENING:
         xp = pkt;
-        *((ushort *) pkt)++ = 0;
-        *((uchar *) pkt)++ = (NMRP_CODE_CONF_REQ);
-        *((uchar *) pkt)++ = 0;
-        *((ushort *) pkt)++ = htons(6);
+        *((ushort *) pkt) = 0; pkt++;
+        *((uchar *) pkt) = (NMRP_CODE_CONF_REQ); pkt++;
+        *((uchar *) pkt) = 0; pkt++;
+        *((ushort *) pkt) = htons(6); pkt++;
 
         len = pkt - xp;
         (void)NetSendPacket((uchar *) NetTxPacket, eth_len + len);
@@ -149,10 +149,10 @@
         break;
     case STATE_CONFIGING:
         xp = pkt;
-        *((ushort *) pkt)++ = 0;
-        *((uchar *) pkt)++ = (NMRP_CODE_TFTP_UL_REQ);
-        *((uchar *) pkt)++ = 0;
-        *((ushort *) pkt)++ = htons(6);
+        *((ushort *) pkt) = 0; pkt++;
+        *((uchar *) pkt) = (NMRP_CODE_TFTP_UL_REQ); pkt++;
+        *((uchar *) pkt) = 0; pkt++;
+        *((ushort *) pkt) = htons(6); pkt++;
         len = pkt - xp;
         (void)NetSendPacket((uchar *) NetTxPacket, eth_len + len);
         StartTftpServerToRecoveFirmware();
@@ -160,20 +160,20 @@
     case STATE_KEEP_ALIVE:
         printf("NMRP Send Keep alive REQ\n");
         xp = pkt;
-        *((ushort *) pkt)++ = 0;
-        *((uchar *) pkt)++ = (NMRP_CODE_KEEP_ALIVE_REQ);
-        *((uchar *) pkt)++ = 0;
-        *((ushort *) pkt)++ = htons(6);
+        *((ushort *) pkt) = 0; pkt++;
+        *((uchar *) pkt) = (NMRP_CODE_KEEP_ALIVE_REQ); pkt++;
+        *((uchar *) pkt) = 0; pkt++;
+        *((ushort *) pkt) = htons(6); pkt++;
         len = pkt - xp;
         (void)NetSendPacket((uchar *) NetTxPacket, eth_len + len);
         break;
     case STATE_CLOSING:
         printf("NMRP Send Closing REQ\n");
         xp = pkt;
-        *((ushort *) pkt)++ = 0;
-        *((uchar *) pkt)++ = (NMRP_CODE_CLOSE_REQ);
-        *((uchar *) pkt)++ = 0;
-        *((ushort *) pkt)++ = htons(6);
+        *((ushort *) pkt) = 0; pkt++;
+        *((uchar *) pkt) = (NMRP_CODE_CLOSE_REQ); pkt++;
+        *((uchar *) pkt) = 0; pkt++;
+        *((ushort *) pkt) = htons(6); pkt++;
         len = pkt - xp;
         NmrpSetTimeout(NMRP_CODE_CLOSE_ACK, (1 * CFG_HZ),
                    Nmrp_Closing_Timeout);

I didn't follow the entire topic, but is there a particular reason to not use the u-boot packages within openwrt? They can be compiled with the openwrt buildroot and do not require any special toolchains.

jow wrote:

I didn't follow the entire topic, but is there a particular reason to not use the u-boot packages within openwrt? They can be compiled with the openwrt buildroot and do not require any special toolchains.

Because it's not for the WNDR3700?

openwrt@devel-env:~/wndr3700$ du -ah package/uboot-ar71xx/ | grep -v svn
4.0K    package/uboot-ar71xx/Makefile
12K     package/uboot-ar71xx/files/drivers/net/ag71xx.h
20K     package/uboot-ar71xx/files/drivers/net/ag71xx.c
20K     package/uboot-ar71xx/files/drivers/net/phy/rtl8366_mii.c
8.0K    package/uboot-ar71xx/files/drivers/net/phy/rtl8366.h
104K    package/uboot-ar71xx/files/drivers/net/phy
216K    package/uboot-ar71xx/files/drivers/net
8.0K    package/uboot-ar71xx/files/drivers/spi/ar71xx_spi.c
60K     package/uboot-ar71xx/files/drivers/spi
316K    package/uboot-ar71xx/files/drivers
8.0K    package/uboot-ar71xx/files/cpu/mips/ar71xx_serial.c
60K     package/uboot-ar71xx/files/cpu/mips
100K    package/uboot-ar71xx/files/cpu
8.0K    package/uboot-ar71xx/files/include/configs/nbg460n.h
60K     package/uboot-ar71xx/files/include/configs
4.0K    package/uboot-ar71xx/files/include/asm-mips/ar71xx_gpio.h
16K     package/uboot-ar71xx/files/include/asm-mips/ar71xx.h
88K     package/uboot-ar71xx/files/include/asm-mips
188K    package/uboot-ar71xx/files/include
4.0K    package/uboot-ar71xx/files/board/zyxel/nbg460n/Makefile
4.0K    package/uboot-ar71xx/files/board/zyxel/nbg460n/u-boot.lds
4.0K    package/uboot-ar71xx/files/board/zyxel/nbg460n/config.mk
4.0K    package/uboot-ar71xx/files/board/zyxel/nbg460n/lowlevel_init.S
4.0K    package/uboot-ar71xx/files/board/zyxel/nbg460n/nbg460n.c
92K     package/uboot-ar71xx/files/board/zyxel/nbg460n
132K    package/uboot-ar71xx/files/board/zyxel
172K    package/uboot-ar71xx/files/board
816K    package/uboot-ar71xx/files
4.0K    package/uboot-ar71xx/patches/001-ar71xx.patch
4.0K    package/uboot-ar71xx/patches/011-switch-rtl8366sr.patch
4.0K    package/uboot-ar71xx/patches/010-enet-ag71xx.patch
4.0K    package/uboot-ar71xx/patches/002-ar71xx-spi.patch
72K     package/uboot-ar71xx/patches
940K    package/uboot-ar71xx/
openwrt@devel-env:~/wndr3700$

Did not the OP mention wndr3700 with usb support?

When you are done, would you be so kind as to barf some knowledge into the wiki?

http://wiki.openwrt.org/doc/techref/bootloader

It will be made pretty some day in the future. Some deep links to denx would already help.

jow wrote:

I didn't follow the entire topic, but is there a particular reason to not use the u-boot packages within openwrt?

What packages are you referring to? The only ar71xx stuff I can find seems to be for the Zyxel nbg460n/550n/550nh. What am I missing?

Obviously the netgear changes must be added to it first, it should be easy to extract them by diffing the gpl source against the vanilla release of u-boot.

jow wrote:

Obviously the netgear changes must be added to it first, it should be easy to extract them by diffing the gpl source against the vanilla release of u-boot.

I've been looking into that and though it looks quite easy, it's actually not!

First of all the WNDR3700 code is not based on the release version of u-boot 1.1.4. After a bit of digging I found a git snapshot from 06/Apr/2006 which comes somewhat close:
http://git.denx.de/cgi-bin/gitweb.cgi?p … 23662182a8

Turns out the guys at Netgear not only added Atheros-specific code (ar7100, ap94) but also an old squashfs patch (possibly the same as tuxbox) as well as their NMRP network recovery driver stuff (btw, official squashfs support for u-boot has just recently been proposed; maybe one can use that once it's ready.)

The main problem however is the age of the code. I did some comparisons with u-boot-2010.12; the old version is hugely different and by the looks of it would probably require some major rewrites.

Sorry to interrupt, but is the Kernel on a SquashFS-formated partition (what is the correct term for this anyway, blockdevice-partition??) or is it just g'ziped on the raw flash-memory:

http://wiki.openwrt.org/toh/tp-link/tl- … ash.layout

I thought kernel is g'ziped and the system is on SquashFS (and overlay on JFFS2). Am i wrong?

I did compare NetGears wndr3700 u-boot with the revision wimsop provided us with.
I have made a tar.gz containing only added files & changed files NetGear have made - you can grab it here if anyone is interested
http://unlogical.net/files/misc/wndr370 … iff.tar.gz

(Last edited by Insecure on 21 Feb 2011, 21:23)

Infact i wonder if it would be easier to base the code from uboot-ar71xx/files/board/zyxel/nbg460n instead of merging the old wndr3700 code.
I don't know how much the wndr3700 and nbg460n have in common, if we could do that i think it would be less painful since it seems not to use that much code.
The first step would be to get the most basic functionality eg *no NMRP* - With that said i need to address that my programming knowledge is very limited and even more when it comes to hardware, but i am however willing to experiment.

I've only got a v1 or I'd dd the mtd0 and send it your way.

The discussion might have continued from here.