1010#include <suit_platform.h>
1111#include <suit_plat_decode_util.h>
1212#include <suit_cpu_run.h>
13+ #ifdef CONFIG_SUIT_EVENTS
14+ #include <suit_events.h>
15+ #endif /* CONFIG_SUIT_EVENTS */
1316
1417LOG_MODULE_REGISTER (suit_plat_invoke , CONFIG_SUIT_LOG_LEVEL );
1518
@@ -26,8 +29,8 @@ int suit_plat_check_invoke(suit_component_t image_handle, struct zcbor_string *i
2629 return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
2730 }
2831
29- if (suit_plat_decode_component_id (component_id , & cpu_id , & run_address , & size )
30- != SUIT_PLAT_SUCCESS ) {
32+ if (suit_plat_decode_component_id (component_id , & cpu_id , & run_address , & size ) !=
33+ SUIT_PLAT_SUCCESS ) {
3134 LOG_ERR ("suit_plat_decode_component_id failed" );
3235 return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
3336 }
@@ -37,6 +40,11 @@ int suit_plat_check_invoke(suit_component_t image_handle, struct zcbor_string *i
3740 return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
3841 }
3942
43+ if (suit_plat_decode_invoke_args (invoke_args , NULL , NULL )) {
44+ LOG_ERR ("suit_plat_decode_invoke_args failed" );
45+ return SUIT_ERR_UNSUPPORTED_PARAMETER ;
46+ }
47+
4048 /* Check if component type supports invocation */
4149 switch (component_type ) {
4250 case SUIT_COMPONENT_TYPE_MEM :
@@ -54,6 +62,9 @@ int suit_plat_invoke(suit_component_t image_handle, struct zcbor_string *invoke_
5462{
5563 struct zcbor_string * component_id ;
5664 suit_component_type_t component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED ;
65+ uint32_t timeout_ms = 0 ;
66+ bool synchronous = false;
67+ int ret = 0 ;
5768 intptr_t run_address ;
5869 uint8_t cpu_id ;
5970 size_t size ;
@@ -63,8 +74,8 @@ int suit_plat_invoke(suit_component_t image_handle, struct zcbor_string *invoke_
6374 return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
6475 }
6576
66- if (suit_plat_decode_component_id (component_id , & cpu_id , & run_address , & size )
67- != SUIT_PLAT_SUCCESS ) {
77+ if (suit_plat_decode_component_id (component_id , & cpu_id , & run_address , & size ) !=
78+ SUIT_PLAT_SUCCESS ) {
6879 LOG_ERR ("suit_plat_decode_component_id failed" );
6980 return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
7081 }
@@ -74,15 +85,45 @@ int suit_plat_invoke(suit_component_t image_handle, struct zcbor_string *invoke_
7485 return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
7586 }
7687
88+ if (suit_plat_decode_invoke_args (invoke_args , & synchronous , & timeout_ms )) {
89+ LOG_ERR ("suit_plat_decode_invoke_args failed" );
90+ return SUIT_ERR_UNSUPPORTED_PARAMETER ;
91+ }
92+
93+ #ifdef CONFIG_SUIT_EVENTS
94+ /* Clear all pending invoke events */
95+ (void )suit_event_clear (cpu_id , SUIT_EVENT_INVOKE_MASK );
96+ #endif /* CONFIG_SUIT_EVENTS */
97+
7798 /* Check if component type supports invocation */
7899 switch (component_type ) {
79100 case SUIT_COMPONENT_TYPE_MEM :
80101 /* memory-mapped */
81- return suit_plat_cpu_run (cpu_id , run_address );
102+ ret = suit_plat_cpu_run (cpu_id , run_address );
103+ break ;
82104 default :
83105 LOG_ERR ("Unsupported component type" );
84- break ;
106+ return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
85107 }
86108
87- return SUIT_ERR_UNSUPPORTED_COMPONENT_ID ;
109+ if ((ret == SUIT_SUCCESS ) && synchronous ) {
110+ #ifdef CONFIG_SUIT_EVENTS
111+ /* Wait for one of the invoke events */
112+ uint32_t invoke_events =
113+ suit_event_wait (cpu_id , SUIT_EVENT_INVOKE_MASK , false, timeout_ms );
114+
115+ if (invoke_events & SUIT_EVENT_INVOKE_SUCCESS ) {
116+ return SUIT_SUCCESS ;
117+ }
118+
119+ /* Event timeout or invoke failed */
120+ /* Allow to handle invoke failure inside the manifest. */
121+ return SUIT_FAIL_CONDITION ;
122+ #else
123+ /* Synchronous invoke not supported */
124+ return SUIT_ERR_CRASH ;
125+ #endif /* CONFIG_SUIT_EVENTS */
126+ }
127+
128+ return ret ;
88129}
0 commit comments