Building OpenWRT as a foundation for FreeSA work

What we need from the OpenWRT project at the moment is just a toolchain and kernel. As described elsewhere on the wiki, we can then use the kernel by NetworkBooting rather than something like ReflashingWithTftp.

Here's how to do it.

  1. Check out openwrt from https://svn.openwrt.org/openwrt/trunk
  2. Install a basic configuration file as .config -- when we have made it a little further, the configuration files we use might wind up in subversion.
  3. Build OpenWRT with make. This will bootstrap the cross-toolchain and build the kernel and firmware images. We will basically throw away the firmware images, since they are irrelevant to us. 1. The target we want is brcm47xx-2.6. This builds (as of r6955) a 2.6.19.2 kernel with patches to support bcrm47xx SOCs.
  4. copy the kernel to the tftp location
  5. Updating the root filesystem for the NFS server
    1. cd to build_mipsel/linux
    2. ARCH=mips INSTALL_MOD_PATH=/tmp/fsanfs make modules_install

To work around a build error,

      eric@xyzzy:~/freesa/openwrt-trunk/build_mipsel/linux$ ARCH=mips make
        CHK     include/linux/version.h
        CHK     include/linux/utsrelease.h
        CHK     include/linux/compile.h
        MODPOST vmlinux
        Building modules, stage 2.
        MODPOST 283 modules
      WARNING: "local_flush_data_cache_page" [drivers/ide/ide-core.ko] undefined!
      maker1: *** [+modpost] Error 1
      make: *** [modules] Error 2
      eric@xyzzy:~/freesa/openwrt-trunk/build_mipsel/linux

Is resolved by editing
openwrt-trunk/build_mipsel/linux/arch/mips/mm/cache.c and adding the line:
      EXPORT_SYMBOL(local_flush_data_cache_page); 

more later

TODO - modify these instructions such that they pertain more directly to NetworkBooting:
  • Be more explicit about the two cycle config/build process
    • add note about changing to the correct directory to run rerun kernel config to configure the linux kernel
    • do we need to delete the original vmlinux before rebuilding after re-configuring?
  • ARCH=mips make menuconfig
  • ARCH=mips make from top level

Flashless nearly-bog-standard OpenWRT on WL-700gE?

Is there a way to do the "flashless" loading of a squashfs? Maybe .... We could try the following:

  • set rootfs_in_ram=yes
  • set kernel_args = "root=/dev/mtdblock5 noinitrd console=ttyS0,115200 mem=56M"
  • put the squashfs and vmlinux into the tftp dir
  • CFE> load -addr=0x83800000 -max=0x800000 -tftp ip.address.of.server:/path/to/squashfs
  • CFE> boot -addr=0x80001000 -max=0x800000 -tftp ip.address.of.server:/path/to/vmlinux

Will this work? Not sure, here's the thing ... mtdblock5 is created by the Asus kernel. It might not be set up in the OpenWRT kernel. We need to build switch figure a way to make a RAM region visible as a mtd device so that the kernel can find it.

'''Also, it ''might'' be possible to build switch use initramfs instead, in which case the kernel file includes everything for us.'''


How to build switch kernel mods

make -C switch compile
maker3: Entering directory @/home/random/src/openwrt-7196/package/switch'
mkdir -p /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch
cp -fpR ./src/* /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/
touch /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/.prepared_76ed7876d303097cdb8d3f5b26b8a960
(cd /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/./; if [ -x ./configure ]; then AR=mipsel-linux-uclibc-ar AS="mipsel-linux-uclibc-gcc -c -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time" LD=mipsel-linux-uclibc-ld NM=mipsel-linux-uclibc-nm CC="mipsel-linux-uclibc-gcc" GCC="mipsel-linux-uclibc-gcc" CXX=mipsel-linux-uclibc-g++ RANLIB=mipsel-linux-uclibc-ranlib STRIP=mipsel-linux-uclibc-strip OBJCOPY=mipsel-linux-uclibc-objcopy OBJDUMP=mipsel-linux-uclibc-objdump CFLAGS="-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -I/home/random/src/openwrt-7196/staging_dir_mipsel/usr/include -I/home/random/src/openwrt-7196/staging_dir_mipsel/include" CXXFLAGS="-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -I/home/random/src/openwrt-7196/staging_dir_mipsel/usr/include -I/home/random/src/openwrt-7196/staging_dir_mipsel/include" CPPFLAGS="-I/home/random/src/openwrt-7196/staging_dir_mipsel/usr/include -I/home/random/src/openwrt-7196/staging_dir_mipsel/include -I/home/random/src/openwrt-7196/staging_dir_mipsel/usr/include -I/home/random/src/openwrt-7196/staging_dir_mipsel/include" LDFLAGS="-L/home/random/src/openwrt-7196/staging_dir_mipsel/usr/lib -L/home/random/src/openwrt-7196/staging_dir_mipsel/lib" PKG_CONFIG_PATH="/home/random/src/openwrt-7196/staging_dir_mipsel/usr/lib/pkgconfig" PKG_CONFIG_LIBDIR="/home/random/src/openwrt-7196/staging_dir_mipsel/usr/lib/pkgconfig"  ./configure --target=mipsel-linux --host=mipsel-linux --build=i686-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls ; fi; )
touch /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/.configured
make -C "/home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/linux-2.6.19.2" CROSS_COMPILE="mipsel-linux-uclibc-" ARCH="mips" SUBDIRS="/home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch" EXTRA_CFLAGS="-DBROADCOM" modules
maker4: Entering directory @/home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/linux-2.6.19.2'
  CC [M]  /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-core.o
  CC [M]  /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-adm.o
  CC [M]  /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-robo.o
  Building modules, stage 2.
  MODPOST 3 modules
  CC      /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-adm.mod.o
  LD [M]  /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-adm.ko
  CC      /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-core.mod.o
  LD [M]  /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-core.ko
  CC      /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-robo.mod.o
  LD [M]  /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-robo.ko
maker4: Leaving directory @/home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/linux-2.6.19.2'
maker4: Entering directory @/home/random/src/openwrt-7196/package/switch'
maker4: Leaving directory @/home/random/src/openwrt-7196/package/switch'
touch /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/.built
mkdir -p /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL
echo "Package: kmod-switch" > /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/control
echo "Version: 2.6.19.2-brcm47xx-1" >> /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/control
( DEPENDS='kernel (=2.6.19.2-brcm47xx-1)'; for depend in ; do DEPENDS=${DEPENDS:+$DEPENDS, }${depend##+}; done; echo "Depends: $DEPENDS"; echo "Source: package/switch"; echo "Section: kernel"; echo "Priority: optional"; echo "Maintainer: OpenWrt Developers Team <openwrt-devel@openwrt.org>"; echo "Architecture: mipsel"; echo -n "Description: "; getvar V_Package_kmod_switch_description | sed -e 's,^:space:*, ,g'; ) >> /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/control
chmod 644 /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/control
(cd /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL; var2file "V_Package_kmod_switch_conffiles" conffiles; var2file "V_Package_kmod_switch_preinst" preinst; var2file "V_Package_kmod_switch_postinst" postinst; var2file "V_Package_kmod_switch_prerm" prerm; var2file "V_Package_kmod_switch_postrm" postrm; )
mkdir -p /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/modules/2.6.19.2
cp -fpR -L /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-core.ko /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-adm.ko /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/switch-robo.ko /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/modules/2.6.19.2/
export modules=; add_module() { mkdir -p /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/etc/modules.d; ( for mod in $2; do getvar mod; done ) > /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/etc/modules.d/$1-switch; modules="${modules:+$modules }$1-switch"; }; add_module 20 "switch-core switch-robo switch-adm"; if [ -n "$modules" ]; then mkdir -p /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/etc/modules.d; echo "#!/bin/sh" > /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/postinst; echo "[ -z \"\$IPKG_INSTROOT\" ] || exit 0" >> /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/postinst; echo ". /etc/functions.sh" >> /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/postinst; echo "load_modules $modules" >> /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/postinst; chmod 0755 /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/CONTROL/postinst; fi
install -d -m0755 /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/network/
install -m0755 ./files/switch.sh /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/network/
mkdir -p /home/random/src/openwrt-7196/bin/packages
find /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch -name CVS   | xargs -r rm -rf
find /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch -name .svn  | xargs -r rm -rf
find /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch -name '.#*' | xargs -r rm -f
NM="mipsel-linux-uclibc-nm" STRIP="/home/random/src/openwrt-7196/staging_dir_mipsel/bin/sstrip" STRIP_KMOD="mipsel-linux-uclibc-strip --strip-unneeded --remove-section=.comment" /home/random/src/openwrt-7196/scripts/rstrip.sh /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch
rstrip.sh: /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/modules/2.6.19.2/switch-adm.ko:relocatable
rstrip.sh: /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/modules/2.6.19.2/switch-core.ko:relocatable
rstrip.sh: /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch/lib/modules/2.6.19.2/switch-robo.ko:relocatable
ipkg-build -c -o 0 -g 0 /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch /home/random/src/openwrt-7196/bin/packages
Packaged contents of /home/random/src/openwrt-7196/build_mipsel/linux-2.6-brcm47xx/kmod-switch/ipkg/kmod-switch into /home/random/src/openwrt-7196/bin/packages/kmod-switch_2.6.19.2-brcm47xx-1_mipsel.ipk
maker3: Leaving directory @/home/random/src/openwrt-7196/package/switch'

Also available in: HTML TXT