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