firmware/buildscript

409 lines
9.9 KiB
Plaintext
Raw Normal View History

#!/bin/bash
builddir=./build
OPENWRTREV=42096
OPENWRTURL=svn://svn.openwrt.org/openwrt/branches/barrier_breaker
PACKAGEREV=${OPENWRTREV}
PACKAGEURL=svn://svn.openwrt.org/openwrt/packages
## Feed definition [0]: name aka directory [1]: type git vs svn [2]: url [3]: revision evtl [4]: Patches
#official openwrt packages
OPENWRT=(openwrt
svn
svn://svn.openwrt.org/openwrt/packages
$OPENWRTREV)
OPENWRT_PKGS="bridge gpioctl-sysfs libugpio mii-tool kmod-gpiotoggling"
#official openwrt routing packages
ROUTING=(routing
git
https://github.com/openwrt-routing/packages.git
44318d05898069300ce2ad6eb05eb40f232e7123
../../../build_patches/0001-batman-adv-no-rebroadcast-option.patch)
ROUTING_PKGS="kmod-batman-adv"
FASTD=(fastd
git
git://git.metameute.de/lff/pkg_fastd
v14-1)
FASTD_PKGS="fastd"
FEEDS=(OPENWRT ROUTING FASTD)
checkout_svn(){
local DIRECTORY=$1
local REPO_URL=$2
local REVISION=$3
echo checking out $REPO_URL to $DIRECTORY in version $REVISION
if [ -d $DIRECTORY ]; then
local url=$(svn info ${DIRECTORY} | awk '/^URL/ { print $2 }')
if [ "$url" = "$REPO_URL" ]; then
if [ -z "$REVISION" ]; then
svn update $DIRECTORY
else
local rev=$(svn info $DIRECTORY | awk '/^Revision:/ { print $2 }')
if [ "$rev" -ne "$REVISION" ]; then
svn update -r $REVISION $DIRECTORY
fi
fi
else
echo wrong svn url -\> deleting whole directory
/bin/rm -rf $DIRECTORY
svn checkout -r $REVISION $REPO_URL $DIRECTORY
fi
else
svn checkout -r $REVISION $REPO_URL $DIRECTORY
fi
}
checkout_git(){
local DIRECTORY=$1
local REPO_URL=$2
local COMMITID=$3
local MYGIT="git -C $DIRECTORY"
echo checking out $REPO_URL to $DIRECTORY in version $REVISION
if [ -d $DIRECTORY ]; then
if $MYGIT remote -v | grep $REPO_URL ; then
echo Right remote detected
if ! $MYGIT checkout $COMMITID ; then
echo commitid not found trying to fetch new commits
$MYGIT pull && $MYGIT checkout $COMMITID
fi
else
echo wrong remote or not an git repo at all -\> deleting whole directory
/bin/rm -rf $DIRECTORY
$MYGIT clone $REPO_URL $DIRECTORY
$MYGIT checkout $COMMITID
fi
else
echo We need to do a fresh checkout
#needs to be without -C!!!
git clone $REPO_URL $DIRECTORY
$MYGIT checkout $COMMITID
fi
}
get_source() {
test -d src || mkdir src
cd src
#Get the OpenWrt Core Source for Firmware
checkout_svn openwrt $OPENWRTURL $OPENWRTREV
test -d packages || mkdir packages
cd packages
#checkout needed package feeds
for FEEDVAR in ${FEEDS[@]} ; do
FEED=$FEEDVAR[@] FEED=( ${!FEED} )
local NAME=${FEED[0]}
local TYPE=${FEED[1]}
local URL=${FEED[2]}
local REV=${FEED[3]}
local PATCH=${FEED[4]}
echo Adding Feed $NAME
if [[ $TYPE == "svn" ]] ; then
checkout_svn $NAME $URL $REV
elif [[ $TYPE == "git" ]] ; then
checkout_git $NAME $URL $REV
# Patches for feeds could be stored in known directories like build_patches/$NAME/
# That way multiple patches for one feed could be supported
if [ ! -z "$PATCH" ] ; then
echo Patching $PATCH
git -C $NAME am --whitespace=nowarn $PATCH
fi
fi
done
cd .. # packages
cd .. # src
}
prepare() {
get_source
test -d $builddir || mkdir $builddir
/bin/rm -rf $target
svn export src/openwrt $target
## generate own feeds.conf
#this local variable should be globally configure variable used in get_source and here
local PACKAGEBASE=${PWD}/src/packages
rm -f $target/feeds.conf
for FEEDVAR in ${FEEDS[@]} ; do
FEED=$FEEDVAR[@] FEED=( ${!FEED} )
local NAME=${FEED[0]}
echo adding $NAME to package feeds
echo src-link $NAME $PACKAGEBASE/$NAME >> $target/feeds.conf
done
echo cleaning feeds
test -d $target/feeds && /bin/rm -rf $target/feeds
$target/scripts/feeds update
for FEEDVAR in ${FEEDS[@]} ; do
FEED=$FEEDVAR[@] FEED=( ${!FEED} )
local NAME=${FEED[0]}
local PACKAGESVAR=${FEEDVAR}_PKGS
if [[ -n "${!PACKAGESVAR}" ]] ; then
echo adding ${!PACKAGESVAR} from feed $NAME to available packages
$target/scripts/feeds install -p $NAME ${!PACKAGESVAR}
fi
done
# todo evaluate this with the new openwrt
# This changes the default behavior of sysupgrade to not save the config
cat build_patches/sysupgrade_no_config_save.patch | patch -p0 -d $target
#saves ~200MB for each build
test -d ./src/dl || mkdir ./src/dl
ln -s ../../src/dl $target/dl
board_prepare
}
prebuild() {
#create filesdir for our config
/bin/rm -rf $target/files
mkdir $target/files
cp -r ./bsp/default/root_file_system/* $target/files/
cp -r ./bsp/$machine/root_file_system/* $target/files/
cp ./bsp/$machine/.config $target/.config
arch=$(awk -F= '/^CONFIG_TARGET_BOARD/{print gsub(/"/,"",$2); print $2;}' ./bsp/$machine/.config)
version=$(awk '/^CONFIG_LINUX/ { sub(/CONFIG_LINUX_/,""); sub(/=y/,""); gsub(/_/,"."); print; }' ./bsp/$machine/.config)
test -f ./bsp/$machine/.kernelconfig-$version && \
cp ./bsp/$machine/.kernelconfig-$version \
$target/target/linux/$arch/config-$version
board_prebuild
for template in $(find $target/files -name *.tpl)
do
echo "Translating $template .."
$tpl_translate $template > $(dirname $template)/$(basename $template .tpl)
/bin/rm $template
done
#insert actual firware version informations into release file
version=$(git describe --tags --dirty)
echo "FIRMWARE_VERSION=\"$version\"" > $target/files/etc/firmware_release
echo "RELEASE_DATE=\"build date: "`date`"\"" >> $target/files/etc/firmware_release
echo "FIRMWARE_REVISION=\"build date: "`date`"\"" >> $target/files/etc/firmware_release
echo "OPENWRT_CORE_REVISION=\""${OPENWRTREV}"\"" >> $target/files/etc/firmware_release
echo "OPENWRT_FEEDS_PACKAGES_REVISION=\""${PACKAGEREV}"\"" >> $target/files/etc/firmware_release
}
build() {
prebuild
opath=$(pwd)
cd $target
cpus=$(grep processor /proc/cpuinfo | wc -l)
case "$1" in
"debug")
make V=99
;;
"fast")
ionice -c 2 -- nice -n 1 -- make -j$[$cpus*2]
;;
*)
ionice -c 3 -- nice -n 10 -- make -j$[$cpus+1]
;;
esac
cd $opath
if [ ! -d bin ]; then
mkdir bin
fi
postbuild
}
config() {
prebuild
opath=$(pwd)
cd $target
case "$1" in
"openwrt")
make menuconfig
;;
"kernel")
make kernel_menuconfig
;;
esac
cd $opath
save=""
until [ "$save" = "y" -o "$save" = "n" ]; do
echo "Do you want to save the generated config? (y/n)"
read save
done
if [ "$save" = "y" ]; then
case "$1" in
"openwrt")
grep '^CON\|^# CON' $target/.config | sort > ./bsp/$machine/.config
;;
"kernel")
arch=$(awk -F= '/^CONFIG_TARGET_BOARD/{gsub(/"/,"",$2); print $2;}' ./bsp/$machine/.config)
version=$(awk '/^CONFIG_LINUX/ { sub(/CONFIG_LINUX_/,""); sub(/=y/,""); gsub(/_/,"."); print; }' ./bsp/$machine/.config)
grep '^CON\|^# CON' $target/target/linux/$arch/config-$version | sort > ./bsp/$machine/.kernelconfig-$version
;;
esac
fi
}
postbuild() {
board_postbuild
}
clean() {
board_clean
/bin/rm -rf bin $builddir
}
buildall() {
2014-11-11 21:29:41 +01:00
for bsp in $(/bin/ls bsp/*.bsp); do
./buildscript selectcommunity $1
./buildscript selectbsp $bsp
./buildscript prepare
./buildscript build $2
done
}
if [ "$1" != "selectbsp" -a "$1" != "selectcommunity" -a "$1" != "buildall" ]; then
if [ ! -h selected_bsp ]; then
echo "Please select a Board-Support-Package using:"
echo "$0 selectbsp"
exit
fi
if [ ! -h selected_community ]; then
echo "Please select a community file using:"
echo "$0 selectcommunity"
exit
fi
echo "Working with $(/bin/ls -l selected_bsp | awk '{ print $11 }') and" \
"$(/bin/ls -l selected_community | awk '{ print $11 }')"
. selected_bsp
tpl_translate=$(awk -F= 'BEGIN{printf("sed")} /^.+$/{gsub("/", "\\/", $0); printf(" -es/\\${%s}/%s/g",$1,$2)}' selected_community)
echo
fi
case "$1" in
"selectbsp")
if [ "$2" = "help" ] || [ "$2" = "" ]; then
echo "Select a Board-Support-Package:"
echo
echo "Usage: $0 $1 bsp"
2014-11-13 00:05:07 +01:00
echo "available packages:"
/bin/ls bsp/*.bsp
else
if [ ! -f $2 ]; then
echo "Could not find $2"
else
/bin/rm -rf selected_bsp
/bin/ln -s $2 selected_bsp
fi
fi
;;
"selectcommunity")
if [ "$2" = "help" ] || [ "$2" = "" ]; then
echo "Select a Community-File:"
echo
echo "Usage: $0 $1 community.cfg"
echo "community.cfg: "
/bin/ls community/*.cfg
else
if [ ! -f $2 ]; then
echo "Could not find $2"
else
/bin/rm -rf selected_community
/bin/ln -s $2 selected_community
fi
fi
;;
"prepare")
if [ "$2" = "help" ] || [ "$2" = "x" ]; then
echo "This option fetches the sources for the images and configurates the build so that it can be compiled"
echo "Usage: $0 $1"
else
prepare
fi
;;
"build")
if [ "$2" = "help" ] || [ "$2" = "x" ]; then
echo "This option compiles the firmware"
echo "Normaly the build uses lower IO and System priorities, "
echo "you can append \"fast\" option, to use normal user priorities"
echo "Usage: $0 $1 [fast|debug]"
else
build "$2"
fi
;;
"config")
case "$2" in
openwrt)
config openwrt
;;
kernel)
config kernel
;;
*)
echo "This open the OpenWRT menuconfig dialog"
echo
echo "Usage: $0 $1 openwrt|kernel"
;;
esac
;;
"clean")
if [ "$2" = "help" ] || [ "$2" = "x" ]; then
echo "This option cleans all build files."
2014-11-12 22:49:28 +01:00
echo "$0 $1"
else
clean
fi
;;
"buildall")
if [ "$2" = "help" ] || [ "$2" = "" ]; then
echo "This option builds the firmware for all routers of a given community."
echo "Usage: $0 $1 community.cfg [fast]"
echo "community.cfg: "
/bin/ls community/*.cfg
else
buildall $2 $3
fi
;;
*)
2014-11-11 21:29:41 +01:00
echo "This is the Build Environment Script of the Freifunk Community Franken."
echo "Usage: $0 command"
echo "command:"
echo " selectcommunity [communityfile]"
echo " selectbsp [bsp file]"
echo " prepare"
2014-11-13 00:05:07 +01:00
echo " config <openwrt|kernel>"
echo " build [<fast|debug>]"
echo " buildall <community> [<fast>]"
2014-11-12 22:49:28 +01:00
echo " clean"
echo ""
echo "If you need help to one of these options just type $0 command help"
;;
esac
2014-11-13 00:05:07 +01:00
# vim: noexpandtab