xref: /linux/drivers/base/firmware_loader/builtin/Makefile (revision 4c25df5640ae6e4491ee2c50d3f70c1559ef037d)
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,%,$@)
11comma     := ,
12FWSTR     = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME)))))
13ASM_WORD  = $(if $(CONFIG_64BIT),.quad,.long)
14ASM_ALIGN = $(if $(CONFIG_64BIT),3,2)
15PROGBITS  = $(if $(CONFIG_ARM),%,@)progbits
16
17filechk_fwbin = \
18	echo "/* Generated by $(src)/Makefile */"		;\
19	echo "    .section .rodata"				;\
20	echo "    .p2align 4"					;\
21	echo "_fw_$(FWSTR)_bin:"				;\
22	echo "    .incbin \"$(fwdir)/$(FWNAME)\""		;\
23	echo "_fw_end:"						;\
24	echo "    .section .rodata.str,\"aMS\",$(PROGBITS),1"	;\
25	echo "    .p2align $(ASM_ALIGN)"			;\
26	echo "_fw_$(FWSTR)_name:"				;\
27	echo "    .string \"$(FWNAME)\""			;\
28	echo "    .section .builtin_fw,\"a\",$(PROGBITS)"	;\
29	echo "    .p2align $(ASM_ALIGN)"			;\
30	echo "    $(ASM_WORD) _fw_$(FWSTR)_name"		;\
31	echo "    $(ASM_WORD) _fw_$(FWSTR)_bin"			;\
32	echo "    $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin"
33
34$(obj)/%.gen.S: FORCE
35	$(call filechk,fwbin)
36
37# The .o files depend on the binaries directly; the .S files don't.
38$(addprefix $(obj)/, $(obj-y)): $(obj)/%.gen.o: $(fwdir)/%
39
40targets := $(patsubst $(obj)/%,%, \
41                                $(shell find $(obj) -name \*.gen.S 2>/dev/null))
42