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: https://github.com/kibab/freebsd/tree/mmcam-new . It does have the required KERNCONF file with stable SDIO driver.

A lot of steps below are similar to the one given on: https://forums.freebsd.org/threads/cross-compiling-beaglebone-on-amd64.64718/#post-384835  with slight but inevitable changes.

Procedure:

  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 https://github.com/kibab/freebsd.git /BBB/src
  4. Setup environment variables as
    setenv BASEDIR /BBB
    setenv MAKEOBJDIRPREFIX $BASEDIR/obj
    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
    make buildkernel TARGET_ARCH=armv6 KERNCONF=BEAGLEBONE-MMCCAM

    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: https://www.freebsd.org/doc/handbook/adding-swap-space.html

  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
    make installkernel TARGET_ARCH=armv6 KERNCONF=BEAGLEBONE-MMCCAM 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
    hostname="beaglebone"
    ifconfig_DEFAULT="DHCP"
    sshd_enable="YES"
    sendmail_enable="NONE"
    sendmail_submit_enable="NO"
    sendmail_outbound_enable="NO"
    sendmail_msp_queue_enable="NO"
  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.

UPDATE(24/06/18):

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.

References:

  • https://forums.freebsd.org/threads/cross-compiling-beaglebone-on-amd64.64718/#post-384835
  • http://freebsd-arm.freebsd.narkive.com/dZ0TaVwR/bbb-imx6-hummingboard-sdio-driver#post14
  • https://wiki.freebsd.org/SDIO

Leave a Reply

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