[COMMON] support exynos in-kernel firmware
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / firmware / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 #
3 # kbuild file for firmware/
4 #
5
6 CONFIG_EXTRA_FIRMWARE_DIR="firmware"
7
8 # Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
9 # leading /, it's relative to $(srctree).
10 fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
11 fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
12
13 fw-external-y := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))
14
15 quiet_cmd_fwbin = MK_FW $@
16 cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)"; \
17 FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst \
18 firmware/%.gen.S,%,$@))))"; \
19 ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long); \
20 ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \
21 PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \
22 echo "/* Generated by firmware/Makefile */" > $@;\
23 echo " .section .rodata" >>$@;\
24 echo " .p2align $${ASM_ALIGN}" >>$@;\
25 echo "_fw_$${FWSTR}_bin:" >>$@;\
26 echo " .incbin \"$(2)\"" >>$@;\
27 echo "_fw_end:" >>$@;\
28 echo " .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\
29 echo " .p2align $${ASM_ALIGN}" >>$@;\
30 echo "_fw_$${FWSTR}_name:" >>$@;\
31 echo " .string \"$$FWNAME\"" >>$@;\
32 echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\
33 echo " .p2align $${ASM_ALIGN}" >>$@;\
34 echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\
35 echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\
36 echo " $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin" >>$@;
37
38 # One of these files will change, or come into existence, whenever
39 # the configuration changes between 32-bit and 64-bit. The .S files
40 # need to change when that happens.
41 wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
42 include/config/ppc32.h include/config/ppc64.h \
43 include/config/superh32.h include/config/superh64.h \
44 include/config/x86_32.h include/config/x86_64.h \
45 firmware/Makefile)
46
47 $(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps)
48 $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
49
50 # The .o files depend on the binaries directly; the .S files don't.
51 $(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
52
53 # .ihex is used just as a simple way to hold binary files in a source tree
54 # where binaries are frowned upon. They are directly converted with objcopy.
55 $(obj)/%: $(obj)/%.ihex
56 $(call cmd,ihex)
57
58 obj-y += $(patsubst %,%.gen.o, $(fw-external-y))
59
60 ifeq ($(KBUILD_SRC),)
61 # Makefile.build only creates subdirectories for O= builds, but external
62 # firmware might live outside the kernel source tree
63 _dummy := $(foreach d,$(addprefix $(obj)/,$(dir $(fw-external-y))), $(shell [ -d $(d) ] || mkdir -p $(d)))
64 endif
65
66 targets := $(patsubst $(obj)/%,%, \
67 $(shell find $(obj) -name \*.gen.S 2>/dev/null))
68 # Without this, built-in.o won't be created when it's empty, and the
69 # final vmlinux link will fail.
70 obj- := dummy