* perform read-memory operation
* read 'count' bytes from 'addr' to 'data' buffer
*/
-int isp_read_memory(char* data, uint32_t addr, unsigned int count)
+int isp_read_memory(char* data, uint32_t addr, unsigned int count, unsigned int uuencoded)
{
/* Serial communication */
char buf[SERIAL_BUFSIZE];
return ret;
}
+ if (uuencoded == 0) {
+ if (SERIAL_BUFSIZE < count) {
+ printf("Error when trying to read %u bytes of memory, buffer too small.\n", count);
+ printf("Read %d max bytes at a time.\n", SERIAL_BUFSIZE);
+ return -7;
+ }
+ len = isp_serial_read(buf, SERIAL_BUFSIZE, count);
+ if (len <= 0) {
+ printf("Error reading memory.\n");
+ return -6;
+ }
+ /* Wait some time before reading possible remaining data */
+ usleep( 1000 );
+ len += isp_serial_read((buf + len), (SERIAL_BUFSIZE - len), count);
+ if (len < 0) { /* Length may be null, as we may already have received everything */
+ printf("Error reading memory.\n");
+ return -5;
+ }
+ return len;
+ }
+
/* Now, find the number of blocks of the reply. */
blocks = get_nb_blocks(count, "Reading");
return -8;
}
+ /* First check if we must UU-encode data */
+ if (perform_uuencode == 0) {
+ if (isp_serial_write(data, count) != (int)count) {
+ printf("Error sending raw binary data.\n");
+ return -7;
+ }
+ /* No checks required, we are done */
+ return 0;
+ }
/* Now, find the number of blocks of data to send. */
blocks = get_nb_blocks(count, "Sending");
if (datasize >= MAX_DATA_BLOCK_SIZE) {
datasize = MAX_DATA_BLOCK_SIZE;
}
- if (perform_uuencode == 0) {
- if (isp_serial_write(data + total_bytes_sent, datasize) != (int)datasize) {
- printf("Error sending raw binary data.\n");
- ret = -7;
- break;
- } else {
- /* No checks required */
- return ret;
- }
- }
/* uuencode data */
encoded_size = isp_uu_encode(buf, data + total_bytes_sent, datasize);
* perform read-memory operation
* read 'count' bytes from 'addr' to 'data' buffer
*/
-int isp_read_memory(char* data, uint32_t addr, unsigned int count);
+int isp_read_memory(char* data, uint32_t addr, unsigned int count, unsigned int uuencoded);
/*
* write-to-ram
/*
* read-memory
- * aruments : address count file
- * read 'count' bytes from 'address', store then in 'file'
+ * aruments : address count file uuencoded
+ * read 'count' bytes from 'address', store then in 'file', and maybe decode uuencoded data.
*/
int isp_cmd_read_memory(int arg_count, char** args)
{
/* Reply handling */
char* data;
int ret = 0, len = 0;
+ unsigned int uuencoded = 1;
/* Check read-memory arguments */
- if (arg_count != 3) {
+ if (arg_count < 3) {
printf("read-memory command needs address and count. Both must be multiple of 4.\n");
return -12;
}
return -11;
}
out_file_name = args[2];
+ if (arg_count > 3) {
+ uuencoded = strtoul(args[3], NULL, 0);
+ }
/* Allocate buffer */
data = malloc(count);
}
/* Read data */
- len = isp_read_memory(data, addr, count);
+ len = isp_read_memory(data, addr, count, uuencoded);
if (len != (int)count) {
printf("Read returned %d bytes instead of %lu.\n", len, count);
}
" command specific arguments are as follow:\n" \
" \t unlock \n" \
" \t write-to-ram address file uuencode : send 'file' to 'address' in ram with or without uuencoding\n" \
- " \t read-memory address count file : read 'count' bytes from 'address', store then in 'file'\n" \
+ " \t read-memory address count file uuencoded : read 'count' bytes from 'address', store then in 'file' (maybe decode)\n" \
" \t prepare-for-write first last : prepare sectors from 'first' to 'last' for write operation\n" \
" \t copy-ram-to-flash flash_addr ram_addr count : copy count bytes (256, 512, 1024 or 4096)\n" \
" \t from 'ram_addr' to 'flash_addr'\n" \
}
/* Read data */
- len = isp_read_memory(data, part->flash_base, part->flash_size);
+ len = isp_read_memory(data, part->flash_base, part->flash_size, part->uuencode);
if (len != (int)(part->flash_size)) {
printf("Read returned %d bytes instead of %u.\n", len, part->flash_size);
}
int ret = 0, len = 0;
uint32_t addr = 0;
- len = isp_read_memory((char*)&addr, (part->flash_base + part->reset_vector_offset), sizeof(addr));
+ len = isp_read_memory((char*)&addr, (part->flash_base + part->reset_vector_offset), sizeof(addr), part->uuencode);
if (len != sizeof(addr)) {
printf("Unable to read reset address from flash.\n");
return len;