component_ulp_common.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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) --version output might be localized, for example the first line could be
  25. # "Ensamblador (GNU Binutils) 2.28.51-esp-20191205 de GNU" instead of
  26. # "GNU assembler (GNU Binutils) 2.28.51-esp-20191205".
  27. ULP_AS_VER := $(shell $(ULP_AS) --version | sed -E -n 's/.+ \(GNU Binutils\) ([a-z0-9\.-]+)( .*)?/\1/gp')
  28. $(info Building ULP app $(ULP_APP_NAME))
  29. $(info ULP assembler version: $(ULP_AS_VER))
  30. ifeq (,$(findstring $(ULP_AS_VER), $(SUPPORTED_ULP_ASSEMBLER_VERSION)))
  31. $(info WARNING: ULP assembler version $(ULP_AS_VER) is not supported.)
  32. $(info Expected to see version: $(SUPPORTED_ULP_ASSEMBLER_VERSION))
  33. $(info Please check ESP-IDF ULP setup instructions and update the toolchain, or proceed at your own risk.)
  34. endif
  35. # Preprocess LD script used to link ULP program
  36. $(ULP_LD_SCRIPT): $(ULP_LD_TEMPLATE)
  37. $(summary) CPP $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  38. $(CC) $(CPPFLAGS) -MT $(ULP_LD_SCRIPT) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
  39. # Generate preprocessed assembly files.
  40. # To inspect these preprocessed files, add a ".PRECIOUS: %.ulp.pS" rule.
  41. %.ulp.pS: $(COMPONENT_PATH)/ulp/%.S
  42. $(summary) CPP $(patsubst $(PWD)/%,%,$<)
  43. $(CC) $(CPPFLAGS) -MT $(patsubst %.ulp.pS,%.ulp.o,$@) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
  44. # Compiled preprocessed files into object files.
  45. %.ulp.o: %.ulp.pS
  46. $(summary) ULP_AS $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  47. $(ULP_AS) -al=$(patsubst %.ulp.o,%.ulp.lst,$@) -o $@ $<
  48. # Link object files and generate map file
  49. $(ULP_ELF): $(ULP_OBJECTS) $(ULP_LD_SCRIPT)
  50. $(summary) ULP_LD $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  51. $(ULP_LD) -o $@ -A elf32-esp32ulp -Map=$(ULP_MAP) -T $(ULP_LD_SCRIPT) $(ULP_OBJECTS)
  52. # Dump the list of global symbols in a convenient format.
  53. $(ULP_SYM): $(ULP_ELF)
  54. $(ULP_NM) -g -f posix $< > $@
  55. # Dump the binary for inclusion into the project
  56. $(COMPONENT_BUILD_DIR)/$(ULP_BIN): $(ULP_ELF)
  57. $(summary) ULP_BIN $(patsubst $(PWD)/%,%,$@)
  58. $(ULP_OBJCOPY) -O binary $< $@
  59. # Left and right side of the rule are the same, but the right side
  60. # is given as an absolute path.
  61. # (Make can not resolve such things automatically)
  62. $(ULP_EXPORTS_HEADER): $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)
  63. # Artificial intermediate target to trigger generation of .h and .ld files.
  64. .INTERMEDIATE: $(COMPONENT_NAME)_ulp_mapgen_intermediate
  65. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)\
  66. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD): $(COMPONENT_NAME)_ulp_mapgen_intermediate
  67. # Convert the symbols list into a header file and linker export script.
  68. $(COMPONENT_NAME)_ulp_mapgen_intermediate: $(ULP_SYM)
  69. $(summary) ULP_MAPGEN $(patsubst $(PWD)/%,%,$(CURDIR))/$<
  70. $(ULP_MAP_GEN) -s $(ULP_SYM) -o $(ULP_EXPORTS_LD:.ld=)
  71. # Building the component separately from the project should result in
  72. # ULP files being built.
  73. build: $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER) \
  74. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD) \
  75. $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
  76. # Objects listed as being dependent on $(ULP_EXPORTS_HEADER) must also
  77. # depend on $(ULP_SYM), to order build steps correctly.
  78. $(ULP_EXP_DEP_OBJECTS) : $(ULP_EXPORTS_HEADER) $(ULP_SYM)
  79. # Finally, set all the variables processed by the build system.
  80. COMPONENT_EXTRA_CLEAN += $(ULP_OBJECTS) \
  81. $(ULP_LD_SCRIPT) \
  82. $(ULP_PREPROCESSED) \
  83. $(ULP_ELF) $(ULP_BIN) \
  84. $(ULP_MAP) $(ULP_SYM) \
  85. $(ULP_EXPORTS_LD) \
  86. $(ULP_EXPORTS_HEADER) \
  87. $(ULP_DEP) \
  88. $(ULP_LISTINGS)
  89. COMPONENT_EMBED_FILES += $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
  90. COMPONENT_ADD_LDFLAGS += -l$(COMPONENT_NAME) -T $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD)
  91. COMPONENT_EXTRA_INCLUDES += $(COMPONENT_BUILD_DIR)