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 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)

# OpenWrt Makefile for helloworld program
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.

include $(TOPDIR)/

# Name and release number of this package

# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory

include $(INCLUDE_DIR)/


# Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/helloworld
______TITLE:=Helloworld demo program

# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
#define Package/helloworld/description
#______Simple hello world demo


# Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default. The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
______mkdir -p $(PKG_BUILD_DIR)
______$(CP) ./src/* $(PKG_BUILD_DIR)/

#define Build/Compile
#______$(MAKE) -C $(PKG_BUILD_DIR) \

# We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one

# Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
______$(INSTALL_DIR) $(1)/bin
______$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/

# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))

To compile first cd to the backfire root folder and do -
make menuconfig
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
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!

also see

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/

as here

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 update
opkg install kmod-usb-uhci
insmod usbcore
insmod uhci

opkg update
opkg install kmod-usb-ohci
insmod 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 -
root@Slug54Backfire:~# lsusb
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
// Model 510 5LB Scale
{0x1446, 0x6a73},
so the last one is the Model 510

I can now read weights on the postal scale with a slug running openwrt in internal flash!!

root@Slug54Backfire:~# usbscale
0 oz
root@Slug54Backfire:~# usbscale
13.3 oz


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

seems to be dead - Google for Blassic)

My misc. notes on Blassic for Sweex are here menu item 12

download blassic-0.10.0.tgz
then compile in the toolchain exactly as for usbscale above

My blassic_1_ixp4xx.ipk for Backfire slug is here

Backfire with extras

I downloaded the Backfire toolchain from
svn co svn://
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

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
Blassic basic
i2c tools

In terminal -
login - root
password root

The main slug web addresss is

Two HD cameras can be added and are at and

A 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 -!105

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 update
opkg install usbutils

- and there are some old notes on OpenWrt slug here