rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
hooks.c File Reference

Functions

 __attribute__ ((weak))
 Initializes the backdoor entry option.
 
blt_bool BackDoorEntryHook (void)
 Checks if a backdoor entry is requested.
 
blt_bool CpuUserProgramStartHook (void)
 Callback that gets called when the bootloader is about to exit and hand over control to the user program. This is the last moment that some final checking can be performed and if necessary prevent the bootloader from activiting the user program.
 
void UsbConnectHook (blt_bool connect)
 Callback that gets called whenever the USB device should be connected to the USB bus.
 
void UsbEnterLowPowerModeHook (void)
 Callback that gets called whenever the USB host requests the device to enter a low power mode.
 
void UsbLeaveLowPowerModeHook (void)
 Callback that gets called whenever the USB host requests the device to exit low power mode.
 
void NvmInitHook (void)
 Callback that gets called at the start of the internal NVM driver initialization routine.
 
void NvmReinitHook (void)
 Callback that gets called at the start of a firmware update to reinitialize the NVM driver.
 
blt_int8u NvmWriteHook (blt_addr addr, blt_int32u len, blt_int8u *data)
 Callback that gets called at the start of the NVM driver write routine. It allows additional memory to be operated on. If the address is not within the range of the additional memory, then BLT_NVM_NOT_IN_RANGE must be returned to indicate that the data hasn't been written yet.
 
blt_int8u NvmEraseHook (blt_addr addr, blt_int32u len)
 Callback that gets called at the start of the NVM driver erase routine. It allows additional memory to be operated on. If the address is not within the range of the additional memory, then BLT_NVM_NOT_IN_RANGE must be returned to indicate that the memory hasn't been erased yet.
 
blt_bool NvmDoneHook (void)
 Callback that gets called at the end of the NVM programming session.
 
blt_bool NvmVerifyChecksumHook (void)
 Verifies the checksum, which indicates that a valid user program is present and can be started.
 
blt_bool NvmWriteChecksumHook (void)
 Writes a checksum of the user program to non-volatile memory. This is performed once the entire user program has been programmed. Through the checksum, the bootloader can check if a valid user programming is present and can be started.
 
blt_int8u XcpGetSeedHook (blt_int8u resource, blt_int8u *seed)
 Provides a seed to the XCP master that will be used for the key generation when the master attempts to unlock the specified resource. Called by the GET_SEED command.
 
blt_int8u XcpVerifyKeyHook (blt_int8u resource, blt_int8u *key, blt_int8u len)
 Called by the UNLOCK command and checks if the key to unlock the specified resource was correct. If so, then the resource protection will be removed.
 

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

Initializes the backdoor entry option.

Returns
none.

Definition at line 54 of file hooks.c.

55{
56} /*** end of BackDoorInitHook ***/

◆ BackDoorEntryHook()

blt_bool BackDoorEntryHook ( void  )

Checks if a backdoor entry is requested.

Returns
BLT_TRUE if the backdoor entry is requested, BLT_FALSE otherwise.

Definition at line 65 of file hooks.c.

66{
67 return BLT_TRUE;
68} /*** end of BackDoorEntryHook ***/

◆ CpuUserProgramStartHook()

blt_bool CpuUserProgramStartHook ( void  )

Callback that gets called when the bootloader is about to exit and hand over control to the user program. This is the last moment that some final checking can be performed and if necessary prevent the bootloader from activiting the user program.

Returns
BLT_TRUE if it is okay to start the user program, BLT_FALSE to keep keep the bootloader active.

Definition at line 86 of file hooks.c.

87{
88 /* additional and optional backdoor entry through the pushbutton on the board. to
89 * force the bootloader to stay active after reset, keep the pushbutton pressed while
90 * resetting the microcontroller.
91 */
92 if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_SET)
93 {
94 /* pushbutton pressed, so do not start the user program and keep the
95 * bootloader active instead.
96 */
97 return BLT_FALSE;
98 }
99
100 /* clean up the LED driver */
101 LedBlinkExit();
102
103 /* okay to start the user program */
104 return BLT_TRUE;
105} /*** end of CpuUserProgramStartHook ***/
void LedBlinkExit(void)
Cleans up the LED blink driver. This is intended to be used upon program exit.
Definition led.c:101

Referenced by CpuStartUserProgram().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NvmDoneHook()

blt_bool NvmDoneHook ( void  )

Callback that gets called at the end of the NVM programming session.

Returns
BLT_TRUE is successful, BLT_FALSE otherwise.

Definition at line 234 of file hooks.c.

235{
236 return BLT_TRUE;
237} /*** end of NvmDoneHook ***/

◆ NvmEraseHook()

blt_int8u NvmEraseHook ( blt_addr  addr,
blt_int32u  len 
)

Callback that gets called at the start of the NVM driver erase routine. It allows additional memory to be operated on. If the address is not within the range of the additional memory, then BLT_NVM_NOT_IN_RANGE must be returned to indicate that the memory hasn't been erased yet.

Parameters
addrStart address.
lenLength in bytes.
Returns
BLT_NVM_OKAY if successful, BLT_NVM_NOT_IN_RANGE if the address is not within the supported memory range, or BLT_NVM_ERROR is the erase operation failed.

Definition at line 223 of file hooks.c.

224{
225 return BLT_NVM_NOT_IN_RANGE;
226} /*** end of NvmEraseHook ***/

◆ NvmInitHook()

void NvmInitHook ( void  )

Callback that gets called at the start of the internal NVM driver initialization routine.

Returns
none.

Definition at line 174 of file hooks.c.

175{
176} /*** end of NvmInitHook ***/

◆ NvmReinitHook()

void NvmReinitHook ( void  )

Callback that gets called at the start of a firmware update to reinitialize the NVM driver.

Returns
none.

Definition at line 185 of file hooks.c.

186{
187} /*** end of NvmReinitHook ***/

◆ NvmVerifyChecksumHook()

blt_bool NvmVerifyChecksumHook ( void  )

Verifies the checksum, which indicates that a valid user program is present and can be started.

Returns
BLT_TRUE if successful, BLT_FALSE otherwise.

Definition at line 248 of file hooks.c.

249{
250 return BLT_TRUE;
251} /*** end of NvmVerifyChecksum ***/

◆ NvmWriteChecksumHook()

blt_bool NvmWriteChecksumHook ( void  )

Writes a checksum of the user program to non-volatile memory. This is performed once the entire user program has been programmed. Through the checksum, the bootloader can check if a valid user programming is present and can be started.

Returns
BLT_TRUE if successful, BLT_FALSE otherwise.

Definition at line 262 of file hooks.c.

263{
264 return BLT_TRUE;
265}

◆ NvmWriteHook()

blt_int8u NvmWriteHook ( blt_addr  addr,
blt_int32u  len,
blt_int8u data 
)

Callback that gets called at the start of the NVM driver write routine. It allows additional memory to be operated on. If the address is not within the range of the additional memory, then BLT_NVM_NOT_IN_RANGE must be returned to indicate that the data hasn't been written yet.

Parameters
addrStart address.
lenLength in bytes.
dataPointer to the data buffer.
Returns
BLT_NVM_OKAY if successful, BLT_NVM_NOT_IN_RANGE if the address is not within the supported memory range, or BLT_NVM_ERROR is the write operation failed.

Definition at line 204 of file hooks.c.

205{
206 return BLT_NVM_NOT_IN_RANGE;
207} /*** end of NvmWriteHook ***/

◆ UsbConnectHook()

void UsbConnectHook ( blt_bool  connect)

Callback that gets called whenever the USB device should be connected to the USB bus.

Parameters
connectBLT_TRUE to connect and BLT_FALSE to disconnect.
Returns
none.

Definition at line 132 of file hooks.c.

133{
134 /* Note that this is handled automatically by the OTG peripheral. */
135} /*** end of UsbConnect ***/

Referenced by PCD_ConnectCallback(), and PCD_DisconnectCallback().

Here is the caller graph for this function:

◆ UsbEnterLowPowerModeHook()

void UsbEnterLowPowerModeHook ( void  )

Callback that gets called whenever the USB host requests the device to enter a low power mode.

Returns
none.

Definition at line 144 of file hooks.c.

145{
146 /* support to enter a low power mode can be implemented here */
147} /*** end of UsbEnterLowPowerMode ***/

Referenced by PCD_SuspendCallback().

Here is the caller graph for this function:

◆ UsbLeaveLowPowerModeHook()

void UsbLeaveLowPowerModeHook ( void  )

Callback that gets called whenever the USB host requests the device to exit low power mode.

Returns
none.

Definition at line 156 of file hooks.c.

157{
158 /* support to leave a low power mode can be implemented here */
159} /*** end of UsbLeaveLowPowerMode ***/

Referenced by PCD_ResumeCallback().

Here is the caller graph for this function:

◆ XcpGetSeedHook()

blt_int8u XcpGetSeedHook ( blt_int8u  resource,
blt_int8u seed 
)

Provides a seed to the XCP master that will be used for the key generation when the master attempts to unlock the specified resource. Called by the GET_SEED command.

Parameters
resourceResource that the seed if requested for (XCP_RES_XXX).
seedPointer to byte buffer wher the seed will be stored.
Returns
Length of the seed in bytes.

Definition at line 283 of file hooks.c.

284{
285 /* request seed for unlocking ProGraMming resource */
286 if ((resource & XCP_RES_PGM) != 0)
287 {
288 seed[0] = 0x55;
289 }
290
291 /* return seed length */
292 return 1;
293} /*** end of XcpGetSeedHook ***/

◆ XcpVerifyKeyHook()

blt_int8u XcpVerifyKeyHook ( blt_int8u  resource,
blt_int8u key,
blt_int8u  len 
)

Called by the UNLOCK command and checks if the key to unlock the specified resource was correct. If so, then the resource protection will be removed.

Parameters
resourceresource to unlock (XCP_RES_XXX).
keypointer to the byte buffer holding the key.
lenlength of the key in bytes.
Returns
1 if the key was correct, 0 otherwise.

Definition at line 306 of file hooks.c.

307{
308 /* suppress compiler warning for unused parameter */
309 len = len;
310
311 /* the example key algorithm in "libseednkey.dll" works as follows:
312 * - PGM will be unlocked if key = seed - 1
313 */
314
315 /* check key for unlocking ProGraMming resource */
316 if ((resource == XCP_RES_PGM) && (key[0] == (0x55-1)))
317 {
318 /* correct key received for unlocking PGM resource */
319 return 1;
320 }
321
322 /* still here so key incorrect */
323 return 0;
324} /*** end of XcpVerifyKeyHook ***/

Go to the source code of this file.