- retval = dap_run(dap);
- if (retval != ERROR_OK)
- break;
-
- count -= 2;
- address += 2;
- buffer += 2;
- }
-
- return retval;
-}
-
-static int mem_ap_write_buf_packed_u8(struct adiv5_dap *dap,
- uint8_t *buffer, int count, uint32_t address)
-{
- int retval = ERROR_OK;
- int wcount, blocksize, writecount, i;
-
- wcount = count;
-
- while (wcount > 0)
- {
- int nbytes;
-
- /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
- blocksize = max_tar_block_size(dap->tar_autoincr_block, address);
-
- if (wcount < blocksize)
- blocksize = wcount;
-
- retval = dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_PACKED, address);
- if (retval != ERROR_OK)
- return retval;
- writecount = blocksize;
-
- do
- {
- nbytes = MIN(writecount, 4);
-
- if (nbytes < 4)
- {
- retval = mem_ap_write_buf_u8(dap, buffer, nbytes, address);
- if (retval != ERROR_OK)
- {
- LOG_WARNING("Block write error address "
- "0x%" PRIx32 ", count 0x%x",
- address, count);
- return retval;
- }
-
- address += nbytes;
- }
- else
- {
- uint32_t outvalue;
- memcpy(&outvalue, buffer, sizeof(uint32_t));
-
- for (i = 0; i < nbytes; i++)
- {
- *((uint8_t*)buffer + (address & 0x3)) = outvalue;
- outvalue >>= 8;
- address++;
- }
-
- memcpy(&outvalue, buffer, sizeof(uint32_t));
- retval = dap_queue_ap_write(dap,
- AP_REG_DRW, outvalue);
- if (retval != ERROR_OK)
- break;
-
- if ((retval = dap_run(dap)) != ERROR_OK)
- {
- LOG_WARNING("Block write error address "
- "0x%" PRIx32 ", count 0x%x",
- address, count);
- return retval;
- }
- }
-
- buffer += nbytes;
- writecount -= nbytes;
-
- } while (writecount);
- wcount -= blocksize;