Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #
  2. # kbuild file for firmware/
  3. #
  4. # Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
  5. # leading /, it's relative to $(srctree).
  6. fwdir := $(subst ",,$(CONFIG_EXTRA_FIRMWARE_DIR))
  7. fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
  8. fw-external-y := $(subst ",,$(CONFIG_EXTRA_FIRMWARE))
  9. # If CONFIG_FIRMWARE_IN_KERNEL is not set, then don't include any firmware
  10. ifneq ($(CONFIG_FIRMWARE_IN_KERNEL),y)
  11. fw-shipped-y :=
  12. endif
  13. firmware-y := $(fw-external-y) $(fw-shipped-y)
  14. firmware-dirs := $(sort $(patsubst %,$(objtree)/$(obj)/%/,$(dir $(firmware-y) $(fw-shipped-))))
  15. quiet_cmd_mkdir = MKDIR $(patsubst $(objtree)/%,%,$@)
  16. cmd_mkdir = mkdir -p $@
  17. quiet_cmd_ihex = IHEX $@
  18. cmd_ihex = $(OBJCOPY) -Iihex -Obinary $< $@
  19. quiet_cmd_fwbin = MK_FW $@
  20. cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)"; \
  21. FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst \
  22. firmware/%.gen.S,%,$@))))"; \
  23. ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long); \
  24. ASM_ALIGN=$(if $(CONFIG_64BIT),3,2); \
  25. PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \
  26. echo "/* Generated by firmware/Makefile */" > $@;\
  27. echo " .section .rodata" >>$@;\
  28. echo " .p2align $${ASM_ALIGN}" >>$@;\
  29. echo "_fw_$${FWSTR}_bin:" >>$@;\
  30. echo " .incbin \"$(2)\"" >>$@;\
  31. echo "_fw_end:" >>$@;\
  32. echo " .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\
  33. echo " .p2align $${ASM_ALIGN}" >>$@;\
  34. echo "_fw_$${FWSTR}_name:" >>$@;\
  35. echo " .string \"$$FWNAME\"" >>$@;\
  36. echo " .section .builtin_fw,\"a\",$${PROGBITS}" >>$@;\
  37. echo " .p2align $${ASM_ALIGN}" >>$@;\
  38. echo " $${ASM_WORD} _fw_$${FWSTR}_name" >>$@;\
  39. echo " $${ASM_WORD} _fw_$${FWSTR}_bin" >>$@;\
  40. echo " $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin" >>$@;
  41. # One of these files will change, or come into existence, whenever
  42. # the configuration changes between 32-bit and 64-bit. The .S files
  43. # need to change when that happens.
  44. wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
  45. include/config/ppc32.h include/config/ppc64.h \
  46. include/config/superh32.h include/config/superh64.h \
  47. include/config/x86_32.h include/config/x86_64.h)
  48. # Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
  49. # It'll end up depending on these targets, so make them a PHONY rule which
  50. # depends on _all_ the directories in $(firmware-dirs), and it'll work out OK.
  51. PHONY += $(objtree)/$$(%) $(objtree)/$(obj)/$$(%)
  52. $(objtree)/$$(%) $(objtree)/$(obj)/$$(%): $(firmware-dirs)
  53. @true
  54. # For the $$(dir %) trick, where we need % to be expanded first.
  55. .SECONDEXPANSION:
  56. $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) \
  57. | $(objtree)/$$(dir %)
  58. $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
  59. $(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
  60. include/config/builtin/firmware/dir.h | $(objtree)/$$(dir %)
  61. $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
  62. # The .o files depend on the binaries directly; the .S files don't.
  63. $(patsubst %,$(obj)/%.gen.o, $(fw-shipped-y)): %.gen.o: %
  64. $(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
  65. $(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
  66. $(call cmd,ihex)
  67. $(firmware-dirs):
  68. $(call cmd,mkdir)
  69. obj-y := $(patsubst %,%.gen.o, $(firmware-y))
  70. # Remove .S files and binaries created from ihex
  71. # (during 'make clean' .config isn't included so they're all in $(fw-shipped-))
  72. targets := $(fw-shipped-) $(patsubst $(obj)/%,%, \
  73. $(shell find $(obj) -name \*.gen.S 2>/dev/null))
  74. # Without this, built-in.o won't be created when it's empty, and the
  75. # final vmlinux link will fail.
  76. obj-n := dummy