Posted: Wed Feb 27, 2008 16:41 Post subject: Adding USB support into firmware
Ok. I am working on creating a new firmware to incorporate USB support. These are highly experimental builds that I am doing. If they brick your router then I am not responsible. Make sure you understand that before downloading.
NOTE: I found that if you have a 4MB flash router then my firmware may brick your router. It is built against the nokaid but it goes up to 3.9MB in size. Another thread suggests that it may not load on 4MB flash routers properly. Tread with care if you have a 4MB flash router with USB support.
Anyways here is my current code. If the devs could take a look at them here are the usb.webconfig and usb.nvramconfig that I created. Please tell me if I did something wrong. Thanks.
EDIT: I should mention that I am using Brainslayers 9134 build as a base for my experimental builds. Yes I know. Using a test firmware for an experimental feature integration. I know that others have already done USB support however you can't disable it without flashing a different firmware. With mine I hope to be able to do that now.
EDIT: The USB startup script is done. It is loading all modules as expected. Build 4 will remove the debugging lines I've been using.
Make sure you read the readme.txt file in the root directory of the site! It contains the various options needed to enable usb support. It will be disabled by default.
Here is the output of dmesg with all modules enabled on a usb storage test
Quote:
usb.c: registered new driver usbdevfs
usb.c: registered new driver hub
uhci.c: USB Universal Host Controller Interface driver v1.1
PCI: Enabling device 01:03.0 (0000 -> 0001)
uhci.c: USB UHCI at I/O 0x100, IRQ 2
usb.c: new USB bus registered, assigned bus number 1
hub.c: USB hub found
hub.c: 2 ports detected
PCI: Enabling device 01:03.1 (0000 -> 0001)
uhci.c: USB UHCI at I/O 0x120, IRQ 2
usb.c: new USB bus registered, assigned bus number 2
hub.c: USB hub found
hub.c: 2 ports detected
PCI: Enabling device 01:03.2 (0000 -> 0002)
ehci_hcd 01:03.2: PCI device 1106:3104
ehci_hcd 01:03.2: irq 2, pci mem c000b000
usb.c: new USB bus registered, assigned bus number 3
ehci_hcd 01:03.2: USB 2.0 enabled, EHCI 1.00, driver 2003-Dec-29/2.4
hub.c: USB hub found
hub.c: 4 ports detected
SCSI subsystem driver Revision: 1.00
Initializing USB Mass Storage driver...
usb.c: registered new driver usb-storage
USB Mass Storage support registered.
Journalled Block Device driver loaded
SGI XFS with no debug enabled
usb.c: registered new driver usblp
printer.c: v0.13: USB Printer Device Class driver
vlan1: dev_set_allmulti(master, 1)
vlan1: add 01:00:5e:7f:ff:fa mcast address to master interface
hub.c: new USB device 01:03.2-1, assigned address 2
scsi0 : SCSI emulation for USB Mass Storage devices
Vendor: LEXAR Model: JUMPDRIVE SECURE Rev: 1000
Type: Direct-Access ANSI SCSI revision: 02
Attached scsi disk sda at scsi0, channel 0, id 0, lun 0
SCSI device sda: 502880 512-byte hdwr sectors (257 MB)
Partition check:
/dev/scsi/host0/bus0/target0/lun0: p1
WARNING: USB Mass Storage data integrity not assured
USB Mass Storage device found at 2
All modules are controlled via nvram settings. When changed they have to be committed otherwise they will revert back on next boot. I am aware that Brainslayer has released 9140. I don't plan on using that version right now. I will continue as is with 9134 until I get a proper build environment done.
Ok. Here is a build log for you guys.
Quote:
Brainslayer 9134 USB Enabled Builds
1:
* Added USB Modules
* Created startup script that will check against nvram variables
* WWW language strings file override test
* Inserted my own SSL certificate
2:
* Rewrite script -- crashed at the beginning?
* WWW language strings file override test fail -- try again
3:
* Make correction to typo in script
* Unable to add additional language strings -- remove
/www/lang_pack/english.js file
* Change conditionals -- I messed up!
* Added additional init checks at the beginning. Now we init all usb settings into nvram -- default to 0
4:
* Added OHCI modules for additional USB support
* Added additional nvram setting usb_ohci to control new OHCI module
* Added sections into bootup to load OHCI module
Thanks to braza for pointing out that we actually do need the OHCI one.
TODO:
Quote:
* Implement Web GUI support
-- OR --
* Implement shell script to be used with telnet/ssh access
* Implement UFS support?
Note: The Web GUI one is more streamlined than the shell script one but then again the latter is easier to implement and less likely to crash the http daemon.
DEFER to Eko 9180 firmware rebuild -- will release mini and nokaid versions with USB support.
If anyone wants me to insert their own SSL certificate then let me know. You will need to provide me with the public key and private key. If you can provide both unencrypted and encrypted keys then that would be great but I will at least need an unencrypted key. This is for the https support in the web gui.
usb.nvramconfig.txt
Description:
USB nvram config -- Not actually being used right now
It should. If BrainSlayer's 9134 std nokaid build works on your router then the usb support should also work. Obviously it is an "at your own risk" type firmware as I can't guarantee that it will work all over the place.
Here are my goal marks.
* Inclusion of the key usb and filesystem kernel modules
* Integration into the Web GUI -- You can enable and disable at will
* Add additional settings into nvram area so the change persists between reboots.
* Keep this under 4MB for mini, std, and nokaid builds
* Keep this under 2MB for micro builds
The last one is not likely as it is barely making it under 2MB as it is. voip isn't included here as it will exceed 4MB just with the size it is already.
Not right now. At the moment I am just focusing on the startup script and seeing if I can get that working properly. It will be configurable via nvram settings. Once that goes then I will try again with the Web GUI bit and hopefully get that to function. I still don't know why it did a segmentation fault but I'll figure that out when the time comes. I will at minimum put a shell script that the user can run that will allow them to enable/disable the features if I can't get the Web GUI to cooperate.
BTW, I would appreciate it if Eko or BrainSlayer could go ahead and take a look at my nvramconfig file and check to make sure it is formatted correctly. I have figured out most of it except for the last 2 arguments for each line. I don't know what they are for. I know that it goes like this...
nvram setting, description, setting type, number of options or range, possible choices, ...(more choices) then I am stuck on the last two. Right now I just have them set to false and 0 in that order.
You should ask Cascade to collaberate with you on this....he did a USB build which is linked in another topic, for a friend of his, and improved upon it due to requests from other members of this board. I am positive he will be able to help you with this. You should as Rekoil as well, he had a USB build using an older RC. With all 3 of you working together, I am sure good things will come of this.
Yes. I'm aware of those but they are not quite what I was looking for. Adding USB support is easy enough but the goal I want is to make it so that it can be shut off after flashing. This can't be done with their firmware. In order to accomplish this I have to create settings in nvram. I would actually like it if the devs could comment on how the nvramconfig file is supposed to be formatted so that I know.
if you are going to go as far as setting up variables in nvram, you should probably also go as far as correctly setting up the src/router/services/sysinit/sysinit-*.c and recompile the firmware. By recompiling you can use the native sysinit and nvram for the usb startup. You would also get the native usb modules for the 2.4.35 kernel, and just as info the read/write speed will probably double that of the 2.4.30 modules availabe through the ipkgs. I also noticed that the usb light will work correctly when using the CONFIG_USB=y for the src/router/.config_* and fixing some small issues in the sysinit-broadcom.c for a wrt350n.
I would leave it up to the sysinit to load the various usb modules based on nvram settings, and have a startup script to load the fs modules and do the directory mounting. This way you can get more options for file systems and such.
shinji257, should mention that I have already do what I have stated in my post above. I have been trying to formalize instruction for creating a build environment, compiling the firmware from svn, built in usb support using the sysinit-broadcom.c (only type of routers I have to test) and native modules for 2.4.35, create a patch or process to incorporate my changes into a svn checkout for other users to compile. I have not gotten to the point of creating a web interface, but I can use the cli to enable/disable the loading of usb modules at startup. I am just short on time and will be travelling the next few weeks and unable to work further. I will see what I can put up this weekend, maybe something can help you.
shinji257, should mention that I have already do what I have stated in my post above. I have been trying to formalize instruction for creating a build environment, compiling the firmware from svn, built in usb support using the sysinit-broadcom.c (only type of routers I have to test) and native modules for 2.4.35, create a patch or process to incorporate my changes into a svn checkout for other users to compile. I have not gotten to the point of creating a web interface, but I can use the cli to enable/disable the loading of usb modules at startup. I am just short on time and will be travelling the next few weeks and unable to work further. I will see what I can put up this weekend, maybe something can help you.
That would be great if you could do that. If you could also let me know which parts of the repository I need I can then create my own build environment. The only reason that I am doing it using the firmware modification kit is because I can't seem to get a proper environment started. Another advantage is that making full integration into the web interface will be loads easier since I will have access to all of the files and not just the ones visable via the rootfs (the firmware kit doesn't extract all of them )
Just so you know I am almost done with the usb startup script. I think I am at my final build really for that part of it. My 2nd one didn't go so well. The first flash failed (router went to recovery mode automatically). I reflashed it using the tool and it worked so...
@kodo -- You will keep dd-wrt. The goal is full integration for usb support.
I am building for a wrt350n using the linux.v24_2 branch. The write of using Microsoft VirtualPC and the mini.iso from debian to get a working build environment was posted http://www.dd-wrt.com/phpBB2/viewtopic.php?t=26737 which I summarized below
Code:
I created a virtual machine using MS VPC 2007. I created a 10gig virtual drive and set the virtual machine up for 512mb of ram.
Used Tiny CD of current stable version of Debian (http://www.debian.com/distrib/netinst).
***This will install a basic console based debian linux system.***
-Choose language and click continue
-Choose language and click continue
-Select a keyboard layout and click continue
-set Hostname: to dd-wrt and click continue
-Leave Domain name: blank and click continue
-Choose a mirror county location and click continue
-Choose a mirror sight and click continue
-Enter HTTP proxy info if needed and click continue
-Choose Guided - use entire disk and click continue
-Select partition and click continue
-Select Separate /home partition and click continue (makes it easy to backup/restore src if needed)
-Select Finish partitioning and write changes to disk and click continue
-Select Yes to write changes and click continue
-Configure time zone and click continue
-Enter a root password and verfiy and click continue
-Enter dd-wrt and Full name for new user and click continue
-Enter dd-wrt for your account and click continue
-Enter a password and verify and click continue
-Select No to the Configuring popularity-contest and click continue
-For Software selection uncheck all boxes except for Standard System, Standard System should be the only one check and click continue
-Select Yes and click continue to install the GRUB boot loader to mbr
-Install is finished, click continue to reboot
After the vm reboots, login with username=root and the password set during install. Issue the following apt-get commands to setup the environment.
I use the following script after a clean debain install to get the required apps, toolchain, and src from svn
wget http://www.dd-wrt.com/dd-wrtv2/downloads/others/sourcecode/toolchains/toolchains.x86.debian.sp1.tar.bz2
tar -jxf toolchains.x86.debian.sp1.tar.bz2
cd DD-WRT/
svn co svn://svn.dd-wrt.com/DD-WRT/tools
svn co svn://svn.dd-wrt.com/DD-WRT/opt
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/Makefile?format=raw
mv Makefile\?format\=raw Makefile
cd src/
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/src/cy_conf.h?format=raw
mv cy_conf.h\?format\=raw cy_conf.h
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/src/cy_conf.mak?format=raw
mv cy_conf.mak\?format\=raw cy_conf.mak
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/src/Makefile?format=raw
mv Makefile\?format\=raw Makefile
svn co svn://svn.dd-wrt.com/DD-WRT/src/include.bcm
svn co svn://svn.dd-wrt.com/DD-WRT/src/include.v23
svn co svn://svn.dd-wrt.com/DD-WRT/src/include.v24
svn co svn://svn.dd-wrt.com/DD-WRT/src/led
svn co svn://svn.dd-wrt.com/DD-WRT/src/ses
svn co svn://svn.dd-wrt.com/DD-WRT/src/shared
svn co svn://svn.dd-wrt.com/DD-WRT/src/router
svn co svn://svn.dd-wrt.com/DD-WRT/src/squashfs-tools
svn co svn://svn.dd-wrt.com/DD-WRT/src/switch
svn co svn://svn.dd-wrt.com/DD-WRT/src/tools
svn co svn://svn.dd-wrt.com/DD-WRT/src/wl
cd linux/brcm
svn co svn://svn.dd-wrt.com/DD-WRT/src/linux/brcm/linux.v24_2
and remove the current code in /src/router/services/sysinit/sysinit-broadcom.c for the ifdef HAVE_USB section around line 870 and replaced it with the following
Thanks! This will give me a head start on this one. Since I know my WL-500g router will work with the v2 kernel then that is the one I will primarily work with.
BTW, Since this does not appear to load any of the graphics stuff I will boot the VM headless and just use PuTTY to gain access to the machine once it is done setting it up. I am going to use VirtualBox to do all of this so...
I am building for a wrt350n using the linux.v24_2 branch. The write of using Microsoft VirtualPC and the mini.iso from debian to get a working build environment was posted http://www.dd-wrt.com/phpBB2/viewtopic.php?t=26737 which I summarized below
I use the following script after a clean debain install to get the required apps, toolchain, and src from svn
wget http://www.dd-wrt.com/dd-wrtv2/downloads/others/sourcecode/toolchains/toolchains.x86.debian.sp1.tar.bz2
tar -jxf toolchains.x86.debian.sp1.tar.bz2
cd DD-WRT/
svn co svn://svn.dd-wrt.com/DD-WRT/tools
svn co svn://svn.dd-wrt.com/DD-WRT/opt
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/Makefile?format=raw
mv Makefile\?format\=raw Makefile
cd src/
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/src/cy_conf.h?format=raw
mv cy_conf.h\?format\=raw cy_conf.h
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/src/cy_conf.mak?format=raw
mv cy_conf.mak\?format\=raw cy_conf.mak
wget http://svn.dd-wrt.com:8000/dd-wrt/browser/src/Makefile?format=raw
mv Makefile\?format\=raw Makefile
svn co svn://svn.dd-wrt.com/DD-WRT/src/include.bcm
svn co svn://svn.dd-wrt.com/DD-WRT/src/include.v23
svn co svn://svn.dd-wrt.com/DD-WRT/src/include.v24
svn co svn://svn.dd-wrt.com/DD-WRT/src/led
svn co svn://svn.dd-wrt.com/DD-WRT/src/ses
svn co svn://svn.dd-wrt.com/DD-WRT/src/shared
svn co svn://svn.dd-wrt.com/DD-WRT/src/router
svn co svn://svn.dd-wrt.com/DD-WRT/src/squashfs-tools
svn co svn://svn.dd-wrt.com/DD-WRT/src/switch
svn co svn://svn.dd-wrt.com/DD-WRT/src/tools
svn co svn://svn.dd-wrt.com/DD-WRT/src/wl
cd linux/brcm
svn co svn://svn.dd-wrt.com/DD-WRT/src/linux/brcm/linux.v24_2
The initial steps to get debian installed are fine. However the above script is flawed. You forgot that by the time I run that script I am running as root. The very first line uses sudo then the third line runs apt-get to get sudo. Also you forgot the install keyword for that line. Just thought to let you know. I think I can work the rest myself but this is something better done as two scripts. One script as root for initial setup then the other to finish setting it up since all the building should be done on a regular user account anyways.