Makefile 2.7 KB

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