Skip to content

Instantly share code, notes, and snippets.

@landonf
Created June 23, 2016 01:57
Show Gist options
  • Save landonf/1fa989517a57f8d2384f663568ba3f2f to your computer and use it in GitHub Desktop.
Save landonf/1fa989517a57f8d2384f663568ba3f2f to your computer and use it in GitHub Desktop.
freebsd build/test scripts
#!/bin/sh
SCRIPT_NAME=$0
SRC_DIR=${SRC_DIR:="`pwd`"}
BASE_DIR=${BASE_DIR:="$SRC_DIR/../"}
# Load user configuration
BT_SETTINGS=${BT_SETTINGS:-${SRC_DIR}/.freebsd-build-target.cfg}
test -e ${BT_SETTINGS} && . ${BT_SETTINGS}
# Default configuration
NETBOOT_ROOT=${NETBOOT_ROOT:="/export"}
FBSD_WIFI=${FBSD_WIFI:="$BASE_DIR/freebsd-wifi-build"}
OBJ_DIR=${OBJ_DIR:="$BASE_DIR/obj"}
TFTPBOOT=${TFTPBOOT:="$NETBOOT_ROOT/tftpboot"}
export X_TFTPBOOT="$TFTPBOOT"
WIFI_BUILD="${FBSD_WIFI}/build/bin/build"
# Target config
target_bcm43225_name="BCM43225"
target_bcm43225_arch="amd64"
target_bcm43225_deploy="ssh talbot.local ./vmctl.sh reset"
target_bcm4312_name="BCM4312"
target_bcm4312_arch="i386"
#target_bcm4312_deploy=""
target_wgt634U_name="WGT634U"
target_wgt634U_wifi="sentry5"
#target_wgt634U_deploy=""
target_n16_name="RT-N16"
target_n16_wifi="bcm-trx"
#target_n16_deploy=""
target_n53_name="RT-N53"
target_n53_wifi="bcm-trx"
#target_n53_deploy=""
JOBS=4
REFRESH=0
DEPLOY=0
RESET_VM=0
WORLD=0
NO_MOD_FLG="NO_MODULES=1"
NO_CLEAN_FLG="NO_CLEAN=1"
print_targets () {
grep -E '^target_.*_name' "$SCRIPT_NAME" | sed -E -e 's/^target_([A-Za-z0-9]+)_name="(.*)"/ \1 (\2)/g'
}
print_usage () {
echo "Usage: $SCRIPT_NAME [options] <targets>"
echo " -c allow clean (i.e. don't pass NO_CLEAN to the build). Implies -r"
echo ' -r update config/dependencies'
echo ' -m include kernel modules in fast build'
echo ' -w build and install world'
echo ' -k (re)build the kernel toolchain'
echo ' -d deploy results to all targets'
echo ' -j <jobs> number of build jobs'
echo ''
echo 'Known targets:'
print_targets
}
args=`getopt hwcrkdmj: $*`
if [ $? -ne 0 ]; then
exit 2
fi
set -- $args
while true; do
case "$1" in
-c)
NO_CLEAN_FLG=""
REFRESH=1
shift
;;
-r)
REFRESH=1
shift
;;
-d)
DEPLOY=1
shift
;;
-w)
WORLD=1
shift
;;
-m)
NO_MOD_FLG=""
shift
;;
-k)
TOOLCHAIN=1
shift
;;
-j)
JOBS="$2"
shift; shift
;;
-h)
print_usage
exit 0
;;
--)
shift; break
;;
esac
done
if [ ! -f "$SRC_DIR/UPDATING" ] || [ ! -d "$SRC_DIR/sys" ]; then
echo "$SRC_DIR does not look like a FreeBSD source checkout"
fi
if [ ! -d "${FBSD_WIFI}" ]; then
echo "Missing freebsd-wifi-build at $FBSD_WIFI"
fi
unique_list () {
echo -n "$1" | tr -s '[:space:]' '\n' | sort | uniq | tr -s '[:space:]' ' '
}
# Build list of targets, architectures, and freebsd-wifi configurations
TARGETS=$(unique_list "$*")
if [ -z "$TARGETS" ]; then
echo "No targets. Must specify at least one of:"
print_targets
exit 1
fi
for target in $TARGETS; do
eval _tname=\$target_${target}_name
if [ -z "$_tname" ]; then
echo "Unrecognized target: $target"
exit 1
fi
eval _tarch=\$target_${target}_arch
eval _twifi=\$target_${target}_wifi
if [ ! -z ${_tarch} ]; then
TARGET_ARCHS="${TARGET_ARCHS} $_tarch"
elif [ ! -z ${_twifi} ]; then
TARGET_WIFI_CFGS="${TARGET_WIFI_CFGS} $_twifi"
fi
done
TARGET_ARCHS=$(unique_list "$TARGET_ARCHS")
WIFI_CFGS=$(unique_list "$TARGET_WIFI_CFGS")
echo "Targets:"
echo " $TARGETS"
echo ''
echo "Standard Architectures:"
echo " $TARGET_ARCHS"
echo ''
echo "WiFi Configuration:"
echo " $TARGET_WIFI_CFGS"
echo ''
do_make() {
local root_cmd=""
local jobs=$JOBS
local margs=`getopt rj: $*`
set -- $margs
while true; do
case "$1" in
-r)
local root_cmd="sudo"
shift
;;
-j)
local jobs="$2"
shift; shift
;;
--)
shift; break
;;
esac
done
if [ -z "$tarch" ]; then
echo "Missing target arch (-a)"
exit 1
fi
local tarch=$1
local tgt=$2
shift; shift
local objdir="${OBJ_DIR}/${tarch}"
mkdir -p "$objdir" || exit 1
$root_cmd make \
-j$jobs \
$tgt \
MAKEOBJDIRPREFIX="${objdir}" \
TARGET=${tarch} \
TARGET_ARCH="${tarch}" \
${NO_CLEAN_FLG} \
DESTDIR="${NETBOOT_ROOT}/netboot-$tarch" \
$* || exit 1
}
do_make_build () {
local ARCH=$1
if [ "${WORLD}" = "1" ]; then
do_make $ARCH buildworld
elif [ "${TOOLCHAIN}" = "1" ]; then
do_make $ARCH kernel-toolchain
fi
if [ "${REFRESH}" = "1" ]; then
# do_make $ARCH cleandepend
do_make $ARCH buildkernel
else
do_make $ARCH buildkernel KERNFAST=1
fi
do_make -r -j 1 $ARCH installkernel
if [ "${WORLD}" = "1" ]; then
do_make -r -j 1 $ARCH installworld
do_make -r -j 1 $ARCH distribution
fi
}
for tarch in $TARGET_ARCHS; do
do_make_build $tarch
done
do_wifi_build() {
local twifi=$1
local buildflags="-j${JOBS} ${NO_CLEAN_FLG}"
if [ "${WORLD}" = "1" ]; then
env BUILD_FLAGS="$buildflags" $WIFI_BUILD $twifi
elif [ "${TOOLCHAIN}" = "1" ]; then
env BUILD_FLAGS="$buildflags" $WIFI_BUILD $twifi kernel-toolchain
fi
if [ "${REFRESH}" = "1" ]; then
env BUILD_FLAGS="$buildflags" $WIFI_BUILD $twifi buildkernel installkernel mfsroot fsimage trx
else
env BUILD_FLAGS="$buildflags KERNFAST=1" $WIFI_BUILD $twifi buildkernel installkernel mfsroot fsimage trx
fi
}
for twifi in $WIFI_CFGS; do
do_wifi_build $twifi
done
if [ $DEPLOY = 1 ]; then
for target in $TARGETS; do
eval _tdeploy=\$target_${target}_deploy
if [ ! -z "${_tdeploy}" ]; then
eval "$_tdeploy" || exit 1
fi
done
fi
exit 0
#!/bin/sh
VMCTL="$0"
BASEDIR=`dirname "$0"`
VM_NAME="fbsd-dbg"
TAP_DEV="tap10"
NETBOOT_EXPORT="/export/netboot-amd64"
NETBOOT_ROOT="10.133.7.1:$NETBOOT_EXPORT"
MEM="512"
# pci0:2:0:0 BCM43225 802.11b/g/n
# pci0:3:0:0 BCM4321 802.11a/b/g/n
PCI_PASSTHROUGH="-s 4:0,passthru,2/0/0"
#PCI_PASSTHROUGH="-s 4:0,passthru,2/0/0 -s 5:0,passthrough,3/0/0"
COMMAND=$1
shift;
if [ -z "$COMMAND" ]; then
echo "Usage: $0 <command> [extra args...]"
echo "Commands:"
echo " start"
echo " stop"
echo " reset"
echo " destroy"
fi
case $COMMAND in
stop)
sudo bhyvectl --vm "$VM_NAME" --force-poweroff
;;
reset)
sudo bhyvectl --vm "$VM_NAME" --force-reset
;;
destroy)
sudo bhyvectl --vm "$VM_NAME" --destroy
;;
start)
while [ 1 ]; do
sudo bhyveload \
-S -m $MEM \
-h "$NETBOOT_EXPORT" \
-e boot.netif.name=vtnet0 \
-e boot.netif.hwaddr=00:a0:98:8f:0d:e8 \
-e boot.netif.ip=10.133.7.33 \
-e boot.netif.netmask=255.255.255.0 \
-e vfs.root.mountfrom=nfs:$NETBOOT_ROOT \
$(sudo $BASEDIR/boot_root_nfs/boot_root_nfs "$NETBOOT_ROOT" /) \
"$VM_NAME"
sudo /usr/sbin/bhyve \
-S -m $MEM \
-A -H -P \
-s 0:0,hostbridge \
-s 1:0,lpc \
-s 2:0,virtio-net,${TAP_DEV} \
$PCI_PASSTHROUGH \
-l com1,stdio \
-l com2,/dev/nmdm255A \
$* \
$VM_NAME
bhyve_exit=$?
if [ $bhyve_exit != 0 ]; then
break
fi
done
case $bhyve_exit in
0|1|2)
$VMCTL destroy >/dev/null 2>&1
;;
esac
exit $bhyve_exit
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment