FreeBsd kernel development preparations (amd64 on bhyve VM)

The plan is just to get kernel’s early start phase trace to be able to cross check the sources for initialization order. It shall be an exemplary for further development of BeagleBoneBlack platform device driver.
I just wonder why there is no documentation considering kernel early boot phase. But on the other side, FreeBSD is not worse than Linux…
There is a tiny piece which can be considered as a seed for further investigations:
Clock management for am335x is provided by /usr/src/sys/arm/ti/am335x/am335x_prcm.c. Device is “am335x,prcm” aka “AM335x Power and Clock Management”.
Clock management device “AM335x Power and Clock Management” is used by /usr/src/sys/arm/ti/ti_prcm.c. Generally only ti_clk_devmap[] array seems to be relevant.
Modules like ti_sdma.c or ti_priuss.c enable peripherial clock by calling ti_prcm_clk_enable(…) and using callbacks from am335x_prcm.c wrapper via structs. See ti_prcm.h for available clocks in clk_ident_t enum. Pin muxers are configured by am335x_scm_padconf.c module.

Using bhyve (works without modifications and quirks): Just install basic system configuration. It is done amazingly fast.

Using mdconf to mount virtualized disk as loop device: Watch out not to use -t option while mounting. It results in “Operation not permitted”. If you are unsure what kind of slice do you have, just use file -s /dev/ada0sX to inspect it. Be sure to have a clean slice, otherwise it will not mount – as physical partition does not. Run fsck if needed. See dmesg output if something goes wrong. It contains additional info.

Cool command to make you proud of SSD disk:
diskinfo -t /dev/ada0s1a

SH script for running VM:



if [ -z "$2" ]

destroy_interface () {
i=`ifconfig tap0 2>&1|grep "does not"`
  if [ -z "$i"  ]
      ifconfig $1 destroy; echo "Interface $1 destroyed";

create_bridge () {
echo "Creating bridge"
ifconfig tap0 create
ifconfig bridge0 create
ifconfig bridge0 addm $NET_INTERFACE addm tap0
ifconfig bridge0 up    

echo "Preparing bhyve network environment"
destroy_interface bridge0
destroy_interface tap0


echo "Starting VM"
sh /usr/share/examples/bhyve/ -c 4 -m 1024M -t tap0 -d ./$VM_IMG_NAME fbsd_10_3_amd64_test_guest

echo "Cleanup network environment"
ifconfig bridge0 down
destroy_interface bridge0
destroy_interface tap0

Shell programming help:

Git ignore file tolerating only SH scripts in repository:


Linux kernel start up and debugging

Slightly off-topic, but linux is stil a unixoid operating system. And every hint on system startup and debugging is valuable.

Seems like running OpenOCD and Turtelizer2 JTAG dongle with NanosG20 will be necesssary. AT91SAM9G20 support should be available, I hope.

Other points are:

  • Use QEMU/VirtualBox + GDB to observe startup behaviour of FreeBSD
  • Remember, nobody forbids looking at certain portions of Linux/NetBSD/OpenBSD kernel sources
  • OpenBSD and NetBSD are also a source of knowledge
  • Take a look at Atmel startup code
  • Make a table of prio 1 peripherials used by the kernel
  • Prioritize other peripherials

So, in summary I will use NanosG20 hardware, U-boot for PortuxG20 and FreeBSD kernel (no idea what is implemented at the moment)