compile_fw 7.58 KB
Newer Older
1 2 3 4 5
#!/bin/bash -xe

# Cleaning
[ -d ./tmp ] && rm -rf ./tmp
[ -d ./bin ] && rm -rf ./bin
6
[ -d ./bin-nor ] && rm -rf ./bin-nor
7 8 9 10 11
[ -d ./logs ] && rm -rf ./logs
[ -d ./logs-nand ] && rm -rf ./logs-nand
[ -d ./logs-nor ] && rm -rf ./logs-nor
[ -d ./logs-initram ] && rm -rf ./logs-initram

12
export TMPDIR="$PWD/tmp"
13 14
mkdir $TMPDIR

15 16 17 18 19 20 21 22 23
if [ "$1" = turris ] || [ "$1" = omnia ]; then
    export TARGET_BOARD="$1"
    shift
else
    echo "The first argument is empty or unknown!"
    echo "You have to specify target board - options are 'turris' or 'omnia'"
    exit 1
fi

24
make_defconfig() {
25
	make defconfig "$@"
26
	egrep '^(#[[:space:]]+)?CONFIG_KERNEL' configs/common configs/$TARGET_BOARD | sed 's|.*:||' >> ./.config
27 28 29 30 31 32 33
	if [ -n "${PKG_BRANCH}" ] && [ "${PKG_BRANCH}" \!= master ] && [ "${PKG_BRANCH}" \!= stable ] && [ "${PKG_BRANCH}" \!= stable-omnia ]; then
		echo CONFIG_PACKAGE_cznic-repo-keys-test=y >> .config
		echo CONFIG_PACKAGE_getbranch-test=y >> .config
	else
		echo CONFIG_PACKAGE_cznic-repo-keys-test=m >> .config
		echo CONFIG_PACKAGE_getbranch-deploy=y >> .config
	fi
34 35
}

36 37 38
# Clean feeds
./scripts/feeds clean
./scripts/feeds update -a
39 40 41 42 43 44 45 46 47 48 49 50
# Patch feeds
pushd patches
for feed in *; do
	pushd $feed
	for patch in *; do
		pushd ../../feeds/$feed
		patch -p1 < ../../patches/$feed/$patch
		popd
	done
	popd
done
popd
51
./scripts/feeds update -i
52 53 54
./scripts/feeds install -a

# Uninstall broken pkgs
55 56 57 58
./scripts/feeds uninstall \
$([ \! -f ./disabled_packages.common ] || echo $(cut -d '#' -f1 ./disabled_packages.common)) \
$([ \! -f ./disabled_packages.$TARGET_BOARD ] || echo $(cut -d '#' -f1 ./disabled_packages.$TARGET_BOARD))

59

60 61
# Override packages release numbers
scripts/override_release_numbers.sh
62

63
# Build NAND FW
64 65
[ -z "$OPENWRT_BRANCH"  ] || PKG_BRANCH="-$OPENWRT_BRANCH"
[ -n "$REAL_PKG_BRANCH" ] || REAL_PKG_BRANCH="$PKG_BRANCH"
66
cat configs/common configs/$TARGET_BOARD | sed -e "s|@BOARD@|$TARGET_BOARD|" -e "s|@BRANCH@|$PKG_BRANCH|" > .config
67
[ -n "$BUILD_ALL" ] && echo -e "CONFIG_ALL=y\nCONFIG_SDK=y\nCONFIG_IB=y\nCONFIG_IB_STANDALONE=n\nCONFIG_PACKAGE_ucollect-meta=m" >> .config
68
echo CONFIG_ALL_KMODS=y >> .config
69

70
[ -n "$USE_CCACHE" ] && echo "CONFIG_CCACHE=y" >> .config
71 72


73
if [ -f "$HOME"/mime.key ]; then
74
	echo "CONFIG_SIGNED_PACKAGES=y" >> .config
75
	rm -f key-build key-build.pub
76 77
	cp "$HOME/mime.key" key-build
	cp "$HOME/mime.pub" key-build.pub
78
fi
79 80


81
make_defconfig
82

83 84 85
if [ -d .git ] ; then
	git log -n1 --format='%H' >files/etc/git-version
fi
86

87
make clean
88

89
[ -z "$BUILD_ALL" ] || make dirclean
90

91
set -- "$@" PKG_BRANCH=${PKG_BRANCH/-/}
92

93
[ -z "$PERSISTENT_CCACHE" ] || set -- "$@" CCACHE_DIR="`pwd`/ccache" CCACHE_HOST_DIR="`pwd`/ccache-host"
94

95 96 97 98 99
if [ -n "$FORCE" ]; then
	make "$@" || make "$@" -j"`echo x"$@" | sed 's|.*-j\([0-9]\+\).*|\1 / 2 + 1|' | bc`" || make "$@" -j1 V=s
else
	make "$@"
fi
100

101 102 103
# Get Turris OS and OpenWRT version
./scripts/unpack-version.sh bin/*/packages bin/*/

104
if [ -n "$PRIMARY_ONLY" ] ; then
105 106 107 108
	# If we want only the primary system and want to use the build directory for more tests, exit now
	exit
fi

109
# Nice junit export
110 111
./scripts/generate_junit.sh

112
[ \! -d ./logs ] || cp ./.config logs/config
113
[ \! -d ./logs ] || mv ./logs ./logs-nand
114

115 116
COMMIT_DATE="`git log --format=format:%cD -1`"

117 118 119 120 121 122 123 124 125
if [ "$TARGET_BOARD" = turris ]; then
	# Preserve the uncompressed image too
	mv build_dir/target-powerpc_*/root-mpc85xx bin/mpc85xx/root
	cd bin/mpc85xx/root
	rm var
	find -type l ! -exec test -r {} \; -delete
	cd ../../..
fi

126 127 128 129 130 131
# Clean
[ -d ./bin-nand ] && rm -rf ./bin-nand
mv ./bin ./bin-nand
[ -d ./tmp ] && rm -rf ./tmp

PUB_BIN_DIR="`ls -1d bin-nand/* | head -n1`"
132 133
# Generate lists
[ -n "$BUILD_ALL" ] || USRLISTS_ARGS="--minimal"
134 135
LIST_BRANCH="${PKG_BRANCH#-}"
[ -n "$LIST_BRANCH" ] || LIST_BRANCH="$(echo "$GIT_BRANCH" | sed 's|.*/||')"
136
scripts/gen-userlists.sh --model $TARGET_BOARD --branch "${LIST_BRANCH}" $USRLISTS_ARGS $PUB_BIN_DIR/lists
137

138 139
# Generate packages that block each other, based on their file collisions
# For some reason, mktemp -d doesn't work with TMPDIR set, so avoid that here.
140 141
# This is deactivated for now until updater #186 is resolved.
#TMPDIR= ./scripts/negative_deps.pl $PUB_BIN_DIR >>$PUB_BIN_DIR/lists/base.lua
142 143

# Sign all lists
144
make package/system/usign/host/install
145 146 147 148 149
if [ -f "$HOME"/mime.key ]; then
	for i in $PUB_BIN_DIR/lists/*.lua; do
		if [ -r "$i" ]; then
			staging_dir/host/bin/usign -S -m $i -s "$HOME"/mime.key
		fi
150
	done
151 152
fi

153 154
if [ "$TARGET_BOARD" = "omnia" ]; then
	rm -f $PUB_BIN_DIR/*.ext4 $PUB_BIN_DIR/*sums
155 156 157 158
fi

if [ -n "$BUILD_ALL" ]; then
	# Compile host tools
159
	make package/curl/host/install package/libevent2/host/install package/lua/host/install package/usign/host/install
160 161
	make package/updater-ng/host/install
	# Generate medkit
162 163 164 165 166
	if [ "$TARGET_BOARD" = "turris" ]; then
		MED_ARCH=mpc85xx
	else
		MED_ARCH=mvebu-musl
	fi
167
	BASE_PATH="`pwd`"
168
	MED_PATH="bin-nand/${MED_ARCH}/medkit"
169 170
	MED_TAR="$TARGET_BOARD-medkit-$(date -d "$COMMIT_DATE" +%Y%m%d%H%M).tar.gz"
	mkdir -p "$MED_PATH"
171
	MED_BIN_SOURCE="bin-nand/${MED_ARCH}"
172 173 174 175 176 177 178 179
	ERR_CMD="false"
	if fakeroot ./scripts/updater-medkit.sh --model "$TARGET_BOARD" $MED_ARGS $MED_BIN_SOURCE "$MED_PATH/$MED_TAR"; then
		pushd "$MED_PATH"
		ln -s "$MED_TAR" "$TARGET_BOARD"-medkit-latest.tar.gz || 
		if [ -f "$HOME"/mime.key ]; then
			"$BASE_PATH"/staging_dir/host/bin/usign -S -m "$MED_TAR" -s "$HOME"/mime.key
			ln -s "$MED_TAR".sig "$TARGET_BOARD"-medkit-latest.tar.gz.sig
		fi
180
		../../../staging_dir/host/bin/usign -S -m "$MED_TAR" -s "$HOME"/mime.key
181
		ln -s "$MED_TAR".sig "$TARGET_BOARD"-medkit-latest.tar.gz.sig
182 183 184 185 186 187 188 189 190
		md5sum "$MED_TAR" > "$MED_TAR".md5
		ln -s "$MED_TAR".md5 "$TARGET_BOARD"-medkit-latest.tar.gz.md5
		sha256sum "$MED_TAR" > "$MED_TAR".sha256
		ln -s "$MED_TAR".sha256 "$TARGET_BOARD"-medkit-latest.tar.gz.sha256
		popd
	elif [ -n "`echo "$@" | grep 'IGNORE_ERRORS="m"'`" ]; then
		true
	else
		false
191
	fi
192
fi
193

194
if [ "$TARGET_BOARD" = omnia ]; then
195 196
	cp configs/config-omnia-rescue .config
	[ -n "$USE_CCACHE" ] && echo "CONFIG_CCACHE=y" >> .config
197 198
    # Ugly hack, make python compile first to avoid possible race
    ./scripts/feeds uninstall python
199
	make defconfig CONFDEFAULT=n
200 201 202 203 204 205
	make clean
	make "$@"
	echo -e "CONFIG_TARGET_ROOTFS_INITRAMFS=y\nCONFIG_TARGET_INITRAMFS_COMPRESSION_XZ=y" >> .config
	sed -i 's/^TARGET_ROOTFS_INCLUDE_KERNEL=.*/# TARGET_ROOTFS_INCLUDE_KERNEL is not set/' .config
	sed -i 's/^CONFIG_TARGET_ROOTFS_INCLUDE_DTB.*/# CONFIG_TARGET_ROOTFS_INCLUDE_DTB is not set/' .config
	make defconfig
206
	cp build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/root-mvebu/boot/uboot* build_dir
207 208 209
	rm -f build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/root-mvebu/boot/* build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/root-mvebu/etc/rc.d/*rainbow
	make target/linux/compile "$@"
	cp `ls -d build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/linux-mvebu`/{zImage-initramfs,zImage-initramfs-armada-385-turris-omnia}
210
	cat build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/linux-mvebu/linux-4.4*/arch/arm/boot/dts/armada-385-turris-omnia.dtb >> `ls -d build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/linux-mvebu`/zImage-initramfs-armada-385-turris-omnia
211
	[ \! -d ./logs ] || cp ./.config logs/config
212
	[ \! -d ./logs ] || mv ./logs ./logs-initram
213
	cp build_dir/target-arm_*/linux-mvebu/zImage-initramfs-armada-385-turris-omnia bin/mvebu-musl/omnia-initramfs-zimage
214 215 216 217 218 219
	SIZE="`du -b bin/mvebu-musl/omnia-initramfs-zimage | sed 's|[[:blank:]].*||'`"
	echo "Rescue image size is ${SIZE}."
	if [ "$SIZE" -ge $(( 7 * 1024 * 1024 )) ]; then
		echo FATAL: Image too big.
		exit 1
	fi
220
	mv build_dir/uboot* bin/mvebu-musl
221 222
	mkdir -p bin/mvebu-musl/x86-64
	cp build_dir/host/uboot-turris-omnia*/turris-omnia-uboot/* bin/mvebu-musl/x86-64
223
	mv bin bin-nor
224
	rm -rf bin-nor/mvebu-musl/packages
225 226
elif [ "$TARGET_BOARD" = turris ]; then
	cp -r turris-legacy/* .
227
fi