1 # SPDX-License-Identifier: GPL-2.0
3 # kbuild file for firmware/
6 CONFIG_EXTRA_FIRMWARE_DIR
="firmware"
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
))
13 fw-external-y
:= $(subst $(quote
),,$(CONFIG_EXTRA_FIRMWARE
))
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" >>$@
;
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 \
47 $(patsubst %,$(obj
)/%.gen.S
, $(fw-external-y
)): %: $(wordsize_deps
)
48 $(call cmd
,fwbin
,$(fwabs
)/$(patsubst $(obj
)/%.gen.S
,%,$@
))
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
)/%
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
58 obj-y
+= $(patsubst %,%.gen.o
, $(fw-external-y
))
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
)))
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.