]> granicus.if.org Git - esp-idf/blob - components/bootloader/Makefile.projbuild
Flash encryption: Support enabling flash encryption in bootloader, app support
[esp-idf] / components / bootloader / Makefile.projbuild
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
13 BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
14 BOOTLOADER_BUILD_DIR=$(abspath $(BUILD_DIR_BASE)/bootloader)
15 BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
16
17 # signing key path is resolved relative to the project directory
18 SECURE_BOOT_SIGNING_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOT_SIGNING_KEY)))
19 export SECURE_BOOT_SIGNING_KEY  # used by bootloader_support component
20
21 # Has a matching value in bootloader_support esp_flash_partitions.h
22 BOOTLOADER_OFFSET := 0x1000
23
24 # Custom recursive make for bootloader sub-project
25 BOOTLOADER_MAKE=+$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src \
26         V=$(V) BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) TEST_COMPONENTS=
27
28 .PHONY: bootloader-clean bootloader-flash bootloader $(BOOTLOADER_BIN)
29
30 $(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
31         $(BOOTLOADER_MAKE) $@
32
33 clean: bootloader-clean
34
35 ifdef CONFIG_SECURE_BOOTLOADER_DISABLED
36 # If secure boot disabled, bootloader flashing is integrated
37 # with 'make flash' and no warnings are printed.
38
39 bootloader: $(BOOTLOADER_BIN)
40         @echo $(SEPARATOR)
41         @echo "Bootloader built. Default flash command is:"
42         @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $^"
43
44 ESPTOOL_ALL_FLASH_ARGS += $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)
45
46 bootloader-flash: $(BOOTLOADER_BIN)
47         $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
48
49 else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
50
51 # One time flashing requires user to run esptool.py command themselves,
52 # and warning is printed about inability to reflash.
53
54 bootloader: $(BOOTLOADER_BIN)
55         @echo $(SEPARATOR)
56         @echo "Bootloader built. One-time flash command is:"
57         @echo "$(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
61 else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
62 # Reflashable secure bootloader
63 # generates a digest binary (bootloader + digest)
64
65 BOOTLOADER_DIGEST_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
66 SECURE_BOOTLOADER_KEY := $(BOOTLOADER_BUILD_DIR)/secure-bootloader-key.bin
67
68 $(SECURE_BOOTLOADER_KEY): $(SECURE_BOOT_SIGNING_KEY)
69         $(Q) $(ESPSECUREPY) digest_private_key -k $< $@
70
71 bootloader: $(BOOTLOADER_DIGEST_BIN)
72         @echo $(SEPARATOR)
73         @echo "Bootloader built and secure digest generated. First time flash command is:"
74         @echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
75         @echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
76         @echo $(SEPARATOR)
77         @echo "To reflash the bootloader after initial flash:"
78         @echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
79         @echo $(SEPARATOR)
80         @echo "* After first boot, only re-flashes of this kind (with same key) will be accepted."
81         @echo "* Not recommended to re-use the same secure boot keyfile on multiple production devices."
82
83 $(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY)
84         @echo "DIGEST $(notdir $@)"
85         $(Q) $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
86
87 else
88 bootloader:
89         @echo "Invalid bootloader target: bad sdkconfig?"
90         @exit 1
91 endif
92
93 all_binaries: $(BOOTLOADER_BIN)
94
95 bootloader-clean:
96         $(BOOTLOADER_MAKE) app-clean
97         rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN)
98
99 $(BOOTLOADER_BUILD_DIR):
100         mkdir -p $@
101
102 else
103 CFLAGS += -D BOOTLOADER_BUILD=1 -I $(IDF_PATH)/components/esp32/include
104
105 endif