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