Setting up a tool chain for Openwrt Backfire on a NSLU2 (Slug)
and learning to use makefiles to compile C programs
- - - - - beware! - early versions! - - - - -
But also see the new notes on using OpenWrt Attitude adgustment (November 2012)
1) Compile helloworld for an nslu2 (slug) - done
2) Compile usbscale.c for a Stamps.com Model 510 5LB Scale - done
3) Compile Blassic basic - done
This is the best toolchain tutorial I have found (thanks!) - it is old and does not seem to be maintained and might disappear so my backup is here
Bt following the tutorial I tested helloworld.c in Ubuntu - it worked.
My Ubuntu 12 Backfire toolchain folder looks like this -
The helloworld.c and makefile in a folder src and this could be compiled OK for the Ubuntu host.
I copied the src folder into a new folder helloworld within the the backfire/package/ folder in the toolchain.
The helloworld folder contained the special Openwrt toolchain below.
It seems that if you have a folder called "src" containing .c and .h files plus a makefile that compiles OK in the host then you can use this same folder without modifications.
This "src" folder is then be enclosed within a folder called <program-name> in /backfire/package/
The folder <program-name> has the simple name of the program being built for OpenWrt (in this case "helloworld") and it must also contain the special OpenWrt makefile
OpenWrt Makefile for helloworld program thanks! - - - - replace ______ by tabs (This download of the file shown below has real tabs)
# Name and release number of this package
# This specifies the directory where we're going to build the program.
# Specify package information for this program.
# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
# Specify what needs to be done to prepare for building the package.
# We do not need to define Build/Configure or Build/Compile directives
# Specify where and how to install the program. Since we only have one file,
# This line executes the necessary commands to compile our program.
To compile first cd to the backfire root folder and do -
Select the utility helloworld with a "y" so a star appears in the check box - save
make package helloworld V=99 ( V=99 so you can see what happens)
I think this also works (?) make package/helloworld/compile V=99
In backfire/bin/ixp4xx/packages will be found helloworld_1_ixp4xx.ipk
ftp this to a folder in the slug and in the same folder do
opkg install helloworld_1_ixp4xx.ipk
this puts helloworld in /bin so it can be called from any program.
NB - update -
I found I got errors
/usr/sbin/helloworld: line 1: syntax error: unexpected "("
It is important that the folder /user/backfire/packages/helloworld/src contains ONLY helloworld.c and the small makefile
and NO binary or .o file
When I create a new utility for I2C (for example) I rename the new program helloworld and put it in here.
- when you get to opkg install helloworld_1_ixp4xx.ipk you get a new helloworld in the bin folder of the Slug
- rename it to the new program name
NB I also use - - - make package/helloworld/compile V=99
These were compiled for backfire Slug -
Even though I have created a working toolchain containing
I used http://downloads.openwrt.org/backfire/10.03.1/ixp4xx_generic/openwrt-nslu2-squashfs.bin
because the detail of setting up all the files was difficult - but see below - I had to get it to work for mjpg-streamer to run OK
I used upslug2 in Linux Mint in VMWare to send the file openwrt-nslu2-squashfs.bin to the slug - upslug2 could not find the Slug on the network in Ubuntu
To get my slug into upgrade mode was tricky - in the end I held down the power and reset keys then turned on the power.
When the orange light changed its shade of orange to a bit darker orange I released the reset key.
The led then flashed green/orange and the Slug could be re-flashed - (it never went green/orange while the reset was still pressed but just proceeded to boot the slug)
- But see below for a fix!
This program needed libusb_1.0 which Backfire uses - earlier OpenWrts use libusb_0.1 do not - hence the upgrade.
This was compiled with the same OpenWrt makefile structure as above - I just changed helloworld to usbscale in the makefile.
I first proved that the src folder worked in the Ubuntu host
(the scales measured weight when plugged in)
I then just enclosed the src folder and the new makefile in a folder called usbscale and put this in backfire/package/
It compiled as an ipkg as here and was transfered to the slug via ftp and installed with
opkg install usbscale_1_ixp4xx.ipk
At first there were various errors but after doing the following it worked
I did the following but am not sure yet which was essential!
opkg install kmod-usb-uhci
opkg install kmod-usb-ohci
opkg install libusb
but this loaded version 0.1 which is not as specified by usbscale
so then I did
opkg install libusb_1.0
opkg install usbutils
so that lsusb would work
so I saw -
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 1446:6a73
- and scales.h includes
// Stamps.com Model 510 5LB Scale
so the last one is the Stamps.com Model 510
I can now read weights on the postal scale with a slug running openwrt in internal flash!!
I found basic very convenient as a device control language on the Sweex router (the ability to think is not mandatory)
- I use a context coloured text editor on my iMac that can read and save to the Slug directly by ftp
How to compile Blassic on Openwrt Backfire Slug
(http://blassic.org/ seems to be dead - Google for Blassic)
My misc. notes on Blassic for Sweex are here menu item 12
then compile in the toolchain exactly as for usbscale above
My blassic_1_ixp4xx.ipk for Backfire slug is here
I downloaded the Backfire toolchain from
svn co svn://svn.openwrt.org/openwrt/branches/backfire
to Linux Mint 13 on VMWare on iMac
(MUCH better than the new Ubuntu 12 - you can't find anything in Ubuntu now!)
I did "make menuconfig" and made sure that kmod-i2c-core was built in
(NB! the binary of Backfire that you can download from OpenWrt does not have it and mjpg-streamer will not install without it)
after make V=99 it gave at the end -
Checked out revision 34253.
I added vsftpd for ftp (not secure ftp)
lighttpd for a webserver with cgi scripting - (I could not get the istalled one to work with cgi-bin)
luci web page graphic system control
In terminal -
login - root
The main slug web addresss is 192.168.0.55:8055
Two HD cameras can be added and are at
192.168.0.55:8088 and 192.168.0.55:8089
A stamps.com model 510 5lb postal scale using usbscale runs from the webpage.
The weight value updates every second (OK on Firefox - not IE I think)
A Linux format USB memory stick will mount on boot and the contents are at /mnt/usb1
I have failed to mount a FAT32 memory stick so far.
A backup of the slug firmware was created like this -
do in sequence -
dd if=/dev/mtdblock0 > /mnt/usb1/55dump/nslu2_backfire-121125_image.bin
dd if=/dev/mtdblock1 >> /mnt/usb1/55dump/nslu2_backfire-121125_image.bin
dd if=/dev/mtdblock2 >> /mnt/usb1/55dump/nslu2_backfire-121125_image.bin
dd if=/dev/mtdblock3 >> /mnt/usb1/55dump/nslu2_backfire-121125_image.bin
dd if=/dev/mtdblock4 >> /mnt/usb1/55dump/nslu2_backfire-121125_image.bin
dd if=/dev/mtdblock6 >> /mnt/usb1/55dump/nslu2_backfire-121125_image.bin
and a copy of nslu2_backfire-121125_image.bin may be downloaded from -
Loading the image onto another slug -
I have found that on some versions of Linux in VMWare on my iMac upslug2 fails to find a slug in upgrade mode on the home network.
So I tried SercommFirmwareUpdate using a VMWare image of Windows XP - that works very well and my backup copy is here
I was having trouble getting a slug into upgrade mode then remembered that I had done the "boot on power up" modification.
This works - hold down the reset button with a paperclip then insert the power plug. Do not touch the on/off button on the front!
Count to 12 and the front slug power LED starts to flash red/green (or orange/dark orange on some slugs) then release the paperclip.
The image does not contain usbutils
So to see what is connected to USB do -
opkg install usbutils
- and there are some old notes on OpenWrt slug here