xref: /OK3568_Linux_fs/buildroot/board/freescale/common/mxs/post-image.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/usr/bin/env bash
2
3#
4# dtb_list extracts the list of DTB files from BR2_LINUX_KERNEL_INTREE_DTS_NAME
5# in ${BR_CONFIG}, then prints the corresponding list of file names for the
6# genimage configuration file
7#
8dtb_list()
9{
10	local DTB_LIST="$(sed -n 's/^BR2_LINUX_KERNEL_INTREE_DTS_NAME="\([a-z0-9 \-]*\)"$/\1/p' ${BR2_CONFIG})"
11
12	for dt in $DTB_LIST; do
13		echo -n "\"$dt.dtb\", "
14	done
15}
16
17#
18# linux_image extracts the Linux image format from BR2_LINUX_KERNEL_UIMAGE in
19# ${BR_CONFIG}, then prints the corresponding file name for the genimage
20# configuration file
21#
22linux_image()
23{
24	if grep -Eq "^BR2_LINUX_KERNEL_UIMAGE=y$" ${BR2_CONFIG}; then
25		echo "\"uImage\""
26	else
27		echo "\"zImage\""
28	fi
29}
30
31main()
32{
33	local FILES="$(dtb_list) $(linux_image)"
34	local GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)"
35	local GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
36
37	sed -e "s/%FILES%/${FILES}/" \
38		board/freescale/common/mxs/genimage.cfg.template > ${GENIMAGE_CFG}
39
40	rm -rf "${GENIMAGE_TMP}"
41
42	genimage \
43		--rootpath "${TARGET_DIR}" \
44		--tmppath "${GENIMAGE_TMP}" \
45		--inputpath "${BINARIES_DIR}" \
46		--outputpath "${BINARIES_DIR}" \
47		--config "${GENIMAGE_CFG}"
48
49	rm -f ${GENIMAGE_CFG}
50
51	exit $?
52}
53
54main $@
55