rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
openblt_flash.cpp File Reference

Functions

void FlashInit ()
 
blt_addr FlashGetUserProgBaseAddress ()
 
blt_bool FlashWrite (blt_addr addr, blt_int32u len, blt_int8u *data)
 
blt_bool FlashErase (blt_addr addr, blt_int32u len)
 
blt_bool FlashDone ()
 
blt_bool FlashWriteChecksum ()
 
blt_bool FlashVerifyChecksum ()
 
blt_bool isFlashDualBank (void)
 

Function Documentation

◆ FlashDone()

blt_bool FlashDone ( void  )

Definition at line 45 of file openblt_flash.cpp.

45 {
46 return BLT_TRUE;
47}

Referenced by NvmDone().

Here is the caller graph for this function:

◆ FlashErase()

blt_bool FlashErase ( blt_addr  addr,
blt_int32u  len 
)

Definition at line 32 of file openblt_flash.cpp.

32 {
33 // don't allow erasing the bootloader
35 return BLT_FALSE;
36 }
37
38 if (!intFlashIsErased(addr, len)) {
39 return (FLASH_RETURN_SUCCESS == intFlashErase(addr, len)) ? BLT_TRUE : BLT_FALSE;
40 }
41
42 return BLT_TRUE;
43}
constexpr uint8_t addr
Definition ads1015.cpp:14
return FLASH_RETURN_SUCCESS
Definition flash_int.cpp:80
int intFlashErase(flashaddr_t address, size_t size)
Erase the sectors containing the span of size bytes starting at address.
bool intFlashIsErased(flashaddr_t address, size_t size)
Check if the size bytes of flash memory starting at address are erased.
Definition flash_int.cpp:89
blt_addr FlashGetUserProgBaseAddress()

Referenced by NvmErase().

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

◆ FlashGetUserProgBaseAddress()

blt_addr FlashGetUserProgBaseAddress ( void  )

Definition at line 13 of file openblt_flash.cpp.

13 {
14#ifdef STM32H7XX
15 return FLASH_BASE + 128 * 1024;
16#else // not STM32H7
17 return FLASH_BASE + 32 * 1024;
18#endif
19}

Referenced by FlashErase(), FlashVerifyChecksum(), FlashWrite(), and NvmGetUserProgBaseAddress().

Here is the caller graph for this function:

◆ FlashInit()

void FlashInit ( void  )

Definition at line 9 of file openblt_flash.cpp.

9 {
10 // Flash already init by ChibiOS
11}

Referenced by NvmInit().

Here is the caller graph for this function:

◆ FlashVerifyChecksum()

blt_bool FlashVerifyChecksum ( void  )

Definition at line 53 of file openblt_flash.cpp.

53 {
54 // Naive check: if the first block is blank, there's no code there
56 return BLT_FALSE;
57 }
58
59 static const size_t checksumOffset = 0x1C;
60
61 // Now do the actual CRC check to ensure we didn't get stuck with a half-written firmware image
62 uint8_t* start = reinterpret_cast<uint8_t*>(FlashGetUserProgBaseAddress());
63
64 size_t imageSize = *reinterpret_cast<size_t*>(start + checksumOffset + 4);
65
66 if (imageSize > 1024 * 1024) {
67 // impossibly large size, invalid
68 return BLT_FALSE;
69 }
70
71 // part before checksum+size
72 uint32_t calcChecksum = crc32(start, checksumOffset);
73 // part after checksum+size
74 calcChecksum = crc32inc(start + checksumOffset + 4, calcChecksum, imageSize - (checksumOffset + 4));
75
76 uint32_t storedChecksum = *reinterpret_cast<uint32_t*>(start + checksumOffset);
77
78 return calcChecksum == storedChecksum ? BLT_TRUE : BLT_FALSE;
79}

Referenced by NvmVerifyChecksum().

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

◆ FlashWrite()

blt_bool FlashWrite ( blt_addr  addr,
blt_int32u  len,
blt_int8u data 
)

Definition at line 21 of file openblt_flash.cpp.

21 {
22 // don't allow overwriting the bootloader
24 return BLT_FALSE;
25 }
26
27 return (FLASH_RETURN_SUCCESS == intFlashWrite(addr, (const char*)data, len)) ? BLT_TRUE : BLT_FALSE;
28
29 return BLT_TRUE;
30}
int intFlashWrite(flashaddr_t address, const char *buffer, size_t size)
Copy data from a buffer to the flash memory.

Referenced by NvmWrite().

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

◆ FlashWriteChecksum()

blt_bool FlashWriteChecksum ( void  )

Definition at line 49 of file openblt_flash.cpp.

49 {
50 return BLT_TRUE;
51}

Referenced by NvmDone().

Here is the caller graph for this function:

◆ isFlashDualBank()

blt_bool isFlashDualBank ( void  )

Definition at line 81 of file openblt_flash.cpp.

81 {
82#ifdef STM32F7XX
83 // cleared bit indicates dual bank
84 return (FLASH->OPTCR & FLASH_OPTCR_nDBANK) == 0 ? BLT_TRUE : BLT_FALSE;
85#else
86 return BLT_TRUE;
87#endif
88}

Go to the source code of this file.