Makefile.projbuild 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. SECURE_BOOT_SIGNING_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOT_SIGNING_KEY)))
  16. export SECURE_BOOT_SIGNING_KEY # used by bootloader_support component
  17. # Has a matching value in bootloader_support esp_flash_partitions.h
  18. BOOTLOADER_OFFSET := 0x1000
  19. # Custom recursive make for bootloader sub-project
  20. #
  21. # NB: Some variables are cleared in the environment, not
  22. # overriden, because they need to be re-defined in the child
  23. # project.
  24. BOOTLOADER_MAKE= +\
  25. PROJECT_PATH= \
  26. COMPONENT_DIRS= \
  27. $(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/subproject \
  28. V=$(V) \
  29. BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
  30. TEST_COMPONENTS= \
  31. TESTS_ALL=
  32. .PHONY: bootloader-clean bootloader-flash bootloader-list-components bootloader $(BOOTLOADER_BIN)
  33. $(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
  34. $(BOOTLOADER_MAKE) $@
  35. clean: bootloader-clean
  36. bootloader-list-components:
  37. $(BOOTLOADER_MAKE) list-components
  38. ifndef CONFIG_SECURE_BOOT_ENABLED
  39. # If secure boot disabled, bootloader flashing is integrated
  40. # with 'make flash' and no warnings are printed.
  41. bootloader: $(BOOTLOADER_BIN)
  42. @echo $(SEPARATOR)
  43. @echo "Bootloader built. Default flash command is:"
  44. @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $^"
  45. ESPTOOL_ALL_FLASH_ARGS += $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)
  46. bootloader-flash: $(BOOTLOADER_BIN) $(call prereq_if_explicit,erase_flash)
  47. $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
  48. else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
  49. # One time flashing requires user to run esptool.py command themselves,
  50. # and warning is printed about inability to reflash.
  51. #
  52. # The flashing command is deliberately printed without an auto-reset
  53. # step, so the device doesn't immediately reset to flash itself.
  54. bootloader: $(BOOTLOADER_BIN)
  55. @echo $(SEPARATOR)
  56. @echo "Bootloader built. One-time flash command is:"
  57. @echo "$(subst hard_reset,no_reset,$(ESPTOOLPY_WRITE_FLASH)) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
  58. @echo $(SEPARATOR)
  59. @echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
  60. else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
  61. # Reflashable secure bootloader
  62. # generates a digest binary (bootloader + digest)
  63. BOOTLOADER_DIGEST_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
  64. SECURE_BOOTLOADER_KEY := $(BOOTLOADER_BUILD_DIR)/secure-bootloader-key.bin
  65. ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
  66. $(SECURE_BOOTLOADER_KEY): $(SECURE_BOOT_SIGNING_KEY)
  67. $(ESPSECUREPY) digest_private_key -k $< $@
  68. else
  69. $(SECURE_BOOTLOADER_KEY):
  70. @echo "No pre-generated key for a reflashable secure bootloader is available, due to signing configuration."
  71. @echo "To generate one, you can use this command:"
  72. @echo "espsecure.py generate_flash_encryption_key $@"
  73. @echo "then re-run make."
  74. exit 1
  75. endif
  76. bootloader: $(BOOTLOADER_DIGEST_BIN)
  77. @echo $(SEPARATOR)
  78. @echo "Bootloader built and secure digest generated. First time flash command is:"
  79. @echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
  80. @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
  81. @echo $(SEPARATOR)
  82. @echo "To reflash the bootloader after initial flash:"
  83. @echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
  84. @echo $(SEPARATOR)
  85. @echo "* After first boot, only re-flashes of this kind (with same key) will be accepted."
  86. @echo "* Not recommended to re-use the same secure boot keyfile on multiple production devices."
  87. $(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY)
  88. @echo "DIGEST $(notdir $@)"
  89. $(Q) $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
  90. else
  91. bootloader:
  92. @echo "Invalid bootloader target: bad sdkconfig?"
  93. @exit 1
  94. endif
  95. ifndef CONFIG_SECURE_BOOT_ENABLED
  96. # don't build bootloader by default is secure boot is enabled
  97. all_binaries: $(BOOTLOADER_BIN)
  98. endif
  99. bootloader-clean:
  100. $(BOOTLOADER_MAKE) app-clean
  101. rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN)