Makefile.projbuild 4.2 KB

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