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

Functions

static void FlashBufferReset ()
 
static blt_bool FlashBufferFlush ()
 
static blt_bool FlashBufferedWrite (blt_addr addr, blt_int32u len, blt_int8u *data)
 
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)
 

Variables

static blt_int8u flashBuffer [FLASH_ECC_LINE_SIZE]
 
static blt_addr flashAddr = 0x0
 

Function Documentation

◆ FlashBufferedWrite()

static blt_bool FlashBufferedWrite ( blt_addr  addr,
blt_int32u  len,
blt_int8u data 
)
static

Definition at line 39 of file openblt_flash.cpp.

40{
41 while (len) {
42 if ((addr & FLASH_WRITE_ADDR_MASK) != flashAddr) {
43 // crossing ECC line boundary
45
46 flashAddr = addr & FLASH_WRITE_ADDR_MASK;
47 }
48
49 off_t off = addr - flashAddr;
50 size_t chunk = minI(sizeof(flashBuffer) - off, len);
51 memcpy(flashBuffer + off, data, chunk);
52
53 addr += chunk;
54 data += chunk;
55 len -= chunk;
56 }
57
58 return BLT_TRUE;
59}
constexpr uint8_t addr
Definition ads1015.cpp:14
beuint16_t off
static blt_int8u flashBuffer[FLASH_ECC_LINE_SIZE]
static blt_bool FlashBufferFlush()
static blt_addr flashAddr

Referenced by FlashWrite().

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

◆ FlashBufferFlush()

static blt_bool FlashBufferFlush ( )
static

Definition at line 26 of file openblt_flash.cpp.

27{
28 if (flashAddr == 0x0) {
29 return BLT_TRUE;
30 }
31
32 int result = intFlashWrite(flashAddr, (const char*)flashBuffer, sizeof(flashBuffer));
33
35
36 return (result == FLASH_RETURN_SUCCESS) ? BLT_TRUE : BLT_FALSE;
37}
return FLASH_RETURN_SUCCESS
Definition flash_int.cpp:80
int intFlashWrite(flashaddr_t address, const char *buffer, size_t size)
Copy data from a buffer to the flash memory.
static void FlashBufferReset()

Referenced by FlashBufferedWrite(), and FlashDone().

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

◆ FlashBufferReset()

static void FlashBufferReset ( )
static

Definition at line 20 of file openblt_flash.cpp.

21{
22 memset(flashBuffer, 0xff, sizeof(flashBuffer));
23 flashAddr = 0;
24}

Referenced by FlashBufferFlush(), and FlashInit().

Here is the caller graph for this function:

◆ 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}

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}
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}

Referenced by NvmInit().

Here is the call graph for this function:
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}
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}

Variable Documentation

◆ flashAddr

blt_addr flashAddr = 0x0
static

Definition at line 15 of file openblt_flash.cpp.

Referenced by FlashBufferedWrite(), FlashBufferFlush(), and FlashBufferReset().

◆ flashBuffer

blt_int8u flashBuffer[FLASH_ECC_LINE_SIZE]
static

Definition at line 14 of file openblt_flash.cpp.

Referenced by FlashBufferedWrite(), FlashBufferFlush(), and FlashBufferReset().

Go to the source code of this file.