Update: Raspberry Pi 2 is supported by the Crochet build tool.

  • Build and install the u-boot port in sysutils/u-boot-rpi2 (or install the package)
  • Create the image file (and setup the partitions):
# truncate -s 2g rpi2.img
# mdconfig -f rpi2.img -x 63 -y 255
md0
# gpart create -s MBR md0
md0 created
# gpart add -t '\!12' -a 63 -s 50m md0
md0s1 added
# gpart set -a active -i 1 md0
active set on md0s1
# newfs_msdos -F 16 /dev/md0s1
/dev/md0s1: 102240 sectors in 12780 FAT16 clusters (4096 bytes/cluster)
BytesPerSec=512 SecPerClust=8 ResSectors=1 FATs=2 RootDirEnts=512 Media=0xf0 FATsecs=50 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=102375
# gpart add -t freebsd -a 4m md0
md0s2 added
# gpart create -s BSD md0s2
md0s2 created
# gpart add -t freebsd-ufs md0s2
md0s2a added
# newfs -U md0s2a
/dev/md0s2a: 1992.0MB (4079616 sectors) block size 32768, fragment size 4096
        using 4 cylinder groups of 498.03MB, 15937 blks, 63872 inodes.
        with soft updates
super-block backups (for fsck_ffs -b #) at:
 192, 1020160, 2040128, 3060096
  • Build and install FreeBSD into ufs partition:
# mount /dev/md0s2a /mnt
# make TARGET_ARCH=armv6 UBLDR_LOADADDR=0x2000000 buildworld
# make TARGET_ARCH=armv6 KERNCONF=RPI2 buildkernel
# make TARGET_ARCH=armv6 DESTDIR=/mnt installkernel
# make TARGET_ARCH=armv6 DESTDIR=/mnt installworld distribution
  • Save a copy of ubldr and rpi2.dtb that will be used by Raspberry pi firmware:
# cp /mnt/boot/ubldr .
# cp /mnt/boot/dtb/rpi2.dtb .
  • Install the fstab, (a basic) rc.conf and /etc/ttys:
 # mkdir /mnt/boot/msdos
 # cat << EOF > /mnt/etc/fstab
/dev/mmcsd0s1   /boot/msdos     msdosfs rw,noatime      0 0
/dev/mmcsd0s2a  /               ufs rw,noatime          1 1
md              /tmp            mfs rw,noatime,-s30m    0 0
md              /var/log        mfs rw,noatime,-s15m    0 0
md              /var/tmp        mfs rw,noatime,-s5m     0 0
EOF
 # cat << EOF > /mnt/etc/rc.conf
hostname="rpi2"
ifconfig_ue0="DHCP"
sshd_enable="YES"
sendmail_enable="NONE"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
EOF
 # cat << EOF > /mnt/etc/ttys
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
ttyu0   "/usr/libexec/getty 3wire"      vt100   on  secure
EOF
  • Copy your ssh key:
# mkdir /mnt/root/.ssh
# chmod 700 /mnt/root/.ssh
# cat ~myuser/.ssh/id_rsa.pub >> /mnt/root/.ssh/authorized_keys
# echo "PermitRootLogin yes" >> /mnt/etc/ssh/sshd_config
# umount /mnt
  • Copy the u-boot to FAT partition:
# mount_msdosfs /dev/md0s1 /mnt
# cp /usr/local/share/u-boot/u-boot-rpi2/* /mnt
# cp ubldr rpi2.dtb /mnt
# umount /mnt
  • Detach the memory disk and write the image to SD card:
# mdconfig -d -u 0
# dd if=rpi2.img of=/dev/<SD_card_device> bs=1m

Enjoy!

References

  • arm/raspberry_pi_2_image.txt
  • Last modified: 2019/09/06 23:17
  • by LorenzoSalvadore