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