Skip to content

Commit 98011ce

Browse files
committed
Fix MISRA violation and add comments for required violations
1 parent 1b388bc commit 98011ce

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

dspic33a_secure_boot/boot.X/mdfu/mdfu_partition_executable.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,27 @@ static enum MDFU_PARTITION_STATUS Run(void)
226226
IVTBASE = MDFU_CONFIG_EXECUTABLE_DATA_ORIGIN;
227227
PACCON1bits.IVTBASEWR = 0;
228228

229-
/* cppcheck-suppress misra-c2012-11.6
229+
/* cppcheck-suppress misra-c2012-11.4
230230
*
231-
* (Rule 11.6) REQUIRED: Required: A cast shall not be performed between
232-
* pointer to void and an arithmetic type
231+
* (Rule 11.4) ADVISORY: A conversion should not be performed between a
232+
* pointer to object and an integer type
233233
*
234-
* Reasoning: This function represents a jump between the boot code and the
235-
* user code. Because the address of the jump lives outside of boot space,
236-
* there is no way to create an object at that address to references so
237-
* an integer address is used for the pre-defined executable entry point.
234+
* Reasoning: This is required for the bootloader to jump to the executable
235+
* code. The reset vector is stored at a fixed address, and this cast is
236+
* necessary to read it.
238237
*/
239-
int (*user_executable)(void);
238+
uint32_t resetVector = *((const uint32_t *)MDFU_CONFIG_EXECUTABLE_DATA_ORIGIN);
240239

241-
uint32_t *resetVectorPtr = (uint32_t *)MDFU_CONFIG_EXECUTABLE_DATA_ORIGIN;
242-
uint32_t resetVector = *resetVectorPtr;
243-
244-
user_executable = (int(*)(void))resetVector;
240+
/* cppcheck-suppress misra-c2012-11.4
241+
*
242+
* (Rule 11.4) ADVISORY: A conversion should not be performed between a
243+
* pointer to object and an integer type
244+
*
245+
* Reasoning: This is required for the bootloader to jump to the executable
246+
* code. The application entry point is stored in the reset vector and must
247+
* be cast to a function pointer.
248+
*/
249+
int (*user_executable)(void) = (int (*)(void))resetVector;
245250

246251
/* Disable IRT access before transferring control to the executable.
247252
*
@@ -251,7 +256,8 @@ static enum MDFU_PARTITION_STATUS Run(void)
251256
* executable non-IRT sections. The keystore, although classified as IRT, is
252257
* non-executable and thus serves as the recommended buffer. */
253258
IRTCTRLbits.DONE = 1U;
254-
user_executable();
259+
260+
(void)user_executable();
255261

256262
return MDFU_PARTITION_STATUS_OPERATION_FAILED;
257263
}

0 commit comments

Comments
 (0)