xref: /src/sys/conf/dtb.build.mk (revision cf202819af2337c0b652ac9290964c2ef7a1ae3c)
1.include "kern.opts.mk"
2
3DTC?=		dtc
4
5.if !defined(SYSDIR)
6.if defined(S)
7SYSDIR=	${S}
8.else
9.include <bsd.sysdir.mk>
10.endif	# defined(S)
11.endif	# defined(SYSDIR)
12
13.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
14.error "can't find kernel source tree"
15.endif
16
17.for _dts in ${DTS}
18# DTBs for aarch64 and riscv need to preserve the immediate parent of the .dts,
19# because these DTS are vendored and should be installed into their vendored
20# directories.
21.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv"
22DTB+=	${_dts:R:S/$/.dtb/}
23.else
24DTB+=	${_dts:T:R:S/$/.dtb/}
25.endif
26.endfor
27
28DTBO=${DTSO:T:R:S/$/.dtbo/}
29
30.SUFFIXES: .dtb .dts .dtbo .dtso
31.PATH.dts: ${SYSDIR}/contrib/device-tree/src/${MACHINE} ${SYSDIR}/dts/${MACHINE}
32.PATH.dtso: ${SYSDIR}/dts/${MACHINE}/overlays
33
34.export DTC ECHO
35
36.dts.dtb:	${OP_META}
37	${SYSDIR}/tools/fdt/make_dtb.sh ${SYSDIR} ${.IMPSRC} ${.OBJDIR}
38
39.dtso.dtbo:	${OP_META}
40	${SYSDIR}/tools/fdt/make_dtbo.sh ${SYSDIR} ${.IMPSRC} ${.OBJDIR}
41
42# Add dependencies on the source file so that out-of-tree things can be included
43# without any .PATH additions.
44.for _dts in ${DTS} ${FDT_DTS_FILE}
45${_dts:R:T}.dtb: ${_dts}
46.endfor
47
48.for _dtso in ${DTSO}
49${_dtso:R:T}.dtbo: ${_dtso}
50.endfor
51
52_dtbinstall:
53# Need to create this because installkernel doesn't invoke mtree with BSD.root.mtree
54# to make sure the tree is setup properly. We don't recreate it to avoid duplicate
55# entries in the NO_ROOT case.
56	test -d ${DESTDIR}${DTBDIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}
57.for _dtb in ${DTB}
58.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv"
59	# :H:T here to grab the vendor component of the DTB path in a way that
60	# allows out-of-tree DTS builds, too.  We make the assumption that
61	# out-of-tree DTS will have a similar directory structure to in-tree,
62	# with .dts files appearing in a vendor/ directory.
63	test -d ${DESTDIR}${DTBDIR}/${_dtb:H:T} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}/${_dtb:H:T}
64	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
65	    ${_INSTALLFLAGS} ${_dtb:T} ${DESTDIR}${DTBDIR}/${_dtb:H:T}
66.else
67	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
68	    ${_INSTALLFLAGS} ${_dtb} ${DESTDIR}${DTBDIR}/
69.endif
70.endfor
71	test -d ${DESTDIR}${DTBODIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBODIR}
72.for _dtbo in ${DTBO}
73	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
74	    ${_INSTALLFLAGS} ${_dtbo} ${DESTDIR}${DTBODIR}/
75.endfor
76