xref: /freebsd/sys/conf/dtb.mk (revision d34048812292b714a0bf99967270d18fe3097c62)
1# $FreeBSD$
2#
3# The include file <dtb.mk> handles building and installing dtb files.
4#
5# +++ variables +++
6#
7# DTC		The Device Tree Compiler to use
8#
9# DTS		List of the dts files to build and install.
10#
11# DTBDIR	Base path for dtb modules [/boot/dtb]
12#
13# DTBOWN	.dtb file owner. [${BINOWN}]
14#
15# DTBGRP	.dtb file group. [${BINGRP}]
16#
17# DTBMODE	Module file mode. [${BINMODE}]
18#
19# DESTDIR	The tree where the module gets installed. [not set]
20#
21# +++ targets +++
22#
23# 	install:
24#               install the kernel module; if the Makefile
25#               does not itself define the target install, the targets
26#               beforeinstall and afterinstall may also be used to cause
27#               actions immediately before and after the install target
28#		is executed.
29#
30
31.include <bsd.init.mk>
32# Grab all the options for a kernel build. For backwards compat, we need to
33# do this after bsd.own.mk.
34.include "kern.opts.mk"
35
36DTC?=		dtc
37
38# Search for kernel source tree in standard places.
39.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
40.if !defined(SYSDIR) && exists(${_dir}/kern/)
41SYSDIR=	${_dir:tA}
42.endif
43.endfor
44.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
45.error "can't find kernel source tree"
46.endif
47
48.SUFFIXES: .dtb .dts .dtbo .dtso
49
50.PATH: ${SYSDIR}/gnu/dts/${MACHINE} ${SYSDIR}/dts/${MACHINE} ${SYSDIR}/dts/${MACHINE}/overlays
51
52DTB=${DTS:R:S/$/.dtb/}
53DTBO=${DTSO:R:S/$/.dtbo/}
54
55all: ${DTB} ${DTBO}
56
57.if defined(DTS)
58.export DTC ECHO
59.for _dts in ${DTS}
60${_dts:R:S/$/.dtb/}:	${_dts} ${OP_META}
61	@${ECHO} Generating ${.TARGET} from ${_dts}
62	@${SYSDIR}/tools/fdt/make_dtb.sh ${SYSDIR} ${_dts} ${.OBJDIR}
63CLEANFILES+=${_dts:R:S/$/.dtb/}
64.endfor
65.endif
66
67.if defined(DTSO)
68.export DTC ECHO
69.for _dtso in ${DTSO}
70${_dtso:R:S/$/.dtbo/}:	${_dtso} ${OP_META}
71	@${ECHO} Generating ${.TARGET} from ${_dtso}
72	@${SYSDIR}/tools/fdt/make_dtbo.sh ${SYSDIR} overlays/${_dtso} ${.OBJDIR}
73CLEANFILES+=${_dtso:R:S/$/.dtbo/}
74.endfor
75.endif
76
77.if !target(install)
78.if !target(realinstall)
79realinstall: _dtbinstall
80.ORDER: beforeinstall _kmodinstall
81_dtbinstall:
82# Need to create this because installkernel doesn't invoke mtree with BSD.root.mtree
83# to make sure the tree is setup properly. We don't recreate it to avoid duplicate
84# entries in the NO_ROOT case.
85	test -d ${DESTDIR}${DTBDIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}
86.for _dtb in ${DTB}
87.if ${MACHINE_CPUARCH} == "aarch64"
88	test -d ${DESTDIR}${DTBDIR}/${_dtb:H} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}/${_dtb:H}
89	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
90	    ${_INSTALLFLAGS} ${_dtb:T} ${DESTDIR}${DTBDIR}/${_dtb:H}
91.else
92	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
93	    ${_INSTALLFLAGS} ${_dtb} ${DESTDIR}${DTBDIR}/
94.endif
95.endfor
96	test -d ${DESTDIR}${DTBODIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBODIR}
97.for _dtbo in ${DTBO}
98	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
99	    ${_INSTALLFLAGS} ${_dtbo} ${DESTDIR}${DTBODIR}/
100.endfor
101.endif # !target(realinstall)
102.endif # !target(install)
103
104.include <bsd.dep.mk>
105.include <bsd.obj.mk>
106.include <bsd.links.mk>
107