Previous Home Next


I do most of my development work on an x86 Linux system, and thus wanted to be able to cross-build the NetBSD system from within the Linux environment. Fortunately, NetBSD provides a great build system that supports both cross-compilation (building for a processor architecture different from that of the build host) and cross-platform builds (building the system on a non-NetBSD build host).

The build process consists of several steps:
NetBSD comes with a wonderful shell script,, that makes all of this easy.

Building the Toolchain

Building the toolchain can be accomplished using the script: just run
./ -u -m evbarm tools
from within the top-level source directory.

I actually found I had a problem when trying to build the toolchain on a Fedora Core 5 system because the native Fedora tools (which are used to build the NetBSD toochain) were too new (gcc 4.1). The NetBSD toolchain would build cleanly only with gcc version 3 tools. Luckily, Fedora provides optional packages for the GCC 3.2 toolset, which can be installed with
yum install compat-gcc-3.2

The toolchain build process then becomes
export HOST_CC=gcc32
export HOST_CXX=g++32
./ -u -m evbarm tools
to ensure the gcc-3-based tools are used to build the toolchain. Note that these tools (and the export statements) aren't needed once the NetBSD toolchain is built - they're just needed to "bootstrap" the toolchain itself. Note also that the latest NetBSD distribution should build cleanly with the gcc 4-based tools, so this step shouldn't be necessary.

Building the Kernel

Building the NetBSD kernel is also accomplished using the script: just run
./ -u -m evbarm kernel=VX115_VEP
from within the top-level source directory.


This command performs a number of operations:
When the command completes, it will create the kernel objects in the sys/arch/evbarm/compile/obj/VX115_VEP directory. The object files will include the ELF kernel object, and may contain the output in different formats depending on the configuration.

Building the Userspace Libraries and Applications

Since the NetBSD distribution includes all of the userspace libraries and applications, the script handles these, too: just run
./ -u -m evbarm 
from within the top-level source directory. This will create a directory obj/destdir.evbarm with all of the userspace files. 

Building the Root Filesystem

The default build for NetBSD creates a filesystem for a desktop system, which is way too big for an embedded system. I pulled out just the minimum basic libraries and apps needed to have a console into a separate directory called rootfs_ramdisk. (In fact, this is almost certainly not the bare minimum, but was small enough to fit in the ramdisk, so I didn't bother to strip it further.)
This directory is a directory of files on the build host filesystem (Linux, in my case, using an ext3 filesystem). It's necessary to create a single file which contains the filesystem image for NetBSD - that is, the  set of objects which are currently in the build host filesystem, but packaged such that they form a NetBSD filesystem. This is done with the tool nbmakefs, which is built as part of the toolchain.
nbmakefs -s 5000k rootfs_ramdisk.img rootfs_ramdisk
This will create a filesystem of total size 5000 kB - the resulting image will be 5000 kB in size (or about 4.9 MB). This value is also used in the kernel configuration to "reserve" this much space in the kernel for the filesystem ramdisk image.

Inserting the Ramdisk Image into the Kernel

The ramdisk created above is inserted into the kernel using the tool mdsetimage:
arm--netbsdelf-mdsetimage -v -s netbsd rootfs_ramdisk.img
where netbsd is the kernel image created from the kernel build process.

Further Packaging

For the evaluation platform here, the platform loader used s-record format for the loadable files, so it was necessary to use the objcopy tool to generate the loadable srec from the kernel+ramdisk image. In addition, the kernel was to be loaded at address 0x20400000 in the system Flash, while it was configured to execute at 0x24300000, which required the --change-addresses argument during s-record generation. This sort of thin is very platform-specific, so these steps may not be relevant for another platform.
arm--netbsdelf-objcopy -S -O binary netbsd netbsd.bin
arm--netbsdelf-objcopy --input-target=binary --output-target=srec --change-addresses=0x20400000 -v netbsd.bin netbsd.bin.srec

Previous Home Next