Update 1: Add -DDB_FROM_SRC to install targets
Update 2: Add user “pi” with password “raspberry”
It’s been a while since I posted original build instruction and a lot has change. Here is new version of it with some explanations:
All code has been moved to HEAD. freebsd-pi repository on github serves only historical purpose and I guess will be removed at some point in future. So in order to build image you need sources for -head
svn co svn://svn.freebsd.org/base/head
TARGET_CPUTYPE is dropped to in favor of TARGET_ARCH=armv6. U-Boot, firmware files and boot process were upgraded too. Current boot chain is as follows:
- Pi is powered up and loads firmware files
- Firmware loads FDT blob defined in config.txt as device_tree variable at address defined as device_tree_address and fixes up fields like memory size, clock frequency and MAC address
- Firmware loads u-boot and passes control to it
- U-boot loads boot.scr and executes it
- Default boot.scr loads ubldr(loader(8)-compatible implementation built over U-Boot API) and passes control
- ubldr checks FreeBSD partition for /boot/loader.rc, loads it, the loads /boot/kernel/kernel and passes control to it
- loader.rc should contain “fdt addr 0×100″ command. It will pass FDT blob filled in step #2 to kernel
So updated build script will look something like this:
#!/bin/sh
set -e
# Change this
export GPU_MEM=128
export PI_USER=pi
export PI_USER_PASSWORD=raspberry
export SRCROOT=/src/FreeBSD/head
export MNTDIR=/mnt
export MAKEOBJDIRPREFIX=/src/FreeBSD/obj
export IMG=/src/FreeBSD/obj/bsd-pi.img
export TARGET_ARCH=armv6
export MAKESYSPATH=$SRCROOT/share/mk
export KERNCONF=RPI-B
if [ -z "$MNTDIR" ]; then
echo "MNTDIR is not set properly"
exit 1
fi
KERNEL=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/$KERNCONF/kernel
UBLDR=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/boot/arm/uboot/ubldr
DTB=`realpath $MAKEOBJDIRPREFIX`/arm.armv6/`realpath $SRCROOT`/sys/$KERNCONF/bcm2835-rpi-b.dtb
make -C $SRCROOT kernel-toolchain
make -C $SRCROOT KERNCONF=$KERNCONF WITH_FDT=yes buildkernel
make -C $SRCROOT MALLOC_PRODUCTION=yes buildworld
buildenv=`make -C $SRCROOT buildenvvars`
eval $buildenv make -C $SRCROOT/sys/boot clean
eval $buildenv make -C $SRCROOT/sys/boot obj
eval $buildenv make -C $SRCROOT/sys/boot UBLDR_LOADADDR=0x2000000 all
rm -f $IMG
dd if=/dev/zero of=$IMG bs=128M count=8
MDFILE=`mdconfig -a -f $IMG`
gpart create -s MBR ${MDFILE}
# Boot partition
gpart add -s 32m -t '!12' ${MDFILE}
gpart set -a active -i 1 ${MDFILE}
newfs_msdos -L boot -F 16 /dev/${MDFILE}s1
mount_msdosfs /dev/${MDFILE}s1 $MNTDIR
fetch -q -o - http://people.freebsd.org/~gonzo/arm/rpi/freebsd-uboot-20130201.tar.gz | tar -x -v -z -C $MNTDIR -f -
cat >> $MNTDIR/config.txt <<__EOC__
gpu_mem=$GPU_MEM
device_tree=devtree.dat
device_tree_address=0x100
disable_commandline_tags=1
__EOC__
cp $UBLDR $MNTDIR
cp $DTB $MNTDIR/devtree.dat
umount $MNTDIR
# FreeBSD partition
gpart add -t freebsd ${MDFILE}
gpart create -s BSD ${MDFILE}s2
gpart add -t freebsd-ufs ${MDFILE}s2
newfs /dev/${MDFILE}s2a
# Turn on Softupdates
tunefs -n enable /dev/${MDFILE}s2a
# Turn on SUJ with a minimally-sized journal.
# This makes reboots tolerable if you just pull power on the BB
# Note: A slow SDHC reads about 1MB/s, so a 30MB
# journal can delay boot by 30s.
tunefs -j enable -S 4194304 /dev/${MDFILE}s2a
# Turn on NFSv4 ACLs
tunefs -N enable /dev/${MDFILE}s2a
mount /dev/${MDFILE}s2a $MNTDIR
make -C $SRCROOT DESTDIR=$MNTDIR -DDB_FROM_SRC installkernel
make -C $SRCROOT DESTDIR=$MNTDIR -DDB_FROM_SRC installworld
make -C $SRCROOT DESTDIR=$MNTDIR -DDB_FROM_SRC distribution
echo 'fdt addr 0x100' > $MNTDIR/boot/loader.rc
echo '/dev/mmcsd0s2a / ufs rw,noatime 1 1' > $MNTDIR/etc/fstab
cat > $MNTDIR/etc/rc.conf <<__EORC__
hostname="raspberry-pi"
ifconfig_ue0="DHCP"
sshd_enable="YES"
devd_enable="YES"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
__EORC__
cat > $MNTDIR/etc/ttys <<__EOTTYS__
ttyv0 "/usr/libexec/getty Pc" xterm on secure
ttyv1 "/usr/libexec/getty Pc" xterm on secure
ttyv2 "/usr/libexec/getty Pc" xterm on secure
ttyv3 "/usr/libexec/getty Pc" xterm on secure
ttyv4 "/usr/libexec/getty Pc" xterm on secure
ttyv5 "/usr/libexec/getty Pc" xterm on secure
ttyv6 "/usr/libexec/getty Pc" xterm on secure
ttyu0 "/usr/libexec/getty 3wire.115200" dialup on secure
__EOTTYS__
echo $PI_USER_PASSWORD | pw -V $MNTDIR/etc useradd -h 0 -n $PI_USER -c "Raspberry Pi User" -s /bin/csh -m
pw -V $MNTDIR/etc groupmod wheel -m $PI_USER
PI_USER_UID=`pw -V $MNTDIR/etc usershow $PI_USER | cut -f 3 -d :`
PI_USER_GID=`pw -V $MNTDIR/etc usershow $PI_USER | cut -f 4 -d :`
mkdir -p $MNTDIR/home/$PI_USER
chown $PI_USER_UID:$PI_USER_GID $MNTDIR/home/$PI_USER
umount $MNTDIR
mdconfig -d -u $MDFILE
Why no vchiq this time?
I’m planning on bringing vchiq into the tree after all. So no point in writing instruction that will be obsolete in few weeks.
Success on a FreeBSD 9.1R amd64 build server. I needed to manually add the auditdistd user like so:
# pw useradd auditdistd -u 78 -g 77 -d /var/empty -s /usr/sbin/nologin -c “Auditdistd unprivileged user”
Oh, I totally missed that. Actually Brooks Davis merged NetBSD’s mtree(8) that fixed this problem. You just need to add -DDB_FROM_SRC to install targets. I updated script.
I had to hack Makefile.inc1 to get the script to run (r246525)
-IMAKE_MTREE= MTREE_CMD=”nmtree ${MTREEFLAGS}”
+IMAKE_MTREE= MTREE_CMD=”/usr/sbin/nmtree ${MTREEFLAGS}”
I forgot to cc you on the email I sent brooks. Other than that, I have a running FreeBSD RPi Obviously not the right fix but got it working.
FreeBSD raspberry-pi 10.0-CURRENT FreeBSD 10.0-CURRENT #1 r246571M: Fri Feb 8 18:46:52 EST 2013 root@odyssey:/home/db/FreeBSD/obj/arm.armv6/home/db/svn/system/head/sys/RPI-B arm
And a question: It looks like you are enabling SSH in the image. What would be the username/password?
Actually, I was able to enable root login via ssh and set up a key pair for SSH, thus not having to plug into a monitor keyboard to get logged in.
That’s a good point. I updated script so user “pi” with password “raspberry” is created and could be used for remote login.
Would the pi user then be able to su to root? What would be the password?
Yes, pi user is in wheel group. No password required.
Thanks!
Do you no how to change overscan settings on FreeBSD I have been searching about for about 2 days and I cant find any info I am running my pi on a old tube tv and I am loosing about a inch on each side of the screen so I cant see much on the console. It has been annoying me I would really appreciate it if you could help.
I haven’t tried FreeBSD on Raspberry Pi with composite output so don’t have first hand experience. From OS point of view there are not many knobs to control video output. Did you check video-related options for config.txt? Here is the link: http://elinux.org/RPiconfig#Video There seems to be several overscan-related
Thanks for that also sorry for the slow reply I have been busy but it works I had it in my head that they /boot/config.txt was Linux only lol.
What is -DDB_FROM_SRC for?
Oops my bad. Ok got it after reading your reply to dave
All of these images are crashing when I run portsnap fetch extract lately.
Replying to my own comment: I have confirmed this on two seaprate RPi’s. A lookup will hang the unit:
# host msn.com
[hang]
Thanks for reporting, I’ll look into it.
Tim Kientzle fixed it:
http://lists.freebsd.org/pipermail/freebsd-arm/2013-February/004810.html
I do not have my RPi here to test though
Just tested an image built with r246608, and now it works – thanks for getting back!
One other tweak would be to change the value of IMG to $MAKEOBJDIRPREFIX/bsd-pi.img so that IMG and MAKEOBJDIRPREFIX are always synchronized.
I do not think people would want image in their obj/ directory. It’s just that in my VM obj/ is a separate mountpoint with enough space for image.
In the three lines invoking pw(8) near the end of the script the pi user is hardcoded as ‘pi’ , which breaks the script if $PI_USER is set to something different. Those three lines should use the user name in $PI_USER too.
Fixed. Thanks, René.
i have build a image on virtualbox and wrote the bsd.img to a 4gb sdcard, but when i turn the rasp on it only sees 1gb / not all 4GB, how to fix that? so all the space is used on the card for /
Replace
with
or otherwise adjust size that fits your card
This does not seem to work with a 16GB card. I adjusted above to make a 16GB image, but when I write to card, I get dd: /dev/da1: end of device. Is there a good guide on the math/physics behind this?
I’m not sure about a guide. I’d just dump image from the target card, check real size and adjusted blocksize/count properly.
Thanks. I think what I was missing was diskinfo(8). Once I manned that and was able to get a REAL size for my card in MB, I was able to create an image tailored to my card, with swap too!
Hei,
is it possible to compile freebsd with included gcc 4.2.2 or later?
thanks.
In theory – yes. There were patches for building FreeBSD with out-of-tree toolchains. I believe Warner Losh was the one who worked on it. Try emailing to freebsd-arm@freebsd.org to get the latest version
Hei gonzo.
There is a problem with some packages too like minidlna. it says that armv6… is not supported just like with gcc.
Any suggestions?
Thanks
Yes, I tried to build mididlna and it fails in binutils ports. I think you should file bugreport to port maintainers about it as I believe they’d have more knowledge about port than me
im out of BSD. Most things are outdated or unsuported for ARM.
Sorry to hear this. I hope things will improve in next few months.
I have added a number of switches and updates to this script in my own copy. Would like your permission to post on github. With a link back of course. Thoughts?
Of course, go ahead! This script is just a simple reference not full-fledged build system
Well, my script is not a full-fledged build system either, but I will post what I have, and perhaps others will have an interest in contributing…
Posted here: https://github.com/daveish/freebsd-arm-tools
Also added a handy copy of pkg-static as mentioned here: http://kernelnomicon.org/?p=261
————————————————————–
>>> World build completed on Wed Feb 20 11:36:44 MSK 2013
————————————————————–
“/usr/head/sys/boot/Makefile”, line 4: Could not find bsd.arch.inc.mk
make: fatal errors encountered — cannot continue
Try setting MAKESYSPATH=$SRCROOT/share/mk
I amended the build script to suit my system:
-export SRCROOT=/usr/src/head
-export MNTDIR=/mnt/rpi
-export MAKEOBJDIRPREFIX=/usr/src/obj
-export IMG=/usr/src/obj/bsd-pi.img
+export SRCROOT=/src/FreeBSD/head
+export MNTDIR=/mnt
+export MAKEOBJDIRPREFIX=/src/FreeBSD/obj
+export IMG=/src/FreeBSD/obj/bsd-pi.img
-dd if=/dev/zero of=$IMG bs=128M count=32
+dd if=/dev/zero of=$IMG bs=128M count=8
But when I try to boot I get:
Mounting from ufs:/dev/mmcsd0s2a failed with error 19.
Do you have full boot log?
SDHCI controller is still picky about cards, I’m working on fixing it. You can try adding
set
set hw.bcm2835.sdhci.hs=”0″
to loader.rc.
Or hw.bcm2835.min_freq=8000000
mine is a bit worst as it does not completely boot at all.
at boot time, i end up getting the
mountroot>
prompt. And if i do a “?” it shows sometimes it only shows “mmcsd0″ as the device.
a few seconds later
it shows panic: mountroot: unable to (re-)mount root.
then screen gets filled with
db>
db>
db>
db>
… (at this point, remove the power and re-position the card), boot again
i may get lucky when aftter
mountroot> ?
it may show:
mmcsd0s2a
mmcsd0s2
mmcsd0s1
mmcsd0
if there’s no panic… then after the list ill do
ufs:/dev/mmcsd0s2a
then it boots, and goes through just fine. However, if I reboot again, it will not re-mount.
As I told to caesius – try experimenting with SDHCI driver tunables in loader.rc. On my raspberry Pi this combination works best:
If it doesn’t work – try reducing min_freq to 400000.
This is a little bit annoying, two of my three different sd cards need these settings. Unfortunately, the problem does not occur at every reboot, so I’ve noticed it late. I made automatic reboot loops (100 reboots) to find it out. With both affected cards it occurs only in ~ 10% of the reboots. With these settings it does not occur.
I’ll be looking into this issue soon. Hope to find permanent solution for this bug.
I’m having trouble getting the world to build. It seems to error out during the fsck_ffs compile. I’ve poked around but can’t seem to find the problem. Any ideas?
cc1: warnings being treated as errors
/root/FreeBSD/head/sbin/fsck_ffs/fsutil.c: In function ‘printIOstats’:
/root/FreeBSD/head/sbin/fsck_ffs/fsutil.c:452: warning: format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘time_t’
*** [fsutil.o] Error code 1
Stop in /root/FreeBSD/head/sbin/fsck_ffs.
*** [fsck_ffs_make] Error code 1
Stop in /root/FreeBSD/obj/arm.armv6/root/FreeBSD/head/rescue/rescue.
*** [objs] Error code 1
Stop in /root/FreeBSD/head/rescue/rescue.
*** [all] Error code 1
Stop in /root/FreeBSD/head/rescue.
*** [rescue.all__D] Error code 1
Stop in /root/FreeBSD/head.
*** [everything] Error code 1
Stop in /root/FreeBSD/head.
*** [buildworld] Error code 1
Stop in /root/FreeBSD/head.
Please update to the latest version. Problem should be fixed by r247269
Nevermind, it needed to be type %lld instead of %ld. It looks like someone already fixed it in the latest svn.
Whoops, didn’t see your post. Yeah. Building again! =)
I was going to setup my personal server to do nightly builds and pack them into a normal and Berryboot compatible image. Would it be okay if I posted a download link when I get it all up and running?
This is a good idea, I’m interested!
Sorry, missed this message.
Sure it would be OK. Ping me when you’ll have it ready.
Hi, gonzo, I had build the img successful, but yet we only have the img, and how can i make a kernel for the qemu -kernel arg?
Oh, I have saw the older post about qemu, sorry about that.
Does overclocking work as usual in the config.txt, and is there any way I could measure CPU frequency in freebsd?
Yes, overclocking settings should work just fine. As for measuring CPU frequency – I do not think there is a way to do it right now, but I’ll take a look what can be done there
Hello Gonzo
great job getting FreeBSD running on the Raspberry. I love it.
I booted it from the freebsd-pi-r245446.img.gz from http://downloads.raspberrypi.org
It works fine, slow, but it works. ports compiles, so everything is fine in that department.
I wanted to update kernel and world on my system, and then came my problems:
On the Pi:
The kernel and the tool-chain compiles fine. Building world fails in the the crypto/heimdal part w. “compile_et not found” I did try to get newer sources several times. still no joy.
On a i386 vm:
The code cross compiles fine. I can build bot kernel and world. works like a charm.
The final problem the one that really nags me:
If I do a make installkernel KERNCONF=RPI-B neither the cross-compiled kernel nor the kernel compiled on Pi will boot.
In both cases: It reads in the kernel. I get all the way to the line:
kernel arguments (null)
Then nothing more happens. Not that I’m aware off
I never see:
root mount waiitng for: usb…
On both machines I did :
make kernel-toolchain
make KERNCONF=RPI-B WITH_FDT=yes buildkernel
make MALLOC_PRODUCTION=yes buildworld
Just as described above. Of cause I remembered export =TARGET_ARCH=armv6 when cross compiling.
On the Pi / was aready mounted. On the vm i mounted the sd card under /mnt and used DESTDIR=
In both cases /boot is updated w. new kerne.
Any suggestions is highly appreciated.
Cheers
Try adding WITHOUT_KERBEROS=yes to your make commands.AFAIR there might be problem when you’re trying to build kerberos stuff on the system built originally without it.
Great work!
Are you familiar with http://www.pcduino.com/ ?
Same CPU/GPU to the Hackberry.
What is your view on a bsd supporting all functionality in pcduino?
Port is in very basic state but there is some work going on right now. ganbold@ works on Cubieboard and imp@ got a MarsBoard, so we can expect fairly decent port soon-ish.
I could build the rpi image with 10-CURRENT as of 2013-03-27, but today (2013-04-13) the build fails with the following error message:
cc -c -O -pipe -std=c99 -g -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -fformat-extensions -Wmissing-include-dirs -fdiagnostics-show-option -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -nostdinc -I. -I/root/rpi/head/sys -I/root/rpi/head/sys/contrib/altq -I/root/rpi/head/sys/contrib/libfdt -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h -ffreestanding -Werror /root/rpi/head/sys/arm/broadcom/bcm2835/bcm2835_intr.c
/root/rpi/head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c:389:13: error: unsequenced modification and access to ‘flags’ [-Werror,-Wunsequenced]
if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
^ ~~~~~
1 error generated.
*** [bcm2835_gpio.o] Error code 1
1 error
*** [buildkernel] Error code 2
1 error
*** [buildkernel] Error code 2
1 error
NOTE: the error arrows are broken because the font is not fixed. The ^ is below the “&=”, while the ~~~~~ is below the “flags” at the end.
The code section is:
/* Filter out unwanted flags. */
if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
return (EINVAL);
I can see you would want to filter out flags which are not supported (by doing &= with gp_caps), but i do not see what the comparison with flags after that should do. Either it’s the old flags and the expression would be false if flags was changed – you could do & instead of &= then… Or it’s the new flags, the expression would be always true then. I changed the code so that it does what the comment above says. After applying this patch, it compiles for me. You might want to commit this. If the formatting is broken, i can email it to you.
Index: sys/arm/broadcom/bcm2835/bcm2835_gpio.c
===================================================================
— sys/arm/broadcom/bcm2835/bcm2835_gpio.c (revision 249439)
+++ sys/arm/broadcom/bcm2835/bcm2835_gpio.c (working copy)
@@ -386,8 +386,7 @@
return (EINVAL);
/* Filter out unwanted flags. */
- if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
- return (EINVAL);
+ flags &= sc->sc_gpio_pins[i].gp_caps;
/* Can’t mix input/output together. */
if ((flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) ==
Thanks for reporting! Turns out there is PR for this:
http://www.freebsd.org/cgi/query-pr.cgi?pr=177759
It will be taken care of today.
Hi, is it possible I can run this installation from a Linux machine?
No. FreeBSD build requires FreeBSD host machine. Although AFAIR there are some experimental patches around that make it possible. Try asking in arm@freebsd.org mailing list for them.
Is it possible to run a diskless system (apart from the FAT32 boot partition)? I notice that you were TFTP loading kernels previously so I guess it’s possible but it looks like uboot.img doesn’t probe the USB NIC by default.
I’ve been running Linux with root-on-NFS but it’s a bit easier there because the kernel is in the FAT32 partition so I can just use cmdline.txt to tell the kernel to use root over NFS.
Ideally, I’d like uboot (or ubldr) to use DHCP and either TFTP or NFS to load the kernel. Is this possible? If so, can you point me to some documentation on the necessary steps.
Yes, it’s possible. I run my development Pi in diskless mode. U-Boot just executes script in boot.scr if USB is not strarted – please attach serial port output for further investigation.
As for how setup diskless boot I recently posted series of articles on this topic:
http://kernelnomicon.org/?tag=netboot
If there is some information missing – let me know, I’ll fill in missing pieces.
Managed to get it running as a router now with USB ethernet. Thank you very much
. It seems to be running at less than full speed but I have to test it thoroughly to say so confidently.
One interesting behaviour is that ping latency seems to cycle in the following fashion for both ethernet cards: 10 ms, 9 ms, 8ms, … , 1ms, 10 ms, 9ms, 8ms, …, 1 ms and round again.
Another problem seems to be the C++-compiler that get some kind of memory alignment error everytime I use it. (http://llvm.org/bugs/show_bug.cgi?id=15696)
If not known, it’s possible to switch from clang to gcc (which is still part
of the base system), you have only to redefine CC, CXX and CPP in your
/etc/make.conf . Not all ports will compile with clang at the moment.
Knew that already, but thanks anyway. Another approach is to set USE_GCC=any in the makefile of the port in question.
Ok, now I’m running in the same problem, tried to compile my first world directly on the pi. When sending my first post, I thought this was related to the llvm port and not to the world itself. Do you have a solution in the meanwhile?
Last time I checked, the clang-compiler built with world had the same version number as clang-devel in ports.
If GCC won’t do for the world compilation, I do not think you can build world on the Pi before that bug is fixed.
I’ve tried to build the world with gcc, it breaks after 1 day compiling with
an error.
gcc -O -pipe -I/usr/src/lib/libc/include -I/usr/src/lib/libc/../../include -I/usr/src/lib/libc/arm -DNLS -D__DBINTERFACE_PRIVATE -I/usr/src/lib/libc/../../contrib/gdtoa -I/usr/src/lib/libc/../../contrib/libc-vis -DINET6 -I/usr/obj/usr/src/lib/libc -I/usr/src/lib/libc/resolv -D_ACL_PRIVATE -DPOSIX_MISTAKE -I/usr/src/lib/libc/../../contrib/jemalloc/include -I/usr/src/lib/libc/../../contrib/tzcode/stdtime -I/usr/src/lib/libc/stdtime -I/usr/src/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -I/usr/src/lib/libc/rpc -I/usr/src/lib/libc/arm/softfloat -I/usr/src/lib/libc/softfloat -DSOFTFLOAT_FOR_GCC -DYP -DNS_CACHING -DSYMBOL_VERSIONING -std=gnu99 -Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -c accept4.S
accept4.S: Assembler messages:
accept4.S:3: Error: undefined symbol `SYS_accept4′ in operation
*** [accept4.o] Error code 1
Stop in /usr/src/lib/libc.
*** [lib/libc__L] Error code 1
Stop in /usr/src.
*** [libraries] Error code 1
Stop in /usr/src.
*** [_libraries] Error code 1
Stop in /usr/src.
*** [buildworld] Error code 1
As I tried to compile NodeJS (I know, ridiculous :p).. Does the current FreeBSD ARM support HardFloat, and if not.. are you aware of any work on adding HFloat support?