rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
openblt_chibios.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3extern "C" {
4 #include "boot.h"
5 #include "flash.h"
6}
7
8void CpuInit() { }
9
10void TimerInit() { }
11void TimerReset() { }
12
13void TimerUpdate() { }
14
16 return 0;
17}
18
20{
21 memcpy((void*)dest, (void*)src, len);
22}
23
24void CpuMemSet(blt_addr dest, blt_int8u value, blt_int16u len)
25{
26 memset((void*)dest, value, len);
27}
28
29/* See crt1.c for __cpu_init() */
30void __cpu_deinit(void) {
31#if CORTEX_MODEL == 7
32 SCB_DisableICache();
33 SCB_DisableDCache();
34#endif
35}
36
37/** \brief Pointer to the user program's reset vector. */
38#define CPU_USER_PROGRAM_STARTADDR_PTR ((blt_addr)(NvmGetUserProgBaseAddress() + 0x00000004))
39/** \brief Pointer to the user program's vector table. */
40#define CPU_USER_PROGRAM_VECTABLE_OFFSET ((blt_int32u)NvmGetUserProgBaseAddress())
41
43{
44 void (*pProgResetHandler)(void);
45
46 /* check if a user program is present by verifying the checksum */
47 if (NvmVerifyChecksum() == BLT_FALSE)
48 {
49#if (BOOT_COM_DEFERRED_INIT_ENABLE > 0) && (BOOT_COM_ENABLE > 0)
50 /* bootloader will stay active so perform deferred initialization to make sure
51 * the communication interface that were not yet initialized are now initialized.
52 * this is needed to make sure firmware updates via these communication interfaces
53 * will be possible.
54 */
55 ComDeferredInit();
56#endif
57 /* not a valid user program so it cannot be started */
58 return;
59 }
60#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
61 /* invoke callback */
62 if (CpuUserProgramStartHook() == BLT_FALSE)
63 {
64 #if (BOOT_COM_DEFERRED_INIT_ENABLE > 0) && (BOOT_COM_ENABLE > 0)
65 /* bootloader will stay active so perform deferred initialization to make sure
66 * the communication interface that were not yet initialized are now initialized.
67 * this is needed to make sure firmware updates via these communication interfaces
68 * will be possible.
69 */
70 ComDeferredInit();
71 #endif
72 /* callback requests the user program to not be started */
73 return;
74 }
75#endif
76#if (BOOT_COM_ENABLE > 0)
77 /* release the communication interface */
78 ComFree();
79#endif
80 /* reset the HAL */
81 chSysDisable();
82 /* reset the timer */
83 TimerReset();
84
85 /* Core deinitialization to jump into Prog in fresh state.*/
87
88 /* remap user program's vector table */
89 SCB->VTOR = CPU_USER_PROGRAM_VECTABLE_OFFSET & (blt_int32u)0x1FFFFF80;
90 /* set the address where the bootloader needs to jump to. this is the address of
91 * the 2nd entry in the user program's vector table. this address points to the
92 * user program's reset handler.
93 */
94 pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
95 /* The Cortex-M4 core has interrupts enabled out of reset. the bootloader
96 * explicitly disables these for security reasons. Enable them here again, so it does
97 * not have to be done by the user program.
98 */
99 /* start the user program by activating its reset interrupt service routine */
100 pProgResetHandler();
101#if (BOOT_COM_DEFERRED_INIT_ENABLE > 0) && (BOOT_COM_ENABLE > 0)
102 /* theoretically, the code never gets here because the user program should now be
103 * running and the previous function call should not return. In case it did return
104 * for whatever reason, make sure all communication interfaces are initialized so that
105 * firmware updates can be started.
106 */
107 ComDeferredInit();
108#endif
109} /*** end of CpuStartUserProgram ***/
110
111
blt_bool CpuUserProgramStartHook(void)
Callback that gets called when the bootloader is about to exit and hand over control to the user prog...
Definition hooks.c:86
blt_bool NvmVerifyChecksum(void)
Verifies the checksum, which indicates that a valid user program is present and can be started.
Definition nvm.c:108
void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
void CpuStartUserProgram(void)
void TimerUpdate()
void __cpu_deinit(void)
void TimerInit()
void TimerReset()
blt_int32u TimerGet()
void CpuInit()
void CpuMemSet(blt_addr dest, blt_int8u value, blt_int16u len)
unsigned short blt_int16u
Definition types.h:51
unsigned char blt_int8u
Definition types.h:49
unsigned int blt_int32u
Definition types.h:53
unsigned long blt_addr
Definition types.h:48