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…
UPDATE:
There is a tiny piece which can be considered as a seed for further investigations: https://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/boot-kernel.html
UPDATE:
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”.
UPDATE:
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):
https://www.freebsd.org/doc/handbook/virtualization-host-bhyve.html. Just install basic system configuration. It is done amazingly fast.

Using mdconf to mount virtualized disk as loop device:
http://gdr.geekhood.net/gdrwpl/loop-freebsd.php. 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:


#!/bin/sh

NET_INTERFACE=$1

if [ -z "$2" ]
then
    VM_IMG_NAME="fbsd_10_3_amd64_guest.img"
else
    VM_IMG_NAME=$2
fi

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

create_bridge () {
echo "Creating bridge"
ifconfig tap0 create
sysctl net.link.tap.up_on_open=1
ifconfig bridge0 create
ifconfig bridge0 addm $NET_INTERFACE addm tap0
ifconfig bridge0 up    
}

echo "Preparing bhyve network environment"
destroy_interface bridge0
destroy_interface tap0

create_bridge

echo "Starting VM"
sh /usr/share/examples/bhyve/vmrun.sh -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:
http://www.tldp.org/LDP/abs/html/

Git ignore file tolerating only SH scripts in repository:


/*
!*.sh

Booting FreeBSD with GRUB2 on MBR

DO:

https://wiki.bsdforen.de/howto:grub2-anleitung

menuentry “FreeBSD 9.0 (1)” –class freebsd –class bsd –class os

{

echo Chainloading slice hd0,2 … chainloader (hd0,2)+1

}

DO NOT:

Two other possibilities from this post. Third one eliminates boot1, boot2 and loader stage leaving the job to grub2. Stuff like loader.conf will be entirely ignored… Mountroot will require manual ufs:/dev/da0xxx entry.

UPDATE:

This procedure does not work for another PC, what works is:

menuentry "FreeBSD" {
insmod ufs2
insmod part_gpt
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 574744019d04da3b
kfreebsd /boot/kernel/kernel
kfreebsd_loadenv /boot/device.hints
set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada0s1a
set kFreeBSD.vfs.root.mountfrom.options=rw
}

To find out fs_uuid under linux (debianoid): sudo grub-probe -t fs_uuid -d /dev/sda1

This GRUB2 crap is not funny anymore!

NanosG20 FreeBSD

I would be glad to see FreeBSD running on NanosG20. Since I have no idea how to do that, I need  to investigate. One way would be finding a posibility to run u-boot for AT91SAM9G20 out of the NanosG20 2nd Stage Bootloader (stripped linux kernel). But another solution does exist:

http://www.armbedded.eu/node/445

It is a transplantation of PortuxG20 u-boot into NanosG20.

If this will work, next step would be flashing AT91SAM9G20 u-boot with FreeBSD booting support. And last but not least a working AT91SAM9G20 kernel must be available.

Another help:

Similar processor:

http://www.hytherion.com/beattidp/comput/armbsd/freebsd-on-at91sam9260ek.html

http://wiki.freebsd.org/FreeBSDAtmel

Comparison of linux and bsd kernel startup sequence:

http://cisr.nps.edu/downloads/papers/05paper_linux.pdf

BSD kernel structure:

http://www.atmnis.com/~proger/openkyiv/openkyiv2009_proger_sys.pdf