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