compile_fw 11.7 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 13 14
export TMPDIR="`pwd`/tmp"
mkdir $TMPDIR

15
make_defconfig() {
16
	make defconfig "$@"
17
	egrep '^(#[[:space:]]+)?CONFIG_KERNEL' configs/common configs/$TARGET_BOARD | sed 's|.*:||' >> ./.config
18 19
}

20 21 22 23 24 25 26 27 28 29 30 31 32 33
if [ "$1" = turris ] || [ "$1" = omnia ]; then
	export TARGET_BOARD="$1"
	shift
fi

if [ -z "$TARGET_BOARD" ]; then
	echo "You have to specify target board - options are 'turris' or 'omnia'"
	exit 1
fi
# Clean feeds
./scripts/feeds clean

# Install luci feed
./scripts/feeds update -a
34 35 36 37 38 39 40 41 42 43 44 45
# 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
46 47 48 49 50 51
./scripts/feeds install -a

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

52
# Bump release numbers when asked for
53 54
while read pkg orig_release release; do
	if [ $orig_release = X ]; then
55
		sed -i 's|^PKG_RELEASE\(:\?\)=\$(PKG_SOURCE_VERSION)$|PKG_RELEASE\1=\$(PKG_SOURCE_VERSION)-'"$release"'|' "$pkg"/Makefile || true
56
	else
57 58
		sed -i 's|^PKG_RELEASE\(:\?\)='"$orig_release"'\+$|PKG_RELEASE\1='"$release"'|' "$pkg"/Makefile || true
		sed -i 's|^PKG_RELEASE\(:\?\)=\$(PKG_SOURCE_VERSION)-'"$orig_release"'\+$|PKG_RELEASE\1=\$(PKG_SOURCE_VERSION)-'"$release"'|' "$pkg"/Makefile || true
59
	fi
60 61
done < release-override

62 63 64
# Build NAND FW
[ -z "$OPENWRT_BRANCH" ] || PKG_BRANCH="-$OPENWRT_BRANCH"
cat configs/common configs/$TARGET_BOARD | sed -e "s|@BOARD@|$TARGET_BOARD|" -e "s|@BRANCH@|$PKG_BRANCH|" > .config
65
[ -n "$BUILD_ALL" ] && echo "CONFIG_ALL=y" >> .config && echo "CONFIG_SDK=y" >> .config
66
echo CONFIG_ALL_KMODS=y >> .config
67 68

# Include important userlists
69 70 71 72
# Base list generation
cat > base.lua << EOF
-- The basic repository
Repository 'turris' 'https://api.turris.cz/openwrt-repo/${TARGET_BOARD}${PKG_BRANCH}/packages' {
73
	subdirs = {'base', $(echo $(sed -n 's|^src-git[[:blank:]]\+\([^[:blank:]]*\)[[:blank:]]\+http.*|\1|p' ./feeds.conf.default) | sed -e 's|\([^[:blank:]]\+\)|'"'\\1'|g" -e 's|\ |,\ |g')}
74 75 76 77 78 79 80
}
EOF
if [ -z "$BUILD_ALL" ]; then
cat >> base.lua << EOF

-- The fallback repository
Repository 'turris-fallback' 'https://api.turris.cz/openwrt-repo/${TARGET_BOARD}-nightly/packages' {
81
	subdirs = {'base', $(echo $(sed -n 's|^src-git[[:blank:]]\+\([^[:blank:]]*\)[[:blank:]]\+http.*|\1|p' ./feeds.conf.default) | sed -e 's|\([^[:blank:]]\+\)|'"'\\1'|g" -e 's|\ |,\ |g')},
82 83
	priority = 40,
	ignore = {'missing'}
84 85 86 87 88 89 90
}
EOF
fi
cat >> base.lua << EOF

-- Make sure the updater is up to date before continuing
Package 'opkg-trans' { replan = true }
91 92
Install 'opkg-trans' 'updater-ng' { critical = true }
Install 'userlists' { critical = true }
93

94
-- Install everything that was in the image
95
EOF
96
if [ -n "${PKG_BRANCH}" ] && [ "${PKG_BRANCH}" \!= master ] && [ "${PKG_BRANCH}" \!= stable ]; then
97 98
	echo 'Install "cznic-repo-keys-test"' >> base.lua
	echo CONFIG_PACKAGE_cznic-repo-keys-test=y >> .config
99
	echo CONFIG_PACKAGE_getbranch-test=y >> .config
100 101
else
	echo CONFIG_PACKAGE_cznic-repo-keys-test=m >> .config
102
	echo CONFIG_PACKAGE_getbranch-deploy=y >> .config
103
fi
104
# Other lists
105
echo 'config pkglists pkglists' > package/feeds/turrispackages/opkg-trans/files/updater.config
106
for i in lists/*.list; do
107
	echo "	list lists '`basename ${i/.list}`'" >> package/feeds/turrispackages/opkg-trans/files/updater.config
108
	cat "$i" "${i/%list/${TARGET_BOARD}}" | sed 's|#.*||' 2> /dev/null | while read PKG; do
109
		if expr "$PKG" : CONFIG_;then
110 111 112 113 114
			if [ "$TARGET_BOARD" = omnia ]; then
				echo "$PKG" | sed 's|=m|=y|' >> .config
			else
				echo "$PKG" >> .config
			fi
115
		elif [ -n "$PKG" ]; then
116
			if [ "$TARGET_BOARD" = omnia ] || [ "$i" = lists/base.list ]; then
117 118 119
				if [ "$BUILD_ALL" ] || [ "$i" = lists/base.list ]; then
					echo "CONFIG_PACKAGE_$PKG=y" >> .config
				fi
120 121 122
			else
				[ -z "$BUILD_ALL" ] || echo "CONFIG_PACKAGE_$PKG=m" >> .config
			fi
123
		fi
124
	done
125 126
done

127
[ -n "$USE_CCACHE" ] && echo "CONFIG_CCACHE=y" >> .config
128
if [ -f "$HOME"/mime.key ]; then
129
	echo "CONFIG_SIGNED_PACKAGES=y" >> .config
130
	rm -f key-build key-build.pub
131 132
	cp "$HOME/mime.key" key-build
	cp "$HOME/mime.pub" key-build.pub
133
fi
134
[ "${TARGET_BOARD}" = omnia ] || echo "CONFIG_PACKAGE_updater-ng=m" >> ./.config
135
make_defconfig
136 137 138 139
if [ -d .git ] ; then
	git log -n1 --format='%H' >files/etc/git-version
fi
make clean
140
[ -z "$BUILD_ALL" ] || make dirclean
141 142 143
set -- "$@" PKG_BRANCH=${PKG_BRANCH/-/}
[ -z "$PERSISTENT_CCACHE" ] || set -- "$@" CCACHE_DIR="`pwd`/ccache" CCACHE_HOST_DIR="`pwd`/ccache-host"
make "$@"
144
# Nice junit export
145
mkdir -p logs
146 147 148 149 150 151 152 153 154 155 156
cat > logs/junit.xml << EOF
<?xml version='1.0' encoding='utf-8'?>
<testsuites errors='`cat logs/package/error.txt | wc -l`' tests='`find logs/package/ -name compile.txt | wc -l`'>
EOF
(cd logs; find package/ -name compile.txt; cd ..) | while read log; do
PKG_NAME="`dirname $log`"
if grep "ERROR: $PKG_NAME failed" logs/package/error.txt; then
cat >> logs/junit.xml << EOF
<testsuite errors='1' name='$PKG_NAME' tests='1'>
<testcase name='compile'>
<error message='$PKG_NAME failed to compile' type='error'><![CDATA[
157
`tail -n 100 logs/$log | sed -e 's|\]\]>|\]\] >|g' -e 's/\x1b//g'`
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
]]></error>
</testcase>
</testsuite>
EOF
else
cat >> logs/junit.xml << EOF
<testsuite errors='0' failures='0' name='$PKG_NAME' tests='1'>
<testcase name='compile'/>
</testsuite>
EOF
fi
done
cat >> logs/junit.xml << EOF
</testsuites>
EOF
173 174 175 176 177
if [ -n "`cat logs/package/error.txt 2> /dev/null`" ] && [ -z "$PKG_BRANCH" ]; then
	echo "Following packages are failing in stable release"
	cat logs/package/error.txt
	exit 1
fi
178
[ \! -d ./logs ] || mv ./logs ./logs-nand
179

180 181
COMMIT_DATE="`git log --format=format:%cD -1`"

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
if [ "$TARGET_BOARD" = turris ]; then
	#Build initramfs
	echo -e "CONFIG_TARGET_ROOTFS_INITRAMFS=y\nCONFIG_TARGET_INITRAMFS_COMPRESSION_XZ=y" >> .config
	make_defconfig
	make target/linux/compile "$@"
	[ \! -d ./logs ] || mv ./logs ./logs-initram

	cp build_dir/target-powerpc_*/linux-mpc85xx_p2020-nand/zImage-initramfs bin/mpc85xx/turris-initramfs-zimage

	# 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 ../../..
elif [ "$TARGET_BOARD" = omnia ]; then
198
	mkdir bin/mvebu-musl/medkit
199
	MED_PATH="bin/mvebu-musl/medkit"
200
	if [ -n "$BUILD_ALL" ]; then
201
		FLAVOR="full"
202
	else
203
		FLAVOR="minimal"
204 205
	fi
	mkdir -p "$MED_PATH"
206
	mv bin/mvebu-musl/openwrt-mvebu-Turris-Omnia-rootfs.tar.gz "$MED_PATH"/omnia-medkit-`date -d "$COMMIT_DATE" +%Y%m%d%H%M`-$FLAVOR.tar.gz
207 208
	# Preserve the uncompressed image too
	mv build_dir/target-arm_*/root-mvebu* bin/mvebu-musl/root
209
	pushd bin/mvebu-musl/root
210 211
	rm var
	find -type l ! -exec test -r {} \; -delete
212
	popd
213 214
fi

215 216 217 218 219
# Clean
[ -d ./bin-nand ] && rm -rf ./bin-nand
mv ./bin ./bin-nand
[ -d ./tmp ] && rm -rf ./tmp

220
# Generate lists
221
PUB_BIN_DIR="`ls -1d bin-nand/* | head -n1`"
222
mkdir -p $PUB_BIN_DIR/lists
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238

# On Omnia full build generate a minimal image as well and use it for base list
if [ -n "$BUILD_ALL" ] && [ "$TARGET_BOARD" = omnia ]; then
	make dirclean
	cat configs/common configs/$TARGET_BOARD | sed -e "s|@BOARD@|$TARGET_BOARD|" -e "s|@BRANCH@|$PKG_BRANCH|" > .config
	echo CONFIG_ALL_KMODS=y >> .config
	cat "lists/base.list" "lists/base.${TARGET_BOARD}" | sed 's|#.*||' 2> /dev/null | while read PKG; do
		if expr "$PKG" : CONFIG_;then
			echo "$PKG" >> .config
		elif [ -n "$PKG" ]; then
			echo "CONFIG_PACKAGE_$PKG=y" >> .config
		fi
	done
	make_defconfig
	make "$@" PKG_BRANCH=${PKG_BRANCH/-/}
	mkdir -p bin-nand/mvebu-musl/medkit/minimal
239
	mv bin/mvebu-musl/openwrt-mvebu-Turris-Omnia-rootfs.tar.gz bin-nand/mvebu-musl/medkit/omnia-medkit-`date -d "$COMMIT_DATE" +%Y%m%d%H%M`-minimal.tar.gz
240 241 242 243 244
	OPKG_STATUS="`ls -1d build_dir/target-arm_*/root-mvebu*/usr/lib/opkg/status`"
else
	OPKG_STATUS="`ls -1d bin-nand/*/root/usr/lib/opkg/status`"
fi

245 246 247
echo Install $(sed -n 's|Package: \(.*\)|"\1"|p' $OPKG_STATUS | egrep -v '"updater(|-deps|-consolidator)"') " { critical = true }" >> base.lua
[ \! -f "lists/base_add" ]               || echo Install $(cat "lists/base_add.$TARGET_BOARD" | sed 's|^\([^#]\+\)$|"\1"|') " { critical = true }" >> base.lua
[ \! -f "lists/base_add.$TARGET_BOARD" ] || echo Install $(cat "lists/base_add.$TARGET_BOARD" | sed 's|^\([^#]\+\)$|"\1"|') " { critical = true }" >> base.lua
248
mv base.lua $PUB_BIN_DIR/lists
249
for i in lists/*.list; do
250
	[ "$i" = lists/base.list ] || rm -f $PUB_BIN_DIR/lists/$(basename $i .list).lua
251
	echo -n "Install" >> $PUB_BIN_DIR/lists/$(basename $i .list).lua
252
	grep -h -v CONFIG_ "$i" "${i/%list/${TARGET_BOARD}}" 2> /dev/null | grep . | grep -v '^#' | while read pkg; do
253
		echo -n " \"$pkg\"" >> $PUB_BIN_DIR/lists/$(basename $i .list).lua
254
	done
255
	echo " { ignore = { 'missing' } }" >> $PUB_BIN_DIR/lists/$(basename $i .list).lua
256
	sed -i '/^Install[[:blank:]]*$/ d' $PUB_BIN_DIR/lists/$(basename $i .list).lua
257
	if [ -f "$HOME"/mime.key ]; then
258
		staging_dir/host/bin/usign -S -m $PUB_BIN_DIR/lists/$(basename $i .list).lua -s "$HOME"/mime.key
259 260
	fi
done
261
for i in lists/*.lua; do
262 263 264
	if [ -r "$i" ]; then
		cp $i $PUB_BIN_DIR/lists
		if [ -f "$HOME"/mime.key ]; then
265
			staging_dir/host/bin/usign -S -m $PUB_BIN_DIR/lists/$(basename $i) -s "$HOME"/mime.key
266
		fi
267 268
	fi
done
269 270
if [ "$TARGET_BOARD" = "omnia" ]; then
	rm -f $PUB_BIN_DIR/*.ext4 $PUB_BIN_DIR/*sums
271
	for i in $PUB_BIN_DIR/medkit/*.tar.gz; do
272 273 274 275 276 277 278
		staging_dir/host/bin/usign -S -m "$i" -s "$HOME"/mime.key
		pushd "`dirname $i`"
		md5sum "`basename $i`" > "`basename $i`".md5
		sha256sum "`basename $i`" > "`basename $i`".sha256
		popd
	done
fi
279 280 281 282 283 284 285 286

if [ "$TARGET_BOARD" = turris ]; then
	# Build NOR FW
	cp configs/config-turris-nor .config
	[ -n "$USE_CCACHE" ] && echo "CONFIG_CCACHE=y" >> .config
	make defconfig
	make clean
	make "$@"
287
	[ \! -d ./logs ] || mv ./logs ./logs-nor
288 289 290
	[ -d ./bin/mpc85xx/packages ] && rm -rf ./bin/mpc85xx/packages
	[ -d ./bin-nor ] && rm -rf ./bin-nor
	mv ./bin ./bin-nor
291 292 293
elif [ "$TARGET_BOARD" = omnia ]; then
	cp configs/config-omnia-rescue .config
	[ -n "$USE_CCACHE" ] && echo "CONFIG_CCACHE=y" >> .config
294 295
    # Ugly hack, make python compile first to avoid possible race
    ./scripts/feeds uninstall python
296
	make defconfig CONFDEFAULT=n
297 298 299 300 301 302
	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
303
	cp build_dir/target-arm_cortex-a9+vfpv3_musl-*_eabi/root-mvebu/boot/uboot* build_dir
304 305 306
	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}
307
	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
308
	[ \! -d ./logs ] || mv ./logs ./logs-initram
309
	cp build_dir/target-arm_*/linux-mvebu/zImage-initramfs-armada-385-turris-omnia bin/mvebu-musl/omnia-initramfs-zimage
310
	[ "`du -b bin/mvebu-musl/omnia-initramfs-zimage | sed 's|[[:blank:]].*||'`" -lt 7000000 ] || exit 1
311
	mv build_dir/uboot* bin/mvebu-musl
312 313
	mkdir -p bin/mvebu-musl/x86-64
	cp build_dir/host/uboot-turris-omnia*/turris-omnia-uboot/* bin/mvebu-musl/x86-64
314
	mv bin bin-nor
315
	rm -rf bin-nor/mvebu-musl/packages
316
fi