From 05bd6211b5ce5f05ca07e61bf4cb6f6ed419b974 Mon Sep 17 00:00:00 2001 From: lukasostendorf Date: Thu, 9 Jul 2020 15:32:48 +0200 Subject: [PATCH] Add scripts to automate firmware and sysroot build process Related to #27 --- build_scripts/build-firmware.sh | 138 ++++++++++++++++++++++++++++++++ build_scripts/create_sysroot.sh | 60 ++++++++++++++ config-firmware.sh | 100 ----------------------- 3 files changed, 198 insertions(+), 100 deletions(-) create mode 100755 build_scripts/build-firmware.sh create mode 100755 build_scripts/create_sysroot.sh delete mode 100755 config-firmware.sh diff --git a/build_scripts/build-firmware.sh b/build_scripts/build-firmware.sh new file mode 100755 index 0000000..2d2198f --- /dev/null +++ b/build_scripts/build-firmware.sh @@ -0,0 +1,138 @@ +#!/bin/bash + +# This script creates our custom firmware image +# based on analog decices plutosdr-fw + +# Required plutosdr-fw version +REQUIRED_PLUTOSDR_FW_VERSION="v0.32" + + +#Check if env variable for Xilinx tools exists +: "${VIVADO_SETTINGS?Need to set VIVADO_SETTINGS (e.g. /opt/Xilinx/Vivado/2019.1/settings64.sh)}" +source $VIVADO_SETTINGS || (echo "Specified wrong Vivado settings path?"; exit 1;) + +#Check if env variable for Path to pluto sysroot directory exists +: "${PLUTO_SYSROOT_DIR?Need to set PLUTO_SYSROOT_DIR}" + +SCRIPT_DIR=`pwd`/`dirname "$0"` +cd $SCRIPT_DIR || exit 1 + +# Download the current plutosdr-fw image +if [[ ! -d plutosdr-fw ]] +then + echo "plutosdr-fw repository not found. Downloading it..." + git clone --recurse-submodules -j8 https://github.com/analogdevicesinc/plutosdr-fw.git +else + echo "plutosdr-fw already exists. Skipping git clone." +fi + + +cd plutosdr-fw || (echo "Failed to cd"; exit 1) +if [[ $REQUIRED_PLUTOSDR_FW_VERSION != $(git describe --tags) ]]; +then + echo "Got wrong plutosdr-fw version. Checking out "$REQUIRED_PLUTOSDR_FW_VERSION + git reset --hard + git submodule foreach --recursive git reset --hard + git checkout $PLUTOSDR_FW_VERSION -b master + git submodule update --recursive + + # Changes to buildroot + BR_CONFIG=buildroot/configs/zynq_pluto_defconfig + echo 'BR2_ROOTFS_OVERLAY="'"$PLUTOSDR_FW_ROOTOVERLAY"'"' >> $BR_CONFIG + echo 'BR2_PACKAGE_LIBCONFIG=y' >> $BR_CONFIG + echo 'BR2_PACKAGE_FFTW_SINGLE=y' >> $BR_CONFIG + echo 'BR2_PACKAGE_TUNCTL=y' >> $BR_CONFIG + echo 'BR2_PACKAGE_IPERF3=y' >> $BR_CONFIG + echo 'BR2_PACKAGE_LLDPD=y' >> $BR_CONFIG + + # Changes to the linux kernel + echo "Applying PREEMPT_RT kernel patch..." + wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19-rt1.patch.gz + gunzip patch-4.19-rt1.patch.gz + cd linux || exit 1 + patch -p1 < ../patch-4.19-rt1.patch + + # Configure RT kernel + KERNEL_CONFIG=arch/arm/configs/zynq_pluto_defconfig + echo "CONFIG_TUN=y" >> $KERNEL_CONFIG + echo "CONFIG_PREEMPT_RT_FULL=y" >> $KERNEL_CONFIG +else + echo "plutosdr-fw already seems to be configured." +fi + + +## Init rootfs overlay structure +PLUTOSDR_FW_ROOTOVERLAY=$SCRIPT_DIR/plutosdr-fw/rootfs-overlay +if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY ]] +then + mkdir $PLUTOSDR_FW_ROOTOVERLAY +fi +if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/usr/ ]] +then + mkdir $PLUTOSDR_FW_ROOTOVERLAY/usr/ +fi +if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ ]] +then + mkdir $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ +fi +if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/root/ ]] +then + mkdir $PLUTOSDR_FW_ROOTOVERLAY/root/ +fi +if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/etc/ ]] +then + mkdir $PLUTOSDR_FW_ROOTOVERLAY/etc/ +fi +if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/etc/init.d/ ]] +then + mkdir $PLUTOSDR_FW_ROOTOVERLAY/etc/init.d/ +fi + +cd $SCRIPT_DIR || exit 1 + +## Create sysroot +./create_sysroot.sh || exit 1 + +# Copy libfec and liquid-dsp to rootfs overlay. These libs are not built with buildroot +# so we have to manually copy them. +cp $PLUTO_SYSROOT_DIR/usr/lib/libliquid.so $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ +cp $PLUTO_SYSROOT_DIR/usr/lib/libfec.so $PLUTOSDR_FW_ROOTOVERLAY/usr/lib + +## Build Main Apps +echo "Building main application..." +cd $SCRIPT_DIR/../ || exit 1 +if [[ ! -d cmake-build ]] +then + mkdir cmake-build +fi +cd cmake-build || exit 1 +cmake -DCMAKE_TOOLCHAIN_FILE=CmakeArmToolchain.cmake .. +make basestation +make client +make client-calib +cp basestation $PLUTOSDR_FW_ROOTOVERLAY/root/ +cp client $PLUTOSDR_FW_ROOTOVERLAY/root/ +cp client-calib $PLUTOSDR_FW_ROOTOVERLAY/root/ +cd .. + +# Create VERSION file +touch $PLUTOSDR_FW_ROOTOVERLAY/root/VERSION +echo "hnap "`git describe --tags` > $PLUTOSDR_FW_ROOTOVERLAY/root/VERSION +echo "plutosdr-fw "$PLUTOSDR_FW_VERSION >> $PLUTOSDR_FW_ROOTOVERLAY/root/VERSION + +## Copy network init script to rootfs +echo "Copy network autoconfig script to rootfs..." +cp startup_scripts/* $PLUTOSDR_FW_ROOTOVERLAY/etc/init.d/ + + +## Copy FIR filter to rootfs +echo "Copy FIR filter coefficients to rootfs..." +cp AD9361_256kSPS.ftr $PLUTOSDR_FW_ROOTOVERLAY/root/ + +## Copy the default configuration file to rootfs +echo "Copy config.txt to rootfs..." +cp config.txt $PLUTOSDR_FW_ROOTOVERLAY/root/ + +cd $SCRIPT_DIR/plutosdr-fw/ || exit 1 +make || exit 1 +cp build/pluto.frm ../ \ No newline at end of file diff --git a/build_scripts/create_sysroot.sh b/build_scripts/create_sysroot.sh new file mode 100755 index 0000000..ed766e4 --- /dev/null +++ b/build_scripts/create_sysroot.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# This script customizes the plutosdr-fw sysroot image to our needs. +# NOTE: you only need this script if you want to rebuild the sysroot +# folder, i.e. after a new release of the plutosdr-fw! +# Usually it is enough to download an already customized sysroot +# from the releases page. + + +#Check if env variable for Path to pluto sysroot directory exists +: "${PLUTO_SYSROOT_DIR?Need to set PLUTO_SYSROOT_DIR}" + +SCRIPT_DIR=`pwd`/`dirname "$0"` +cd $SCRIPT_DIR || exit 1 + +mkdir .tmp_create_sysroot +cd .tmp_create_sysroot || exit 1 + +echo "Downloading fftw3" +wget http://www.fftw.org/fftw-3.3.8.tar.gz +tar -xzf fftw-3.3.8.tar.gz + +echo "Installing fftw3" +cd fftw-3.3.8 || exit 1 +./configure arm --enable-float --enable-shared --host=arm-linux-gnueabihf --prefix="$PLUTO_SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$PLUTO_SYSROOT_DIR/" +make install + +echo "Downloading libconfig" +wget https://hyperrealm.github.io/libconfig/dist/libconfig-1.7.2.tar.gz +tar -xzf libconfig-1.7.2.tar.gz +echo "Installing libconfig" +cd libconfig-1.7.2 || exit 1 +./configure --host=arm-linux-gnueabihf --prefix="$PLUTO_SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$PLUTO_SYSROOT_DIR/" +make install + +cd $SCRIPT_DIR/../libfec || exit 1 +echo "Installing libfec..." +./configure arm --host=arm-linux-gnueabihf --prefix="$PLUTO_SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$PLUTO_SYSROOT_DIR/" +make install + +echo "Installing liquid-dsp..." +cd ../liquid-dsp || exit 1 +./bootstrap.sh +./configure arm --host=arm-linux-gnueabihf --prefix="$PLUTO_SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$PLUTO_SYSROOT_DIR" +# Configure somehow does not correctly identify malloc and realloc +# and redefines them in the generated config.h script as rpl_malloc. +# This makes the code unusable, therefore we delete this: +sed -i '/rpl_realloc/d' config.h +sed -i '/rpl_malloc/d' config.h + +make install + +echo "Cleaning up..." +cd $SCRIPT_DIR || exit 1 +rm -R .tmp_create_sysroot + +SYSROOT_NAME="sysroot-custom-"`git describe --tags`".tar.gz" +tar -czf $SYSROOT_NAME $PLUTO_SYSROOT_DIR +echo "Created sysroot archive "$SYSROOT_NAME +exit 0 \ No newline at end of file diff --git a/config-firmware.sh b/config-firmware.sh deleted file mode 100755 index f2f4ee8..0000000 --- a/config-firmware.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash - -#Script generates the custom root system overlay for the Adalm Pluto linux system firmware - -#Path to the plutosdr firmware directory -PLUTOSDR_FW_ROOTOVERLAY=$HOME/plutosdr-fw/rootfs-overlay - -#Check if env variable for Path to pluto sysroot directory exists -: "${PLUTO_SYSROOT_DIR?Need to set PLUTO_SYSROOT_DIR}" - -SCRIPT_DIR=`pwd`/`dirname "$0"` -cd $SCRIPT_DIR - -## Init rootfs overlay structure -if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY ]] -then - mkdir $PLUTOSDR_FW_ROOTOVERLAY -fi -if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/usr/ ]] -then - mkdir $PLUTOSDR_FW_ROOTOVERLAY/usr/ -fi -if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ ]] -then - mkdir $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ -fi -if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/root/ ]] -then - mkdir $PLUTOSDR_FW_ROOTOVERLAY/root/ -fi -if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/etc/ ]] -then - mkdir $PLUTOSDR_FW_ROOTOVERLAY/etc/ -fi -if [[ ! -d $PLUTOSDR_FW_ROOTOVERLAY/etc/init.d/ ]] -then - mkdir $PLUTOSDR_FW_ROOTOVERLAY/etc/init.d/ -fi - -## Build libfec -echo "Building libfec..." -cd libfec -./configure arm --host=arm-linux-gnueabihf --prefix="$PLUTO_SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$PLUTO_SYSROOT_DIR/" -make -make install - -cp $PLUTO_SYSROOT_DIR/usr/lib/libfec.so $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ -cd .. - -## Build liquidsdr -echo "Building liquidsdr..." -cd liquid-dsp -if [[ ! -f configure ]] -then - ./bootstrap.sh -fi -./configure arm --host=arm-linux-gnueabihf --prefix="$PLUTO_SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$PLUTO_SYSROOT_DIR" - -# Configure somehow does not correctly identify malloc and realloc -# and redefines them in the generated config.h script as rpl_malloc. -# This makes the code unusable, therefore we delete this: -sed -i '/rpl_realloc/d' config.h -sed -i '/rpl_malloc/d' config.h - -make -make install -cp $PLUTO_SYSROOT_DIR/usr/lib/libliquid.so $PLUTOSDR_FW_ROOTOVERLAY/usr/lib/ -cd .. - -## Build Main Apps -echo "Building main application..." -if [[ ! -d cmake-build ]] -then - mkdir cmake-build -fi -cd cmake-build -cmake -DCMAKE_TOOLCHAIN_FILE=CmakeArmToolchain.cmake .. -make basestation -make client -make client-calib -cp basestation $PLUTOSDR_FW_ROOTOVERLAY/root/ -cp client $PLUTOSDR_FW_ROOTOVERLAY/root/ -cp client-calib $PLUTOSDR_FW_ROOTOVERLAY/root/ -cd .. - -## Copy network init script to rootfs -echo "Copy network autoconfig script to rootfs..." -cp startup_scripts/* $PLUTOSDR_FW_ROOTOVERLAY/etc/init.d/ - - -## Copy FIR filter to rootfs -echo "Copy FIR filter coefficients to rootfs..." -cp AD9361_256kSPS.ftr $PLUTOSDR_FW_ROOTOVERLAY/root/ - -## Copy the default configuration file to rootfs -echo "Copy config.txt to rootfs..." -cp config.txt $PLUTOSDR_FW_ROOTOVERLAY/root/ - -echo "Done." -