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