OpenWRT on the NS-K330

At the start of 2011 I began experimenting with an NS-K330 “NAS”, eventually running SnakeOSDebian and FreeBSD 9. This post describes my more recent experiments with OpenWRT on the NS-K330.

Overview

As of r34759 (2012-12-19) OpenWRT’s trunk branch support for the CNS21XX target (and the NS-K330 in particular) is no longer marked as ‘broken’. I never had much success building SnakeOS myself, but did have success (and positive results) building and using OpenWRT for a variety of other devices. So, it seemed only natural for me to explore the potential for running OpenWRT on my NS-K330.

The rest of this post covers a number of topics — building OpenWRT, a two-step process for installing OpenWRT into Flash, setting up system defaults for OpenWRT image, and building new OpenWRT packages for the NS-K330.

OpenWRT build environment

My OpenWRT build environment is an Ubuntu Server 10.04 virtual machine (VM), initially created for CAIA’s Diffuse4OpenWRT project (download the ~382MB VirtualBox .ova file here, and installation/use instructions here). The VM image comes with OpenWRT Attitude Adjustment (r29537) installed, but this is irrelevant —  I downloaded and used OpenWRT trunk r34812 (December 21st 2012) instead.

Steps are basically as listed here:

diffuse@diffuse:~$ mkdir newopenwrt
diffuse@diffuse:~$ cd newopenwrt/
diffuse@diffuse:~/newopenwrt$ svn co svn://svn.openwrt.org/openwrt/trunk/
A    trunk/Config.in
A    trunk/Makefile
A    trunk/toolchain
A    trunk/toolchain/musl
A    trunk/toolchain/musl/Config.version
   [...]
diffuse@diffuse:~/newopenwrt$

Ultimately I had OpenWRT’s trunk version r34812 build environment installed under ~/newopenwrt/trunk.

Background on NS-K330’s Flash

The NS-K330’s uBoot is somewhat crippled in that it seems unable  to write to its own Flash chip. The solution/workaround used by most  discussions of the NS-K330 is to use the original built-in firmware (itself running from Flash),  SnakeOS or some other OS running temporarily in RAM that has drivers  for spio access (so enabling dd to write to flash) or the mtd sub-system  (enabling use of mtd command to write to particular Flash blocks hardwired into the kernel).

Summarising an earlier discussion here, the NS-K330’s Flash contains uBoot between 0x0 and 0x40000, and uBoot assumes the kernel (whatever the OS) starts at 0x60000. Once booted, the kernel gets to decide how to divide up the space between 0x60000 and 0x3f0000.

For example, SnakeOS uses 0x60000-0x150000 for the kernel itself, and the rest for its base (rootfs) file system. From my SnakeOS boot message back in 2010:

Dec 31 02:38:34 boot-kernel: m25p80 spi1.0: m25p64 (8192 Kbytes)
Dec 31 02:38:34 boot-kernel: Creating 6 MTD partitions on "m25p80":
Dec 31 02:38:34 boot-kernel: 0x00000000-0x00040000 : "BOOT"
Dec 31 02:38:34 boot-kernel: 0x00040000-0x00060000 : "CFG"
Dec 31 02:38:34 boot-kernel: 0x00060000-0x00150000 : "KERNEL"
Dec 31 02:38:34 boot-kernel: 0x00150000-0x003f0000 : "INITRD"
Dec 31 02:38:34 boot-kernel: 0x00000000-0x003f0000 : "WEB"
Dec 31 02:38:35 boot-kernel: 0x00000000-0x003f0000 : "ALL"

The CNS21XX version of OpenWRT (currently) uses 0x60000-0x160000 for the kernel itself, and the rest for its rootfs file system. From my OpenWRT boot message later in this post:

  [    1.290000] m25p80 spi0.0: found en25p32, expected m25p80
  [    1.300000] m25p80 spi0.0: en25p32 (4096 Kbytes)
  [    1.310000] Creating 5 MTD partitions on "spi0.0":
  [    1.320000] 0x000000000000-0x000000040000 : "boot"
  [    1.340000] 0x000000040000-0x000000060000 : "config"
  [    1.360000] 0x000000060000-0x000000160000 : "kernel"
  [    1.380000] 0x000000160000-0x0000003f0000 : "rootfs"
  [    1.400000] mtd: partition "rootfs" set to be root filesystem
  [    1.410000] mtd: partition "rootfs_data" created automatically, ofs=250000, len=1A0000
  [    1.420000] 0x000000250000-0x0000003f0000 : "rootfs_data"
  [    1.440000] 0x000000060000-0x0000003f0000 : "firmware"

(In each case above, the kernel’s mtd subsystem provides access to the Flash. Partition start addresses, lengths and symbolic names are statically configured into each kernel.)

Writing OpenWRT to Flash on the NS-K330

Because the NS-K330’s uBoot cannot write to the Flash, I used the following steps:

  • Compile both Ramdisk and Flash-resident versions of OpenWRT
  • Copy over and boot the Ramdisk version from within uBoot
  • Copy over the Flash-resident OpenWRT images to /tmp
  • Use the Ramdisk OpenWRT’s mtd to write the Flash-resident OpenWRT images to Flash
  • Reboot

Compiling Ramdisk OpenWRT

Given that my trunk is under /home/diffuse/newopenwrt/trunk, the following steps create a Ramdisk version of OpenWRT:

diffuse@diffuse:~$ cd newopenwrt/trunk/
diffuse@diffuse:~/newopenwrt/trunk$ make defconfig
  [...]
diffuse@diffuse:~/newopenwrt/trunk$ make prereq
diffuse@diffuse:~/newopenwrt/trunk$ make menuconfig
  [...Selected CNS21XX as Target System,
      use Default as Target Profile,
      then select Ramdisk as Target Image option.
      All other settings left to defaults.]

Now make the actual target:

diffuse@diffuse:~/newopenwrt/trunk$ make
  [...lots of blah...]
diffuse@diffuse:~/newopenwrt/trunk$

The file we want is bin/cns21xx/openwrt-cns21xx-ns-k330-zImage-initramfs

diffuse@diffuse:~/newopenwrt/trunk$ ll -t bin/cns21xx/
total 17008
-rw-r--r-- 1 diffuse diffuse     852 2012-12-23 07:10 md5sums
drwxr-xr-x 3 diffuse diffuse    4096 2012-12-23 07:10 ./
  [...]
-rw-r--r-- 1 diffuse diffuse 1632152 2012-12-23 07:10 openwrt-cns21xx-ns-k330-zImage-initramfs
  [...]
drwxr-xr-x 3 diffuse diffuse    4096 2012-12-22 13:59 ../
diffuse@diffuse:~/newopenwrt/trunk$

I copied openwrt-cns21xx-ns-k330-zImage-initramfs to my local tftpboot server, for later retrieval by the NS-K330’s uBoot.

Compiling Flash-resident OpenWRT

We go back in to the menuconfig system to adjust the Target Image and create a Flash-resident version:

diffuse@diffuse:~/newopenwrt/trunk$ make menuconfig
  [...Selected CNS21XX as Target System,
      use Default as Target Profile,
      then under Target Image options
      de-select Ramdisk and ensure squashfs is
      selected under "Root filesystem images".
      All other settings left to defaults.]
diffuse@diffuse:~/newopenwrt/trunk$ make
  [...lots of blah...]
diffuse@diffuse:~/newopenwrt/trunk$

The two files we now want are bin/cns21xx/{openwrt-cns21xx-ns-k330-zImage,openwrt-cns21xx-ns-k330-root.squashfs}

diffuse@diffuse:~/newopenwrt/trunk$ ll -t bin/cns21xx/
total 17008
-rw-r--r-- 1 diffuse diffuse     852 2012-12-23 07:10 md5sums
drwxr-xr-x 3 diffuse diffuse    4096 2012-12-23 07:10 ./
  [...]
-rw-r--r-- 1 diffuse diffuse 1114116 2012-12-22 19:05 openwrt-cns21xx-ns-k330-root.squashfs
-rw-r--r-- 1 diffuse diffuse  779520 2012-12-22 19:05 openwrt-cns21xx-ns-k330-zImage
  [...]
drwxr-xr-x 3 diffuse diffuse    4096 2012-12-22 13:59 ../
diffuse@diffuse:~/newopenwrt/trunk$

I also copied these two files to my local tftpboot server, for later retrieval by the NS-K330 when it is running the Ramdisk version of OpenWRT.

Booting Ramdisk OpenWRT

From this point onwards I assume you have serial console access to your NS-K330. My FreeBSD desktop machine is connected to the NS-K330 via /dev/cuaU0.  Booting the Ramdisk image involves starting the NS-K330, escaping to the uBoot command prompt, tftp’ing the Ramdisk image over into NS-K330 RAM, then booting the newly arrived kernel.

First, start the NS-K330 and copy over the OpenWRT Ramdisk image. In the example below, my TFTP server is 10.1.1.12 and I set the NS-K330 to be 10.1.1.67 on my home LAN. (The OpenWRT images are stored under 10.1.1.12:/tftpboot/nsk330/, which is nsk330/ from the TFTP client’s perspective.)

  [gja@gjadesktop] /home/gja# cu -l /dev/cuaU0 -s 38400
  Connected

  U-Boot 1.1.4 (Mar  3 2008 - 16:51:36)

  U-Boot code: 00000000 -> 0001A410  BSS: -> 0001F354
  IRQ Stack: 00e6ff7c
  FIQ Stack: 00e6ef7c
  RAM Configuration:
  Bank #0: 00000000 32 MB
  Flash Manufacturer: Unknown(0x1c)
  Flash:  0 kB
  *** Warning - bad CRC, using default environment

  In:    serial
  Out:   serial
  Err:   serial
  PLL clock at 250MHz
  CPU clock at 250MHz
  AHB clock at 125MHz
  APB clock at 62MHz
  Hit any key to stop autoboot:  3
  kernel:30060000-301e0000
  0
  Star Equuleus #
  Star Equuleus # setenv ipaddr 10.1.1.67
  Star Equuleus # setenv serverip 10.1.1.12
  Star Equuleus # tftpboot 0x600000 nsk330/openwrt-cns21xx-ns-k330-zImage-initramfs
  Check Link Status ..Up
  Waiting 3 seconds ..
  TFTP from server 10.1.1.12; our IP address is 10.1.1.67
  Filename 'nsk330/openwrt-cns21xx-ns-k330-zImage-initramfs'.
  Load address: 0x600000
  Loading: #################################################################
	  #################################################################
	  #################################################################
	  #################################################################
	  ###########################################################
  done
  Bytes transferred = 1632152 (18e798 hex)
  Star Equuleus #

Now boot the Ramdisk OpenWRT:

  Star Equuleus # go 0x600000
  ## Starting application at 0x00600000 ...
  Uncompressing Linux... done, booting the kernel.
  [    0.000000] Booting Linux on physical CPU 0
  [    0.000000] Linux version 3.6.11 (diffuse@diffuse) (gcc version 4.6.4 20121106 (prerelease) (Linaro GCC 4.6-2012.11) ) #3 Sun Dec 23 07:09:53 EST 2012
  [    0.000000] CPU: FA526 [66015261] revision 1 (ARMv4), cr=0000397f
  [    0.000000] CPU: VIVT data cache, VIVT instruction cache
  [    0.000000] Machine: NS-K330 NAS
  [    0.000000] Ignoring unrecognised tag 0x00000000
  [    0.000000] Memory policy: ECC disabled, Data cache writeback
  [    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 8128
  [    0.000000] Kernel command line: console=ttyS0,38400 rootfstype=squashfs,jffs2 noinitrd
  [    0.000000] PID hash table entries: 128 (order: -3, 512 bytes)
  [    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
  [    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
  [    0.000000] Memory: 32MB = 32MB total
  [    0.000000] Memory: 27532k/27532k available, 5236k reserved, 0K highmem
  [    0.000000] Virtual kernel memory layout:
  [    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
  [    0.000000]     fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
  [    0.000000]     vmalloc : 0xc2800000 - 0xff000000   ( 968 MB)
  [    0.000000]     lowmem  : 0xc0000000 - 0xc2000000   (  32 MB)
  [    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
  [    0.000000]       .text : 0xc0008000 - 0xc01f1000   (1956 kB)
  [    0.000000]       .init : 0xc01f1000 - 0xc048c9c4   (2671 kB)
  [    0.000000]       .data : 0xc048e000 - 0xc04a2020   (  81 kB)
  [    0.000000]        .bss : 0xc04a2044 - 0xc04ca640   ( 162 kB)
  [    0.000000] NR_IRQS:96
  [    0.000000] sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286ms
  [    0.070000] Calibrating delay loop... 190.87 BogoMIPS (lpj=954368)
  [    0.070000] pid_max: default: 32768 minimum: 301
  [    0.070000] Mount-cache hash table entries: 512
  [    0.070000] CPU: Testing write buffer coherency: ok
  [    0.070000] Setting up static identity map for 0x1b98d8 - 0x1b9920
  [    0.080000] NET: Registered protocol family 16
  [    0.080000] DMA: preallocated 256 KiB pool for atomic coherent allocations
  [    0.130000] bio: create slab <bio-0> at 0
  [    0.160000] NET: Registered protocol family 2
  [    0.170000] TCP established hash table entries: 1024 (order: 1, 8192 bytes)
  [    0.170000] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
  [    0.170000] TCP: Hash tables configured (established 1024 bind 1024)
  [    0.170000] TCP: reno registered
  [    0.170000] UDP hash table entries: 256 (order: 0, 4096 bytes)
  [    0.170000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
  [    0.170000] NET: Registered protocol family 1
  [    0.600000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
  [    0.600000] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
  [    0.600000] msgmni has been set to 53
  [    0.600000] io scheduler noop registered
  [    0.600000] io scheduler deadline registered (default)
  [    1.270000] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
  [    1.280000] serial8250.0: ttyS0 at MMIO 0x78000000 (irq = 9) is a 16550A
  [    1.670000] console [ttyS0] enabled
  [    1.690000] cns21xx-spi cns21xx-spi: master is unqueued, this is deprecated
  [    1.700000] m25p80 spi0.0: found en25p32, expected m25p80
  [    1.710000] m25p80 spi0.0: en25p32 (4096 Kbytes)
  [    1.730000] Creating 5 MTD partitions on "spi0.0":
  [    1.740000] 0x000000000000-0x000000040000 : "boot"
  [    1.750000] 0x000000040000-0x000000060000 : "config"
  [    1.770000] 0x000000060000-0x000000160000 : "kernel"
  [    1.790000] 0x000000160000-0x0000003f0000 : "rootfs"
  [    1.810000] mtd: partition "rootfs" set to be root filesystem
  [    1.820000] split_squashfs: no squashfs found in "spi0.0"
  [    1.830000] 0x000000060000-0x0000003f0000 : "firmware"
  [    1.850000] cns21xx-spi cns21xx-spi: iomem at 71000000
  [    1.870000] net eth0: Internal PHY
  [    1.890000] TCP: cubic registered
  [    1.900000] NET: Registered protocol family 17
  [    1.910000] 8021q: 802.1Q VLAN Support v1.8
  [    1.980000] Freeing init memory: 2668K
  [    7.010000] input: gpio-keys as /devices/platform/gpio-keys/input/input0
  [    7.070000] Button Hotplug driver version 0.4.1
  - preinit -
  Press the [f] key and hit [enter] to enter failsafe mode
  - regular preinit -
  - init -

  Please press Enter to activate this console. [   11.650000] usbcore: registered new interface driver usbfs
  [   11.660000] usbcore: registered new interface driver hub
  [   11.680000] usbcore: registered new device driver usb
  [   11.820000] PPP generic driver version 2.4.2
  [   12.000000] ip_tables: (C) 2000-2006 Netfilter Core Team
  [   12.400000] NET: Registered protocol family 24
  [   12.450000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
  [   12.570000] cns21xx-ehci cns21xx-ehci: cns21xx-ehci
  [   12.580000] cns21xx-ehci cns21xx-ehci: new USB bus registered, assigned bus number 1
  [   12.590000] cns21xx-ehci cns21xx-ehci: irq 24, io mem 0xcc000000
  [   12.620000] cns21xx-ehci cns21xx-ehci: USB 2.0 started, EHCI 1.00
  [   12.640000] hub 1-0:1.0: USB hub found
  [   12.650000] hub 1-0:1.0: 2 ports detected
  [   12.720000] nf_conntrack version 0.5.0 (471 buckets, 1884 max)
  [   12.980000] usb 1-1: new high-speed USB device number 2 using cns21xx-ehci
  [   13.440000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
  [   13.560000] cns21xx-ohci cns21xx-ohci: cns21xx-ohci
  [   13.570000] cns21xx-ohci cns21xx-ohci: new USB bus registered, assigned bus number 2
  [   13.580000] cns21xx-ohci cns21xx-ohci: irq 23, io mem 0xc4000000
  [   13.650000] hub 2-0:1.0: USB hub found
  [   13.660000] hub 2-0:1.0: 2 ports detected
  [   24.670000] device eth0 entered promiscuous mode
  [   24.700000] br-lan: port 1(eth0) entered forwarding state
  [   24.710000] br-lan: port 1(eth0) entered forwarding state
  [   26.170000] net eth0: link up (100Mbps/Full duplex)
  [   26.710000] br-lan: port 1(eth0) entered forwarding state

  BusyBox v1.19.4 (2012-12-22 18:47:35 EST) built-in shell (ash)
  Enter 'help' for a list of built-in commands.

    _______                     ________        __
  |       |.-----.-----.-----.|  |  |  |.----.|  |_
  |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
  |_______||   __|_____|__|__||________||__|  |____|
	    |__| W I R E L E S S   F R E E D O M
  -----------------------------------------------------
  BARRIER BREAKER (Bleeding Edge, r34812)
  -----------------------------------------------------
    * 1/2 oz Galliano         Pour all ingredients into
    * 4 oz cold Coffee        an irish coffee mug filled
    * 1 1/2 oz Dark Rum       with crushed ice. Stir.
    * 2 tsp. Creme de Cacao
  -----------------------------------------------------
  root@OpenWrt:/#

Yay! OpenWRT booted from RAM!

Installing Flash-resident OpenWRT

Now that OpenWRT is running on the NS-K330, establish IP connectivity so we can download the next two image files.

  root@OpenWrt:/# ifconfig br-lan 10.1.1.67 netmask 255.255.255.0
  root@OpenWrt:/# ifconfig
  br-lan    Link encap:Ethernet  HWaddr 1E:ED:19:27:1A:B3
	    inet addr:10.1.1.67  Bcast:10.1.1.255  Mask:255.255.255.0
	    UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
	    RX packets:417 errors:0 dropped:17 overruns:0 frame:0
	    TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
	    collisions:0 txqueuelen:0
	    RX bytes:122585 (119.7 KiB)  TX bytes:816 (816.0 B)
	[..]
  root@OpenWrt:/#

Copy the .zImage (kernel) and root.squashfs (rootfs) images into /tmp (a RAM-based file system at this point, with plenty of space).

  root@OpenWrt:/tmp# scp gja@10.1.1.12:/tftpboot/nsk330/{openwrt-cns21xx-ns-k330-root.squashfs,openwrt-cns21xx-ns-k330-zImage} .
  Login for gja@10.1.1.12
  Password:
  openwrt-cns21xx-ns-k330-root.squashfs         100% 1088KB 362.7KB/s   00:03
  openwrt-cns21xx-ns-k330-zImage                100%  761KB 253.8KB/s   00:03
  root@OpenWrt:/tmp#
  root@OpenWrt:/tmp# df -h /tmp
  Filesystem                Size      Used Available Use% Mounted on
  tmpfs                    14.7M      1.9M     12.9M  13% /tmp
  root@OpenWrt:/tmp#
  root@OpenWrt:/tmp# ls -al
	  [..]
  -rw-r--r--    1 root     root       1114116 Dec 22 23:41 openwrt-cns21xx-ns-k330-root.squashfs
  -rw-r--r--    1 root     root        779520 Dec 22 23:41 openwrt-cns21xx-ns-k330-zImage
	  [..]
  root@OpenWrt:/tmp#

Now the key step — use mtd to write both images to the flash. The partitions are identified using names (kernel and rootfs) statically configured into the mtd subsystem of the OpenWRT NS-K330 kernel.

  root@OpenWrt:/tmp# mtd write openwrt-cns21xx-ns-k330-zImage kernel
  Unlocking kernel ...

  Writing from openwrt-cns21xx-ns-k330-zImage to kernel ...  [w]

  root@OpenWrt:/tmp#
  root@OpenWrt:/tmp# mtd write openwrt-cns21xx-ns-k330-root.squashfs rootfs
  Unlocking rootfs ...

  Writing from openwrt-cns21xx-ns-k330-root.squashfs to rootfs ...
  root@OpenWrt:/tmp#

Finally, reboot the running OpenWRT (dropping us back into uBoot). Let uBoot fall through to booting from the image now resident in Flash at uBoot’s default start location (0x600000 ).

  root@OpenWrt:/tmp# reboot
  root@OpenWrt:/tmp# [12441.320000] br-lan: port 1(eth0) entered disabled state
  [12441.350000] device eth0 left promiscuous mode
  [12441.360000] br-lan: port 1(eth0) entered disabled state
  [12444.590000] Restarting system.

  U-Boot 1.1.4 (Mar  3 2008 - 16:51:36)

  U-Boot code: 00000000 -> 0001A410  BSS: -> 0001F354
  IRQ Stack: 00e6ff7c
  FIQ Stack: 00e6ef7c
  RAM Configuration:
  Bank #0: 00000000 32 MB
  Flash Manufacturer: Unknown(0x1c)
  Flash:  0 kB
  *** Warning - bad CRC, using default environment

  In:    serial
  Out:   serial
  Err:   serial
  PLL clock at 250MHz
  CPU clock at 250MHz
  AHB clock at 125MHz
  APB clock at 62MHz
  Hit any key to stop autoboot:  3
  kernel:30060000-301e0000
  0
  ## Starting application at 0x00600000 ...
  Uncompressing Linux... done, booting the kernel.
  [    0.000000] Booting Linux on physical CPU 0
  [    0.000000] Linux version 3.6.11 (diffuse@diffuse) (gcc version 4.6.4 20121106 (prerelease) (Linaro GCC 4.6-2012.11) ) #2 Sat Dec 22 19:05:41 EST 2012
  [    0.000000] CPU: FA526 [66015261] revision 1 (ARMv4), cr=0000397f
  [    0.000000] CPU: VIVT data cache, VIVT instruction cache
  [    0.000000] Machine: NS-K330 NAS
  [    0.000000] Ignoring unrecognised tag 0x00000000
  [    0.000000] Memory policy: ECC disabled, Data cache writeback
  [    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 8128
  [    0.000000] Kernel command line: console=ttyS0,38400 rootfstype=squashfs,jffs2 noinitrd
  [    0.000000] PID hash table entries: 128 (order: -3, 512 bytes)
  [    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
  [    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
  [    0.000000] Memory: 32MB = 32MB total
  [    0.000000] Memory: 30108k/30108k available, 2660k reserved, 0K highmem
  [    0.000000] Virtual kernel memory layout:
  [    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
  [    0.000000]     fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
  [    0.000000]     vmalloc : 0xc2800000 - 0xff000000   ( 968 MB)
  [    0.000000]     lowmem  : 0xc0000000 - 0xc2000000   (  32 MB)
  [    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
  [    0.000000]       .text : 0xc0008000 - 0xc01f1000   (1956 kB)
  [    0.000000]       .init : 0xc01f1000 - 0xc0208ee4   (  96 kB)
  [    0.000000]       .data : 0xc020a000 - 0xc021e020   (  81 kB)
  [    0.000000]        .bss : 0xc021e044 - 0xc0246640   ( 162 kB)
  [    0.000000] NR_IRQS:96
  [    0.000000] sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286ms
  [    0.070000] Calibrating delay loop... 190.87 BogoMIPS (lpj=954368)
  [    0.070000] pid_max: default: 32768 minimum: 301
  [    0.070000] Mount-cache hash table entries: 512
  [    0.070000] CPU: Testing write buffer coherency: ok
  [    0.070000] Setting up static identity map for 0x1b98d8 - 0x1b9920
  [    0.080000] NET: Registered protocol family 16
  [    0.080000] DMA: preallocated 256 KiB pool for atomic coherent allocations
  [    0.140000] bio: create slab <bio-0> at 0
  [    0.170000] NET: Registered protocol family 2
  [    0.170000] TCP established hash table entries: 1024 (order: 1, 8192 bytes)
  [    0.170000] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
  [    0.170000] TCP: Hash tables configured (established 1024 bind 1024)
  [    0.170000] TCP: reno registered
  [    0.170000] UDP hash table entries: 256 (order: 0, 4096 bytes)
  [    0.170000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
  [    0.170000] NET: Registered protocol family 1
  [    0.180000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
  [    0.180000] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
  [    0.180000] msgmni has been set to 58
  [    0.180000] io scheduler noop registered
  [    0.180000] io scheduler deadline registered (default)
  [    0.850000] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
  [    0.860000] serial8250.0: ttyS0 at MMIO 0x78000000 (irq = 9) is a 16550A
  [    1.250000] console [ttyS0] enabled
  [    1.270000] cns21xx-spi cns21xx-spi: master is unqueued, this is deprecated
  [    1.290000] m25p80 spi0.0: found en25p32, expected m25p80
  [    1.300000] m25p80 spi0.0: en25p32 (4096 Kbytes)
  [    1.310000] Creating 5 MTD partitions on "spi0.0":
  [    1.320000] 0x000000000000-0x000000040000 : "boot"
  [    1.340000] 0x000000040000-0x000000060000 : "config"
  [    1.360000] 0x000000060000-0x000000160000 : "kernel"
  [    1.380000] 0x000000160000-0x0000003f0000 : "rootfs"
  [    1.400000] mtd: partition "rootfs" set to be root filesystem
  [    1.410000] mtd: partition "rootfs_data" created automatically, ofs=250000, len=1A0000
  [    1.420000] 0x000000250000-0x0000003f0000 : "rootfs_data"
  [    1.440000] 0x000000060000-0x0000003f0000 : "firmware"
  [    1.460000] cns21xx-spi cns21xx-spi: iomem at 71000000
  [    1.470000] net eth0: Internal PHY
  [    1.490000] TCP: cubic registered
  [    1.500000] NET: Registered protocol family 17
  [    1.510000] 8021q: 802.1Q VLAN Support v1.8
  [    1.550000] VFS: Mounted root (squashfs filesystem) readonly on device 31:3.
  [    1.560000] Freeing init memory: 92K
  [   10.410000] input: gpio-keys as /devices/platform/gpio-keys/input/input0
  [   10.670000] Button Hotplug driver version 0.4.1
  - preinit -
  Press the [f] key and hit [enter] to enter failsafe mode
  - regular preinit -
  jffs2 not ready yet; using ramdisk
  - init -

  Please press Enter to activate this console. [   16.520000] usbcore: registered new interface driver usbfs
  [   16.530000] usbcore: registered new interface driver hub
  [   16.550000] usbcore: registered new device driver usb
  [   16.690000] PPP generic driver version 2.4.2
  [   16.870000] ip_tables: (C) 2000-2006 Netfilter Core Team
  [   17.270000] NET: Registered protocol family 24
  [   17.330000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
  [   17.450000] cns21xx-ehci cns21xx-ehci: cns21xx-ehci
  [   17.460000] cns21xx-ehci cns21xx-ehci: new USB bus registered, assigned bus number 1
  [   17.470000] cns21xx-ehci cns21xx-ehci: irq 24, io mem 0xcc000000
  [   17.500000] cns21xx-ehci cns21xx-ehci: USB 2.0 started, EHCI 1.00
  [   17.520000] hub 1-0:1.0: USB hub found
  [   17.530000] hub 1-0:1.0: 2 ports detected
  [   17.600000] nf_conntrack version 0.5.0 (471 buckets, 1884 max)
  [   17.860000] usb 1-1: new high-speed USB device number 2 using cns21xx-ehci
  [   18.330000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
  [   18.450000] cns21xx-ohci cns21xx-ohci: cns21xx-ohci
  [   18.460000] cns21xx-ohci cns21xx-ohci: new USB bus registered, assigned bus number 2
  [   18.470000] cns21xx-ohci cns21xx-ohci: irq 23, io mem 0xc4000000
  [   18.540000] hub 2-0:1.0: USB hub found
  [   18.550000] hub 2-0:1.0: 2 ports detected
  [   32.100000] net eth0: link down
  [   32.220000] device eth0 entered promiscuous mode
  [   33.840000] net eth0: link up (100Mbps/Full duplex)
  [   33.850000] br-lan: port 1(eth0) entered forwarding state
  [   33.860000] br-lan: port 1(eth0) entered forwarding state
  [   35.860000] br-lan: port 1(eth0) entered forwarding state
  [   63.280000] jffs2_scan_eraseblock(): End of filesystem marker found at 0x0
  [   63.310000] jffs2_build_filesystem(): unlocking the mtd device... done.
  [   63.330000] jffs2_build_filesystem(): erasing all blocks after the end marker...
  [   74.520000] jffs2: notice: (1907) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.

	[... hit enter ...]

  BusyBox v1.19.4 (2012-12-22 18:47:35 EST) built-in shell (ash)
  Enter 'help' for a list of built-in commands.

    _______                     ________        __
  |       |.-----.-----.-----.|  |  |  |.----.|  |_
  |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
  |_______||   __|_____|__|__||________||__|  |____|
	    |__| W I R E L E S S   F R E E D O M
  -----------------------------------------------------
  BARRIER BREAKER (Bleeding Edge, r34812)
  -----------------------------------------------------
    * 1/2 oz Galliano         Pour all ingredients into
    * 4 oz cold Coffee        an irish coffee mug filled
    * 1 1/2 oz Dark Rum       with crushed ice. Stir.
    * 2 tsp. Creme de Cacao
  -----------------------------------------------------
  root@OpenWrt:/#
  root@OpenWrt:/# cat /proc/version
  Linux version 3.6.11 (diffuse@diffuse) (gcc version 4.6.4 20121106 (prerelease) (Linaro GCC 4.6-2012.11) ) #2 Sat Dec 22 19:05:41 EST 2012
  root@OpenWrt:/#
  root@OpenWrt:/# cat /proc/cpuinfo
  Processor       : FA526 rev 1 (v4l)
  BogoMIPS        : 190.87
  Features        : swp half
  CPU implementer : 0x66
  CPU architecture: 4
  CPU variant     : 0x0
  CPU part        : 0x526
  CPU revision    : 1

  Hardware        : NS-K330 NAS
  Revision        : 0000
  Serial          : 0000000000000000
  root@OpenWrt:/#

At the tail end of the console output we can see the kernel building a small, writable jffs2 file system at the end of the rootfs section of Flash. This creates the /overlay file system, where we can add OpenWRT packages that we wish to have survive reboots.

  root@OpenWrt:/# df -h
  Filesystem                Size      Used Available Use% Mounted on
  rootfs                    1.6M    204.0K      1.4M  12% /
  /dev/root                 1.0M      1.0M         0 100% /rom
  tmpfs                    14.7M     52.0K     14.7M   0% /tmp
  tmpfs                   512.0K         0    512.0K   0% /dev
  root                     14.7M     20.0K     14.7M   0% /tmp/root
  overlayfs:/tmp/root      14.7M     20.0K     14.7M   0% /tmp/root
  /dev/mtdblock4            1.6M    204.0K      1.4M  12% /overlay
  overlayfs:/overlay        1.6M    204.0K      1.4M  12% /
  root@OpenWrt:/#
  root@OpenWrt:/#
  root@OpenWrt:/# mount
  rootfs on / type rootfs (rw)
  /dev/root on /rom type squashfs (ro,relatime)
  proc on /proc type proc (rw,noatime)
  sysfs on /sys type sysfs (rw,noatime)
  tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
  tmpfs on /dev type tmpfs (rw,noatime,size=512k,mode=755)
  devpts on /dev/pts type devpts (rw,noatime,mode=600)
  root on /tmp/root type tmpfs (rw,noatime,mode=755)
  overlayfs:/tmp/root on /tmp/root type overlayfs (ro,relatime,lowerdir=/,upperdir=/tmp/root)
  debugfs on /sys/kernel/debug type debugfs (rw,noatime)
  /dev/mtdblock4 on /overlay type jffs2 (rw,noatime)
  overlayfs:/overlay on / type overlayfs (rw,noatime,lowerdir=/,upperdir=/overlay)
  root@OpenWrt:/#

Rebooting a 2nd time (and all subsequent times) differs only in that the kernel now finds a properly formatted jffs2 partition in Flash immediately after the static rootfs. This speeds up booting (taking ~20 seconds rather than ~75 seconds).

Embedding local settings

Rather than manually configuring /etc/config/network each time we re-flash and reboot the NS-K330, the correct solution is to embed local settings into the OpenWRT rootfs itself.

For example, if I create /home/diffuse/newopenwrt/trunk/files/etc/config/network before building my OpenWRT images, this file will be copied into /etc/config/network of the newly booted OpenWRT. In my case I created the file with the following contents:

    config interface loopback
	    option ifname   lo
	    option proto    static
	    option ipaddr   127.0.0.1
	    option netmask  255.0.0.0

    config interface lan
	    option ifname   eth0
	    option type     bridge
	    option proto    static
	    option ipaddr   10.1.1.67
	    option netmask  255.255.255.0
	    option dns 10.1.1.12
	    option gateway 10.1.1.12

This ensured that my OpenWRT-based NS-K330 would boot with the local LAN identity of 10.1.1.67. Naturally, you should season to suit if you’re not me!

(See http://wiki.openwrt.org/doc/howto/build#custom.files for more details.)

Adding feeds for lots more packages

Since there aren’t (currently) any packages being built centrally for the CNS21XX platform, you’ll need to build whatever you need locally. This means ensuring that you run “./scripts/feeds update” to get the latest package definitions and “./scripts/feeds install -a” to install symlinks into “./package/feeds/*” before you next run “make menuconfig”. Once you’ve got the feeds installed, a whole new range of packages are available to “make menconfig”.

(See http://wiki.openwrt.org/doc/howto/build for more details.)

Advertisements

3 comments

  1. Hi! Assuming I have working snake os, is it possible to flash non-ramdisk image from it ?

  2. I always becom the following error message, after i try to boot the zimage:

    Kernel panic – not syncing: No init found. Try passing init= option to kernel. See Linux Documentation/init.txt for guidance….

    Can you please help me?

  3. This majorly helped me get OpenWRT installed onto a Hitachi SimpleNET. I had to use the “nsb3ast” version of the files it builds, and had to use jffs2, but it worked. I was able to write the image to the flash with U-Boot.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: