forked from freifunk-franken/firmware
461 lines
13 KiB
Bash
Executable File
461 lines
13 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
|
|
builddir=./build
|
|
|
|
OPENWRTREV="eadf19c0b43d2f75f196ea8d875a08c7c348530c"
|
|
OPENWRTURL="git://git.openwrt.org/15.05/openwrt.git"
|
|
PACKAGEREV="ee0bb7b9df86cec0f1d7c27046c50b1fc45b7c4f"
|
|
PACKAGEURL="https://github.com/openwrt/packages.git"
|
|
|
|
## Feed definition [0]: name aka directory, [1]: url, [2]: revision, [3..n]: patches
|
|
|
|
#official openwrt packages
|
|
OPENWRT=(openwrt
|
|
$PACKAGEURL
|
|
$PACKAGEREV)
|
|
OPENWRT_PKGS="gpioctl-sysfs libugpio fastd haserl"
|
|
|
|
## Be careful: FFF uses COMPAT_VERSION 14 at the moment.
|
|
## See http://www.open-mesh.org/projects/batman-adv/wiki/Compatversion
|
|
GLUON=(gluon
|
|
https://github.com/freifunk-gluon/packages.git
|
|
bdb56bba02168a7fdd7c8bbf380ae59a4febac7c)
|
|
GLUON_PKGS="kmod-batman-adv-legacy micrond simple-tc uradvd"
|
|
|
|
#official openwrt routing packages
|
|
ROUTING=(routing
|
|
https://github.com/openwrt-routing/packages.git
|
|
e870c3373eea80df852d42fac3f40aaffd7a0f58)
|
|
ROUTING_PKGS="alfred"
|
|
|
|
FFF=(fff)
|
|
FFF_PKGS="-a"
|
|
|
|
FEEDS=(OPENWRT ROUTING GLUON FFF)
|
|
|
|
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 $COMMITID"
|
|
if [ -d "$DIRECTORY" ]; then
|
|
if $MYGIT remote -v | grep -q "$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"
|
|
#needs to be without -C!!!
|
|
git 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_git 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 URL=${FEED[1]}
|
|
local REV=${FEED[2]}
|
|
|
|
if [ -n "$URL" ] && [ -n "$REV" ]; 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
|
|
count=3
|
|
while [ "x${FEED[count]}" != "x" ]
|
|
do
|
|
local PATCH=${FEED[count]}
|
|
if [ ! -z "$PATCH" ] ; then
|
|
echo "Patching $PATCH"
|
|
git -C "$NAME" am --whitespace=nowarn "$PATCH"
|
|
else
|
|
echo "Warning, $PATCH not found."
|
|
fi
|
|
count=$(( count + 1 ))
|
|
done
|
|
fi
|
|
done
|
|
|
|
cd .. # packages
|
|
cd .. # src
|
|
}
|
|
|
|
patch_target() {
|
|
for patch in "$PWD"/build_patches/openwrt/*.patch; do
|
|
patch -p0 -d "$target" -i "$patch"
|
|
done
|
|
}
|
|
|
|
prepare() {
|
|
get_source
|
|
|
|
test -d $builddir || mkdir $builddir
|
|
|
|
/bin/rm -rf "$target"
|
|
cp -a 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"
|
|
/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"
|
|
PACKAGESVAR="${PACKAGESVAR}[@]"
|
|
PACKAGESVAR=(${!PACKAGESVAR})
|
|
|
|
if [[ -n "${PACKAGESVAR[@]}" ]] ; then
|
|
echo "adding ${PACKAGESVAR[*]} from feed $NAME to available packages"
|
|
"$target"/scripts/feeds install -p "$NAME" "${PACKAGESVAR[@]}"
|
|
fi
|
|
done
|
|
|
|
patch_target
|
|
|
|
#saves ~200MB for each build
|
|
test -d ./src/dl || mkdir ./src/dl
|
|
ln -s ../../src/dl "$target"/dl
|
|
}
|
|
|
|
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
|
|
|
|
while IFS= read -r -d '' template
|
|
do
|
|
echo "Translating $template .."
|
|
$tpl_translate "$template" > "$(dirname "$template")"/"$(basename "$template" .tpl)"
|
|
/bin/rm "$template"
|
|
done < <(find "${target}/files" -name '*.tpl' -print0)
|
|
|
|
#insert actual firware version informations into release file
|
|
version=$(git describe --tags --dirty)
|
|
community=$(basename "$(realpath selected_community)" .cfg)
|
|
|
|
{
|
|
echo "FIRMWARE_VERSION=\"$version\""
|
|
echo "FIRMWARE_COMMUNITY=\"$community\""
|
|
echo "BUILD_DATE=\"build date: $(date)\""
|
|
echo "OPENWRT_CORE_REVISION=\"${OPENWRTREV}\""
|
|
echo "OPENWRT_FEEDS_PACKAGES_REVISION=\"${PACKAGEREV}\""
|
|
} > "$target"/files/etc/firmware_release
|
|
|
|
cp selected_community "$target"/files/etc/community.cfg
|
|
|
|
opath=$(pwd)
|
|
cd "$target"
|
|
make defconfig
|
|
cd "$opath"
|
|
}
|
|
|
|
build() {
|
|
prebuild
|
|
|
|
opath=$(pwd)
|
|
cd "$target"
|
|
cpus=$(grep -c processor /proc/cpuinfo)
|
|
|
|
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
|
|
|
|
cp_firmware
|
|
}
|
|
|
|
config() {
|
|
prebuild
|
|
|
|
opath=$(pwd)
|
|
cd "$target"
|
|
|
|
case "$1" in
|
|
"openwrt")
|
|
make menuconfig
|
|
;;
|
|
esac
|
|
|
|
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")
|
|
echo "# Generated using \"./buildscript config openwrt\"." > "$opath"/bsp/"$machine"/.config
|
|
echo "# Do no edit manually" >> "$opath"/bsp/"$machine"/.config
|
|
echo "#" >> "$opath"/bsp/"$machine"/.config
|
|
./scripts/diffconfig.sh >> "$opath"/bsp/"$machine"/.config
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
cd "$opath"
|
|
}
|
|
|
|
cp_firmware() {
|
|
for image in ${images[@]}; do
|
|
filename_build=${image//openwrt/${community}-${version}}
|
|
cp "$target/bin/${chipset}/$image" "./bin/$filename_build"
|
|
|
|
image_factory=${image/sysupgrade/factory}
|
|
if [[ -f "$target/bin/${chipset}/$image_factory" ]]; then
|
|
filename_build_factory=${filename_build/sysupgrade/factory}
|
|
cp "$target/bin/${chipset}/$image_factory" "./bin/$filename_build_factory"
|
|
fi
|
|
done
|
|
}
|
|
|
|
buildrelease() {
|
|
if [ "$1" = "all" ];then
|
|
buildall
|
|
elif [ "$1" = "fast" ];then
|
|
build fast
|
|
elif [ "$1" = "all" ] && [ "$2" = "fast" ];then
|
|
buildall fast
|
|
else
|
|
build
|
|
fi
|
|
cd bin
|
|
for binary in *.bin; do
|
|
md5sum "$binary" > ./"$binary".md5
|
|
sha256sum "$binary" > ./"$binary".sha256
|
|
done
|
|
cd ..
|
|
echo -e "VERSION:$version" > ./bin/release.nfo
|
|
}
|
|
|
|
clean() {
|
|
/bin/rm -rf bin $builddir src/openwrt
|
|
|
|
# remove downloaded package feeds
|
|
for FEEDVAR in "${FEEDS[@]}" ; do
|
|
FEED="${FEEDVAR}[@]"
|
|
FEED=("${!FEED}")
|
|
|
|
local NAME=${FEED[0]}
|
|
local URL=${FEED[1]}
|
|
local REV=${FEED[2]}
|
|
|
|
if [ -n "$URL" ] && [ -n "$REV" ]; then
|
|
/bin/rm -rf src/packages/"$NAME"
|
|
fi
|
|
done
|
|
}
|
|
|
|
buildall() {
|
|
for bsp in $(/bin/ls bsp/*.bsp); do
|
|
./buildscript selectbsp "$bsp"
|
|
./buildscript prepare
|
|
./buildscript build "$1"
|
|
done
|
|
}
|
|
|
|
if [ "$1" != "selectbsp" -a "$1" != "selectcommunity" ]; 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-file>"
|
|
echo "available packages:"
|
|
/bin/ls bsp/*.bsp
|
|
echo
|
|
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-file>"
|
|
echo "available community-files: "
|
|
/bin/ls community/*.cfg
|
|
echo
|
|
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
|
|
echo "Usage: $0 $1"
|
|
echo
|
|
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
|
|
echo "Usage: $0 $1 [fast|debug]"
|
|
echo
|
|
else
|
|
build "$2"
|
|
fi
|
|
;;
|
|
"config")
|
|
case "$2" in
|
|
openwrt)
|
|
config openwrt
|
|
;;
|
|
*)
|
|
echo "This open the OpenWRT menuconfig dialog"
|
|
echo
|
|
echo "Usage: $0 $1 openwrt"
|
|
echo
|
|
;;
|
|
esac
|
|
;;
|
|
"clean")
|
|
if [ "$2" = "help" ] || [ "$2" = "x" ]; then
|
|
echo "This option cleans all build files."
|
|
echo
|
|
echo "Usage: $0 $1"
|
|
echo
|
|
else
|
|
clean
|
|
fi
|
|
;;
|
|
"buildall")
|
|
if [ "$2" = "help" ]; then
|
|
echo "This option builds the firmware for all routers of a given community."
|
|
echo
|
|
echo "Usage: $0 $1 [fast]"
|
|
echo
|
|
else
|
|
buildall "$2"
|
|
fi
|
|
;;
|
|
"release")
|
|
if [ "$2" = help ]; then
|
|
echo "This option builds the firmware for a given board. It also creates hash sums and a the file release.nfo"
|
|
echo
|
|
echo "Usage: $0 $1 [all] [fast]"
|
|
echo
|
|
else
|
|
buildrelease "$2"
|
|
fi
|
|
;;
|
|
*)
|
|
echo "This is the Build Environment Script of the Freifunk Community Franken."
|
|
echo
|
|
echo "Usage: $0 command"
|
|
echo "command:"
|
|
echo " selectcommunity <community-file>"
|
|
echo " selectbsp <bsp-file>"
|
|
echo " prepare"
|
|
echo " config openwrt"
|
|
echo " build [fast|debug]"
|
|
echo " buildall [fast]"
|
|
echo " release [all] [fast]"
|
|
echo " clean"
|
|
echo ""
|
|
echo "If you need help to one of these options just type: $0 <command> help"
|
|
echo
|
|
;;
|
|
esac
|