1# 2# Copyright (c) 2011 The Chromium OS Authors. 3# 4# SPDX-License-Identifier: GPL-2.0+ 5# 6 7# This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is 8# enabled. See doc/README.fdt-control for more details. 9 10DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) 11ifeq ($(DEVICE_TREE),) 12DEVICE_TREE := unset 13endif 14 15ARCH_PATH := arch/$(ARCH)/dts 16dtb_depends := arch-dtbs 17 18ifneq ($(EXT_DTB),) 19DTB := $(EXT_DTB) 20else 21DTB := $(ARCH_PATH)/$(DEVICE_TREE).dtb 22dtb_depends += $(DTB:.dtb=.dts) 23endif 24 25# Pass the original device tree file through fdtgrep twice. The first pass 26# removes any unwanted nodes (i.e. those which don't have the 27# 'u-boot,dm-pre-reloc' property and thus are not needed by SPL. The second 28# pass removes various unused properties from the remaining nodes. 29# The output is typically a much smaller device tree file. 30ifeq ($(CONFIG_TPL_BUILD),y) 31fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-tpl 32else 33fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-spl 34endif 35quiet_cmd_fdtgrep = FDTGREP $@ 36 cmd_fdtgrep = $(objtree)/tools/fdtgrep $(fdtgrep_props) -RT $< \ 37 -n /chosen -n /config -O dtb | \ 38 $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ 39 $(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS))) 40 41fdtgrep_tpl_props := -b u-boot,dm-pre-reloc -b u-boot,dm-tpl 42quiet_cmd_fdtgrep_tpl = FDTGREP $@ 43 cmd_fdtgrep_tpl = $(objtree)/tools/fdtgrep $(fdtgrep_tpl_props) -RT $< \ 44 -n /chosen -n config -O dtb | \ 45 $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ 46 $(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS))) 47 48fdtgrep_spl_minimum_props := -b u-boot,dm-spl 49quiet_cmd_fdtgrep_spl_minimum = FDTGREP $@ 50 cmd_fdtgrep_spl_minimum = $(objtree)/tools/fdtgrep $(fdtgrep_spl_minimum_props) -RT $< \ 51 -n /chosen -n config -O dtb | \ 52 $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ 53 $(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS))) 54 55$(obj)/dt-tpl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE 56 $(call if_changed,fdtgrep_tpl) 57 58ifeq ($(CONFIG_SPL_DTB_MINIMUM),y) 59$(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE 60 $(call if_changed,fdtgrep_spl_minimum) 61else 62$(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE 63 $(call if_changed,fdtgrep) 64endif 65 66ifeq ($(CONFIG_USING_KERNEL_DTB),y) 67$(obj)/dt.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE 68 $(call if_changed,fdtgrep) 69else 70$(obj)/dt.dtb: $(DTB) FORCE 71 $(call if_changed,shipped) 72endif 73 74targets += dt.dtb dt-spl.dtb dt-tpl.dtb 75 76$(DTB): $(dtb_depends) 77ifeq ($(EXT_DTB),) 78 $(Q)$(MAKE) $(build)=$(ARCH_PATH) $@ 79endif 80 $(Q)test -e $@ || ( \ 81 echo >&2; \ 82 echo >&2 "Device Tree Source is not correctly specified."; \ 83 echo >&2 "Please define 'CONFIG_DEFAULT_DEVICE_TREE'"; \ 84 echo >&2 "or build with 'DEVICE_TREE=<device_tree>' argument"; \ 85 echo >&2; \ 86 /bin/false) 87 88arch-dtbs: 89 $(Q)$(MAKE) $(build)=$(ARCH_PATH) dtbs 90 91.SECONDARY: $(obj)/dt.dtb.S $(obj)/dt-spl.dtb.S $(obj)/dt-tpl.dtb.S 92 93 94ifeq ($(CONFIG_SPL_BUILD),y) 95obj-$(CONFIG_OF_EMBED) := dt-spl.dtb.o 96# support "out-of-tree" build for dtb-spl 97$(obj)/dt-tpl.dtb.o: $(obj)/dt-tpl.dtb.S FORCE 98 $(call if_changed_dep,as_o_S) 99 100$(obj)/dt-spl.dtb.o: $(obj)/dt-spl.dtb.S FORCE 101 $(call if_changed_dep,as_o_S) 102else 103obj-$(CONFIG_OF_EMBED) := dt.dtb.o 104endif 105 106dtbs: $(obj)/dt.dtb $(obj)/dt-spl.dtb $(obj)/dt-tpl.dtb 107 @: 108 109clean-files := dt.dtb.S dt-spl.dtb.S dt-tpl.dtb.S 110 111# Let clean descend into dts directories 112subdir- += ../arch/arm/dts ../arch/microblaze/dts ../arch/mips/dts ../arch/sandbox/dts ../arch/x86/dts 113