| 231 | } |
| 232 | |
| 233 | error_t flash_decoder_write(uint32_t addr, const uint8_t *data, uint32_t size) |
| 234 | { |
| 235 | error_t status; |
| 236 | flash_decoder_printf("flash_decoder_write(addr=0x%x, size=0x%x)\r\n", addr, size); |
| 237 | |
| 238 | if (DECODER_STATE_OPEN != state) { |
| 239 | util_assert(0); |
| 240 | return ERROR_INTERNAL; |
| 241 | } |
| 242 | |
| 243 | // Set the initial address the first time through |
| 244 | if (!initial_addr_set) { |
| 245 | initial_addr = addr; |
| 246 | current_addr = initial_addr; |
| 247 | flash_decoder_printf(" initial_addr=0x%x\r\n", initial_addr); |
| 248 | initial_addr_set = true; |
| 249 | } |
| 250 | |
| 251 | if (!flash_initialized) { |
| 252 | uint32_t copy_size; |
| 253 | bool flash_type_known = false; |
| 254 | bool sequential; |
| 255 | // Check if the data is sequential |
| 256 | sequential = addr == current_addr; |
| 257 | current_addr += size; |
| 258 | |
| 259 | // Buffer data until the flash type is known |
| 260 | if (sequential) { |
| 261 | // Copy data into buffer |
| 262 | copy_size = MIN(size, sizeof(flash_buf) - flash_buf_pos); |
| 263 | memcpy(&flash_buf[flash_buf_pos], data, copy_size); |
| 264 | flash_buf_pos += copy_size; |
| 265 | flash_decoder_printf(" buffering %i bytes\r\n", copy_size); |
| 266 | // Update vars so they no longer include the buffered data |
| 267 | data += copy_size; |
| 268 | size -= copy_size; |
| 269 | addr += copy_size; |
| 270 | |
| 271 | // If enough data has been buffered then determine the type |
| 272 | if (flash_buf_pos >= sizeof(flash_buf)) { |
| 273 | util_assert(sizeof(flash_buf) == flash_buf_pos); |
| 274 | // Determine flash type and get info for it |
| 275 | flash_type = flash_decoder_detect_type(flash_buf, flash_buf_pos, initial_addr, true); |
| 276 | flash_decoder_printf(" Buffering complete, setting flash_type=%i\r\n", flash_type); |
| 277 | flash_type_known = true; |
| 278 | } |
| 279 | } else { |
| 280 | flash_type = FLASH_DECODER_TYPE_TARGET; |
| 281 | flash_decoder_printf(" Non sequential addr, setting flash_type=%i\r\n", flash_type); |
| 282 | flash_type_known = true; |
| 283 | } |
| 284 | |
| 285 | // If flash type is known initialize the flash manager |
| 286 | if (flash_type_known) { |
| 287 | const flash_intf_t *flash_intf; |
| 288 | uint32_t flash_start_addr; |
| 289 | status = flash_decoder_get_flash(flash_type, initial_addr, true, &flash_start_addr, &flash_intf); |
| 290 |
no test coverage detected