xref: /freebsd/sys/conf/dtb.build.mk (revision 43d1e6ee299ad4e143d90d3ad374d1c24bd3306f)
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
27DTB=${DTS:T:R:S/$/.dtb/}
28DTBO=${DTSO:T:R:S/$/.dtbo/}
29
30.SUFFIXES: .dtb .dts .dtbo .dtso
31.PATH.dts: ${SYSDIR}/gnu/dts/${MACHINE} ${SYSDIR}/dts/${MACHINE}
32.PATH.dtso: ${SYSDIR}/dts/${MACHINE}/overlays
33
34.export DTC ECHO
35
36.dts.dtb:	${OP_META}
37	@${ECHO} Generating ${.TARGET} from ${.IMPSRC}
38	@${SYSDIR}/tools/fdt/make_dtb.sh ${SYSDIR} ${.IMPSRC} ${.OBJDIR}
39
40.dtso.dtbo:	${OP_META}
41	@${ECHO} Generating ${.TARGET} from ${.IMPSRC}
42	@${SYSDIR}/tools/fdt/make_dtbo.sh ${SYSDIR} ${.IMPSRC} ${.OBJDIR}
43
44# Add dependencies on the source file so that out-of-tree things can be included
45# without any .PATH additions.
46.for _dts in ${DTS}
47${_dts:R:T}.dtb: ${_dts}
48.endfor
49
50.for _dtso in ${DTSO}
51${_dtso:R:T}.dtbo: ${_dtso}
52.endfor
53
54_dtbinstall:
55# Need to create this because installkernel doesn't invoke mtree with BSD.root.mtree
56# to make sure the tree is setup properly. We don't recreate it to avoid duplicate
57# entries in the NO_ROOT case.
58	test -d ${DESTDIR}${DTBDIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}
59.for _dtb in ${DTB}
60.if ${MACHINE_CPUARCH} == "aarch64"
61	# :H:T here to grab the vendor component of the DTB path in a way that
62	# allows out-of-tree DTS builds, too.  We make the assumption that
63	# out-of-tree DTS will have a similar directory structure to in-tree,
64	# with .dts files appearing in a vendor/ directory.
65	test -d ${DESTDIR}${DTBDIR}/${_dtb:H:T} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}/${_dtb:H:T}
66	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
67	    ${_INSTALLFLAGS} ${_dtb:T} ${DESTDIR}${DTBDIR}/${_dtb:H:T}
68.else
69	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
70	    ${_INSTALLFLAGS} ${_dtb} ${DESTDIR}${DTBDIR}/
71.endif
72.endfor
73	test -d ${DESTDIR}${DTBODIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBODIR}
74.for _dtbo in ${DTBO}
75	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
76	    ${_INSTALLFLAGS} ${_dtbo} ${DESTDIR}${DTBODIR}/
77.endfor
78