@@ -153,6 +153,28 @@ function(picotool_check_configurable TARGET)
153153 endif ()
154154endfunction ()
155155
156+ # Compare 2 key files, used by picotool_check_default_keys
157+ function (picotool_compare_keys TARGET KEY DEFAULT TYPE )
158+ if (KEY)
159+ execute_process (COMMAND ${CMAKE_COMMAND} -E compare_files "${KEY} " "${PICO_SDK_PATH} /tools/example_keys/${DEFAULT} "
160+ RESULT_VARIABLE compare_result
161+ )
162+ if (compare_result EQUAL 0)
163+ message (WARNING "${TARGET} is using a default ${TYPE} key - this must be changed before production" )
164+ endif ()
165+ endif ()
166+ endfunction ()
167+
168+ # Check if default signing/encryption keys are being used
169+ function (picotool_check_default_keys TARGET )
170+ get_target_property (picotool_sigfile ${TARGET} PICOTOOL_SIGFILE)
171+ picotool_compare_keys(${TARGET} ${picotool_sigfile} private .pem "signing" )
172+ get_target_property (picotool_aesfile ${TARGET} PICOTOOL_AESFILE)
173+ picotool_compare_keys(${TARGET} ${picotool_aesfile} privateaes.bin "encryption" )
174+ get_target_property (picotool_enc_sigfile ${TARGET} PICOTOOL_ENC_SIGFILE)
175+ picotool_compare_keys(${TARGET} ${picotool_enc_sigfile} private .pem "encrypted signing" )
176+ endfunction ()
177+
156178# Generate pio header and include it in the build
157179# PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build
158180function (pico_generate_pio_header TARGET )
@@ -449,6 +471,17 @@ function(picotool_postprocess_binary TARGET)
449471 set_target_properties (${TARGET} PROPERTIES
450472 PICOTOOL_PROCESSING_CONFIGURED true
451473 )
474+
475+ # Allow using the example keys for pico-examples
476+ if ((NOT DEFINED PICO_ALLOW_EXAMPLE_KEYS) AND (DEFINED PICO_EXAMPLES_PATH))
477+ set (PICO_ALLOW_EXAMPLE_KEYS 1)
478+ endif ()
479+
480+ # PICO_CMAKE_CONFIG: PICO_ALLOW_EXAMPLE_KEYS, Don't throw warning when using default signing/encryption keys, type=bool, default=0, group=build
481+ if (NOT PICO_ALLOW_EXAMPLE_KEYS)
482+ picotool_check_default_keys(${TARGET} )
483+ endif ()
484+
452485 # Read target properties
453486 get_target_property (picotool_sign_output ${TARGET} PICOTOOL_SIGN_OUTPUT)
454487 if (picotool_sign_output)
0 commit comments