Makefile.projbuild 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # Bootloader component (top-level project parts)
  2. #
  3. # The bootloader is not a real component that gets linked into the project.
  4. # Instead it is an entire standalone project (in subproject/) that gets
  5. # built in the upper project's build directory. This Makefile.projbuild provides
  6. # the glue to build the bootloader project from the original project. It
  7. # basically runs Make in the subproject/ directory but it needs to
  8. # zero some variables the ESP-IDF project.mk makefile exports first, to not
  9. # let them interfere.
  10. #
  11. BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
  12. BOOTLOADER_BUILD_DIR=$(abspath $(BUILD_DIR_BASE)/bootloader)
  13. BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
  14. # signing key path is resolved relative to the project directory
  15. CONFIG_SECURE_BOOT_SIGNING_KEY ?=
  16. SECURE_BOOT_SIGNING_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOT_SIGNING_KEY)))
  17. export SECURE_BOOT_SIGNING_KEY # used by bootloader_support component
  18. # Has a matching value in bootloader_support esp_flash_partitions.h
  19. BOOTLOADER_OFFSET := 0x1000
  20. # Custom recursive make for bootloader sub-project
  21. #
  22. # NB: Some variables are cleared in the environment, not
  23. # overriden, because they need to be re-defined in the child
  24. # project.
  25. BOOTLOADER_MAKE= +\
  26. PROJECT_PATH= \
  27. COMPONENT_DIRS= \
  28. $(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/subproject \
  29. V=$(V) \
  30. BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
  31. TEST_COMPONENTS= \
  32. TESTS_ALL= \
  33. EXCLUDE_COMPONENTS=
  34. .PHONY: bootloader-clean bootloader-flash bootloader-list-components bootloader $(BOOTLOADER_BIN)
  35. $(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
  36. $(BOOTLOADER_MAKE) $@
  37. clean: bootloader-clean
  38. bootloader-list-components:
  39. $(BOOTLOADER_MAKE) list-components
  40. ifndef CONFIG_SECURE_BOOT_ENABLED
  41. # If secure boot disabled, bootloader flashing is integrated
  42. # with 'make flash' and no warnings are printed.
  43. bootloader: $(BOOTLOADER_BIN) | check_python_dependencies
  44. @echo $(SEPARATOR)
  45. @echo "Bootloader built. Default flash command is:"
  46. @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $^"
  47. ESPTOOL_ALL_FLASH_ARGS += $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)
  48. bootloader-flash: $(BOOTLOADER_BIN) $(call prereq_if_explicit,erase_flash) | check_python_dependencies
  49. $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
  50. else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
  51. # One time flashing requires user to run esptool.py command themselves,
  52. # and warning is printed about inability to reflash.
  53. #
  54. # The flashing command is deliberately printed without an auto-reset
  55. # step, so the device doesn't immediately reset to flash itself.
  56. bootloader: $(BOOTLOADER_BIN) | check_python_dependencies
  57. @echo $(SEPARATOR)
  58. @echo "Bootloader built. One-time flash command is:"
  59. @echo "$(subst hard_reset,no_reset,$(ESPTOOLPY_WRITE_FLASH)) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
  60. @echo $(SEPARATOR)
  61. @echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
  62. else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
  63. # Reflashable secure bootloader
  64. # generates a digest binary (bootloader + digest)
  65. ifdef CONFIG_SECURE_BOOTLOADER_KEY_ENCODING_192BIT
  66. KEY_DIGEST_LEN=192
  67. else
  68. KEY_DIGEST_LEN=256
  69. endif
  70. BOOTLOADER_DIGEST_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
  71. SECURE_BOOTLOADER_KEY := $(BOOTLOADER_BUILD_DIR)/secure-bootloader-key-$(KEY_DIGEST_LEN).bin
  72. ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
  73. $(SECURE_BOOTLOADER_KEY): $(SECURE_BOOT_SIGNING_KEY) | check_python_dependencies
  74. $(ESPSECUREPY) digest_private_key --keylen $(KEY_DIGEST_LEN) -k $< $@
  75. else
  76. $(SECURE_BOOTLOADER_KEY):
  77. @echo "No pre-generated key for a reflashable secure bootloader is available, due to signing configuration."
  78. @echo "To generate one, you can use this command:"
  79. @echo "espsecure.py generate_flash_encryption_key $@"
  80. @echo "then re-run make."
  81. exit 1
  82. endif
  83. bootloader: $(BOOTLOADER_DIGEST_BIN)
  84. @echo $(SEPARATOR)
  85. @echo "Bootloader built and secure digest generated. First time flash command is:"
  86. @echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
  87. @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
  88. @echo $(SEPARATOR)
  89. @echo "To reflash the bootloader after initial flash:"
  90. @echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
  91. @echo $(SEPARATOR)
  92. @echo "* After first boot, only re-flashes of this kind (with same key) will be accepted."
  93. @echo "* Not recommended to re-use the same secure boot keyfile on multiple production devices."
  94. $(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY) | check_python_dependencies
  95. @echo "DIGEST $(notdir $@)"
  96. $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
  97. else # CONFIG_SECURE_BOOT_ENABLED && !CONFIG_SECURE_BOOTLOADER_REFLASHABLE && !CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
  98. bootloader:
  99. @echo "Invalid bootloader target: bad sdkconfig?"
  100. @exit 1
  101. endif
  102. ifndef CONFIG_SECURE_BOOT_ENABLED
  103. # don't build bootloader by default if secure boot is enabled
  104. all_binaries: $(BOOTLOADER_BIN)
  105. endif
  106. bootloader-clean: $(SDKCONFIG_MAKEFILE)
  107. $(BOOTLOADER_MAKE) app-clean
  108. ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
  109. rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN)
  110. endif