Makefile.projbuild 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #
  2. # Partition table
  3. #
  4. # The partition table is not a real component that gets linked into
  5. # the project. Instead, it is a standalone project to generate
  6. # the partition table binary as part of the build process. This
  7. # binary is then added to the list of files for esptool.py to flash.
  8. #
  9. .PHONY: partition_table partition_table-flash partition_table-clean partition_table_get_info
  10. PARTITION_MD5_OPT :=
  11. ifndef CONFIG_PARTITION_TABLE_MD5
  12. PARTITION_MD5_OPT := "--disable-md5sum"
  13. endif
  14. PARTITION_FLASHSIZE_OPT :=
  15. ifneq ("$(CONFIG_ESPTOOLPY_FLASHSIZE)", "")
  16. PARTITION_FLASHSIZE_OPT := --flash-size $(CONFIG_ESPTOOLPY_FLASHSIZE)
  17. endif
  18. PARTITION_SECURE_OPT :=
  19. ifdef CONFIG_SECURE_BOOT
  20. ifndef CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION
  21. PARTITION_SECURE_OPT += --secure
  22. endif
  23. endif
  24. # Address of partition table
  25. PARTITION_TABLE_OFFSET := $(CONFIG_PARTITION_TABLE_OFFSET)
  26. PARTITION_TABLE_OFFSET_ARG := --offset $(PARTITION_TABLE_OFFSET)
  27. GEN_ESP32PART := $(PYTHON) $(COMPONENT_PATH)/gen_esp32part.py -q $(PARTITION_MD5_OPT) $(PARTITION_FLASHSIZE_OPT) $(PARTITION_TABLE_OFFSET_ARG) $(PARTITION_SECURE_OPT)
  28. GET_PART_INFO := $(COMPONENT_PATH)/parttool.py -q
  29. # if CONFIG_PARTITION_TABLE_FILENAME is unset, means we haven't re-generated config yet...
  30. ifneq ("$(CONFIG_PARTITION_TABLE_FILENAME)","")
  31. ifndef PARTITION_TABLE_CSV_PATH
  32. # Path to partition CSV file is relative to project path for custom
  33. # partition CSV files, but relative to component dir otherwise.
  34. PARTITION_TABLE_ROOT := $(call dequote,$(if $(CONFIG_PARTITION_TABLE_CUSTOM),$(PROJECT_PATH),$(COMPONENT_PATH)))
  35. PARTITION_TABLE_CSV_PATH := $(call dequote,$(abspath $(PARTITION_TABLE_ROOT)/$(call dequote,$(CONFIG_PARTITION_TABLE_FILENAME))))
  36. endif
  37. PARTITION_TABLE_CSV_NAME := $(notdir $(PARTITION_TABLE_CSV_PATH))
  38. PARTITION_TABLE_BIN := $(BUILD_DIR_BASE)/$(PARTITION_TABLE_CSV_NAME:.csv=.bin)
  39. ifdef CONFIG_SECURE_BOOT_V1_ENABLED
  40. ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
  41. PARTITION_TABLE_BIN_UNSIGNED := $(PARTITION_TABLE_BIN:.bin=-unsigned.bin)
  42. # add an extra signing step for secure partition table
  43. $(PARTITION_TABLE_BIN): $(PARTITION_TABLE_BIN_UNSIGNED) $(SDKCONFIG_MAKEFILE) $(SECURE_BOOT_SIGNING_KEY)
  44. $(ESPSECUREPY) sign_data --version 1 --keyfile $(SECURE_BOOT_SIGNING_KEY) -o $@ $<
  45. else
  46. # secure bootloader disabled, both files are the same
  47. PARTITION_TABLE_BIN_UNSIGNED := $(PARTITION_TABLE_BIN)
  48. endif
  49. else
  50. # secure bootloader disabled, both files are the same
  51. PARTITION_TABLE_BIN_UNSIGNED := $(PARTITION_TABLE_BIN)
  52. endif
  53. $(PARTITION_TABLE_BIN_UNSIGNED): $(PARTITION_TABLE_CSV_PATH) $(SDKCONFIG_MAKEFILE) | check_python_dependencies
  54. @echo "Building partitions from $(PARTITION_TABLE_CSV_PATH)..."
  55. $(GEN_ESP32PART) $< $@
  56. all_binaries: $(PARTITION_TABLE_BIN) partition_table_get_info check_table_contents
  57. partition_table_get_info: $(PARTITION_TABLE_BIN)
  58. $(eval PHY_DATA_OFFSET:=$(shell $(GET_PART_INFO) --partition-table-file $(PARTITION_TABLE_BIN) \
  59. --partition-table-offset $(PARTITION_TABLE_OFFSET) \
  60. get_partition_info --partition-type data --partition-subtype phy --info offset))
  61. $(eval APP_OFFSET:=$(shell $(GET_PART_INFO) --partition-table-file $(PARTITION_TABLE_BIN) \
  62. --partition-table-offset $(PARTITION_TABLE_OFFSET) \
  63. get_partition_info --partition-boot-default --info offset))
  64. $(eval OTA_DATA_OFFSET:=$(shell $(GET_PART_INFO) --partition-table-file $(PARTITION_TABLE_BIN) \
  65. --partition-table-offset $(PARTITION_TABLE_OFFSET) \
  66. get_partition_info --partition-type data --partition-subtype ota --info offset))
  67. $(eval OTA_DATA_SIZE:=$(shell $(GET_PART_INFO) --partition-table-file $(PARTITION_TABLE_BIN) \
  68. --partition-table-offset $(PARTITION_TABLE_OFFSET) \
  69. get_partition_info --partition-type data --partition-subtype ota --info size))
  70. $(eval FACTORY_OFFSET:=$(shell $(GET_PART_INFO) --partition-table-file $(PARTITION_TABLE_BIN) \
  71. --partition-table-offset $(PARTITION_TABLE_OFFSET) \
  72. get_partition_info --partition-type app --partition-subtype factory --info offset))
  73. export APP_OFFSET
  74. export PHY_DATA_OFFSET
  75. export OTA_DATA_OFFSET
  76. export OTA_DATA_SIZE
  77. # If anti-rollback option is set then factory partition should not be in Partition Table.
  78. # In this case, should be used the partition table with two ota app without the factory.
  79. check_table_contents: partition_table_get_info
  80. @echo $(if $(CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK), $(if $(FACTORY_OFFSET), $(error "ERROR: Anti-rollback option is enabled. Partition table should consist of two ota app without factory partition."), ""), "")
  81. PARTITION_TABLE_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN)
  82. ESPTOOL_ALL_FLASH_ARGS += $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN)
  83. UF2_ADD_BINARIES += $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN)
  84. partition_table: $(PARTITION_TABLE_BIN) partition_table_get_info | check_python_dependencies
  85. @echo "Partition table binary generated. Contents:"
  86. @echo $(SEPARATOR)
  87. $(GEN_ESP32PART) $<
  88. @echo $(SEPARATOR)
  89. @echo "Partition flashing command:"
  90. @echo "$(PARTITION_TABLE_FLASH_CMD)"
  91. partition_table-flash: $(PARTITION_TABLE_BIN) | check_python_dependencies
  92. @echo "Flashing partition table..."
  93. $(PARTITION_TABLE_FLASH_CMD)
  94. partition_table-clean:
  95. rm -f $(PARTITION_TABLE_BIN)
  96. clean: partition_table-clean
  97. endif