2 # kbuild file for firmware/
5 # Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
6 # leading /, it's relative to $(srctree).
7 fwdir := $(subst ",,$(CONFIG_EXTRA_FIRMWARE_DIR))
8 fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
10 fw-external-y := $(subst ",,$(CONFIG_EXTRA_FIRMWARE))
12 firmware-y := $(fw-external-y) $(fw-shipped-y)
13 firmware-dirs := $(sort $(patsubst %,$(objtree)/$(obj)/%/,$(dir $(firmware-y) $(fw-shipped-))))
15 quiet_cmd_mkdir = MKDIR $(patsubst $(objtree)/%,%,$@)
16 cmd_mkdir = mkdir -p $@
18 quiet_cmd_ihex = IHEX $@
19 cmd_ihex = $(OBJCOPY) -Iihex -Obinary $< $@
21 quiet_cmd_fwbin = MK_FW $@
22 cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)"; \
23 FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst \
24 firmware/%.gen.S,%,$@))))"; \
25 ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long); \
26 ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \
27 PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \
28 echo "/* Generated by firmware/Makefile */" > $@;\
29 echo " .section .rodata" >>$@;\
30 echo " .p2align $${ASM_ALIGN}" >>$@;\
31 echo "_fw_$${FWSTR}_bin:" >>$@;\
32 echo " .incbin \"$(2)\"" >>$@;\
33 echo "_fw_end:" >>$@;\
34 echo " .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\
35 echo " .p2align $${ASM_ALIGN}" >>$@;\
36 echo "_fw_$${FWSTR}_name:" >>$@;\
37 echo " .string \"$$FWNAME\"" >>$@;\
38 echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\
39 echo " .p2align $${ASM_ALIGN}" >>$@;\
40 echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\
41 echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\
42 echo " $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin" >>$@;
44 # One of these files will change, or come into existence, whenever
45 # the configuration changes between 32-bit and 64-bit. The .S files
46 # need to change when that happens.
47 wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
48 include/config/ppc32.h include/config/ppc64.h \
49 include/config/superh32.h include/config/superh64.h \
50 include/config/x86_32.h include/config/x86_64.h)
52 # Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
53 # It'll end up depending on these targets, so make them a PHONY rule which
54 # depends on _all_ the directories in $(firmware-dirs), and it'll work out OK.
55 PHONY += $(objtree)/$$(%) $(objtree)/$(obj)/$$(%)
56 $(objtree)/$$(%) $(objtree)/$(obj)/$$(%): $(firmware-dirs)
59 # For the $$(dir %) trick, where we need % to be expanded first.
62 $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) \
63 | $(objtree)/$$(dir %)
64 $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
65 $(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
66 include/config/builtin/firmware/dir.h | $(objtree)/$$(dir %)
67 $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
69 # The .o files depend on the binaries directly; the .S files don't.
70 $(patsubst %,$(obj)/%.gen.o, $(fw-shipped-y)): %.gen.o: %
71 $(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
73 $(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
79 obj-y := $(patsubst %,%.gen.o, $(firmware-y))
81 # Remove .S files and binaries created from ihex
82 # (during 'make clean' .config isn't included so they're all in $(fw-shipped-))
83 targets := $(fw-shipped-) $(patsubst $(obj)/%,%, \
84 $(shell find $(obj) -name \*.gen.S 2>/dev/null))
86 # Without this, built-in.o won't be created when it's empty, and the
87 # final vmlinux link will fail.