ARM, CAM, FreeBSD, mmccam, SDIO, Software

Building FreeBSD’s SDIO driver for BeagleBone Black

Hi all, This post mainly concern with building FreeBSD’s SDIO driver for BeagleBone Black by cross compiling it on AMD platform. I had few unresolved issues with the master branch of current FreeBSD tree. So, for this i used another unofficial branch: . It does have the required KERNCONF file with stable SDIO driver.

A lot of steps below are similar to the one given on:  with slight but inevitable changes.


  1.  Before proceeding you need to first install git.
    sudo pkg update -f
    sudo pkg install git
  2.  Setup project directory by mkdir /BBB
  3.  Clone the repository to /BBB/src by
    git clone -b mmcam-new /BBB/src
  4. Setup environment variables as
    setenv BASEDIR /BBB
    setenv TARGET arm
    setenv TARGET_ARCH armv6

    Note that sometime it shows an error like: Undefined command setenv, in that case just switch to root as sudo -E su and then try setting the environment variables again.

  5. Create image file and setup MSDOS filesystem for u-boot
    truncate -s 2048M /BBB/bbb.img
    mdconfig -f /BBB/bbb.img -u md0
    gpart create -s MBR md0
    gpart add -t \!12 -s 10m md0
    newfs_msdos -F12 -L 'MSDOSBOOT' /dev/md0s1
    gpart set -a active -i 1 md0
  6. Make Buildworld and buildkernel
    cd $BASEDIR/src
    make -j8 buildworld TARGET=arm TARGET_ARCH=armv6 UBLDR_LOADADDR=0x88000000 -DWITH_FDT __MAKE_CONF=/dev/null SRCCONF=/dev/null

    Note here, that if your FreeBSD AMD environment is on virtual box, for above builds to be successful you need around 2Gb of RAM and 4Gb of Swap memory with -j7 option. Swap space can be checked via swapinfo command. For adding more swap just head towards:

  7. Mount the MSDOS partition and copy the uboot stuff to it.
    mount_msdosfs /dev/md0s1 /mnt
    cp /usr/ports/sysutils/u-boot-beaglebone/work/u-boot-2018.03/MLO /mnt
    cp /usr/ports/sysutils/u-boot-beaglebone/work/u-boot-2018.03/boot.scr /mnt
    cp /usr/ports/sysutils/u-boot-beaglebone/work/u-boot-2018.03/u-boot.img /mnt
    cp /BBB/obj/arm.armv6/BBB/src/sys/boot/arm/uboot/ubldr /mnt
    cp /BBB/obj/arm.armv6/BBB/src/sys/boot/arm/uboot/ubldr.bin /mnt
    umount /mnt

    Note that sysutils/u-boot-beaglebone port doesn’t come by default, in fresh FreeBSD installation. It has to be installed by

    pkg install u-boot-beaglebone
    cd /usr/ports/sysutils/u-boot-beaglebone/ && make install clean
  8. Make the freebsd-ufs partition
    mkdir /mnt1
    gpart add -t freebsd md0
    gpart create -s BSD md0s2
    gpart add -t freebsd-ufs md0s2
    newfs /dev/md0s2a
    tunefs -N enable -j enable -t enable /dev/md0s2a
    mount /dev/md0s2a /mnt1
  9.  Do installworld, installkernel into the partition
    make installworld TARGET_ARCH=armv6 DESTDIR=/mnt1
    make distribution TARGET_ARCH=armv6 DESTDIR=/mnt1
  10.  Install setup, create fstab and rc.conf
    touch /mnt1/firstboot
    mkdir /mnt1/boot/msdos
    ee /mnt1/etc/fstab
    # Custom /etc/fstab for FreeBSD embedded images
    /dev/sdda0s1    /boot/msdos    msdosfs rw,noatime    0 0
    /dev/sdda0s2a    /        ufs rw,noatime        1 1
    ee /mnt1/etc/rc.conf
  11. Complete setup by
    umount /mnt1
    mdconfig -d -u0


Great, you are now ready to go and dd the obtained bbb.img image to sd card. With every thing working kernel should boot up with multiple MMCCAM debug logs as in here. In case of any error, feel free to post it on the forums or comment below.


SDIO driver has now been fixed in FreeBSD-Current head. In order to build for FreeBSD-Current just use GENERIC-MMCCAM kernel config file instead of BEAGLEBONE-MMCCAM.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.