@@ -493,45 +493,67 @@ if (CONFIG_BUILD_WITH_TFM)
493
493
endif ()
494
494
endif ()
495
495
496
- function (tfm_sign OUT_ARG SUFFIX HEADER TRAILER CONFIRM MAX_SECTORS INPUT_FILE OUTPUT_FILE)
497
- if (HEADER AND TRAILER)
496
+ function (tfm_sign OUT_ARG)
497
+ set (options HEADER TRAILER CONFIRM)
498
+ set (oneValueArgs SUFFIX MAX_SECTORS INPUT_FILE OUTPUT_FILE)
499
+ set (multiValueArgs "" )
500
+
501
+ cmake_parse_arguments (
502
+ TFM_SIGN_ARG
503
+ "${options} "
504
+ "${oneValueArgs} "
505
+ "${multiValueArgs} "
506
+ ${ARGN}
507
+ )
508
+
509
+ if (NOT DEFINED TFM_SIGN_ARG_SUFFIX OR
510
+ NOT DEFINED TFM_SIGN_ARG_INPUT_FILE OR
511
+ NOT DEFINED TFM_SIGN_ARG_OUTPUT_FILE)
512
+ message (FATAL_ERROR "SUFFIX, INPUT_FILE and OUTPUT_FILE are required arguments" )
513
+ endif ()
514
+
515
+ set (pad_args "" )
516
+ if (TFM_SIGN_ARG_HEADER AND TFM_SIGN_ARG_TRAILER)
498
517
set (pad_args --pad --pad-header)
499
- elseif (HEADER )
518
+ elseif (TFM_SIGN_ARG_HEADER )
500
519
set (pad_args --pad-header)
501
- elseif (TRAILER )
520
+ elseif (TFM_SIGN_ARG_TRAILER )
502
521
set (pad_args --pad)
503
522
endif ()
504
- if (CONFIRM)
505
- # --confirm imply PAD
523
+
524
+ set (confirm "" )
525
+ if (TFM_SIGN_ARG_CONFIRM)
506
526
set (confirm --confirm)
507
527
endif ()
528
+
508
529
# Secure + Non-secure images are signed the same way as a secure only
509
530
# build, but with a different layout file.
510
- set (layout_file ${PREPROCESSED_FILE_${SUFFIX } })
511
- if (SUFFIX STREQUAL "S_NS" )
512
- set (SUFFIX "S" )
531
+ set (layout_file ${PREPROCESSED_FILE_${TFM_SIGN_ARG_SUFFIX } })
532
+ if (TFM_SIGN_ARG_SUFFIX STREQUAL "S_NS" )
533
+ set (TFM_SIGN_ARG_SUFFIX "S" )
513
534
endif ()
514
- set (${OUT_ARG}
535
+
536
+ set (${OUT_ARG}
515
537
# Add the MCUBoot script to the path so that if there is a version of imgtool in there then
516
538
# it gets used over the system imgtool. Used so that imgtool from upstream
517
539
# mcuboot is preferred over system imgtool
518
540
${CMAKE_COMMAND} -E env PYTHONPATH=${ZEPHYR_MCUBOOT_MODULE_DIR} /scripts
519
541
${PYTHON_EXECUTABLE} ${TFM_MCUBOOT_DIR} /scripts/wrapper/wrapper.py
520
542
--layout ${layout_file}
521
- -k ${CONFIG_TFM_KEY_FILE_${SUFFIX } }
543
+ -k ${CONFIG_TFM_KEY_FILE_${TFM_SIGN_ARG_SUFFIX } }
522
544
--public -key-format ${TFM_PUBLIC_KEY_FORMAT}
523
545
--align ${image_alignment}
524
- --max-sectors ${MAX_SECTORS }
525
- -v ${CONFIG_TFM_IMAGE_VERSION_${SUFFIX } }
546
+ --max-sectors ${TFM_SIGN_ARG_MAX_SECTORS }
547
+ -v ${CONFIG_TFM_IMAGE_VERSION_${TFM_SIGN_ARG_SUFFIX } }
526
548
${pad_args}
527
549
${confirm}
528
- ${HEX_ADDR_ARGS_${SUFFIX } }
529
- ${ADD_${SUFFIX } _IMAGE_MIN_VER}
550
+ ${HEX_ADDR_ARGS_${TFM_SIGN_ARG_SUFFIX } }
551
+ ${ADD_${TFM_SIGN_ARG_SUFFIX } _IMAGE_MIN_VER}
530
552
-s ${CONFIG_TFM_IMAGE_SECURITY_COUNTER}
531
553
--measured-boot-record
532
554
-H ${CONFIG_ROM_START_OFFSET}
533
- ${INPUT_FILE }
534
- ${OUTPUT_FILE }
555
+ ${TFM_SIGN_ARG_INPUT_FILE }
556
+ ${TFM_SIGN_ARG_OUTPUT_FILE }
535
557
PARENT_SCOPE)
536
558
endfunction ()
537
559
@@ -567,8 +589,9 @@ if (CONFIG_BUILD_WITH_TFM)
567
589
)
568
590
569
591
elseif (CONFIG_TFM_MCUBOOT_IMAGE_NUMBER STREQUAL "1" )
570
- tfm_sign(sign_cmd_s_ns_hex S_NS TRUE TRUE TRUE ${S_NS_MAX_SECTORS} ${S_NS_HEX_FILE}
571
- ${S_NS_SIGNED_HEX_FILE} )
592
+ tfm_sign(sign_cmd_s_ns_hex SUFFIX "S_NS"
593
+ HEADER TRAILER CONFIRM MAX_SECTORS ${S_NS_MAX_SECTORS}
594
+ INPUT_FILE ${S_NS_HEX_FILE} OUTPUT_FILE ${S_NS_SIGNED_HEX_FILE} )
572
595
573
596
set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
574
597
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE} /scripts/build /mergehex.py
@@ -593,21 +616,33 @@ if (CONFIG_BUILD_WITH_TFM)
593
616
594
617
else ()
595
618
if (CONFIG_TFM_USE_NS_APP)
596
- tfm_sign(sign_cmd_ns_hex NS TRUE TRUE TRUE ${S_NS_MAX_SECTORS} ${NS_HEX_APP_FILE}
597
- ${NS_SIGNED_HEX_FILE} )
598
- tfm_sign(sign_cmd_ns_bin NS TRUE TRUE FALSE ${S_NS_MAX_SECTORS} ${NS_BIN_APP_FILE}
599
- ${NS_SIGNED_BIN_FILE} )
619
+ tfm_sign(sign_cmd_ns_hex SUFFIX "NS"
620
+ HEADER TRAILER CONFIRM MAX_SECTORS ${S_NS_MAX_SECTORS}
621
+ INPUT_FILE ${NS_HEX_APP_FILE}
622
+ OUTPUT_FILE ${NS_SIGNED_HEX_FILE} )
623
+ tfm_sign(sign_cmd_ns_bin SUFFIX "NS"
624
+ HEADER TRAILER MAX_SECTORS ${S_NS_MAX_SECTORS}
625
+ INPUT_FILE ${NS_BIN_APP_FILE}
626
+ OUTPUT_FILE ${NS_SIGNED_BIN_FILE} )
600
627
else ()
601
- tfm_sign(sign_cmd_ns_hex NS FALSE TRUE TRUE ${S_NS_MAX_SECTORS} ${NS_HEX_APP_FILE}
602
- ${NS_SIGNED_HEX_FILE} )
603
- tfm_sign(sign_cmd_ns_bin NS FALSE TRUE FALSE ${S_NS_MAX_SECTORS} ${NS_BIN_APP_FILE}
604
- ${NS_SIGNED_BIN_FILE} )
628
+ tfm_sign(sign_cmd_ns_hex SUFFIX "NS"
629
+ TRAILER CONFIRM MAX_SECTORS ${S_NS_MAX_SECTORS}
630
+ INPUT_FILE ${NS_HEX_APP_FILE}
631
+ OUTPUT_FILE ${NS_SIGNED_HEX_FILE} )
632
+ tfm_sign(sign_cmd_ns_bin SUFFIX "NS"
633
+ TRAILER MAX_SECTORS ${S_NS_MAX_SECTORS}
634
+ INPUT_FILE ${NS_BIN_APP_FILE}
635
+ OUTPUT_FILE ${NS_SIGNED_BIN_FILE} )
605
636
endif ()
606
637
607
- tfm_sign(sign_cmd_s_hex S TRUE TRUE TRUE ${S_NS_MAX_SECTORS}
608
- $<TARGET_PROPERTY:tfm,TFM_S_HEX_FILE> ${S_SIGNED_HEX_FILE} )
609
- tfm_sign(sign_cmd_s_bin S TRUE TRUE FALSE ${S_NS_MAX_SECTORS}
610
- $<TARGET_PROPERTY:tfm,TFM_S_BIN_FILE> ${S_SIGNED_BIN_FILE} )
638
+ tfm_sign(sign_cmd_s_hex SUFFIX "S"
639
+ HEADER TRAILER CONFIRM MAX_SECTORS ${S_NS_MAX_SECTORS}
640
+ INPUT_FILE $<TARGET_PROPERTY:tfm,TFM_S_HEX_FILE>
641
+ OUTPUT_FILE ${S_SIGNED_HEX_FILE} )
642
+ tfm_sign(sign_cmd_s_bin SUFFIX "S"
643
+ HEADER TRAILER MAX_SECTORS ${S_NS_MAX_SECTORS}
644
+ INPUT_FILE $<TARGET_PROPERTY:tfm,TFM_S_BIN_FILE>
645
+ OUTPUT_FILE ${S_SIGNED_BIN_FILE} )
611
646
612
647
#Create and sign for concatenated binary image, should align with the TF-M BL2
613
648
set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
0 commit comments