18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci# Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
48c2ecf20Sopenharmony_ci# leading /, it's relative to $(srctree).
58c2ecf20Sopenharmony_cifwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
68c2ecf20Sopenharmony_cifwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciobj-y  := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE)))
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciFWNAME    = $(patsubst $(obj)/%.gen.S,%,$@)
118c2ecf20Sopenharmony_cicomma     := ,
128c2ecf20Sopenharmony_ciFWSTR     = $(subst $(comma),_,$(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME)))))
138c2ecf20Sopenharmony_ciASM_WORD  = $(if $(CONFIG_64BIT),.quad,.long)
148c2ecf20Sopenharmony_ciASM_ALIGN = $(if $(CONFIG_64BIT),3,2)
158c2ecf20Sopenharmony_ciPROGBITS  = $(if $(CONFIG_ARM),%,@)progbits
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cifilechk_fwbin = \
188c2ecf20Sopenharmony_ci	echo "/* Generated by $(src)/Makefile */"		;\
198c2ecf20Sopenharmony_ci	echo "    .section .rodata"				;\
208c2ecf20Sopenharmony_ci	echo "    .p2align 4"					;\
218c2ecf20Sopenharmony_ci	echo "_fw_$(FWSTR)_bin:"				;\
228c2ecf20Sopenharmony_ci	echo "    .incbin \"$(fwdir)/$(FWNAME)\""		;\
238c2ecf20Sopenharmony_ci	echo "_fw_end:"						;\
248c2ecf20Sopenharmony_ci	echo "    .section .rodata.str,\"aMS\",$(PROGBITS),1"	;\
258c2ecf20Sopenharmony_ci	echo "    .p2align $(ASM_ALIGN)"			;\
268c2ecf20Sopenharmony_ci	echo "_fw_$(FWSTR)_name:"				;\
278c2ecf20Sopenharmony_ci	echo "    .string \"$(FWNAME)\""			;\
288c2ecf20Sopenharmony_ci	echo "    .section .builtin_fw,\"a\",$(PROGBITS)"	;\
298c2ecf20Sopenharmony_ci	echo "    .p2align $(ASM_ALIGN)"			;\
308c2ecf20Sopenharmony_ci	echo "    $(ASM_WORD) _fw_$(FWSTR)_name"		;\
318c2ecf20Sopenharmony_ci	echo "    $(ASM_WORD) _fw_$(FWSTR)_bin"			;\
328c2ecf20Sopenharmony_ci	echo "    $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin"
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci$(obj)/%.gen.S: FORCE
358c2ecf20Sopenharmony_ci	$(call filechk,fwbin)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci# The .o files depend on the binaries directly; the .S files don't.
388c2ecf20Sopenharmony_ci$(addprefix $(obj)/, $(obj-y)): $(obj)/%.gen.o: $(fwdir)/%
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_citargets := $(patsubst $(obj)/%,%, \
418c2ecf20Sopenharmony_ci                                $(shell find $(obj) -name \*.gen.S 2>/dev/null))
42