rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
flash.h File Reference

Functions

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

Function Documentation

◆ FlashDone()

blt_bool FlashDone ( void  )

Definition at line 104 of file openblt_flash.cpp.

104 {
105#ifdef STM32H7XX
107#endif
108 return BLT_TRUE;
109}
static blt_bool FlashBufferFlush()

Referenced by NvmDone().

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

◆ FlashErase()

blt_bool FlashErase ( blt_addr  addr,
blt_int32u  len 
)

Definition at line 91 of file openblt_flash.cpp.

91 {
92 // don't allow erasing the bootloader
94 return BLT_FALSE;
95 }
96
97 if (!intFlashIsErased(addr, len)) {
98 return (FLASH_RETURN_SUCCESS == intFlashErase(addr, len)) ? BLT_TRUE : BLT_FALSE;
99 }
100
101 return BLT_TRUE;
102}
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 70 of file openblt_flash.cpp.

70 {
71#ifdef STM32H7XX
72 return FLASH_BASE + 128 * 1024;
73#else // not STM32H7
74 return FLASH_BASE + 32 * 1024;
75#endif
76}

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

Here is the caller graph for this function:

◆ FlashInit()

void FlashInit ( void  )

Definition at line 63 of file openblt_flash.cpp.

63 {
64 // Flash already init by ChibiOS
65#ifdef STM32H7XX
67#endif
68}
static void FlashBufferReset()

Referenced by NvmInit().

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

◆ FlashReinit()

void FlashReinit ( void  )

Referenced by NvmReinit().

Here is the caller graph for this function:

◆ FlashVerifyChecksum()

blt_bool FlashVerifyChecksum ( void  )

Definition at line 115 of file openblt_flash.cpp.

115 {
116 // Naive check: if the first block is blank, there's no code there
118 return BLT_FALSE;
119 }
120
121 static const size_t checksumOffset = 0x1C;
122
123 // Now do the actual CRC check to ensure we didn't get stuck with a half-written firmware image
124 uint8_t* start = reinterpret_cast<uint8_t*>(FlashGetUserProgBaseAddress());
125
126 size_t imageSize = *reinterpret_cast<size_t*>(start + checksumOffset + 4);
127
128 if (imageSize > 1024 * 1024) {
129 // impossibly large size, invalid
130 return BLT_FALSE;
131 }
132
133 // part before checksum+size
134 uint32_t calcChecksum = crc32(start, checksumOffset);
135 // part after checksum+size
136 calcChecksum = crc32inc(start + checksumOffset + 4, calcChecksum, imageSize - (checksumOffset + 4));
137
138 uint32_t storedChecksum = *reinterpret_cast<uint32_t*>(start + checksumOffset);
139
140 return calcChecksum == storedChecksum ? BLT_TRUE : BLT_FALSE;
141}

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 78 of file openblt_flash.cpp.

78 {
79 // don't allow overwriting the bootloader
81 return BLT_FALSE;
82 }
83
84#ifdef STM32H7XX
85 return FlashBufferedWrite(addr, len, data);
86#else // not STM32H7
87 return (FLASH_RETURN_SUCCESS == intFlashWrite(addr, (const char*)data, len)) ? BLT_TRUE : BLT_FALSE;
88#endif
89}
int intFlashWrite(flashaddr_t address, const char *buffer, size_t size)
Copy data from a buffer to the flash memory.
static blt_bool FlashBufferedWrite(blt_addr addr, blt_int32u len, blt_int8u *data)

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 111 of file openblt_flash.cpp.

111 {
112 return BLT_TRUE;
113}

Referenced by NvmDone().

Here is the caller graph for this function:

◆ isFlashDualBank()

blt_bool isFlashDualBank ( void  )

Definition at line 143 of file openblt_flash.cpp.

143 {
144#ifdef STM32F7XX
145 // cleared bit indicates dual bank
146 return (FLASH->OPTCR & FLASH_OPTCR_nDBANK) == 0 ? BLT_TRUE : BLT_FALSE;
147#else
148 return BLT_TRUE;
149#endif
150}

Go to the source code of this file.