Skip to content

Commit

Permalink
boot: fix potential bl jump to app failed issue
Browse files Browse the repository at this point in the history
After changing sp, following functions calling will result
in unpredictable behavior in case of jumping

Signed-off-by: wanggang26 <[email protected]>
  • Loading branch information
wanggang26 authored and acassis committed Aug 26, 2024
1 parent ab92b7d commit 289fc24
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
10 changes: 6 additions & 4 deletions boards/arm/imxrt/imxrt1064-evk/src/imxrt_boot_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ int board_boot_image(const char *path, uint32_t hdr_size)

/* Set main and process stack pointers */

__asm__ __volatile__("\tmsr msp, %0\n" : : "r" (vt.spr));
setcontrol(0x00);
ARM_ISB();
((void (*)(void))vt.reset)();
__asm__ __volatile__("\tmsr msp, %0\n"
"\tmsr control, %1\n"
"\tisb\n"
"\tmov pc, %2\n"
:
: "r" (vt.spr), "r" (0), "r" (vt.reset));

return 0;
}
10 changes: 6 additions & 4 deletions boards/arm/nrf52/common/src/nrf52_boot_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ int board_boot_image(const char *path, uint32_t hdr_size)

/* Set main and process stack pointers */

__asm__ __volatile__("\tmsr msp, %0\n" : : "r" (vt.spr));
setcontrol(0x00);
ARM_ISB();
((void (*)(void))vt.reset)();
__asm__ __volatile__("\tmsr msp, %0\n"
"\tmsr control, %1\n"
"\tisb\n"
"\tmov pc, %2\n"
:
: "r" (vt.spr), "r" (0), "r" (vt.reset));

return 0;
}
10 changes: 6 additions & 4 deletions boards/arm/nrf53/common/src/nrf53_boot_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ int board_boot_image(const char *path, uint32_t hdr_size)

/* Set main and process stack pointers */

__asm__ __volatile__("\tmsr msp, %0\n" : : "r" (vt.spr));
setcontrol(0x00);
ARM_ISB();
((void (*)(void))vt.reset)();
__asm__ __volatile__("\tmsr msp, %0\n"
"\tmsr control, %1\n"
"\tisb\n"
"\tmov pc, %2\n"
:
: "r" (vt.spr), "r" (0), "r" (vt.reset));

return 0;
}
10 changes: 6 additions & 4 deletions boards/arm/nrf91/common/src/nrf91_boot_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ int board_boot_image(const char *path, uint32_t hdr_size)

/* Set main and process stack pointers */

__asm__ __volatile__("\tmsr msp, %0\n" : : "r" (vt.spr));
setcontrol(0x00);
ARM_ISB();
((void (*)(void))vt.reset)();
__asm__ __volatile__("\tmsr msp, %0\n"
"\tmsr control, %1\n"
"\tisb\n"
"\tmov pc, %2\n"
:
: "r" (vt.spr), "r" (0), "r" (vt.reset));

#else
/* Non-secure entry point */
Expand Down
10 changes: 6 additions & 4 deletions boards/arm/samv7/common/src/sam_boot_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ int board_boot_image(const char *path, uint32_t hdr_size)

/* Set main and process stack pointers */

__asm__ __volatile__("\tmsr msp, %0\n" : : "r" (vt.spr));
setcontrol(0x00);
ARM_ISB();
((void (*)(void))vt.reset)();
__asm__ __volatile__("\tmsr msp, %0\n"
"\tmsr control, %1\n"
"\tisb\n"
"\tmov pc, %2\n"
:
: "r" (vt.spr), "r" (0), "r" (vt.reset));

return 0;
}
Expand Down

0 comments on commit 289fc24

Please sign in to comment.