FreeBSD/Pi setup HowTo

August 5, 2012 — 59 Comments

This instruction is no longer correct. New version is here

Took some time but it seems we’re there too :)

Alexander Rybalko, who works on USB drivers for the platform got remote telnet shell to the device: http://pastebin.com/6NqQLWD2

Having fixed serial console for userland applications (two lines change) and after some tweaking of SDHCI driver I got access to multiuser shell too: multiuser.txt
Still not usable for putting together distros but stable enough for those who are willing to get their hands dirty with kernel side.

Here is short how to on getting FreeBSD boot on Raspberry Pi:

Get sources:

git clone git://github.com/gonzoua/freebsd-pi.git
cd freebsd-pi
git checkout rpi

Fetch u-boot files from here: freebsd-pi-uboot-20120806-sd.tar.gz.

Build sources and create SD card image with script like this:
#!/bin/sh
set -e

export TARGET_ARCH=arm
export SRCROOT=/usr/home/gonzo/Sources/freebsd-pi
export MAKEOBJDIRPREFIX=/usr/home/gonzo/Sources/obj
export KERNCONF=RPI-B
KERNEL_BIN=`realpath $MAKEOBJDIRPREFIX`/arm.arm/`realpath $SRCROOT`/sys/$KERNCONF/kernel.bin

make -C $SRCROOT kernel-toolchain
make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
make -C $SRCROOT TARGET_CPUTYPE=armv6 MALLOC_PRODUCTION=yes buildworld

IMG=bsd-pi.img
rm -f $IMG
dd if=/dev/zero of=$IMG bs=128M count=8
MDFILE=`mdconfig -a -f bsd-pi.img`
gpart create -s MBR ${MDFILE}
gpart add -s 32m -t '!12' ${MDFILE}
gpart add -s 896m -t '!12' ${MDFILE}
gpart set -a active -i 1 ${MDFILE}
newfs_msdos -L boot -F 16 /dev/${MDFILE}s1
newfs /dev/${MDFILE}s2
mount_msdosfs /dev/${MDFILE}s1 /mnt
tar -x -v -z -C /mnt -f freebsd-uboot-sd.tar.gz
cp $KERNEL_BIN /mnt
umount /mnt
mount /dev/${MDFILE}s2 /mnt
make -C $SRCROOT DESTDIR=/mnt installworld
make -C $SRCROOT DESTDIR=/mnt distribution

# Minimal config
echo 'hostname="freebsd-pi"' > /mnt/etc/rc.conf
echo '/dev/mmcsd0s2 / ufs rw 1 1' > /mnt/etc/fstab

umount /mnt
mdconfig -d -u $MDFILE

dd image to SD card, insert it to Raspberry Pi and check serial port for some output

There is also U-Boot configuration that uses dhcp/tftp method by default freebsd-pi-uboot-20120806-netboot.tar.gz. It’s more suitable for kernel hacking but requires environment setup.

gonzo

Posts

59 responses to FreeBSD/Pi setup HowTo

  1. Hello There!!

    Thans a lot for the imformation!!

    As soon as I fix some mess I’ve made, I’ll try this out!

    Kind Regards!!

  2. Thank you for great information.

    Now I’m creating image file and I will test this image tomorrow with my r-pi.

    By the way, I have below error in script.

    x boot.scr: Can’t set user=1001/group=0 for boot.scr
    x bootcode.bin: Can’t set user=1001/group=0 for bootcode.bin
    x cmdline.txt: Can’t set user=1001/group=0 for cmdline.txt
    x config.txt: Can’t set user=1001/group=0 for config.txt
    x loader.bin: Can’t set user=1001/group=0 for loader.bin
    x start.elf: Can’t set user=1001/group=0 for start.elf
    x u-boot.bin: Can’t set user=1001/group=0 for u-boot.bin
    x uEnv.txt: Can’t set user=1001/group=0 for uEnv.txt
    tar: Error exit delayed from previous errors.

    So, I change tar line as below(added –uname root)
    [NEW]
    tar -x -v -z –uname root -C /mnt -f freebsd-uboot-sd.tar.gz

    Yours
    Yoshiro MIHIRA

  3. Thanks!

    What is next roadmap? make it stable?

  4. Just wanted to feed back, major thanks for your work.

    I can report that following the above instructions I have a RPi booted with 10-Current. Had a bit of an issue building on 9.0-Release due to tar not supporting –uname out of the box, but solved that just by extracting, reowning and recompressing the file to work with the script.

    One comment though is that the serial interface in uboot is set to 115200, but the first tty is set to 9600… Adjusting the tty to 115200 was easy enough and let me get onto the device!

    Thanks again! Looking forward to some usb-age and network-age.

    • Hi, I seem to be hitting the same issue where tar is not taking -uname and -x at the same time. How did you workaround the problem?

  5. Great ! Any chance to have OpenBSD ?

    • I don’t know the state of affairs in OpenBSD but if they have support for armv6 (which seems to be the case) – I see no major road blocks for making a port.

  6. Roberth Sjonøy August 22, 2012 at 4:21 am

    What about hard floting points?

  7. Stanislaw Wadas August 22, 2012 at 2:09 pm

    Hi, great job,
    are there any possibility to merge port files and FTD with 9-RELEASE?
    I was trying to do this using files from your git-src but I think there is to much changes made.

    • my tree is based on projects/armv6 bracnh that has been merged to HEAD recently. I’m not sure how much it would take to get these changes to stable/9.

  8. http://web.archiveorange.com/archive/v/jLTVccKByCJ9JA3o0lA7

    I am getting such errors.

    what can I do to fix them?
    % uname -a
    FreeBSD xxxxxxxx.com 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r239692: Sat Aug 25 16:34:59 PDT 2012 root@xxxxxxxx.com:/usr/obj/usr/src/stable/9/sys/GENERIC amd64

    • Yes. It’s known issue with later version of FreeBSD, both CURRENT and 9.1. I started merging bits back to subversion, so you can try building latest HEAD from svn with this patch: http://people.freebsd.org/~gonzo/arm/rpi/rpi-head-20120825.diff

      • thanks for getting back so quickly.

        After applying the patch, I am getting:

        ————————————————————–
        >>> stage 1: configuring the kernel
        ————————————————————–
        cd /usr/home/stdp/freebsd-pi/sys/arm/conf; PATH=/usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/tmp/legacy/usr/sbin:/usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/tmp/legacy/usr/bin:/usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/tmp/legacy/usr/games:/usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/tmp/usr/sbin:/usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/tmp/usr/bin:/usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/tmp/usr/games:/sbin:/bin:/usr/sbin:/usr/bin config -d /usr/home/stdp/obj/arm.arm/usr/home/stdp/freebsd-pi/sys/RPI-B /usr/home/stdp/freebsd-pi/sys/arm/conf/RPI-B
        config: /usr/home/stdp/freebsd-pi/sys/arm/conf/RPI-B:21: only one machine directive is allowed
        *** [buildkernel] Error code 1

        Stop in /usr/home/stdp/freebsd-pi.
        *** [buildkernel] Error code 1

        Stop in /usr/home/stdp/freebsd-pi.

        • The build script should be changed as well. Use somethin like this:


          #!/bin/sh
          set -e

          export TARGET=arm
          export TARGET_ARCH=armv6
          export SRCROOT=/src/FreeBSD/head
          export MAKEOBJDIRPREFIX=/src/FreeBSD/obj
          export KERNCONF=RPI-B

          make -C $SRCROOT kernel-toolchain
          make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
          make -C $SRCROOT MALLOC_PRODUCTION=yes buildworld

          I haven’t checked buildworld yet, though

  9. Hi,

    Btw is there any timeline for FreeBSD Raspberry Pi development? Are you planning to release the .img here? since no one doing so for FreeBSD arm ports

  10. Very cool. I have no u-boot experience and I am just beginning to explore it. I would like to dhcp/tftp boot the rpi, with a linux kernel though. I was wondering, if you know, would booting a linux kernel be as simple as substituting the linux kernel for a bsd kernel you are using in this example. Thanks, I’m looking at as many u-boot resources as I can find but I’m still a little lost.

  11. Continuing http://kernelnomicon.org/?p=164#comment-918

    Here is how my build script looks:

    #!/bin/sh
    set -e

    export TARGET=arm
    export TARGET_ARCH=arm
    export SRCROOT=/home/hari/git_stuff/freebsd-pi
    export MAKEOBJDIRPREFIX=/usr/home/hari/obj
    export KERNCONF=RPI-B

    make -C $SRCROOT kernel-toolchain
    make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
    make -C $SRCROOT MALLOC_PRODUCTION=yes buildworld

    IMG=bsd-pi.img
    rm -f $IMG
    dd if=/dev/zero of=$IMG bs=128M count=8
    MDFILE=`mdconfig -a -f bsd-pi.img`
    gpart create -s MBR ${MDFILE}
    gpart add -s 32m -t ‘!12′ ${MDFILE}
    gpart add -s 896m -t ‘!12′ ${MDFILE}
    gpart set -a active -i 1 ${MDFILE}
    newfs_msdos -L boot -F 16 /dev/${MDFILE}s1
    newfs /dev/${MDFILE}s2
    mount_msdosfs /dev/${MDFILE}s1 /mnt
    tar -x -v -z -C /mnt -f freebsd-pi-uboot-20120806-sd.tar.gz
    cp $KERNEL_BIN /mnt
    umount /mnt
    mount /dev/${MDFILE}s2 /mnt
    make -C $SRCROOT DESTDIR=/mnt installworld
    make -C $SRCROOT DESTDIR=/mnt distribution

    # Minimal config
    echo ‘hostname=”freebsd-pi”‘ > /mnt/etc/rc.conf
    echo ‘/dev/mmcsd0s2 / ufs rw 1 1′ > /mnt/etc/fstab

    umount /mnt
    mdconfig -d -u $MDFILE

    • Just replace
      make -C $SRCROOT MALLOC_PRODUCTION=yes buildworld
      with
      make -C $SRCROOT MALLOC_PRODUCTION=yes TARGET_CPUTYPE=armv6 buildworld
      and it should work.

      Also make sure you did git checkout rpi after git clone.
      No need to apply any patches for this tree

      • Sorry for the iterations we are going through but it still fails.

        Here is what I have:

        1) this is my kernel:
        $ uname -a
        FreeBSD xxxxx 10.0-CURRENT FreeBSD 10.0-CURRENT #3 r239996M: Sun Sep 2 01:45:39 PDT 2012 root@xxxxx:/usr/obj/usr/src/head/sys/GENERIC amd64

        2) I checked out the git tree:
        git clone git://github.com/gonzoua/freebsd-pi.git
        cd freebsd-pi
        git checkout rpi

        3) here is the buildscript:

        #!/bin/sh
        set -e

        export TARGET=arm
        export TARGET_ARCH=arm
        export SRCROOT=/home/hari/git_stuff/freebsd-pi
        export MAKEOBJDIRPREFIX=/usr/home/hari/obj
        export KERNCONF=RPI-B

        make -C $SRCROOT kernel-toolchain
        make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
        make -C $SRCROOT MALLOC_PRODUCTION=yes TARGET_CPUTYPE=armv6 buildworld

        IMG=bsd-pi.img
        rm -f $IMG
        dd if=/dev/zero of=$IMG bs=128M count=8
        MDFILE=`mdconfig -a -f bsd-pi.img`
        gpart create -s MBR ${MDFILE}
        gpart add -s 32m -t ‘!12′ ${MDFILE}
        gpart add -s 896m -t ‘!12′ ${MDFILE}
        gpart set -a active -i 1 ${MDFILE}
        newfs_msdos -L boot -F 16 /dev/${MDFILE}s1
        newfs /dev/${MDFILE}s2
        mount_msdosfs /dev/${MDFILE}s1 /mnt
        tar -x -v -z -C /mnt -f freebsd-pi-uboot-20120806-sd.tar.gz
        cp $KERNEL_BIN /mnt
        umount /mnt
        mount /dev/${MDFILE}s2 /mnt
        make -C $SRCROOT DESTDIR=/mnt installworld
        make -C $SRCROOT DESTDIR=/mnt distribution

        # Minimal config
        echo ‘hostname=”freebsd-pi”‘ > /mnt/etc/rc.conf
        echo ‘/dev/mmcsd0s2 / ufs rw 1 1′ > /mnt/etc/fstab

        umount /mnt
        mdconfig -d -u $MDFILE

        4) running the script fails:

        /usr/home/hari/git_stuff/freebsd-pi/lib/libc/net/nsparser.y: In function ‘_nsaddsrctomap’:
        /usr/home/hari/git_stuff/freebsd-pi/lib/libc/net/nsparser.y:169: warning: implicit declaration of function ‘free’
        In file included from nsparser.c:398:
        /usr/home/hari/git_stuff/freebsd-pi/lib/libc/../../include/stdlib.h: At top level:
        /usr/home/hari/git_stuff/freebsd-pi/lib/libc/../../include/stdlib.h:93: warning: conflicting types for ‘free’
        /usr/home/hari/git_stuff/freebsd-pi/lib/libc/net/nsparser.y:169: warning: previous implicit declaration of ‘free’ was here
        *** [nsparser.o] Error code 1

        Stop in /usr/home/hari/git_stuff/freebsd-pi/lib/libc.
        *** [lib/libc__L] Error code 1

        Stop in /usr/home/hari/git_stuff/freebsd-pi.
        *** [libraries] Error code 1

        Stop in /usr/home/hari/git_stuff/freebsd-pi.
        *** [_libraries] Error code 1

        Stop in /usr/home/hari/git_stuff/freebsd-pi.
        *** [buildworld] Error code 1

        Stop in /usr/home/hari/git_stuff/freebsd-pi.

        • I keep forgetting about this issue. Sources grew incompatible with -CURRENT. Try building svn. Checkout latest head from http://svn.freebsd.org/base/head
          Then apply this patch: http://people.freebsd.org/~gonzo/arm/rpi/rpi-head-20120902.diff

          Use the same script but TARGET_ARCH should be armv6 and remove TARGET_CPUTYPE=armv6 from buildworld line
          The rest is just the same.
          Sorry about this breakage. I totally forgot about it :(

          • No problem, thanks for the continues help.

            Now buildkernel is failing because it cannot find
            sdhci_if.h.

          • Is there any ethernet support for HEAD?

          • I’ve had no luck with this (will post my build script below) – I should point out I don’t have serial hardware yet, so I can’t see what’s going on, but I’ve uncommented the 4 lines (sc kbdmux etc) in RPI-B for the frame buffer so I should expect to see kernel boot messages on screen (right?) – I just get the rainbow coloured screen and no activity light thereafter. (I wrote an /etc/rc.local script to mount the boot partition and write dmesg etc to it so at least I could see if it made it that far, but that doesn’t seem to be happening)

            Do I absolutely have to have serial hardware connected to make it boot?

            I’m building on FreeBSD 9.1 RC1 if that makes a difference, the patch you supply above seems to apply correctly with no issues and the boot partition contains my kernel.bin:

            -rwxrwxrwx 1 matthewf staff 2823544 7 Sep 14:36 KERNEL.BIN

            I will have another go after posting this, including a complete rebuild of everything (the kernel.bin looks sane and is ARM

            /usr/obj/arm.armv6/usr/src/sys/RPI-B]# file kernel kernel.bin
            kernel: ELF 32-bit LSB executable, ARM, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped
            kernel.bin: data)

            I couldn’t figure out if USB/Ethernet support was in HEAD, but I see Alex Rybalko’s paste bin seems to indicate he has it working?

            Build script for anyone else:
            #!/bin/sh
            set -e
            export TARGET=arm
            export TARGET_ARCH=armv6
            export SRCROOT=/usr/src
            export MAKEOBJDIRPREFIX=/usr/obj
            export KERNCONF=RPI-B
            KERNEL_BIN=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/$KERNCONF/kernel.bin

            make -C $SRCROOT kernel-toolchain
            make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
            make -C $SRCROOT MALLOC_PRODUCTION=yes buildworld

            IMG=bsd-pi.img
            rm -f $IMG
            dd if=/dev/zero of=$IMG bs=128M count=8
            MDFILE=`mdconfig -a -f bsd-pi.img`
            gpart create -s MBR ${MDFILE}
            gpart add -s 32m -t ‘!12′ ${MDFILE}
            gpart add -s 896m -t ‘!12′ ${MDFILE}
            gpart set -a active -i 1 ${MDFILE}

            newfs_msdos -L boot -F 16 /dev/${MDFILE}s1
            newfs /dev/${MDFILE}s2
            mount_msdosfs /dev/${MDFILE}s1 /mnt
            tar -x -v -z –uname root -C /mnt -f freebsd-pi-uboot-20120806-sd.tar.gz
            cp $KERNEL_BIN /mnt
            umount /mnt
            mount /dev/${MDFILE}s2 /mnt
            make -C $SRCROOT DESTDIR=/mnt installworld
            make -C $SRCROOT DESTDIR=/mnt distribution

            # Minimal config
            echo ‘hostname=”freebsd-pi”‘ > /mnt/etc/rc.conf
            echo ‘/dev/mmcsd0s2 / ufs rw 1 1′ > /mnt/etc/fstab

            # this is my “write back to the boot partition” script – optional
            cp /root/rc.local /mnt/etc/rc.local

            umount /mnt
            mdconfig -d -u $MDFILE

            • My latest conclusion is that u-Boot isn’t working (or I need serial hardware connected [ordered]) I’ve even tried the net boot tar.gz version – which you’d expect to DHCP and try to grab a kernel – but nothing happens.

              [I've now updated HEAD and got the DWC OTG bits too].

              Wish I could figure out what was wrong – is it possible to build a FreeBSD kernel that boots in the “normal” way without u-Boot?

  12. i built my kernel with freebsd-current (HEAD), but the mmc/sdhci does not detected?

  13. No work. Black display.
    Raspberry model “B” 512mb.

    fix?

  14. Pacman:v- the iconic recreation character can be employed
    if you experience like leaping for joy. Now that you’ve got all
    those clients, losing them will not be an option. We value a spirit of
    cooperation, which is seen in our ability to perform in teams and
    partnerships.

    Feel free to surf to my homepage … facebook infiltrator

  15. Quality content is the main to attract thee users to pay a visit the
    site, that’s what this web site is providing.

  16. SpamBot Magnet March 13, 2014 at 8:42 pm

    Gonzo, dude:
    This comment thread is a SPAM LINK MAGNET. Please erase the last few comments, and close this thread to further comments. (Also, link to your newer Rasperberry PI how-to…)

Trackbacks and Pingbacks:

  1. FreeBSD on Raspberry Pi « 0ddn1x: tricks with *nix - August 21, 2012

    [...] http://kernelnomicon.org/?p=164 Leave a Comment TrackBack URI [...]

  2. De tout et de rien - September 8, 2012

    [...] un peu de mains dans le cambouis , vous deviez pouvoir faire tourner FreeBSD sans soucis. L’image SD semble être à faire soit [...]

  3. ทดลอง FreeBSD บน Raspberry Pi | Raspberry Pi Thailand - December 9, 2012

    [...] FreeBSD บน Raspberry Pi บ้างไหม อันที่จริงมันมีมานานพอสมควรแล้วครับ แต่ยังไม่มี SD card image [...]

  4. Building image for Raspberry Pi: up to date version « FreeBSD developer's notebook - February 1, 2013

    [...] been a while since I posted original build instruction and a lot has change. Here is new version of it with some [...]

  5. My Blog | FreeBSD 10.0 wydane: ulepszenia zarówno dla serwerów jak i desktopu - January 20, 2014

    [...] Aleksandra Rybałko system przeniesiono na Raspberry Pi. Informacje o instalacji systemu znajdują się w serwisie kernelnomicon.org. [...]

Leave a Reply

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>