evbmips HOWTO by DuratarskeyK shadowpilot34@gmail.com This howto describes an easy way of building a netbsd kernel and userland for atheros boards based on mips cpus found on many routers nowadays. I use gentoo linux to crosscompile for my router - ASUS RT-G32. Sadly, but wireless is not working yet, because of some bug in openhal, and routers spi flash is not detected too, though you won't need it if you will use nfs for userland. 1. Get the sources export CVS_RSH="ssh" export CVSROOT="anoncvs@anoncvs.NetBSD.org:/cvsroot" cvs checkout -r netbsd-5 -D20091101 -P src NOTE: At the moment, O32 ABI support in latest netbsd kernels is broken, so you'll have to use sources before 2009/12(that's when they got broken). 2. Building the toolchain This is done with 1 simple command: ./build.sh -m evbmips-eb tools 3. Configuring the kernel Go to sys/arch/evbmips/conf. I used AP30 config, because it was the closest one for my device, but you'll need to change some things for your router: cp AP30 MYKERNEL Now open MYKERNEL with your favourite text editor. I changed those things for my router: options WISOC_AR5315 #my router's wisoc config netbsd root on ae0 type nfs # this way the kernel will use root file system via nfs If you are not going to use debugging, comment out everything in Debugging options. This will make your kernel lighter. I also disabled Realtek and generic phy support. Save the changes and open std.atheros. You'll need to know the start address where your board's bootloader loads kernel. On my router It's redboot and the address is 0x80041000. Change this line accordingly: makeoptions DEFTEXTADDR="0x80041000" 4. Compiling the kernel This is easy. Just issue the following command in the sources directory: ./build.sh -u -m evbmips-eb kernel=AP30 If everything goes fine, you'll get a netbsd kernel in sys/arch/evbmips/compile/obj/AP30. But before uploading it to the board you need to convert it to pure binary, because most bootloaders don't understand netbsd kernel format. Use the following command: ~/path/to/sources/tooldir*/bin/mipseb--netbsd-objcopy -S -O binary netbsd netbsd.bin 5. Compiling userland I used the following command to do this: ./build.sh -U -u -m evbmips-eb -V MKCRYPTO_IDEA=no distribution I used MKCRYPTO_IDEA=no, because it failed to compile otherwise. This step will take some time. Read netbsd handbook on how to configure userland. 6. Setting up nfs and dhcp servers If you don't have nfs or dhcp server on your computer, install it first. Consult with nfs howto from your OS. For dhcp, I use ISC one. Edit /path/to/dhcpd.conf: subnet ......... { host router { hardware ethernet xx:xx:xx:xx:xx:xx; #mac address of router, you can find it in redboot fixed-address 192.168.0.3; #ip address your router will have next-server 192.168.0.1; #ip address of your nfs server option root-path "/path/to/userland"; } } Restart dhcpd. Now edit /etc/exports(That's the file from gentoo) /path/to/userland 192.168.0.3/24(rw,async,no_root_squash,no_subtree_check) Restart nfs. 7. Uploading the kernel to the board For redboot do this: Turn on the device and connect to it via serial. I use minicom to do this. When you'll see the request to press ^C do it. You can load the kernel via tftp or via serial(slow method). For tftp you'll need to do this: ip_address -l router_ip/mask -h tftp_server_ip load -r -b 0x80041000 netbsd.bin netbsd.bin should be in your tftp server directory. If you are too lazy to set up a tftp server you can use serial to load the kernel: load -r -b 0x80041000 -m xmodem In minicom press Ctrl-A-S, choose xmodem and select netbsd.bin in the file list. Loading takes up from 3 to 5 minutes. After loading kernel into ram, you'll need to burn it onto the flash. Use those commands to do this: fis init choose y fis create netbsd After the kernel was uploaded, you'll need to change boot script. Do this: fconfig Run script at boot: true Now type fis load netbsd(enter) go(enter) (enter) Boot script timeout (1000ms resolution): 5 (How long redboot should wait before loading kernel) Use BOOTP for network configuration: false (leave it) Gateway IP address: ......... (leave it) Local IP address: .......... (leave it) Local IP address mask: ............ (leave it) Default server IP address: ......... (leave it) Console baud rate: 9600 (I changed it to 115200) GDB connection port: 9000 (leave it) Force console for special debug messages: false (leave it) Network debug at boot time: false (leave it) Update RedBoot non-volatile configuration - continue (y/n)? y After Redboot has done configuring, type reset. 8. Congrats. If nothing is wrong, you now have a working netbsd on your router. Special thanks to people from #netbsd(jakllsch, YazzY, ASau) on FreeNode and port-mips mailing list.