Booting FreeBSD 9.0-CURRENT from NS-K330’s Flash

A few days ago I got FreeBSD 9-CURRENT running on my NS-K330. This post summarises my next experiment — getting FreeBSD 9.0-CURRENT to boot from the NS-K330’s flash.

Cross-compiling FreeBSD 9.0-CURRENT

See my previous post for background on using my home FreeBSD 8.0-STABLE server (gjabkup2) to cross-compile an ARM version of FreeBSD 9-CURRENT (world and kernel).

Building a kernel that fits in flash

The main difference between my previous experiment and now is my realisation that the NS-K330’s uBoot boot loader allocates address space 0x30060000-301e0000 for flash-resident kernel, i.e. only 1,572,468 bytes. Consequently the FreeBSD 9-CURRENT kernel image cannot exceed 1,572,468 bytes if we wish to install it onto, and boot from, the NS-K330’s flash. My previous kernel was slightly over this limit and needed to be rebuilt.

I created a new config file (CNS21XXNAS_GJA_1) that stipulated no extra modules be built:

     makeoptions     MODULES_OVERRIDE=""

Then rebuilt the kernel (again without the “-j” option).

gjabkup2# cd /usr/nsk330-dev
gjabkup2# make -s TARGET=arm KERNCONF=CNS21XXNAS_GJA_1 buildkernel

--------------------------------------------------------------
>>> Kernel build for CNS21XXNAS_GJA_1 started on Mon Mar 21 18:42:16 EST 2011
--------------------------------------------------------------
===> CNS21XXNAS_GJA_1

     [....]

--------------------------------------------------------------
>>> stage 3.2: building everything
--------------------------------------------------------------
/usr/local/bin/svnversion
linking kernel
   text    data     bss     dec     hex filename
2776343  161252  150612 3088207  2f1f4f kernel
--------------------------------------------------------------
>>> Kernel build for CNS21XXNAS_GJA_1 completed on Mon Mar 21 18:44:12 EST 2011
--------------------------------------------------------------
gjabkup2#
gjabkup2# ll /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/kernel.gz.tramp.bin
-rwxr-xr-x  1 root  wheel  1485770 Mar 21 18:44 /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/kernel.gz.tramp.bin
gjabkup2# 
gjabkup2# cp /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/kernel.gz.tramp.bin /tftpboot/
gjabkup2#

The newly compiled FreeBSD 9-CURRENT kernel is located at /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/kernel.gz.tramp.bin and then copied to /tftpboot for later use.

Tweak world to work inside NS-K330 context

I built & configured world as previously described and copied it to the 512MB USB memory stick I’ve been using as an external drive.

Boot FreeBSD 9-CURRENT from RAM using TFTP

Start up the NS-K330, with serial console attached. Enter uBoot (hit <space> at the “Hit any key to stop autoboot:” prompt), load the new kernel image into RAM at address 0x600000 using TFTP and boot the new kernel.

Star Equuleus # setenv ipaddr 10.1.1.67
Star Equuleus # setenv serverip 10.1.1.12
Star Equuleus # tftpboot 0x600000 kernel.gz.tramp.bin
Check Link Status ...Up
Waiting 3 seconds ..
TFTP from server 10.1.1.12; our IP address is 10.1.1.67
Filename 'kernel.gz.tramp.bin'.
Load address: 0x600000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         ###################################################
done
Bytes transferred = 1485770 (16abca hex)
Star Equuleus # go 0x600000
## Starting application at 0x00600000 ...
Copyright (c) 1992-2011 The FreeBSD Project.
 [...blah...blah...]

Install new kernel into flash

At this point the NS-K330 is running FreeBSD 9-CURRENT from RAM. First, login as root and TFTP download the new kernel image to the external USB drive (the root file system).

ns-k330# tftp 10.1.1.12
tftp> get kernel.gz.tramp.bin
Received 1485778 bytes during 9.3 seconds in 2920 blocks
tftp>
tftp> quit
ns-k330# ll
total 1486
-rw-r--r--  1 root  wheel      784 Mar 12 18:54 .cshrc
-rw-------  1 root  wheel     2393 Mar 20 14:28 .history
-rw-r--r--  1 root  wheel      142 Mar 12 18:54 .k5login
-rw-r--r--  1 root  wheel      290 Mar 12 18:54 .login
-rw-r--r--  1 root  wheel      247 Mar 12 18:54 .profile
drwx------  2 root  wheel      512 Mar 13 10:06 .ssh
-rw-r--r--  1 root  wheel  1485770 Mar 20 14:40 kernel.gz.tramp.bin
ns-k330#

FreeBSD’s /dev/flash/spi0 device provides an interface to the NS-K330’s flash memory. We use dd to write the new kernel image. The “obs=64k” performs 64kbyte writes (as the default 4k writes didn’t seem to work), and “seek=6” ensures we skip over the initial 384kbytes reserved for uBoot.

ns-k330# dd if=kernel.gz.tramp.bin of=/dev/flash/spi0 obs=64k conv=osync seek=6
2901+1 records in
23+0 records out
1507328 bytes transferred in 18.703278 secs (80592 bytes/sec)
ns-k330#

Boot the flash-resident kernel

Initiate a reboot. This time we do not interrupt uBoot, but let it fall through to booting from the flash-resident kernel image.

ns-k330# reboot
Mar 20 14:42:20 ns-k330 reboot: rebooted by root
Mar 20 14:42:21 ns-k330 syslogd: exiting on signal 15
Syncing disks, vnodes remaining...0 0 done
All buffers synced.
Uptime: 3m56s
Rebooting...

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 ...
Copyright (c) 1992-2011 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 9.0-CURRENT #0 r219528M: Mon Mar 21 18:44:02 EST 2011
gja@gjabkup2.space4me.com:/usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1 arm
Preloaded elf kernel "elf kernel" at 0xc08f01f0.
CPU: FA526 rev 1 (ARM9TDMI core)
DC enabled IC enabled WB enabled LABT branch prediction enabled
8KB/16B 2-way Instruction cache
8KB/16B 2-way write-back-locking-B Data cache
real memory = 33554432 (32 MB)
Physical memory chunk(s):
00000000 - 0x5fffff, 6291456 bytes (1536 pages)
0x93b000 - 0x1f36fff, 23052288 bytes (5628 pages)
avail memory = 29011968 (27 MB)
ULE: setup cpu 0
mem: <memory>
null: <null device, zero device>
random: <entropy source, Software, Yarrow>
nfslock: pseudo-device
econaarm0: <ECONA device bus> on motherboard
pmc0: <pmc> mem 0x77000000-0x77ffffff on econaarm0
PLL Clock: 250Mhz
CPU Clock: 250Mhz
AHB Clock : 125Mhz
APB Clock : 62Mhz
uart0: <Non-standard ns8250 class UART with FIFOs> mem 0x78000000-0x787fffff irq 9 on econaarm0
uart0: fast interrupt
uart0: console (38461,n,8,1)
uart1: <Non-standard ns8250 class UART with FIFOs> mem 0x78800000-0x78ffffff irq 10 on econaarm0
uart1: fast interrupt
timer0: <Econa CPU Timer> mem 0x79000000-0x79ffffff irq 0,1 on econaarm0
Misc probe
misc0: <misc> mem 0x76000000-0x76ffffff on econaarm0
spi0: <SPI> mem 0x71000000-0x71ffffff on econaarm0
spibus0: <spibus bus> on spi0
m25p800: <M25p80 Flash Family> at cs 0 on spibus0
ohci0: <Econa integrated OHCI controller> mem 0xe0000000-0xe7ffffff irq 23 on econaarm0
usbus0 on ohci0
usbus0: bpf attached
ohci0: usbpf attached
ehci0: <CNS11XX USB EHCI> mem 0xe8000000-0xefffffff irq 24 on econaarm0
usbus1: EHCI version 1.0
usbus1: <CNS11XX USB EHCI> on ehci0
usbus1: bpf attached
ehci0: usbpf attached
ece0: <Econa Ethernet Controller> mem 0x70000000-0x70ffffff irq 18,19,20,21,22 on econaarm0
ece0: Generating random ethernet address.
miibus0: <MII bus> on ece0
ukphy0: <Generic IEEE 802.3u media interface> PHY 0 on miibus0
ukphy0: OUI 0x007072, model 0x0025, rev. 1
ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
ece0: bpf attached
ece0: Ethernet address: 62:73:64:12:a6:b1
CPU Clock 250000000 APB clock 62500000
Timecounter "CPU Timer" frequency 62500000 Hz quality 1000
Timecounters tick every 10.000 msec
lo0: bpf attached
m25p800: found m25p80 flash eon en25p32
GEOM: new disk flash/spi0
usbus0: 12Mbps Full Speed USB v1.0
usbus1: 480Mbps High Speed USB v2.0
ugen0.1: <Cavium> at usbus0
uhub0: <Cavium OHCI root HUB, class 9/0, rev 1.00/1.00, addr 1> on usbus0
ugen1.1: <Cavium> at usbus1
uhub1: <Cavium EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus1
uhub0: 2 ports with 2 removable, self powered
Root mount waiting for: usbus1
uhub1: 2 ports with 2 removable, self powered
Root mount waiting for: usbus1
ugen1.2: <Kingston> at usbus1
umass0: <Kingston DataTraveler 2.0, class 0/0, rev 2.00/1.00, addr 2> on usbus1
Root mount waiting for: usbus1
umass0:0:0:-1: Attached to scbus0
Root mount waiting for: usbus1
pass0 at umass-sim0 bus 0 scbus0 target 0 lun 0
pass0: <Kingston DataTraveler 2.0 1.00> Removable Direct Access SCSI-2 device
pass0: 40.000MB/s transfers
GEOM: new disk da0
da0 at umass-sim0 bus 0 scbus0 target 0 lun 0
da0: <Kingston DataTraveler 2.0 1.00> Removable Direct Access SCSI-2 device
da0: 40.000MB/s transfers
da0: 489MB (1001472 512 byte sectors: 64H 32S/T 489C)
ugen1.3: <USB> at usbus1
umass1: <USB Flash Disk, class 0/0, rev 2.00/2.00, addr 3> on usbus1
Root mount waiting for: usbus1
umass1:1:1:-1: Attached to scbus1
Trying to mount root from ufs:da0s1a []...
pass1 at umass-sim1 bus 1 scbus1 target 0 lun 0
pass1: <Generic USB Flash Disk 2.00> Removable Direct Access SCSI-2 device
pass1: Serial Number FCA4B940492AE2F4
pass1: 40.000MB/s transfers
da1 at umass-sim1 bus 1 scbus1 target 0 lun 0
da1: <Generic USB Flash Disk 2.00> Removable Direct Access SCSI-2 device
da1: Serial Number FCA4B940492AE2F4
da1: 40.000MB/s transfers
da1: 499MB (1023488 512 byte sectors: 64H 32S/T 499C)
GEOM: new disk da1
warning: no time-of-day clock registered, system time will not be set accurately
start_init: trying /sbin/init
Setting hostuuid: 6c3dbf08-4cf6-11e0-a390-62736412a6b1.
Setting hostid: 0x3711d759.
No suitable dump device was found.
Entropy harvesting: interrupts ethernet point_to_point kickstart.
Starting file system checks:
/dev/da0s1a: FILE SYSTEM CLEAN; SKIPPING CHECKS
/dev/da0s1a: clean, 143129 free (89 frags, 17880 blocks, 0.0% fragmentation)
Mounting local file systems:.
Setting hostname: ns-k330.
ece0: link state changed to DOWN
ece0: link state changed to UP
ifconfig: ACCEPT_RTADV: bad value
Starting Network: lo0 ece0.
lo0: flags=8049 metric 0 mtu 16384
        options=3
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
        nd6 options=21
ece0: flags=8843 metric 0 mtu 1500
        options=b
        ether 62:73:64:12:a6:b1
        inet 10.1.1.67 netmask 0xffffff00 broadcast 10.1.1.255
        inet6 fe80::6073:64ff:fe12:a6b1%ece0 prefixlen 64 scopeid 0x3
        nd6 options=21
        media: Ethernet autoselect (100baseTX )
        status: active
Starting devd.
Starting Network: usbus0.
Starting Network: usbus1.
add net default: gateway 10.1.1.3
add net ::ffff:0.0.0.0: gateway ::1
add net ::0.0.0.0: gateway ::1
add net fe80::: gateway ::1
add net ff02::: gateway ::1
Creating and/or trimming log files.
Starting syslogd.
/etc/rc: WARNING: Dump device does not exist.  Savecore not run.
ELF ldconfig path: /lib /usr/lib /usr/lib/compat
Clearing /tmp (X related).
Updating motd:.
Starting ntpd.
Starting sshd.
Starting cron.
Mar 20 14:43:56 ns-k330 ntpd[1079]: time correction of 101356 seconds exceeds sanity limit (1000); set clock manually to the correct UTC time.
Starting background file system checks in 60 seconds.

Sun Mar 20 14:43:57 EST 2011

FreeBSD/arm (ns-k330) (ttyu0)

login:

Cool! It worked. We now have the NS-K330 booting a FreeBSD 9-CURRENT kernel from flash. (NOTE: Since the FreeBSD world on the USB disk has been used before, we do not incur again the time penalty of re-calculating ssh host keys.)

Login to confirm….

ns-k330#
ns-k330# uname -a
FreeBSD ns-k330 9.0-CURRENT FreeBSD 9.0-CURRENT #0 r219528M: Mon Mar 21 18:44:02 EST 2011 gja@gjabkup2.space4me.com:/usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1 arm
ns-k330#

Conclusion

Yup, we can boot a patched version of FreeBSD 9.0-CURRENT, although an external USB drive is required to hold World.

Advertisements

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: