xref: /linux/drivers/base/firmware_loader/builtin/Makefile (revision ca31fef11dc83e672415d5925a134749761329bd)
1# SPDX-License-Identifier: GPL-2.0
2
3# Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
4# leading /, it's relative to $(srctree).
5fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
6fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
7
8obj-y  := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE)))
9
10FWNAME    = $(patsubst $(obj)/%.gen.S,%,$@)
11FWSTR     = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME)))))
12ASM_WORD  = $(if $(CONFIG_64BIT),.quad,.long)
13ASM_ALIGN = $(if $(CONFIG_64BIT),3,2)
14PROGBITS  = $(if $(CONFIG_ARM),%,@)progbits
15
16filechk_fwbin = \
17	echo "/* Generated by $(src)/Makefile */"		;\
18	echo "    .section .rodata"				;\
19	echo "    .p2align 4"					;\
20	echo "_fw_$(FWSTR)_bin:"				;\
21	echo "    .incbin \"$(fwdir)/$(FWNAME)\""		;\
22	echo "_fw_end:"						;\
23	echo "    .section .rodata.str,\"aMS\",$(PROGBITS),1"	;\
24	echo "    .p2align $(ASM_ALIGN)"			;\
25	echo "_fw_$(FWSTR)_name:"				;\
26	echo "    .string \"$(FWNAME)\""			;\
27	echo "    .section .builtin_fw,\"a\",$(PROGBITS)"	;\
28	echo "    .p2align $(ASM_ALIGN)"			;\
29	echo "    $(ASM_WORD) _fw_$(FWSTR)_name"		;\
30	echo "    $(ASM_WORD) _fw_$(FWSTR)_bin"			;\
31	echo "    $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin"
32
33$(obj)/%.gen.S: FORCE
34	$(call filechk,fwbin)
35
36# The .o files depend on the binaries directly; the .S files don't.
37$(addprefix $(obj)/, $(obj-y)): $(obj)/%.gen.o: $(fwdir)/%
38
39targets := $(patsubst $(obj)/%,%, \
40                                $(shell find $(obj) -name \*.gen.S 2>/dev/null))
41