Makefile 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. firmware-y := $(fw-external-y) $(fw-shipped-y)
  10. firmware-dirs := $(sort $(patsubst %,$(objtree)/$(obj)/%/,$(dir $(firmware-y) $(fw-shipped-))))
  11. quiet_cmd_mkdir = MKDIR $(patsubst $(objtree)/%,%,$@)
  12. cmd_mkdir = mkdir -p $@
  13. quiet_cmd_ihex = IHEX $@
  14. cmd_ihex = $(OBJCOPY) -Iihex -Obinary $< $@
  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. # One of these files will change, or come into existence, whenever
  38. # the configuration changes between 32-bit and 64-bit. The .S files
  39. # need to change when that happens.
  40. wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
  41. include/config/ppc32.h include/config/ppc64.h \
  42. include/config/superh32.h include/config/superh64.h \
  43. include/config/x86_32.h include/config/x86_64.h)
  44. # Workaround for make < 3.81, where .SECONDEXPANSION doesn't work.
  45. # It'll end up depending on these targets, so make them a PHONY rule which
  46. # depends on _all_ the directories in $(firmware-dirs), and it'll work out OK.
  47. PHONY += $(objtree)/$$(%) $(objtree)/$(obj)/$$(%)
  48. $(objtree)/$$(%) $(objtree)/$(obj)/$$(%): $(firmware-dirs)
  49. @true
  50. # For the $$(dir %) trick, where we need % to be expanded first.
  51. .SECONDEXPANSION:
  52. $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) \
  53. | $(objtree)/$$(dir %)
  54. $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
  55. $(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
  56. include/config/builtin/firmware/dir.h | $(objtree)/$$(dir %)
  57. $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
  58. # The .o files depend on the binaries directly; the .S files don't.
  59. $(patsubst %,$(obj)/%.gen.o, $(fw-shipped-y)): %.gen.o: %
  60. $(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
  61. $(obj)/%: $(obj)/%.ihex | $(objtree)/$(obj)/$$(dir %)
  62. $(call cmd,ihex)
  63. $(firmware-dirs):
  64. $(call cmd,mkdir)
  65. obj-y := $(patsubst %,%.gen.o, $(firmware-y))
  66. # Remove .S files and binaries created from ihex
  67. # (during 'make clean' .config isn't included so they're all in $(fw-shipped-))
  68. targets := $(fw-shipped-) $(patsubst $(obj)/%,%, \
  69. $(shell find $(obj) -name \*.gen.S 2>/dev/null))
  70. # Without this, built-in.o won't be created when it's empty, and the
  71. # final vmlinux link will fail.
  72. obj-n := dummy