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