@@ -393,57 +393,59 @@ if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")
393393endif ()
394394
395395if (CONFIG_BOOT_ENCRYPTION_KEY_FILE AND NOT CONFIG_BOOT_ENCRYPTION_KEY_FILE STREQUAL "" )
396- # CONF_FILE points to the KConfig configuration files of the bootloader.
397- unset (CONF_DIR)
398- foreach (filepath ${CONF_FILE} )
399- file (READ ${filepath} temp_text)
400- string (FIND "${temp_text} " ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} match)
401- if (${match} GREATER_EQUAL 0)
402- if (NOT DEFINED CONF_DIR)
403- get_filename_component (CONF_DIR ${filepath} DIRECTORY )
404- else ()
405- message (FATAL_ERROR "Encryption key file defined in multiple conf files" )
396+ if (NOT CONFIG_BOOT_ENCRYPT_IMAGE_WITH_EMBEDDED_KEY)
397+ # CONF_FILE points to the KConfig configuration files of the bootloader.
398+ unset (CONF_DIR)
399+ foreach (filepath ${CONF_FILE} )
400+ file (READ ${filepath} temp_text)
401+ string (FIND "${temp_text} " ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} match)
402+ if (${match} GREATER_EQUAL 0)
403+ if (NOT DEFINED CONF_DIR)
404+ get_filename_component (CONF_DIR ${filepath} DIRECTORY )
405+ else ()
406+ message (FATAL_ERROR "Encryption key file defined in multiple conf files" )
407+ endif ()
406408 endif ()
407- endif ()
408- endforeach ()
409+ endforeach ()
409410
410- if (IS_ABSOLUTE ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
411- set (KEY_FILE ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
412- elseif ((DEFINED CONF_DIR) AND
413- (EXISTS ${CONF_DIR} /${CONFIG_BOOT_ENCRYPTION_KEY_FILE} ))
414- set (KEY_FILE ${CONF_DIR} /${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
415- else ()
416- set (KEY_FILE ${MCUBOOT_DIR} /${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
417- endif ()
418- message ("MCUBoot bootloader encryption key file: ${KEY_FILE} " )
411+ if (IS_ABSOLUTE ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
412+ set (KEY_FILE ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
413+ elseif ((DEFINED CONF_DIR) AND
414+ (EXISTS ${CONF_DIR} /${CONFIG_BOOT_ENCRYPTION_KEY_FILE} ))
415+ set (KEY_FILE ${CONF_DIR} /${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
416+ else ()
417+ set (KEY_FILE ${MCUBOOT_DIR} /${CONFIG_BOOT_ENCRYPTION_KEY_FILE} )
418+ endif ()
419+ message ("MCUBoot bootloader encryption key file: ${KEY_FILE} " )
420+
421+ # Emit a warning if using one of the default MCUboot key files
422+ set (mcuboot_default_encryption_files
423+ ${MCUBOOT_DIR} /enc-ec256-priv.pem
424+ ${MCUBOOT_DIR} /enc-ec256-pub.pem
425+ ${MCUBOOT_DIR} /enc-rsa2048-priv.pem
426+ ${MCUBOOT_DIR} /enc-rsa2048-pub.pem
427+ ${MCUBOOT_DIR} /enc-x25519-priv.pem
428+ ${MCUBOOT_DIR} /enc-x25519-pub.pem
429+ )
419430
420- # Emit a warning if using one of the default MCUboot key files
421- set (mcuboot_default_encryption_files
422- ${MCUBOOT_DIR} /enc-ec256-priv.pem
423- ${MCUBOOT_DIR} /enc-ec256-pub.pem
424- ${MCUBOOT_DIR} /enc-rsa2048-priv.pem
425- ${MCUBOOT_DIR} /enc-rsa2048-pub.pem
426- ${MCUBOOT_DIR} /enc-x25519-priv.pem
427- ${MCUBOOT_DIR} /enc-x25519-pub.pem
428- )
431+ if (${KEY_FILE} IN_LIST mcuboot_default_encryption_files)
432+ message (WARNING "WARNING: Using default MCUboot encryption key file, this file is for debug use only and is not secure!" )
433+ endif ()
429434
430- if (${KEY_FILE} IN_LIST mcuboot_default_encryption_files)
431- message (WARNING "WARNING: Using default MCUboot encryption key file, this file is for debug use only and is not secure!" )
435+ set (GENERATED_ENCKEY ${ZEPHYR_BINARY_DIR} /autogen-enckey.c)
436+ add_custom_command (
437+ OUTPUT ${GENERATED_ENCKEY}
438+ COMMAND
439+ ${PYTHON_EXECUTABLE}
440+ ${MCUBOOT_DIR} /scripts/imgtool.py
441+ getpriv
442+ -k
443+ ${KEY_FILE}
444+ > ${GENERATED_ENCKEY}
445+ DEPENDS ${KEY_FILE}
446+ )
447+ zephyr_library_sources(${GENERATED_ENCKEY} )
432448 endif ()
433-
434- set (GENERATED_ENCKEY ${ZEPHYR_BINARY_DIR} /autogen-enckey.c)
435- add_custom_command (
436- OUTPUT ${GENERATED_ENCKEY}
437- COMMAND
438- ${PYTHON_EXECUTABLE}
439- ${MCUBOOT_DIR} /scripts/imgtool.py
440- getpriv
441- -k
442- ${KEY_FILE}
443- > ${GENERATED_ENCKEY}
444- DEPENDS ${KEY_FILE}
445- )
446- zephyr_library_sources(${GENERATED_ENCKEY} )
447449endif ()
448450
449451if (CONFIG_MCUBOOT_CLEANUP_ARM_CORE)
@@ -731,3 +733,18 @@ if(SYSBUILD)
731733 set (mcuboot_image_footer_size ${required_size} CACHE INTERNAL "Estimated MCUboot image trailer size" FORCE)
732734 set (mcuboot_image_upgrade_footer_size ${required_upgrade_size} CACHE INTERNAL "Estimated MCUboot update image trailer size" FORCE)
733735endif ()
736+
737+ if (${CONFIG_BOOT_ENCRYPT_IMAGE_GENERATE_BASIC_KEY_PROVIDER} )
738+ # Need to generate single key provider source, from template.
739+ # Take provided key, in form of a string and make it into C array, BOOT_AES_RAW_KEY_HEX_ARRAY,
740+ # of byte size hex values.
741+ set (BOOT_AES_RAW_KEY_HEX_STRING ${BOOT_ENCRYPT_IMAGE_EMBEDDED_RAW_KEY} )
742+ string (REGEX REPLACE "(..)" "0x\\ 1, " BOOT_AES_RAW_KEY_HEX_ARRAY "${BOOT_AES_RAW_KEY_HEX_STRING} " )
743+
744+ # The tamplate references BOOT_AES_RAW_KEY_HEX_ARRAY where it expects the array to be substituted.
745+ set (OUTPUT_BOOT_AES_RAW_KEY_SRC ${ZEPHYR_BINARY_DIR} /mcuboot_generated/builtin_aes_key_provider.c)
746+ configure_file (templates/single_builtin_aes_key_provider.c.template ${OUTPUT_BOOT_AES_RAW_KEY_SRC} @ONLY)
747+
748+ # Add generated source file to build
749+ zephyr_library_sources(${OUTPUT_BOOT_AES_RAW_KEY_SRC} )
750+ endif ()
0 commit comments