Skip to content

Commit

Permalink
Build Scripts: automate build process
Browse files Browse the repository at this point in the history
Related to #27
  • Loading branch information
lukasostendorf committed Jul 10, 2020
1 parent 05bd621 commit d917938
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 155 deletions.
138 changes: 0 additions & 138 deletions build_scripts/build-firmware.sh

This file was deleted.

125 changes: 125 additions & 0 deletions build_scripts/build_firmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash

# This script creates our custom firmware image
# based on Analog Devices plutosdr-fw

# Required plutosdr-fw version
PLUTOSDR_FW_TAG="v0.32"


# Apply linux PREEMPT_RT patch
linux_rt_patch() {
echo "Applying PREEMPT_RT kernel patch..."
cd $BUILD_DIR || exit 1
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 $PLUTOSDR_FW_DIR/linux || exit 1
patch -p1 < $BUILD_DIR/patch-4.19-rt1.patch

# Configure RT kernel
KERNEL_CONFIG=$PLUTOSDR_FW_DIR/linux/arch/arm/configs/zynq_pluto_defconfig
echo "CONFIG_TUN=y" >> $KERNEL_CONFIG
echo "CONFIG_PREEMPT_RT_FULL=y" >> $KERNEL_CONFIG
}

# Changes to buildroot
config_buildroot() {
BR_CONFIG=$BUILD_DIR/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
}

#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 || exit 1

SCRIPT_DIR=`pwd`/`dirname "$0"`
BUILD_DIR=$SCRIPT_DIR/build
PLUTOSDR_FW_DIR=$BUILD_DIR/plutosdr-fw
SYSROOT_DIR=$BUILD_DIR/pluto-custom.sysroot
FW_OVERLAY=$BUILD_DIR/rootfs-overlay

mkdir -p $BUILD_DIR
cd $BUILD_DIR || exit 1

# Download the current plutosdr-fw image
if [[ ! -d $PLUTOSDR_FW_DIR ]]
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_DIR || exit 1
if [[ $PLUTOSDR_FW_TAG != $(git describe --tags) ]];
then
echo "Got wrong plutosdr-fw version. Checking out "PLUTOSDR_FW_TAG
git pull origin master
git checkout $PLUTOSDR_FW_VERSION
git submodule update --recursive

else
echo "plutosdr-fw version is ok."
fi

if [[ ! -f $BUILD_DIR/kernel_configured ]]
then
# Apply kernel patch and configure userspace
echo "Patching Linux kernel and configure userspace"
linux_rt_patch
config_buildroot
touch $BUILD_DIR/kernel_configured
else
echo "Linux kernel seems to be already configured."
fi


## Init rootfs overlay structure
mkdir -p $FW_OVERLAY/usr/lib
mkdir -p $FW_OVERLAY/root
mkdir -p $FW_OVERLAY/etc/init.d

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 $SYSROOT_DIR/usr/lib/libliquid.so $FW_OVERLAY/usr/lib/
cp $SYSROOT_DIR/usr/lib/libfec.so $FW_OVERLAY/usr/lib

## Build Main Apps
./build_standalone_binaries.sh
cd $BUILD_DIR || exit 1
cp basestation client client-calib $FW_OVERLAY/root/


# Create VERSION file
touch $FW_OVERLAY/root/VERSION
echo "hnap "`git describe --tags` > $FW_OVERLAY/root/VERSION
echo "plutosdr-fw "PLUTOSDR_FW_TAG >> $FW_OVERLAY/root/VERSION

## Copy network init script to rootfs
echo "Copy network autoconfig script to rootfs..."
cp startup_scripts/* $FW_OVERLAY/etc/init.d/


## Copy FIR filter to rootfs
echo "Copy FIR filter coefficients to rootfs..."
cp AD9361_256kSPS.ftr $FW_OVERLAY/root/

## Copy the default configuration file to rootfs
echo "Copy config.txt to rootfs..."
cp config.txt $FW_OVERLAY/root/

cd $SCRIPT_DIR/plutosdr-fw/ || exit 1
make || exit 1
cp $PLUTOSDR_FW_DIR/build/pluto.frm $BUILD_DIR
echo "Created pluto.frm in $BUILD_DIR"
28 changes: 28 additions & 0 deletions build_scripts/build_standalone_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Script builds the standalone applications

SCRIPT_DIR=`pwd`/`dirname "$0"`
BUILD_DIR=$SCRIPT_DIR/build
SYSROOT_DIR=$BUILD_DIR/pluto-custom.sysroot
SRC_DIR=$SCRIPT_DIR/..

echo "Building main application..."
mkdir -p $BUILD_DIR/cmake-build

if [[ ! -d $SYSROOT_DIR ]]
then
./create_sysroot.sh
else
echo "Sysroot is present."
fi

cd $BUILD_DIR/cmake-build || exit 1
export PLUTO_SYSROOT_DIR=$SYSROOT_DIR
cmake -DCMAKE_TOOLCHAIN_FILE=$SRC_DIR/CmakeArmToolchain.cmake $SRC_DIR
make basestation
make client
make client-calib

cp basestation client client-calib $BUILD_DIR/
echo "Standalone applications have been created in $BUILD_DIR"
50 changes: 33 additions & 17 deletions build_scripts/create_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,62 @@
# 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.
# The script is automatically invoked by the other build scripts

# Required plutosdr-fw version
PLUTOSDR_FW_TAG="v0.32"

#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
BUILD_DIR=$SCRIPT_DIR/build
PLUTOSDR_FW_DIR=$BUILD_DIR/plutosdr-fw
SYSROOT_DIR=$BUILD_DIR/pluto-custom.sysroot
SRC_DIR=$SCRIPT_DIR/..

mkdir .tmp_create_sysroot
mkdir -p $BUILD_DIR
cd $BUILD_DIR || exit 1
mkdir -p .tmp_create_sysroot
cd .tmp_create_sysroot || exit 1


if [[ ! -d $SYSROOT_DIR ]]
then
echo "Could not locate existing sysroot dir. Downloading sources"
wget https://github.com/analogdevicesinc/plutosdr-fw/releases/download/$PLUTOSDR_FW_TAG/sysroot-$PLUTOSDR_FW_TAG.tar.gz
tar -xzf sysroot-$PLUTOSDR_FW_TAG.tar.gz -d $BUILD_DIR
mv staging pluto-custom.sysroot
else
echo "Found existing sysroot folder. Skip download."
fi

echo "Bulding libraries"

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/"
./configure arm --enable-float --enable-shared --host=arm-linux-gnueabihf --prefix="$SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$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/"
./configure --host=arm-linux-gnueabihf --prefix="$SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$SYSROOT_DIR/"
make install

cd $SCRIPT_DIR/../libfec || exit 1
cd $SRC_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/"
./configure arm --host=arm-linux-gnueabihf --prefix="$SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$SYSROOT_DIR/"
make install

echo "Installing liquid-dsp..."
cd ../liquid-dsp || exit 1
cd $SRC_DIR/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 arm --host=arm-linux-gnueabihf --prefix="$SYSROOT_DIR/usr/" CC="arm-linux-gnueabihf-gcc --sysroot=$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:
Expand All @@ -51,10 +68,9 @@ sed -i '/rpl_malloc/d' config.h
make install

echo "Cleaning up..."
cd $SCRIPT_DIR || exit 1
cd $BUILD_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
SYSROOT_NAME="pluto-custom-"`git describe --tags`".sysroot.tar.gz"
tar -czf $SYSROOT_NAME $BUILD_DIR
echo "Created sysroot archive $SYSROOT_NAME in $BUILD_DIR"

0 comments on commit d917938

Please sign in to comment.