# nanobsd-rasp.conf # # Build NanoBSD (based on FreeBSD 10.0-RELEASE) for Raspberry Pi # # Instructions: # # 1. Download http://people.freebsd.org/~gonzo/arm/rpi/freebsd-uboot-20121129.tar.gz # to /usr/src/tools/tools/nanobsd/ # 2. You may want to adjust NANO_MEDIASIZE, NANO_CONFSIZE, NANO_RAM_ETCSIZE, # NANO_RAM_TMPVARSIZE, TOTAL_MEM, and GPU_MEM # 3. Also, you may want to modify cust_local() (see below) # 4. sh /usr/src/tools/tools/nanobsd/nanobsd.sh -c nanobsd-rasp.conf # (takes about 1 hour on a Core i7 @ 2.6 GHz) # 5. dd if=/usr/obj/nanobsd.nanorpib/_.disk.full of=/dev/daX bs=1m # (replace daX by whatever device node represents your SD card) # NANO_NAME="nanorpib" NANO_KERNEL="RPI-B" NANO_DRIVE="mmcsd0" NANO_PMAKE="${NANO_PMAKE} -DDB_FROM_SRC" # 2 GB SD card NANO_MEDIASIZE=$((2*1000*1000*1000/512)) # 20 MiB /cfg NANO_CONFSIZE=$((20*1024*1024/512)) # 10 MiB /etc NANO_RAM_ETCSIZE=$((10*1024*1024/512)) # 48 MiB /tmp + /var NANO_RAM_TMPVARSIZE=$((48*1024*1024/512)) NANO_NEWFS="-m 0 -b 4096 -f 512 -i 8192 -O1" # 32 MiB partition for u-boot and ubldr ARM_BOOTSIZE=$((32*1024*1024/512)) # RAM in MiB of Raspberry PI TOTAL_MEM=512 # MiB dedicated to GPU GPU_MEM=64 AVAIL_MEM=$((TOTAL_MEM-GPU_MEM)) MEM_HEX=`printf 0x%X ${AVAIL_MEM}` # nanobsd.sh unsets NANO_ARCH very early, so set it again when this file is inlined, hehehe export NANO_ARCH=armv6 # update device tree file, set available RAM echo "Setting RAM to ${AVAIL_MEM} MB" sed -i .bak "s%reg = <0 0x.*%reg = <0 ${MEM_HEX}>; /* ${AVAIL_MEM} MB, Set by nanobsd-rasp.conf */%" ${NANO_SRC}/sys/boot/fdt/dts/rpi.dts build_ubldr ( ) ( pprint 2 "build ubldr" pprint 3 "log: ${NANO_OBJ}/_.ubldr" ( export TARGET_ARCH=armv6 cd ${NANO_SRC} buildenv=`make buildenvvars | sed 's/MACHINE_ARCH=armv6/MACHINE_ARCH=arm/'` cd sys/boot eval $buildenv make UBLDR_LOADADDR=0x2000000 clean obj all cd ${NANO_SRC} ) > ${NANO_OBJ}/_.ubldr 2>&1 ) install_uboot ( ) ( local dev mnt dev=$1 mnt=$2 echo "Installing uboot" newfs_msdos -L boot -F 16 ${dev} mount -t msdosfs ${dev} ${mnt} tar -C ${mnt} -xzf ${NANO_TOOLS}/freebsd-uboot-20121129.tar.gz cp ${NANO_OBJ}/arm.armv6/${NANO_SRC}/sys/boot/arm/uboot/ubldr ${mnt} cp ${NANO_OBJ}/arm.armv6/${NANO_SRC}/sys/RPI-B/rpi.dtb ${mnt}/devtree.dat echo "device_tree=devtree.dat" >> ${mnt}/config.txt echo "device_tree_address=0x100" >> ${mnt}/config.txt echo "disable_commandline_tags=1" >> ${mnt}/config.txt echo "gpu_mem=${GPU_MEM}" >> ${mnt}/config.txt umount ${mnt} echo "fdt addr 0x100" >> ${NANO_WORLDDIR}/boot/loader.rc ) create_bsd_slice ( ) ( local name size md index align name=$1 size=$2 md=$3 index=$4 align=$5 echo "Creating ${name} slice (${size} sectors)" [ -n "$align" ] && align="-a $align" gpart add -i ${index} -s ${size} -t freebsd ${md} gpart create -s BSD ${md}s${index} gpart add ${align} -t freebsd-ufs ${md}s${index} ) create_armv6_diskimage ( ) ( build_ubldr pprint 2 "build diskimage" pprint 3 "log: ${NANO_OBJ}/_.di" ( sed -i "" "s=${NANO_DRIVE}s3=${NANO_DRIVE}s4a=g" ${NANO_WORLDDIR}/conf/default/etc/remount if [ ${NANO_CODESIZE} -le 0 ]; then NANO_CODESIZE=$(((NANO_MEDIASIZE-NANO_CONFSIZE-ARM_BOOTSIZE)/NANO_IMAGES)) fi if [ ${NANO_DATASIZE} -le 0 ]; then NANO_DATASIZE=$((NANO_MEDIASIZE-NANO_CONFSIZE-ARM_BOOTSIZE-NANO_IMAGES*NANO_CODESIZE)) fi IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} MNT=${NANO_OBJ}/_.mnt mkdir -p ${MNT} if [ "${NANO_MD_BACKING}" = "swap" ] ; then MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE}` else echo "Creating md backing file..." rm -f ${IMG} dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 MD=`mdconfig -a -t vnode -f ${IMG}` fi trap "echo 'Running exit trap code' ; df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT echo "Creating boot loader slice (${ARM_BOOTSIZE} sectors)" gpart create -s MBR ${MD} gpart add -a 4k -s ${ARM_BOOTSIZE} -t '!12' ${MD} gpart set -a active -i 1 ${MD} install_uboot /dev/${MD}s1 ${MNT} create_bsd_slice "root" ${NANO_CODESIZE} ${MD} 2 "64k" # Create first image populate_slice /dev/${MD}s2a ${NANO_WORLDDIR} ${MNT} "s2a" mount /dev/${MD}s2a ${MNT} echo "Generating mtree..." ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab do sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f sed -i "" "s=${NANO_DRIVE}s3=${NANO_DRIVE}s4a=g" $f done umount ${MNT} if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then create_bsd_slice "alternative root" ${NANO_CODESIZE} ${MD} 3 "64k" # Duplicate to second image (if present) echo "Duplicating to second image..." dd conv=sparse if=/dev/${MD}s2 of=/dev/${MD}s3 bs=64k mount /dev/${MD}s3a ${MNT} for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab do sed -i "" "s=${NANO_DRIVE}s2=${NANO_DRIVE}s3=g" $f done umount ${MNT} # Override the label from the first partition so we # don't confuse glabel with duplicates. if [ ! -z ${NANO_LABEL} ]; then tunefs -L ${NANO_LABEL}"s3a" /dev/${MD}s3a fi fi create_bsd_slice "config" ${NANO_CONFSIZE} ${MD} 4 # Create Config slice populate_cfg_slice /dev/${MD}s4a "${NANO_CFGDIR}" ${MNT} "s4a" # Create Data slice, if any. if [ $NANO_DATASIZE -ne 0 ] ; then create_bsd_slice "data" ${NANO_DATASIZE} ${MD} 5 populate_data_slice /dev/${MD}s5a "${NANO_DATADIR}" ${MNT} "s5a" fi if [ "${NANO_MD_BACKING}" = "swap" ] ; then echo "Writing out ${NANO_IMGNAME}..." dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k fi if ${do_copyout_partition} ; then echo "Writing out _.disk.image..." dd conv=sparse if=/dev/${MD}s2 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k fi mdconfig -d -u $MD trap - 1 2 15 EXIT ) > ${NANO_OBJ}/_.di 2>&1 ) cust_local ( ) ( # enable gettys on console sed -i "" 's%xterm off %xterm on %' ${NANO_WORLDDIR}/etc/ttys # give it a hostname echo 'hostname="raspberry.local"' >>${NANO_WORLDDIR}/etc/rc.conf # network config echo 'ifconfig_ue0="DHCP"' >>${NANO_WORLDDIR}/etc/rc.conf # allow ssh login using my key echo 'sshd_enable="YES"' >>${NANO_WORLDDIR}/etc/rc.conf mkdir -p -m 0700 ${NANO_WORLDDIR}/root/.ssh cat ~/.ssh/id_rsa.pub >>${NANO_WORLDDIR}/root/.ssh/authorized_keys ) customize_cmd cust_pkg customize_cmd cust_allow_ssh_root customize_cmd cust_local