Embedded Handbook

This Handbook is dedicated for all kernel developer beginners. It provides useful snippets of code and use-cases for begginers. This will not cover the theory of FreeBSD's kernel architecture. Please, read the handbooks, given in links section.

Compiling

Environment variables for building kernel/world:

ARCH=arm
TARGET_ARCH=arm
MAKEOBJDIRPREFIX=/home/aleek/obj

Kernel

export MAKEOBJDIRPREFIX=/home/aleek/obj
export ARCH=arm
export TARGET_ARCH=arm
make kernel-toolchain (not necessary, when building world before kernel)
make buildkernel KERNCONF=BEAGLEBOARD-XM
make buildworld

All object files will be written to MAKEOBJDIRPREFIX directory. Kernel config files are stored in sys/$ARCH/conf

Compiler kernel is stored in $MAKEOBJDIRPREFIX/$TARGET_ARCH.$ARCH/usr/$MAKEOBJDIRPREFIX/sys/$KERNCONF/ i.e. /home/aleek/obj/arm.arm/usr/home/aleek/armv6/sys/BEAGLEBOARD-XM. You are interested in 3 of them:

$ file kernel
kernel: ELF 32-bit LSB executable, ARM, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped
$ file kernel.bin     // raw kernel
kernel.bin: data
$ file kernel.debug   // kernel with debugging symbols, useful for gdb 
kernel.debug: ELF 32-bit LSB executable, ARM, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped

You can make developer's toolchain, instead of regular:

make xdev XDEV=arm XDEV_ARCH=arm

RTEMS provides set of GNU debuggers for a couple of architectures:

# cd /usr/ports; make search name=rtems-gdb                                                                                                                                                                                                                                                                                                    
Port:   arm-rtems-gdb-7.2
Path:   /usr/ports/devel/arm-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

Port:   i386-rtems-gdb-7.2
Path:   /usr/ports/devel/i386-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

Port:   m68k-rtems-gdb-7.2
Path:   /usr/ports/devel/m68k-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

Port:   mips-rtems-gdb-7.2
Path:   /usr/ports/devel/mips-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

Port:   powerpc-rtems-gdb-7.2
Path:   /usr/ports/devel/powerpc-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

Port:   sh-rtems-gdb-7.2
Path:   /usr/ports/devel/sh-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

Port:   sparc-rtems-gdb-7.2
Path:   /usr/ports/devel/sparc-rtems-gdb
Info:   GNU gdb port for cross-target development
Maint:  ports@FreeBSD.org

world

make TARGET_ARCH=arm TARGET_CPUTYPE=armv6 buildworld
make TARGET_ARCH=arm TARGET_CPUTYPE=armv6 DESTDIR=/home/alek/beagle_rootfs SHAREOWN=alek SHAREGRP=wheel INSTALL=/home/alek/beagle-armv6/tools/install.sh installworld -DWITHOUT_SHAREDOCS -DWITHOUT_EXAMPLES -DWITHOUT_GAMES -DWITHOUT_HTML -DWITHOUT_INFO -DWITHOUT_MAN
make distrib-dirs DESTDIR=/home/alek/beagle_rootfs
make distribution DESTDIR=/home/alek/beagle_rootfs

distrib-dirs makes dirs for rootfs (var, etc, usr ), and distribution "populates DESTDIR with various configuration files and scripts, obviously mostly etc, but it will add some files to rootdir, var and probably somewhere else as well"

Running

u-boot with tftp

rootfs via nfs

debugging

kdb

j-tag and gdb

Porting FreeBSD to new boards

Let's see, how to port FreeBSD by example: BeagleBoard-xM. The port is using Flattened Device Tree for describing the software.

Config file

Useful options during development:

makeoptions     DEBUG=-g                #Build kernel with gdb(1) debug symbols
options         BREAK_TO_DEBUGGER       #also ALT_BREAK_TO_DEBUGGER
options         VERBOSE_SYSINIT         #Enable verbose sysinit messages
options         KDB
options         DDB                     #Enable the kernel debugger
options         INVARIANTS              #Enable calls of extra sanity checking
options         INVARIANT_SUPPORT       #Extra sanity checks of internal structures, required by INVARIANTS
options         WITNESS                 #Enable checks to detect deadlocks and cycles
options         WITNESS_SKIPSPIN        #Don't run witness on spinlocks for speed
options         DIAGNOSTIC
options         DEBUG

initarm()

Useful Links

* FreeBSD Architecture Handbook

* FreeBSD Developers' Handbook

* irc://irc.efnet.pl/#bsdmips - The IRC channel for FreeBSD on ARM, AVR32 and PowerPC!

EmbeddedHandbook (last edited 2013-06-28 12:11:32 by AleksanderDutkowski)