Makefile.projbuild 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #
  2. # Bootloader component
  3. #
  4. # The bootloader is not a real component that gets linked into the project.
  5. # Instead it is an entire standalone project ( in src/) that gets built in
  6. # the upper projects build directory. This Makefile.projbuild provides the
  7. # glue to build the bootloader project from the original project. It
  8. # basically runs Make in the src/ directory but it needs to zero some variables
  9. # the ESP-IDF project.mk makefile exports first, to not let them interfere.
  10. #
  11. ifndef IS_BOOTLOADER_BUILD
  12. BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
  13. BOOTLOADER_BUILD_DIR=$(abspath $(BUILD_DIR_BASE)/bootloader)
  14. BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
  15. # signing key path is resolved relative to the project directory
  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. # Custom recursive make for bootloader sub-project
  19. BOOTLOADER_MAKE=+$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src \
  20. V=$(V) BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) TEST_COMPONENTS=
  21. .PHONY: bootloader-clean bootloader-flash bootloader $(BOOTLOADER_BIN)
  22. $(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
  23. $(BOOTLOADER_MAKE) $@
  24. clean: bootloader-clean
  25. ifdef CONFIG_SECURE_BOOTLOADER_DISABLED
  26. # If secure boot disabled, bootloader flashing is integrated
  27. # with 'make flash' and no warnings are printed.
  28. bootloader: $(BOOTLOADER_BIN)
  29. @echo $(SEPARATOR)
  30. @echo "Bootloader built. Default flash command is:"
  31. @echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^"
  32. ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN)
  33. bootloader-flash: $(BOOTLOADER_BIN)
  34. $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
  35. else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
  36. #### TEMPORARILY DISABLE THIS OPTION
  37. ifneq ("$(IDF_INSECURE_SECURE_BOOT)","1")
  38. bootloader:
  39. @echo "Secure boot features are not yet mature, so the current secure bootloader will not properly secure the device"
  40. @echo "If you flash this bootloader, you will be left with an non-updateable bootloader that is missing features."
  41. @echo "If you really want to do this, set the environment variable IDF_INSECURE_SECURE_BOOT=1 and rerun make."
  42. exit 1
  43. else
  44. # One time flashing requires user to run esptool.py command themselves,
  45. # and warning is printed about inability to reflash.
  46. bootloader: $(BOOTLOADER_BIN)
  47. @echo $(SEPARATOR)
  48. @echo "Bootloader built. One-time flash command is:"
  49. @echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
  50. @echo $(SEPARATOR)
  51. @echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
  52. endif # IDF_INSECURE_SECURE_BOOT
  53. else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
  54. # Reflashable secure bootloader
  55. # generates a digest binary (bootloader + digest)
  56. #### TEMPORARILY DISABLE THIS OPTION
  57. ifneq ("$(IDF_INSECURE_SECURE_BOOT)","1")
  58. bootloader:
  59. @echo "Secure boot features are not yet mature, so the current secure bootloader will not properly secure the device."
  60. @echo "If using this feature, expect to reflash the bootloader at least one more time."
  61. @echo "If you really want to do this, set the environment variable IDF_INSECURE_SECURE_BOOT=1 and rerun make."
  62. exit 1
  63. else
  64. BOOTLOADER_DIGEST_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
  65. SECURE_BOOTLOADER_KEY := $(BOOTLOADER_BUILD_DIR)/secure-bootloader-key.bin
  66. $(SECURE_BOOTLOADER_KEY): $(SECURE_BOOT_SIGNING_KEY)
  67. $(Q) $(ESPSECUREPY) digest_private_key -k $< $@
  68. bootloader: $(BOOTLOADER_DIGEST_BIN)
  69. @echo $(SEPARATOR)
  70. @echo "Bootloader built and secure digest generated. First time flash command is:"
  71. @echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
  72. @echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
  73. @echo $(SEPARATOR)
  74. @echo "To reflash the bootloader after initial flash:"
  75. @echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
  76. @echo $(SEPARATOR)
  77. @echo "* After first boot, only re-flashes of this kind (with same key) will be accepted."
  78. @echo "* Not recommended to re-use the same secure boot keyfile on multiple production devices."
  79. $(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY)
  80. @echo "DIGEST $(notdir $@)"
  81. $(Q) $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
  82. endif # IDF_INSECURE_SECURE_BOOT
  83. else
  84. bootloader:
  85. @echo "Invalid bootloader target: bad sdkconfig?"
  86. @exit 1
  87. endif
  88. all_binaries: $(BOOTLOADER_BIN)
  89. bootloader-clean:
  90. $(BOOTLOADER_MAKE) app-clean
  91. rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN)
  92. $(BOOTLOADER_BUILD_DIR):
  93. mkdir -p $@
  94. else
  95. CFLAGS += -D BOOTLOADER_BUILD=1 -I $(IDF_PATH)/components/esp32/include
  96. endif