@@ -41,6 +41,12 @@ define_property(TARGET
41
41
BRIEF_DOCS "AES key for encrypting"
42
42
FULL_DOCS "AES key for encrypting"
43
43
)
44
+ define_property (TARGET
45
+ PROPERTY PICOTOOL_EMBED_DECRYPTION
46
+ INHERITED
47
+ BRIEF_DOCS "Embed decryption stage into encrypted binary"
48
+ FULL_DOCS "Embed decryption stage into encrypted binary"
49
+ )
44
50
define_property (TARGET
45
51
PROPERTY PICOTOOL_ENC_SIGFILE
46
52
INHERITED
@@ -360,7 +366,7 @@ endfunction()
360
366
361
367
# pico_encrypt_binary(TARGET AESFILE [SIGFILE])
362
368
# Encrypt the target binary with the given AES key (should be a binary
363
- # file containing 32 bytes of a random key), and sign the encrypted binary.
369
+ # file containing 128 bytes of a random key), and sign the encrypted binary.
364
370
# This sets PICOTOOL_AESFILE to AESFILE, and PICOTOOL_ENC_SIGFILE to SIGFILE
365
371
# if present, else PICOTOOL_SIGFILE.
366
372
function (pico_encrypt_binary TARGET AESFILE)
@@ -387,6 +393,37 @@ function(pico_encrypt_binary TARGET AESFILE)
387
393
endif ()
388
394
endfunction ()
389
395
396
+ # pico_create_decrypting_binary(TARGET AESFILE [SIGFILE])
397
+ # Encrypt the target binary with the given AES key (should be a binary
398
+ # file containing 128 bytes of a random key), add a decryption stage to
399
+ # decrypt the binary at runtime, and then sign the encrypted binary.
400
+ # This sets PICOTOOL_AESFILE to AESFILE, PICOTOOL_EMBED_DECRYPTION to TRUE,
401
+ # and PICOTOOL_ENC_SIGFILE to SIGFILE if present, else PICOTOOL_SIGFILE.
402
+ function (pico_create_decrypting_binary TARGET AESFILE)
403
+ picotool_check_configurable(${TARGET} )
404
+ set_target_properties (${TARGET} PROPERTIES
405
+ PICOTOOL_AESFILE ${AESFILE}
406
+ PICOTOOL_EMBED_DECRYPTION TRUE
407
+ )
408
+ if (ARGC EQUAL 3)
409
+ set_target_properties (${TARGET} PROPERTIES
410
+ PICOTOOL_ENC_SIGFILE ${ARGV2}
411
+ )
412
+ else ()
413
+ get_target_property (enc_sig_file ${TARGET} PICOTOOL_ENC_SIGFILE)
414
+ if (NOT enc_sig_file)
415
+ get_target_property (sig_file ${TARGET} PICOTOOL_SIGFILE)
416
+ if (NOT sig_file)
417
+ message (FATAL_ERROR "Signature file not set for ${TARGET} " )
418
+ else ()
419
+ set_target_properties (${TARGET} PROPERTIES
420
+ PICOTOOL_ENC_SIGFILE ${sig_file}
421
+ )
422
+ endif ()
423
+ endif ()
424
+ endif ()
425
+ endfunction ()
426
+
390
427
# pico_add_uf2_output(TARGET)
391
428
# Add a UF2 output using picotool - must be called after
392
429
# all required properties have been set
@@ -519,9 +556,20 @@ function(picotool_postprocess_binary TARGET)
519
556
endif ()
520
557
# Encryption
521
558
if (picotool_aesfile)
559
+ get_target_property (picotool_embed_decryption ${TARGET} PICOTOOL_EMBED_DECRYPTION)
560
+ if (picotool_embed_decryption)
561
+ list (APPEND picotool_encrypt_args "--embed" )
562
+ endif ()
563
+
522
564
add_custom_command (TARGET ${TARGET} POST_BUILD
523
565
DEPENDS ${picotool_enc_sigfile} ${picotool_aesfile}
524
- COMMAND picotool encrypt --quiet --hash --sign $<TARGET_FILE:${TARGET} > $<TARGET_FILE:${TARGET} > ${picotool_aesfile} ${picotool_enc_sigfile}
566
+ COMMAND picotool
567
+ ARGS encrypt
568
+ --quiet --hash --sign
569
+ ${picotool_encrypt_args}
570
+ $<TARGET_FILE:${TARGET} > $<TARGET_FILE:${TARGET} >
571
+ ${picotool_aesfile} ${picotool_enc_sigfile}
572
+ COMMAND_EXPAND_LISTS
525
573
VERBATIM )
526
574
if (ARGC EQUAL 2)
527
575
set (${ARGV1} TRUE PARENT_SCOPE)
0 commit comments