Skip to content

Instantly share code, notes, and snippets.

@dmikushin
Created April 20, 2023 11:18
Show Gist options
  • Save dmikushin/6e97f0e7aef0d6b21207aed9720ee9a2 to your computer and use it in GitHub Desktop.
Save dmikushin/6e97f0e7aef0d6b21207aed9720ee9a2 to your computer and use it in GitHub Desktop.
Make a FreeBSD bootable sdcard for NanoPi Neo3
#!/bin/bash
#
# Make a FreeBSD bootable sdcard for NanoPi Neo3.
# The idea is to mix an official ROCK64 snapshot with U-Boot for Neo3 board from Armbian project.
# This script is based on the original forum post at
# https://forums.FreeBSD.org/threads/nanopi-neo-3-rockchip-rk3328.76449/post-493043
#
set -e
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
fi
SDCARD=/dev/sdb
FREEBSD_URL=https://download.freebsd.org/ftp/snapshots/ISO-IMAGES
FREEBSD_VERSION=13.2
FREEBSD_NAME=FreeBSD-$FREEBSD_VERSION-STABLE-arm64-aarch64-ROCK64-20230302-3912f99ecae6-254729
FREEBSD_WGET=$FREEBSD_URL/$FREEBSD_VERSION/$FREEBSD_NAME
CHECKSUM_NAME=CHECKSUM.SHA512-$FREEBSD_NAME
CHECKSUM_WGET=$FREEBSD_URL/$FREEBSD_VERSION/$CHECKSUM_NAME
UBOOT_URL=https://mirrors.dotsrc.org/armbian-apt/pool/main/l/linux-u-boot-nanopineo3-current
UBOOT_VERSION=23.02.2
UBOOT_NAME=linux-u-boot-current-nanopineo3_${UBOOT_VERSION}_arm64
UBOOT_WGET=$UBOOT_URL/$UBOOT_NAME
rm -rf $CHECKSUM_NAME
wget $CHECKSUM_WGET
CHECKSUM=$(cat $CHECKSUM_NAME)
RETRY=1
while [ $RETRY -eq 1 ]; do
if [ ! -e $FREEBSD_NAME.img.xz ]; then
wget $FREEBSD_WGET.img.xz
fi
if [ "$CHECKSUM" != "$(sha512sum --tag $FREEBSD_NAME.img.xz)" ]; then
rm -rf $FREEBSD_NAME.img.xz
else
echo "$FREEBSD_NAME successfully downloaded"
RETRY=0
fi
done
rm -rf $UBOOT_WGET.deb
wget $UBOOT_WGET.deb
ar x $UBOOT_NAME.deb
tar Jxpvf data.tar.xz
echo
echo "Unpacking $FREEBSD_NAME.img.xz, this may take a while..."
xz -d $FREEBSD_NAME.img.xz
echo
echo "Flashing $FREEBSD_NAME.img to $SDCARD, this may take a while..."
dd if=$FREEBSD_NAME.img of=$SDCARD status=progress
cd ./usr/lib/$UBOOT_NAME/
dd if=idbloader.bin of=$SDCARD seek=64 conv=notrunc
dd if=uboot.img of=$SDCARD seek=16384 conv=notrunc
dd if=trust.bin of=$SDCARD seek=24576 conv=notrunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment