Merge branch 'master' into blub/raspberry-pi
diff --git a/core/FreeBSD-RPI-B/ARCHBSD_CUBIEBOARD2 b/core/FreeBSD-RPI-B/ARCHBSD_CUBIEBOARD2
new file mode 100644
index 0000000..847921d
--- /dev/null
+++ b/core/FreeBSD-RPI-B/ARCHBSD_CUBIEBOARD2
@@ -0,0 +1,134 @@
+# CUBIEBOARD2 -- Custom configuration for the CUBIEBOARD2 ARM development
+# platform, check out http://www.cubieboard.org
+#
+# For more information on this file, please read the handbook section on
+# Kernel Configuration Files:
+#
+# http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html
+#
+# The handbook is also available locally in /usr/share/doc/handbook
+# if you've installed the doc distribution, otherwise always see the
+# FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the
+# latest information.
+#
+# An exhaustive list of options and more detailed explanations of the
+# device lines is also present in the ../../conf/NOTES and NOTES files.
+# If you are in doubt as to the purpose or necessity of a line, check first
+# in NOTES.
+#
+# $FreeBSD$
+
+ident CUBIEBOARD2
+
+include "../allwinner/a20/std.a20"
+
+#makeoptions MODULES_OVERRIDE=""
+makeoptions WITHOUT_MODULES="ahc"
+
+options HZ=100
+options SCHED_4BSD #4BSD scheduler
+options INET #InterNETworking
+options INET6 #IPv6 communications protocols
+options FFS #Berkeley Fast Filesystem
+options SOFTUPDATES #Enable FFS soft updates support
+options UFS_ACL #Support for access control lists
+options UFS_DIRHASH #Improve performance on big directories
+options MSDOSFS #MSDOS Filesystem
+options CD9660 #ISO 9660 Filesystem
+options PROCFS #Process filesystem (requires PSEUDOFS)
+options PSEUDOFS #Pseudo-filesystem framework
+options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!]
+options SCSI_DELAY=5000 #Delay (in ms) before probing SCSI
+options KTRACE #ktrace(1) support
+options SYSVSHM #SYSV-style shared memory
+options SYSVMSG #SYSV-style message queues
+options SYSVSEM #SYSV-style semaphores
+options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions
+options KBD_INSTALL_CDEV # install a CDEV entry in /dev
+options PREEMPTION
+options FREEBSD_BOOT_LOADER
+options VFP # vfp/neon
+
+# Debugging
+makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols
+options BREAK_TO_DEBUGGER
+#options VERBOSE_SYSINIT #Enable verbose sysinit messages
+options KDB
+options DDB #Enable the kernel debugger
+options INVARIANTS #Enable calls of extra sanity checking
+options INVARIANT_SUPPORT #Extra sanity checks of internal structures, required by INVARIANTS
+options WITNESS #Enable checks to detect deadlocks and cycles
+options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed
+#options DIAGNOSTIC
+
+# NFS support
+#options NFSCL
+#options NFSSERVER #Network Filesystem Server
+#options NFSCLIENT #Network Filesystem Client
+
+# Uncomment this for NFS root
+#options NFS_ROOT #NFS usable as /, requires NFSCLIENT
+#options BOOTP_NFSROOT
+#options BOOTP_COMPAT
+#options BOOTP
+#options BOOTP_NFSV3
+#options BOOTP_WIRED_TO=cpsw0
+
+# MMC/SD/SDIO card slot support
+device mmc # mmc/sd bus
+device mmcsd # mmc/sd flash cards
+
+# Boot device is 2nd slice on MMC/SD card
+options ROOTDEVNAME=\"ufs:/dev/da0s1\"
+
+# ATA controllers
+#device ahci # AHCI-compatible SATA controllers
+#device ata # Legacy ATA/SATA controllers
+#options ATA_STATIC_ID # Static device numbering
+
+# Console and misc
+device uart
+device uart_ns8250
+device pty
+device snp
+device md
+device random # Entropy device
+
+# I2C support
+#device iicbus
+#device iic
+
+# GPIO
+device gpio
+
+device scbus # SCSI bus (required for SCSI)
+device da # Direct Access (disks)
+device pass
+
+# USB support
+device usb
+options USB_DEBUG
+#options USB_REQ_DEBUG
+#options USB_VERBOSE
+#device uhci
+#device ohci
+device ehci
+
+device umass
+
+# Ethernet
+device loop
+device ether
+device mii
+device smscphy
+#device cpsw
+device bpf
+
+# USB ethernet support, requires miibus
+device miibus
+
+# Flattened Device Tree
+options FDT
+options FDT_DTB_STATIC
+makeoptions FDT_DTS_FILE=cubieboard2.dts
+
diff --git a/core/FreeBSD-RPI-B/PKGBUILD b/core/FreeBSD-RPI-B/PKGBUILD
new file mode 100644
index 0000000..7b34e31
--- /dev/null
+++ b/core/FreeBSD-RPI-B/PKGBUILD
@@ -0,0 +1,278 @@
+#
+# This PKGBUILD needs to be run as root due to FreeBSD chflags used during compiled
+# makepkg --asroot
+#
+pkgname=('freebsd-world' 'freebsd-kernel-rpib' 'freebsd-kernel-cubie2' 'freebsd-source' 'freebsd-init')
+_freebsdver=10.0
+pkgrel=1
+pkgver=10.0.20131026
+arch=('arm')
+url="https://www.freebsd.org"
+license=('BSD')
+options=('!strip' 'emptydirs' '!fbsd10fix')
+epoch=1
+uboot_rpib_src='freebsd-uboot-20130201.tar.gz'
+spl_cubie2_src='sunxi-spl.bin'
+uboot_cubie2_src='u-boot.bin'
+source=('git://github.com/freebsd/freebsd.git#commit=b1f939cc'
+ "http://people.freebsd.org/~gonzo/arm/rpi/${uboot_rpib_src}"
+ "http://files.androtab.info/allwinner/cubieboard2/${spl_cubie2_src}"
+ "http://files.androtab.info/allwinner/cubieboard2/${uboot_cubie2_src}"
+ 'src.conf'
+ 'libcrypto.pc'
+ 'libarchive.pc'
+ 'libarchive-mtree-fix'
+ 'rpib-image.bash'
+ 'ARCHBSD_CUBIEBOARD2'
+ )
+makedepends=('pacman>=4.1.0' 'git')
+
+_gitroot="git://github.com/freebsd/freebsd.git"
+_gitname="freebsd"
+_gitbranch="stable/10"
+
+pkgver() {
+ cd freebsd
+# cd ${srcdir}
+# if [ ! -d ${_gitname} ]; then
+# git clone --depth=1 -b ${_gitbranch} ${_gitroot} ${_gitname}
+# fi
+# cd "${_gitname}"
+ git log -1 --format="${_freebsdver}.%cd" --date=short | sed 's/-//g'
+}
+
+prepare() {
+ cd freebsd
+# cd "${srcdir}"
+# msg "Connecting to GIT server...."
+# if [ -d ${_gitname} ] ; then
+# ## DON'T EVER DO THIS! -.-
+# cd ${_gitname} && git reset --hard && git clean -df && git checkout "$_gitbranch" && git pull
+# msg "The local files are updated."
+# else
+# git clone --depth=1 -b "$_gitbranch" "${_gitroot}" "${_gitname}"
+# fi
+
+ sed -i '' -e 's|db.h|fdb.h|g' "${srcdir}/freebsd/sys/dev/aic7xxx/aicasm/aicasm_symbol.c"
+
+ patch -p1 -i "${srcdir}/libarchive-mtree-fix"
+}
+
+_freebsd_kernconf() {
+ export KERNCONF="$1"
+ export KERNEL="${MAKEOBJDIRPREFIX}/arm.armv6/${srcdir}/freebsd/sys/${KERNCONF}/kernel"
+ export DTB="${MAKEOBJDIRPREFIX}/arm.armv6/${srcdir}/freebsd/sys/${KERNCONF}/rpi.dtb"
+}
+
+flags_for_all() {
+ cd "$srcdir"
+
+ export MAKEOBJDIRPREFIX="$srcdir/obj"
+ unset LDFLAGS CXXFLAGS CPPFLAGS CFLAGS M4 LD RANLIB ld
+ #TARGET=arm
+ export TARGET_ARCH=armv6
+ export MAKESYSPATH="${srcdir}/freebsd/share/mk"
+ export GPU_MEM=128
+
+ #Build with clang
+ export CC=clang
+ export CPP=clang-cpp
+ export CXX=clang++
+
+ export PATH=/usr/local/bin:$PATH
+ export UBLDR="${MAKEOBJDIRPREFIX}/arm.armv6/${srcdir}/freebsd/sys/boot/arm/uboot/ubldr"
+
+ export TARGET=arm
+
+ export IMG="${srcdir}/bsd-pi.img"
+ export MNTDIR="${srcdir}/mnt"
+}
+
+_build() {
+ cd freebsd
+ msg "Building toolchain"
+ make kernel-toolchain
+
+ msg "Building world"
+ make WERROR= NO_WERROR= TARGET=$TARGET MALLOC_PRODUCTION=yes buildworld || (echo buildworld failed... && return 1)
+
+ buildenv=`make buildenvvars`
+
+ eval $buildenv make -C sys/boot clean
+ eval $buildenv make -C sys/boot obj
+ eval $buildenv make -C sys/boot UBLDR_LOADADDR=0x2000000 all
+}
+
+_package_freebsd-kernel-cubie2() {
+ pkgdesc="FreeBSD kernel package for the cubieboard2"
+ groups=('base')
+ options=('!strip')
+ provides=("freebsd-kernel=${pkgver}-${pkgrel}")
+ conflicts=('freebsd-kernel')
+
+ cd freebsd
+
+ msg "Building kernel"
+ _freebsd_kernconf ARCHBSD_CUBIEBOARD2
+ ln -svf "${srcdir}/$KERNCONF" "${srcdir}/freebsd/sys/${TARGET}/conf/$KERNCONF"
+ make NO_WERROR= WERROR= TARGET=$TARGET KERNCONF=${KERNCONF} WITH_FDT=yes buildkernel || (echo buildkernel failed... && return 1)
+
+ msg "Installing kernel"
+ make -j1 DESTDIR="${pkgdir}" -DDB_FROM_SRC installkernel || (echo installkernel failed... && return 1)
+}
+
+_package_freebsd-kernel-rpib() {
+ pkgdesc="FreeBSD kernel package for the Raspberry-PI model B"
+ groups=('base')
+ options=('!strip')
+ provides=("freebsd-kernel=${pkgver}-${pkgrel}")
+ conflicts=('freebsd-kernel')
+
+ cd freebsd
+
+ msg "Building kernel"
+ _freebsd_kernconf RPI-B
+ make NO_WERROR= WERROR= TARGET=$TARGET KERNCONF=${KERNCONF} WITH_FDT=yes buildkernel || (echo buildkernel failed... && return 1)
+
+ msg "Installing kernel"
+ make -j1 DESTDIR="${pkgdir}" -DDB_FROM_SRC installkernel || (echo installkernel failed... && return 1)
+}
+
+_package_freebsd-world() {
+ pkgdesc="FreeBSD base package"
+ groups=('base')
+ depends=('init')
+ conflicts=(libexecinfo binutils libiconv libarchive)
+ provides=(libc=${_freebsdver} zlib=${_freebsdver} libexecinfo openssl binutils=2.23 libiconv libarchive=3.2.1)
+
+ cd freebsd
+
+ msg "Running make installworld distribution..."
+ make NO_FSCHG= -j1 DESTDIR="$pkgdir" SRCONF="${srcdir}/src.conf" \
+ -DWITHOUT_GCC \
+ -DDB_FROM_SRC \
+ installworld distribution
+
+ msg "Installed. Cleaning up and configuring..."
+
+ # solve some conflicts
+ rm -rf "${pkgdir}/usr/share/man/man3/pthread.3.gz"
+ mv "${pkgdir}/usr/include/db.h" "${pkgdir}/usr/include/fdb.h"
+
+ # remove rc tools for openrc
+ rm -rf ${pkgdir}/etc/rc.d*
+ rm -f ${pkgdir}/etc/{rc,rc.conf,rc.shutdown}
+ rm -f ${pkgdir}/usr/share/man/man8/rc.8.gz
+
+ msg "Removing files provided by other packages"
+ for i in lp lpq lpr lprm; do
+ rm -f "${pkgdir}/usr/bin/$i"
+ done
+
+ rm -f "${pkgdir}"/usr/sbin/lpc
+ rm -f "${pkgdir}"/usr/share/man/man1/lp.1.gz
+ rm -f "${pkgdir}"/usr/share/man/man1/lp{q,r,rm}.1.gz
+ rm -f "${pkgdir}"/usr/share/man/man8/lpc.8.gz
+
+ # Remove flex files
+ rm -f "${pkgdir}"/usr/share/man/man1/flex.1.gz
+
+ # Remove files provided by gcc-libs
+ rm -f "${pkgdir}"/usr/lib/{libgcc_s.so,libgomp.so,libgomp.so.1,libstdc++.so,libstdc++.so.6,libsupc++.a,libstdc++.a,libssp_nonshared.a,libssp.a,libgomp.a}
+
+ #Remove unzip provided by world
+ rm -f "${pkgdir}"/usr/bin/unzip
+
+ #Remove freebsd-update
+ rm -f "${pkgdir}"/usr/sbin/freebsd-update
+
+# We won't have a freebsd-config split in the RPi distribution for now.
+# #remove rc.conf in defaults provided by FreeBSD-Configs
+# rm -f "${pkgdir}"/etc/defaults/rc.conf
+# #Remove files now provided by FreeBSD-config
+# for i in /etc/freebsd-update.conf /etc/netstart \
+# /etc/devd/asus.conf /boot/beastie.4th \
+# /boot/brand.4th /etc/csh.cshrc /etc/devd.conf \
+# /etc/devfs.conf /boot/loader.conf /etc/motd \
+# /etc/profile /etc/src.conf /etc/sysctl.conf \
+# /etc/devd/uath.conf /etc/devd/usb.conf
+# do
+# rm -f "${pkgdir}/$i"
+# done
+
+ #Fix iconv path in ndisgen
+ # sed -i '' -e 's|/usr/local/bin/iconv|/usr/bin/iconv|g' "${pkgdir}"/usr/sbin/ndisgen
+
+ #set var/cache to 755
+ chmod -Rv 755 ${pkgdir}/var/cache
+
+ backup=('boot/device.hints'
+ 'boot/loader.conf')
+
+ cd "$pkgdir"
+
+ for f in `find -E etc -type f ! -regex ".*periodic.*|.*mtree.*|.*defaults.*|.*README|.*Makefile"` `find root var -type f`; do
+ backup=(${backup[@]} "${f}")
+ done
+
+ install -dm755 "${pkgdir}/usr/libdata/ldconfig"
+ echo "/lib" > "${pkgdir}/usr/libdata/ldconfig/lib"
+
+ #Install libcrypto pc file
+ install -dm755 "${pkgdir}/usr/lib/pkgconfig"
+ install -m655 "${srcdir}/libcrypto.pc" "${pkgdir}/usr/lib/pkgconfig/"
+ install -m655 "${srcdir}/libarchive.pc" "${pkgdir}/usr/lib/pkgconfig/"
+
+ #Setup console log
+ msg "Setting up console.log"
+ touch "${pkgdir}/var/log/console.log"
+ chmod 600 "${pkgdir}/var/log/console.log"
+}
+
+_package_freebsd-source() {
+ pkgdesc="FreeBSD source matching FreeBSD kernel"
+ options=('!strip')
+ arch=('any')
+ cd freebsd
+ mkdir -p "${pkgdir}/usr/src"
+ cp -a "${srcdir}/freebsd"/* "${pkgdir}/usr/src/"
+ rm -rf "${pkgdir}"/usr/src/.git
+}
+
+_package_freebsd-init() {
+ pkgdesc="FreeBSD init scripts"
+ provides=('init')
+ conflicts=('openrc')
+ options=('!strip')
+ arch=('x86_64')
+
+ cd "${srcdir}/freebsd"
+ #remove rc tools for openrc
+ install -dm755 ${pkgdir}/etc/
+ cp -Ra "${srcdir}/freebsd"/etc/rc* ${pkgdir}/etc/
+
+ #Files kept in world as needed by openrc also
+ rm -f "${pkgdir}"/etc/rc.{bsdextended,firewall,initdiskless,resume,sendmail,subr,suspend}
+}
+
+build() {
+ flags_for_all
+ _build
+}
+for _p in ${pkgname[@]}; do
+ eval "package_${_p}() {
+ flags_for_all
+ arch=('arm')
+ _package_${_p}
+ }"
+done
+sha1sums=('SKIP'
+ '13b23d00abbee9079917911c035b1f4423315a22'
+ '9cdd92e469a768b216ed0dd56a6ffc4ad6c21c65'
+ '6c10a903122dc33cb5e0b6610bfcfbddb3db7be4'
+ '4f39fd653085ae22d181fa585d4a4d82b8ec9850'
+ '5d0a05f619470f49f5a16be5fb1f97df6e3882b4'
+ 'b394ece3b916003fa849601484cea2f724301baa'
+ 'f79da8d1abedab50b4d96b66ca659ca295f8a1c4'
+ '6d36ccc013e0ea469bb29bb037e4d6d746b21bb6'
+ '06fb07f8f225517d93b20f995d1c05cd5b47407e')
diff --git a/core/FreeBSD-RPI-B/freebsdworld.install b/core/FreeBSD-RPI-B/freebsdworld.install
new file mode 100644
index 0000000..3fe6fc5
--- /dev/null
+++ b/core/FreeBSD-RPI-B/freebsdworld.install
@@ -0,0 +1,31 @@
+pre_remove() {
+ for i in bin usr/lib libexec sbin usr/bin usr/sbin usr/lib32; do
+ chflags -R noschg $i
+ done
+
+ #pacman can't remove these files even with flags unset
+ for i in usr/lib/libc.so usr/lib/libcrypt.so usr/lib/libpthread.so \
+ usr/lib/libthr.so usr/libexec/ld-elf32.so.1; do
+ rm -f $i
+ done
+
+}
+
+pre_upgrade() {
+ for i in bin usr/lib libexec sbin usr/bin usr/sbin usr/lib usr/lib32; do
+ chflags -R noschg $i
+ done
+
+ for i in usr/lib/libc.so usr/lib/libcrypt.so usr/lib/libpthread.so \
+ usr/lib/libthr.so usr/libexec/ld-elf32.so.1; do
+ rm -f $i
+ done
+}
+
+post_upgrade() {
+ echo ">>> Configs have been split from world"
+ echo ">>> Please install freebsd-configs"
+
+ usr/sbin/pw groupshow unbound >/dev/null 2>&1 || usr/sbin/pw groupadd unbound -g 59
+ usr/sbin/pw usershow unbound >/dev/null 2>&1 || usr/sbin/pw useradd unbound -u 59 -g 59 -c "unbound group" -d /var/unbound -s /usr/sbin/nologin
+}
diff --git a/core/FreeBSD-RPI-B/libarchive-mtree-fix b/core/FreeBSD-RPI-B/libarchive-mtree-fix
new file mode 100644
index 0000000..b9005d9
--- /dev/null
+++ b/core/FreeBSD-RPI-B/libarchive-mtree-fix
@@ -0,0 +1,11 @@
+--- freebsd/contrib/libarchive/libarchive/archive_write_set_format_mtree.c 2013-10-18 15:55:49.918078350 +0100
++++ freebsd/contrib/libarchive/libarchive/archive_write_set_format_mtree.c.new 2013-10-18 15:57:24.640074710 +0100
+@@ -1857,7 +1857,7 @@
+
+ /* Make a basename from dirname and slash */
+ *slash = '\0';
+- file->parentdir.length = slash - dirname;
++ file->parentdir.length = slash - file->parentdir.s;
+ archive_strcpy(&(file->basename), slash + 1);
+ return (ret);
+ }
diff --git a/core/FreeBSD-RPI-B/libarchive.pc b/core/FreeBSD-RPI-B/libarchive.pc
new file mode 100644
index 0000000..c0e1e5b
--- /dev/null
+++ b/core/FreeBSD-RPI-B/libarchive.pc
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libarchive
+Description: library that can create and read several streaming archive formats
+Version: 3.1.2
+Cflags: -I${includedir}
+Libs: -L${libdir} -larchive
+Libs.private: -lcrypto -llzma -lbz2 -lz
diff --git a/core/FreeBSD-RPI-B/libcrypto.pc b/core/FreeBSD-RPI-B/libcrypto.pc
new file mode 100644
index 0000000..985b70b
--- /dev/null
+++ b/core/FreeBSD-RPI-B/libcrypto.pc
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+goa_enabled=true
+
+Name: libcrypto
+Description: crypto client library
+Version: 0.13.4
+Libs: -L${libdir} -lcrypto
+Cflags: -I${includedir}
diff --git a/core/FreeBSD-RPI-B/makepkg.cross b/core/FreeBSD-RPI-B/makepkg.cross
new file mode 100644
index 0000000..913ffc8
--- /dev/null
+++ b/core/FreeBSD-RPI-B/makepkg.cross
@@ -0,0 +1,58 @@
+#
+# /etc/makepkg.conf
+#
+
+#########################################################################
+# SOURCE ACQUISITION
+#########################################################################
+#
+#-- The download utilities that makepkg should use to acquire sources
+# Format: 'protocol::agent'
+DLAGENTS=('ftp::/usr/bin/curl -4 -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
+ 'http::/usr/bin/curl -4 -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'https::/usr/bin/curl -4 -3 -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'rsync::/usr/bin/rsync --no-motd -z %u %o'
+ 'scp::/usr/bin/scp -C %u %o')
+
+# Other common tools:
+# /usr/bin/snarf
+# /usr/bin/lftpget -c
+# /usr/bin/wget
+
+#########################################################################
+# ARCHITECTURE, COMPILE FLAGS
+#########################################################################
+CARCH="arm"
+CHOST="x86_64-unknown-freebsd"
+CPPFLAGS=""
+CFLAGS=""
+CXXFLAGS=""
+LDFLAGS=""
+#-- Debugging flags
+DEBUG_CFLAGS="-g"
+DEBUG_CXXFLAGS="-g"
+
+#########################################################################
+# BUILD ENVIRONMENT
+#########################################################################
+BUILDENV=(fakeroot !distcc color !ccache check !sign !fbsd10fix !libtoolfix)
+OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug)
+INTEGRITY_CHECK=(sha1)
+STRIP_BINARIES="--strip-all"
+STRIP_SHARED="--strip-unneeded"
+STRIP_STATIC="--strip-debug"
+MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info})
+DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
+PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)
+PACKAGER="Unknown Packager"
+COMPRESSGZ=(gzip -c -f -n)
+COMPRESSBZ2=(bzip2 -c -f)
+COMPRESSXZ=(xz -c -z -)
+COMPRESSLRZ=(lrzip -q)
+COMPRESSLZO=(lzop -q)
+COMPRESSZ=(compress -c -f)
+
+PKGEXT='.pkg.tar.xz'
+SRCEXT='.src.tar.gz'
+
+# vim: set ft=sh ts=2 sw=2 et:
diff --git a/core/FreeBSD-RPI-B/rpib-image.bash b/core/FreeBSD-RPI-B/rpib-image.bash
new file mode 100644
index 0000000..0839425
--- /dev/null
+++ b/core/FreeBSD-RPI-B/rpib-image.bash
@@ -0,0 +1,97 @@
+#!/usr/bin/bash -e -E
+
+# see http://kernelnomicon.org/?p=275
+
+if ! (type -t flags_for_all |grep 'function'); then
+ on_error() {
+ umount "$MNTDIR" || true
+ mdconfig -d -u ${MDFILE} || true
+ msg "There was an error"
+ exit 1
+ }
+
+ trap on_error ERR
+
+ source PKGBUILD
+ msg() {
+ local mesg="$1"; shift
+ printf "\033[1;34m==>\033[0;0m ${mesg}\n" "$@"
+ }
+ srcdir=$PWD/src
+ flags_for_all
+fi
+
+msg "Preparing image"
+cd "${srcdir}"
+dd if=/dev/zero of="${IMG}" bs=128M count=8
+MDFILE=`mdconfig -a -f "${IMG}"`
+gpart create -s MBR "${MDFILE}"
+
+msg "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
+install -dm755 "${MNTDIR}"
+mount_msdosfs /dev/${MDFILE}s1 "$MNTDIR"
+tar -C "$MNTDIR" -xvf "${srcdir}/${uboot_rpib_src}" || true
+
+msg "Config"
+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"
+
+msg "FreeBSD partition"
+# (empty) FreeBSD partition:
+gpart add -t freebsd ${MDFILE}
+gpart create -s BSD ${MDFILE}s2
+gpart add -t freebsd-ufs ${MDFILE}s2
+newfs /dev/${MDFILE}s2a
+tunefs -n enable /dev/${MDFILE}s2a
+tunefs -j enable -S $[4*1024*1024] /dev/${MDFILE}s2a
+# turn on NFSv4 ACLs
+tunefs -N enable /dev/${MDFILE}s2a
+
+msg "Setup"
+mount /dev/${MDFILE}s2a $MNTDIR
+# install the packages there!
+# 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
+
+install -dm755 "${MNTDIR}/boot"
+echo 'fdt addr 0x100' > "${MNTDIR}/boot/loader.rc"
+install -dm755 "${MNTDIR}/etc"
+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__
+
+umount "$MNTDIR"
+mdconfig -d -u $MDFILE
+
diff --git a/core/FreeBSD-RPI-B/src.conf b/core/FreeBSD-RPI-B/src.conf
new file mode 100644
index 0000000..3a1477a
--- /dev/null
+++ b/core/FreeBSD-RPI-B/src.conf
@@ -0,0 +1,12 @@
+WITHOUT_FREEBSD_UPDATE="yes"
+WITHOUT_GAMES="yes"
+WITHOUT_SYSINSTALL="yes"
+WITHOUT_GCC="yes"
+WITH_CLANG="yes"
+WITH_CLANG_EXTRAS="yes"
+WITH_CLANG_IS_CC="yes"
+WITHOUT_SHAREDOCS="yes"
+WITHOUT_BSD_CPIO="yes"
+WITHOUT_TOOLCHAIN="yes"
+NO_WERROR=
+WERROR=