component_ulp_common.mk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Extra make rules for components containing ULP coprocessor code.
  2. #
  3. # ULP program(s) gets built and linked into the application.
  4. # Steps taken here are explained in docs/ulp.rst
  5. # Define names for files generated at different stages
  6. ULP_ELF := $(ULP_APP_NAME).elf
  7. ULP_MAP := $(ULP_ELF:.elf=.map)
  8. ULP_SYM := $(ULP_ELF:.elf=.sym)
  9. ULP_BIN := $(ULP_ELF:.elf=.bin)
  10. ULP_EXPORTS_LD := $(ULP_ELF:.elf=.ld)
  11. ULP_EXPORTS_HEADER := $(ULP_ELF:.elf=.h)
  12. ULP_LD_SCRIPT := $(ULP_ELF:.elf=.common.ld)
  13. ULP_OBJECTS := $(notdir $(ULP_S_SOURCES:.S=.ulp.o))
  14. ULP_DEP := $(notdir $(ULP_S_SOURCES:.S=.ulp.d)) $(ULP_LD_SCRIPT:.ld=.d)
  15. ULP_PREPROCESSED := $(notdir $(ULP_S_SOURCES:.S=.ulp.pS))
  16. ULP_LISTINGS := $(notdir $(ULP_S_SOURCES:.S=.ulp.lst))
  17. ULP_PREPROCESSOR_ARGS := \
  18. $(addprefix -I ,$(COMPONENT_INCLUDES)) \
  19. $(addprefix -I ,$(COMPONENT_EXTRA_INCLUDES)) \
  20. -I$(COMPONENT_PATH) -D__ASSEMBLER__
  21. -include $(ULP_DEP)
  22. # Check the assembler version
  23. include $(IDF_PATH)/components/ulp/toolchain_ulp_version.mk
  24. ULP_AS_VER := $(shell $(ULP_AS) --version | sed -E -n 's|GNU assembler \(GNU Binutils\) ([a-z0-9\.-]+)|\1|gp')
  25. $(info Building ULP app $(ULP_APP_NAME))
  26. $(info ULP assembler version: $(ULP_AS_VER))
  27. ifeq (,$(findstring $(ULP_AS_VER), $(SUPPORTED_ULP_ASSEMBLER_VERSION)))
  28. $(info WARNING: ULP assembler version $(ULP_AS_VER) is not supported.)
  29. $(info Expected to see version: $(SUPPORTED_ULP_ASSEMBLER_VERSION))
  30. $(info Please check ESP-IDF ULP setup instructions and update the toolchain, or proceed at your own risk.)
  31. endif
  32. # Preprocess LD script used to link ULP program
  33. $(ULP_LD_SCRIPT): $(ULP_LD_TEMPLATE)
  34. $(summary) CPP $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  35. $(CC) $(CPPFLAGS) -MT $(ULP_LD_SCRIPT) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
  36. # Generate preprocessed assembly files.
  37. # To inspect these preprocessed files, add a ".PRECIOUS: %.ulp.pS" rule.
  38. %.ulp.pS: $(COMPONENT_PATH)/ulp/%.S
  39. $(summary) CPP $(patsubst $(PWD)/%,%,$<)
  40. $(CC) $(CPPFLAGS) -MT $(patsubst %.ulp.pS,%.ulp.o,$@) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
  41. # Compiled preprocessed files into object files.
  42. %.ulp.o: %.ulp.pS
  43. $(summary) ULP_AS $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  44. $(ULP_AS) -al=$(patsubst %.ulp.o,%.ulp.lst,$@) -o $@ $<
  45. # Link object files and generate map file
  46. $(ULP_ELF): $(ULP_OBJECTS) $(ULP_LD_SCRIPT)
  47. $(summary) ULP_LD $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  48. $(ULP_LD) -o $@ -A elf32-esp32ulp -Map=$(ULP_MAP) -T $(ULP_LD_SCRIPT) $(ULP_OBJECTS)
  49. # Dump the list of global symbols in a convenient format.
  50. $(ULP_SYM): $(ULP_ELF)
  51. $(ULP_NM) -g -f posix $< > $@
  52. # Dump the binary for inclusion into the project
  53. $(COMPONENT_BUILD_DIR)/$(ULP_BIN): $(ULP_ELF)
  54. $(summary) ULP_BIN $(patsubst $(PWD)/%,%,$@)
  55. $(ULP_OBJCOPY) -O binary $< $@
  56. # Left and right side of the rule are the same, but the right side
  57. # is given as an absolute path.
  58. # (Make can not resolve such things automatically)
  59. $(ULP_EXPORTS_HEADER): $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)
  60. # Artificial intermediate target to trigger generation of .h and .ld files.
  61. .INTERMEDIATE: $(COMPONENT_NAME)_ulp_mapgen_intermediate
  62. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)\
  63. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD): $(COMPONENT_NAME)_ulp_mapgen_intermediate
  64. # Convert the symbols list into a header file and linker export script.
  65. $(COMPONENT_NAME)_ulp_mapgen_intermediate: $(ULP_SYM)
  66. $(summary) ULP_MAPGEN $(patsubst $(PWD)/%,%,$(CURDIR))/$<
  67. $(ULP_MAP_GEN) -s $(ULP_SYM) -o $(ULP_EXPORTS_LD:.ld=)
  68. # Building the component separately from the project should result in
  69. # ULP files being built.
  70. build: $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER) \
  71. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD) \
  72. $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
  73. # Objects listed as being dependent on $(ULP_EXPORTS_HEADER) must also
  74. # depend on $(ULP_SYM), to order build steps correctly.
  75. $(ULP_EXP_DEP_OBJECTS) : $(ULP_EXPORTS_HEADER) $(ULP_SYM)
  76. # Finally, set all the variables processed by the build system.
  77. COMPONENT_EXTRA_CLEAN += $(ULP_OBJECTS) \
  78. $(ULP_LD_SCRIPT) \
  79. $(ULP_PREPROCESSED) \
  80. $(ULP_ELF) $(ULP_BIN) \
  81. $(ULP_MAP) $(ULP_SYM) \
  82. $(ULP_EXPORTS_LD) \
  83. $(ULP_EXPORTS_HEADER) \
  84. $(ULP_DEP) \
  85. $(ULP_LISTINGS)
  86. COMPONENT_EMBED_FILES += $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
  87. COMPONENT_ADD_LDFLAGS += -l$(COMPONENT_NAME) -T $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD)
  88. COMPONENT_EXTRA_INCLUDES += $(COMPONENT_BUILD_DIR)