This Page is ment to be a basic howto setup a arm and mips & powerpc dev environment.

/!\ This page was last edited 2012-07-09 and is quite stale.

Note: Arm version 4 and arm 5 ( arm 6 is under devel and will be merged in the future)

For those of you wishing to develop for FreeBSD Arm/Mips/PowerPC this is a simple script

to help you setup a basic bootp or dhcp based load system to boot your board.

(NOTE: if you use the dhcp option please make sure that dhcp is turned off on your router.)

Edit the lines in the Edit area to match your system. save and run. sh scriptname.

This Script has only been tested on FreeBSD 9.

I will work to get it working as a user.

#
#Version : 9
#date July 9, 2012
#writen By RNeese (r.neese@gmail.com)
#

set -eu                                 # reports errors in the script

###### Edit only these lines ######
DEVICE_NAME="dreamplug"                 # Device base name
DEVICE_ARCH="arm"                       # Device Archutecture
DEVICE_KERNEL="DREAMPLUG"               # ls /usr/src/sys/conf and find your cpu
DEVICE_MAC="f0:ad:4e:01:42:18"          # Device Mac Address off of device
DEVICE_INTERFACE="mge0"                 # look in the kernel config file for your device
DOMAIN_NAME="dreamplug.freebsd.org"     # Fully Qualified Domnain Name
DEVICE_IP="192.168.123.155"             # Device Assigned Static IP     
NETMASK="255.255.255.0"                 # Netmask of network device is on
GW_ADDR="192.168.123.1"                 # Gateway the device is on 
DNS_ADDR="192.168.123.1"                # DNS server for name serverice
NFS_SERVER_IP="192.168.123.10"          # Network File Server where devie mounts its root filesystem
TFTP_SERVER_IP="192.168.123.10"         # Tftpboot server where device fetches its kernel file
LOCAL_NETWORK_INTERFACE="em0"           # Your Servers Network Interface
NET="192.168.123"                       # used for exports
######### DO NOT EDIT ############### Envirmental settings for build ################
TFTPDIR="/tftpboot/${DEVICE_KERNEL}"
OBJDIR="/usr/obj/${DEVICE_ARCH}.${DEVICE_ARCH}/usr/src/sys/"
ETCDIR="/usr/local/etc/"
export DESTDIR="/nfsroot/${DEVICE_NAME}"
#####################################################################################

#Make neede directories
[ -d "${DESTDIR}" ] || mkdir -p "${DESTDIR}"
[ -d "${DESTDIR}" ] || mkdir -p "${TFTPDIR}"

######## port checking script ########
port_is_installed(){
[ -x "/usr/local/bin/$1" ] || pkg_add -r $1
}

#check to see needed pkgs are installed
#Add OpenOCD for jtag work, arm-rterms-gdb for debugging
port_is_installed fastest_cvsup
port_is_installed openocd
port_is_installed arm-rtems-gdb

[ -x "/usr/local/bin/svn" ] || pkg_add -r subversion

####### Setup /etc/make.conf for clang ######
####### Test Only Not For Production Machines #########
make_clang(){
cat << EOF >> /etc/make.conf
CC=clang
CXX=clang++
CPP=clang-cpp
# This setting to build world without -Werror:
NO_WERROR=
# This setting to build kernel without -Werror:
WERROR=
EOF
}

####### fetch/update /usr/src dir ###########
fetch_src(){
csup -h `fastest_cvsup -c tld -q` -L2 /usr/share/examples/cvsup/stable-supfile
}
#[ -e "/usr/src/Makefile" ] || fetch_src

fetch_src-head(){
svn co http://svn.freebsd.org/base/head /usr/src-head
}
[ -e "/usr/src-head/Makefile" ] || fetch_src-head

#### Script to rebuild and reinstall the os into the device nfsroot dir ##########
reinstall_base(){
cd /usr/src
make ARCH=arm TARGET_ARCH=arm kernel-toolchain
make -j 8 buildworld TARGET_ARCH="${DEVICE_ARCH}"
make installworld -DWITHOUT_SHAREDOCS -DWITHOUT_EXAMPLES -DWITHOUT_GAMES -DWITHOUT_HTML -DWITHOUT_INFO -DWITHOUT_MAN TARGET_ARCH="${DEVICE_ARCH}"
make distrib-dirs TARGET_ARCH="${DEVICE_ARCH}"
make distribution TARGET_ARCH="${DEVICE_ARCH}"
}

#### Script to rebuild and reinstall the os into the device nfsroot dir using src-head ##########
reinstall_base-head(){
cd /usr/src-head
make xdev XDEV=arm XDEV_ARCH=arm
make -j 8 buildworld TARGET_ARCH="${DEVICE_ARCH}" WITHOUT_IPX=1
make installworld -DWITHOUT_SHAREDOCS -DWITHOUT_EXAMPLES -DWITHOUT_GAMES -DWITHOUT_HTML -DWITHOUT_INFO -DWITHOUT_MAN TARGET_ARCH="${DEVICE_ARCH}" WITHOUT_IPX=1
make distrib-dirs TARGET_ARCH="${DEVICE_ARCH}" WITHOUT_IPX=1
make distribution TARGET_ARCH="${DEVICE_ARCH}" WITHOUT_IPX=1
}

default_kernel(){
cd /usr/src
make buildkernel TARGET_ARCH=${DEVICE_ARCH} KERNCONF=${DEVICE_KERNEL}
cp "${OBJDIR}${DEVICE_KERNEL}/kernel.bin" "${TFTPDIR}"
cp "${OBJDIR}${DEVICE_KERNEL}/kernel" "${TFTPDIR}"
}

default_kernel-head(){
cd /usr/src-head
make buildkernel TARGET_ARCH=${DEVICE_ARCH} KERNCONF=${DEVICE_KERNEL}
cp "${OBJDIR}${DEVICE_KERNEL}/kernel.bin" "${TFTPDIR}/kernel-head.bin"
cp "${OBJDIR}${DEVICE_KERNEL}/kernel" "${TFTPDIR}/kernel-head"
}

server_configs(){
###### Setup basics on the server for build and dev enviroment.######
#setup server side configuration
##### add lines to the /etc/inetd.conf to start up tftpboot needed for device boot
##### and access to its kernel file. Only do this if it is not already done
if ! grep -vE '^#' /etc/inetd.conf|grep -q tftp ;then
mv /etc/inetd.conf /etc/inetd.conf.bak
cat << EOF >> /etc/inetd.conf
tftp   dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /tftpboot
tftp   dgram   udp6    wait    root    /usr/libexec/tftpd      tftpd -l -s /tftpboot
EOF
fi

#Add Daemons to the server /etc/rc.conf needed for device to have proper access to its kernel and root file system. 
cat << EOF >> "/etc/rc.conf"
rpcbind_enable="YES"
rpc_statd_enable="YES"
rpc_lockd_enable="YES"
nfs_server_enable="YES"
mountd_enable="YES"
EOF

#Set /etc/export
cat <<EOF> /etc/exports
/nfsroot/${DEVICE_NAME}       -maproot=0 -network ${NET}/24
EOF

###### Setup device side os and configuration #########
# change to working source dir. Then build and install the os and kernel file into
# the proper directory for device boot.
#kernel_conf && dreamplug_dts && kirkwood_files
reinstall_base-head
#reinstall_base

#### Add Daemons to the devices /etc/rc.conf for startup ########
cat << EOF > "$DESTDIR/etc/rc.conf"
rpcbind_enable="YES"
rpc_statd_enable="YES"
rpc_lockd_enable="YES"
nfs_server_enable="YES"
mountd_enable="YES"
mountd_flags="-r"
inetd_enable="YES"
EOF
}

##### Check to see is the base was previously built and installed #####
##### if found it drops to the menu wiht out building ########
[ -e "/nfsroot/${DEVICE_NAME}/COPYRIGHT" ] || server_configs

####### Install and configure bootpd for devise to recieve proper boot data. ###########
bootpd(){

#add a line to the new /etc/inetd.conf file foor bootpd
echo 'bootps dgram   udp     wait    root    /usr/libexec/bootpd     bootpd' >> "/etc/inetd.conf"

touch /etc/bootptab

# add config data to the /etc/bootpta config file.
cat << EOF > "/etc/bootptab"
default1:\\
        :hn:vm=auto:\\
        :sa=${NFS_SERVERIP}:\\
        :sm=${NETMASK}:\\
        :ds=${DNS_SERVER}:\\
        :gw=${GW_ADDR}:\\
        :ns=${GW_ADDR}:\\
        :ts=${TIME_SERV}:\\
        :hd="${TFTPDIR}":\\
        :bf="/kernel":\\
        :rp="${NFS_SERVERIP}:${DESTDIR}":\\
        :to=auto:\\
        :T37=0x12345927AD3BCF:\\
        :T99="Special ASCII string":

${DEVICE_NAME}:ht=1:ha=${DEVICE_MAC}:ip=${DEVICE_IP}:tc=default1:
EOF
echo 'inetd_enable="YES' >> "/etc/rc.conf"
}

######Install and configure ISC-DHCP for devvise to recieve proper boot data.######
dhcpd(){
pkg_add -r isc-dhcp42-server
cat << EOF > "${ETCDIR}/dhcp.conf"
host ${DEVICE_HOST_NAME} {
        hardware ethernet ${DEVICE_MAC};
        fixed-address ${DEVICE_IP};
        next-server ${NFS_SERVER_IP};
        option root-path "${TFTP_SERVER_IP}:/tftpboot";
        option freebsd-nfsroot-opts "nolockd";
}
EOF
cat << EOF >> /etc/rc.conf
dhcpd_enable="YES"
dhcpd_flags="-q"
dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_ifaces="${LOCAL_NETWORK_INTERFACE}"
dhcpd_withumask="022"
EOF
}

###### Menu Options ########
while : ;do
cat << EOF
 1. Use Clang insted of Gcc (Testing Only) Not for production machines.
 2. Pull/Update /usr/src
 3. Pull/Update /usr/src-head
 4. Build/Rebuild and Install/Reinstall Base os into the nfsroot dir
 5. Build/Rebuild and Install/Reinstall Base os into the nfsroot dir using src-head
 6. Build/Rebuild and Install/Reinstall a default Kernel 
 7. Build/Rebuild and Install/Reinstall a default Kernel using src-head
 8. Enable Bootp Daemon (when not using ICS-DHCP42-SERVER from ports)
 9. Enable ISC-DHCP (DHCP Server and configuration)
 x. Exit 
EOF

 read -er ans
 case "$ans" in
  1) make_clang ;;
  2) fetch_src ;;
  3) fetch_src-head ;;
  4) reinstall_base ;;
  5) reinstall_base-head ;; 
  6) default_kernel ;;
  7) default_kernel-head ;;
  8) bootpd ;;
  9) dhcpd ;;
  x|X) exit ;;
  *) echo "you must select a valid option (one of: 1,2,3,4,5,6,7,8,x|X)" && continue ;;
 esac
done


CategoryStale

DevelopersEnviromentSetup (last edited 2018-03-03T08:17:22+0000 by MarkLinimon)