|
35 | 35 | #include "crc32.h" |
36 | 36 | #include "binary_update.h" |
37 | 37 | #include "flash_adapter.h" |
| 38 | +#include "security.h" |
38 | 39 | #include "signature.h" |
39 | 40 |
|
40 | 41 | __attribute__ ((section(".restart_info"))) |
@@ -146,30 +147,28 @@ BinaryUpdate_erase(uint32_t firmware_size) { |
146 | 147 | } |
147 | 148 |
|
148 | 149 | bool |
149 | | -BinaryUpdate_write(uint8_t* write_buffer, const uint32_t flash_length, uint32_t* crc) { |
| 150 | +BinaryUpdate_write(uint8_t* write_buffer, const uint32_t data_length, uint32_t* crc) { |
| 151 | + |
150 | 152 | bool success = false; |
151 | | - // cppcheck-suppress misra-c2012-18.8; PACKET_SIZE is defined as 256 or W25Q_PAGE_SIZE, depends on EXTERNAL_FLASH |
152 | | - uint8_t readout_buffer[PACKET_SIZE]; |
153 | | - static uint32_t index = 0U; |
154 | | - const uint32_t address_addition = index * PACKET_SIZE; |
155 | | - uint64_t address = s_address + address_addition; |
156 | 153 |
|
157 | | - success = FlashAdapter_program((uint32_t)address, write_buffer, flash_length); |
| 154 | + success = FlashAdapter_program((uint32_t)s_address, write_buffer, data_length); |
158 | 155 |
|
159 | 156 | if (success) { |
160 | | - success = FlashAdapter_readBytes((uint32_t)address, readout_buffer, flash_length); |
| 157 | + // cppcheck-suppress misra-c2012-18.8; |
| 158 | + uint8_t readout_buffer[data_length]; |
| 159 | + success = FlashAdapter_readBytes((uint32_t)s_address, readout_buffer, data_length); |
161 | 160 |
|
162 | 161 | if (success) { |
163 | | - *crc = CalculateCRC32(readout_buffer, flash_length, *crc, 0U, false, false, false); |
164 | | - for (uint32_t i = 0U; (success) && (i < flash_length); ++i) { |
| 162 | + *crc = CalculateCRC32(readout_buffer, data_length, *crc, 0U, false, false, false); |
| 163 | + for (uint32_t i = 0U; (success) && (i < data_length); ++i) { |
165 | 164 | if (write_buffer[i] != readout_buffer[i]) { |
166 | 165 | success = false; |
167 | 166 | } |
168 | 167 | } |
169 | 168 | } |
170 | 169 | } |
171 | 170 |
|
172 | | - ++index; |
| 171 | + s_address += data_length; |
173 | 172 |
|
174 | 173 | return success; |
175 | 174 | } |
|
0 commit comments