summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_dts_dtc.sh
blob: b4d593acd18ead56448944ed9a0db47ceb499f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# Copyright (C) 2014 by Michael Olbrich <m.olbrich@pengutronix.de>
#
# See CREDITS for details about who has contributed to this project.
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

ptxd_make_dts_dtb() {
    local dts tmp_dts deps tmp_deps dtc_include no_linemarker

    case "${dts_dts}" in
	/*)
	    if [ ! -e "${dts_dts}" ]; then
		ptxd_bailout "Device-tree '${dts_dts}' not found."
	    fi
	    dts="${dts_dts}"
	    ;;
	*)
	    if ! ptxd_in_path dts_path "${dts_dts}"; then
		ptxd_bailout "Device-tree '${dts_dts}' not found in '${dts_path}'."
	    fi
	    dts="${ptxd_reply}"
	    ;;
    esac

    if dtc -h 2>&1 | grep -q '^[[:space:]]\+-i\(,.*\)\?$'; then
	dtc_include="-i $(dirname "${dts}") -i ${dts_kernel_dir}/arch/${dts_kernel_arch}/boot/dts"
	tmp_dts="${ptx_state_dir}/$(basename "${dts}").tmp"
	no_linemarker=""
    else
	# the support for "#line ..." was added in the same relase when -i
	# was added. So we add -P only if -i is not supported.
	tmp_dts="${dts}.tmp"
	no_linemarker="-P"
    fi &&

    deps="${ptx_state_dir}/dtc.$(basename "${dts}").deps"
    tmp_deps="${PTXDIST_TEMPDIR}/dtc.$(basename "${dts}").deps"

    echo "CPP $(ptxd_print_path "${tmp_dts}")" &&
    cpp \
	-Wp,-MD,${tmp_deps} \
	-Wp,-MT,${tmp_dts} \
	-nostdinc \
	${no_linemarker} \
	-I$(dirname "${dts}") \
	-I${dts_kernel_dir}/arch/${dts_kernel_arch}/boot/dts \
	-I${dts_kernel_dir}/arch/${dts_kernel_arch}/boot/dts/include \
	-I${dts_kernel_dir}/drivers/of/testcase-data \
	-I${dts_kernel_dir}/include \
	-undef -D__DTS__ -x assembler-with-cpp \
	-o ${tmp_dts} \
	${dts} &&

    sed -e "s;^${tmp_dts}:;${dts_dtb}:;" \
	-e 's;^ \([^ ]*\); $(wildcard \1);' "${tmp_deps}" > "${deps}" &&

    echo "DTC $(ptxd_print_path "${dts_dtb}")" &&
    dtc \
	$(ptxd_get_ptxconf PTXCONF_DTC_EXTRA_ARGS) \
	${dtc_include} \
	-d "${tmp_deps}" \
	-I dts -O dtb -b 0 \
	-o "${dts_dtb}" "${tmp_dts}" &&

    awk '{ \
	    printf "%s", $1 ;  \
	    for (i = 2; i <= NF; i++) { \
		printf " $(wildcard %s)", $i; \
	    }; \
	    print "" \
	}' "${tmp_deps}" >> "${deps}" ||

    ptxd_bailout "Unable to generate dtb file."
}
export -f ptxd_make_dts_dtb