Using modules to extend FreeBSD 9-CURRENT on NS-K330

A few days ago I got a heavily stripped down FreeBSD 9-CURRENT kernel running from flash on my NS-K330. This post summarises my next experiment — building kernel modules to extend the NS-K330’s FreeBSD capabilities without exceeding the space allowed for the flash-resident kernel image.

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

I previously got under this limit by stripping out many unneeded options, and using the following kernel config line to ensure no .ko modules were built-in to the kernel image.

      makeoptions     MODULES_OVERRIDE=""

This helped build a suitably small kernel image.

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#

Building new modules

The trick is to build as much extra functionality as you can in the form of specific .ko modules that will be kldload’ed (from the USB drive) once the FreeBSD kernel itself has booted. This turns out to be as simple as adding the module names to the MODULES_OVERRIDE option.

For example, to build the wlan module:

  makeoptions MODULES_OVERRIDE="wlan"

And then run buildkernel as usual. The new module(s) will be stored under /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/modules/usr/nsk330-dev/sys/modules/wlan/

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 19:15:30 EST 2011
--------------------------------------------------------------
===> CNS21XXNAS_GJA_1

--------------------------------------------------------------
>>> stage 1: configuring the kernel
--------------------------------------------------------------
Kernel build directory is /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1
 [...]
linking kernel
   text data bss dec hex filename
2776343 161252 150612 3088207 2f1f4f kernel
===> wlan (all)
--------------------------------------------------------------
>>> Kernel build for CNS21XXNAS_GJA_1 completed on Mon Mar 21 19:17:33 EST 2011
--------------------------------------------------------------
gjabkup2#
gjabkup2# ll /usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/modules/usr/nsk330-dev/sys/modules/wlan/
total 1248
     [...stuff...]
-rw-r--r-- 1 root wheel 278520 Mar 21 19:17 wlan.kld
-rwxr-xr-x 1 root wheel 270272 Mar 21 19:17 wlan.ko
gjabkup2#

Then on then NS-K330, copy the module to the local USB drive and kldload it into the running kernel.

ns-k330# scp gja@10.1.1.12:/usr/obj/arm.arm/usr/nsk330-dev/sys/CNS21XXNAS_GJA_1/modules/usr/nsk330-dev/sys/modules/wlan/wlan.ko /boot/kernel/
Password:
wlan.ko 100% 264KB 263.9KB/s 00:01
ns-k330# kldstat
Id Refs Address Size Name
 1    1 0xc0600000 2f3054 elf kernel
ns-k330# kldload wlan
ns-k330# kldstat
Id Refs Address Size Name
 1    6 0xc0600000 2f3054 elf kernel
 2    1 0xc0d37000 3c000 wlan.ko
ns-k330#

Voila! The running kernel now has the wlan functionality loaded.

Conclusion

Build stripped down kernel image to store on flash, and keep other functionality stored as kldload’able modules on the root file system.

Ideally in the future FreeBSD will learn how to utilise the rest of the 8MB flash for a root filesystem, removing the need for a USB drive holding world.

Advertisements

One comment

  1. […] been looking for a way to build packages for FreeBSD running on small ARM devices (e.g. the NS-K330 with 32MB RAM), and recently stumbled across Oleksandr Tymoshenko’s work here. He has […]

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: