2018-01-12 02:49:13 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
2018-01-19 04:47:49 +00:00
|
|
|
if(NOT SDKCONFIG)
|
2018-02-27 04:45:30 +00:00
|
|
|
message(FATAL_ERROR "Bootloader subproject expects the SDKCONFIG variable to be passed "
|
|
|
|
"in by the parent build process.")
|
2018-01-19 04:47:49 +00:00
|
|
|
endif()
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-06-15 04:59:45 +00:00
|
|
|
if(NOT IDF_PATH)
|
|
|
|
message(FATAL_ERROR "Bootloader subproject expects the IDF_PATH variable to be passed "
|
|
|
|
"in by the parent build process.")
|
|
|
|
endif()
|
|
|
|
|
2018-09-11 01:44:12 +00:00
|
|
|
set(COMPONENTS bootloader esptool_py esp32 partition_table soc bootloader_support log spi_flash micro-ecc soc main)
|
2018-01-12 02:49:13 +00:00
|
|
|
set(BOOTLOADER_BUILD 1)
|
|
|
|
add_definitions(-DBOOTLOADER_BUILD=1)
|
|
|
|
|
2018-03-22 06:27:10 +00:00
|
|
|
set(COMPONENT_REQUIRES_COMMON log esp32 soc)
|
|
|
|
|
2018-06-15 04:59:45 +00:00
|
|
|
include("${IDF_PATH}/tools/cmake/project.cmake")
|
2018-02-15 03:38:58 +00:00
|
|
|
project(bootloader)
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-04-17 23:30:27 +00:00
|
|
|
target_linker_script(bootloader.elf
|
|
|
|
"main/esp32.bootloader.ld"
|
2018-11-11 07:36:10 +00:00
|
|
|
"main/esp32.bootloader.rom.ld"
|
|
|
|
)
|
|
|
|
|
|
|
|
# as cmake won't attach linker args to a header-only library, attach
|
|
|
|
# linker args directly to the bootloader.elf
|
|
|
|
set(ESP32_BOOTLOADER_LINKER_SCRIPTS
|
|
|
|
"../../esp32/ld/esp32.rom.ld"
|
|
|
|
"../../esp32/ld/esp32.rom.spiram_incompatible_fns.ld"
|
|
|
|
"../../esp32/ld/esp32.peripherals.ld")
|
|
|
|
|
2018-04-17 23:30:27 +00:00
|
|
|
target_linker_script(bootloader.elf ${ESP32_BOOTLOADER_LINKER_SCRIPTS})
|
|
|
|
|
2018-02-09 08:09:47 +00:00
|
|
|
target_link_libraries(bootloader.elf gcc)
|
2018-10-19 19:02:55 +00:00
|
|
|
|
|
|
|
set(secure_boot_signing_key ${SECURE_BOOT_SIGNING_KEY})
|
|
|
|
|
|
|
|
string(REPLACE ";" " " espsecurepy "${ESPSECUREPY}")
|
|
|
|
string(REPLACE ";" " " espefusepy "${ESPEFUSEPY}")
|
|
|
|
set(esptoolpy_write_flash "${ESPTOOLPY_WRITE_FLASH_STR}")
|
|
|
|
|
|
|
|
if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
|
|
|
|
if(CONFIG_SECURE_BOOTLOADER_KEY_ENCODING_192BIT)
|
|
|
|
set(key_digest_len 192)
|
|
|
|
else()
|
|
|
|
set(key_digest_len 256)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_filename_component(bootloader_digest_bin
|
|
|
|
"bootloader-reflash-digest.bin"
|
|
|
|
ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}")
|
|
|
|
|
|
|
|
get_filename_component(secure_bootloader_key
|
|
|
|
"secure-bootloader-key-${key_digest_len}.bin"
|
|
|
|
ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}")
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT "${secure_bootloader_key}"
|
|
|
|
COMMAND ${ESPSECUREPY} digest_private_key
|
|
|
|
--keylen "${key_digest_len}"
|
|
|
|
--keyfile "${secure_boot_signing_key}"
|
|
|
|
"${secure_bootloader_key}"
|
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
|
|
|
add_custom_target(gen_secure_bootloader_key ALL DEPENDS "${secure_bootloader_key}")
|
|
|
|
else()
|
|
|
|
if(NOT EXISTS "${secure_bootloader_key}")
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"No pre-generated key for a reflashable secure bootloader is available, "
|
|
|
|
"due to signing configuration."
|
|
|
|
"\nTo generate one, you can use this command:"
|
|
|
|
"\n\t${espsecurepy} generate_flash_encryption_key ${secure_bootloader_key}"
|
|
|
|
"\nIf a signing key is present, then instead use:"
|
|
|
|
"\n\t${ESPSECUREPY} digest_private_key "
|
|
|
|
"--keylen (192/256) --keyfile KEYFILE "
|
|
|
|
"${secure_bootloader_key}")
|
|
|
|
endif()
|
|
|
|
add_custom_target(gen_secure_bootloader_key)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT "${bootloader_digest_bin}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "DIGEST ${bootloader_digest_bin}"
|
|
|
|
COMMAND ${ESPSECUREPY} digest_secure_bootloader --keyfile "${secure_bootloader_key}"
|
|
|
|
-o "${bootloader_digest_bin}" "${CMAKE_BINARY_DIR}/bootloader.bin"
|
|
|
|
DEPENDS gen_secure_bootloader_key "${CMAKE_BINARY_DIR}/bootloader.bin"
|
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
add_custom_target (gen_bootloader_digest_bin ALL DEPENDS "${bootloader_digest_bin}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH)
|
|
|
|
add_custom_command(TARGET bootloader POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"=============================================================================="
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"Bootloader built. Secure boot enabled, so bootloader not flashed automatically."
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"One-time flash command is:"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"\t${esptoolpy_write_flash} ${BOOTLOADER_OFFSET} ${CMAKE_BINARY_DIR}/bootloader.bin"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
|
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
elseif(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
|
|
|
|
add_custom_command(TARGET bootloader POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"=============================================================================="
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"Bootloader built and secure digest generated."
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"Secure boot enabled, so bootloader not flashed automatically."
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"Burn secure boot key to efuse using:"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"\t${espefusepy} burn_key secure_boot ${secure_bootloader_key}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"First time flash command is:"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"\t${esptoolpy_write_flash} ${BOOTLOADER_OFFSET} ${CMAKE_BINARY_DIR}/bootloader.bin"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"=============================================================================="
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"To reflash the bootloader after initial flash:"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"\t${esptoolpy_write_flash} 0x0 ${bootloader_digest_bin}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"=============================================================================="
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"* After first boot, only re-flashes of this kind (with same key) will be accepted."
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"* Not recommended to re-use the same secure boot keyfile on multiple production devices."
|
|
|
|
DEPENDS gen_secure_bootloader_key gen_bootloader_digest_bin
|
|
|
|
VERBATIM)
|
|
|
|
endif()
|