static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size) { const program_target_t *const flash = target_device.flash_algo; // check if security bits were set if (1 == security_bits_set(addr, (uint8_t *)buf, size)) { return ERROR_SECURITY_BITS; } while (size > 0) { uint32_t write_size = MIN(size, flash->program_buffer_size); // Write page to buffer if (!swd_write_memory(flash->program_buffer, (uint8_t *)buf, write_size)) { return ERROR_ALGO_DATA_SEQ; } // Run flash programming if (!swd_flash_syscall_exec(&flash->sys_call_s, flash->program_page, addr, flash->program_buffer_size, flash->program_buffer, 0)) { return ERROR_WRITE; } addr += write_size; buf += write_size; size -= write_size; } return ERROR_SUCCESS; }
static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size) { const program_target_t *const flash = target_device.flash_algo; // check if security bits were set if (1 == security_bits_set(addr, (uint8_t *)buf, size)) { return ERROR_SECURITY_BITS; } while (size > 0) { uint32_t write_size = MIN(size, flash->program_buffer_size); // Write page to buffer if (!swd_write_memory(flash->program_buffer, (uint8_t *)buf, write_size)) { return ERROR_ALGO_DATA_SEQ; } // Run flash programming if (!swd_flash_syscall_exec(&flash->sys_call_s, flash->program_page, addr, flash->program_buffer_size, flash->program_buffer, 0)) { return ERROR_WRITE; } if (config_get_automation_allowed()) { // Verify data flashed if in automation mode if (flash->verify != 0) { if (!swd_flash_syscall_exec(&flash->sys_call_s, flash->verify, addr, write_size, flash->program_buffer, 0)) { return ERROR_WRITE; } } else { while (write_size > 0) { uint8_t rb_buf[16]; uint32_t verify_size = MIN(write_size, sizeof(rb_buf)); if (!swd_read_memory(addr, rb_buf, verify_size)) { return ERROR_ALGO_DATA_SEQ; } if (memcmp(buf, rb_buf, verify_size) != 0) { return ERROR_WRITE; } addr += verify_size; buf += verify_size; size -= verify_size; write_size -= verify_size; } continue; } } addr += write_size; buf += write_size; size -= write_size; } return ERROR_SUCCESS; }