From: Nathael Pajani Date: Fri, 18 May 2012 23:45:30 +0000 (+0200) Subject: Modified to use new helper functions X-Git-Tag: v1.0~22 X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=1f92cfabb654cf52b928b5039b209a7c539b70a8;p=soft%2Ftools%2Flpctools Modified to use new helper functions --- diff --git a/prog_commands.c b/prog_commands.c index 6864ee9..4446bb6 100644 --- a/prog_commands.c +++ b/prog_commands.c @@ -44,18 +44,28 @@ int get_ids(void) int dump_to_file(struct part_desc* part, char* filename) { - int ret = 0; - int argc = 3; - char* args[3]; - #define STR_SIZE 15 - char flash_size[STR_SIZE]; + int ret = 0, len = 0; + char* data; + + /* Allocate buffer */ + data = malloc(part->flash_size); + if (data == NULL) { + printf("Unable to allocate read buffer, asked %u.\n", part->flash_size); + return -10; + } + + /* Read data */ + len = isp_read_memory(data, part->flash_base, part->flash_size); + if (len != (int)(part->flash_size)) { + printf("Read returned %d bytes instead of %u.\n", len, part->flash_size); + } + + /* Write data to file */ + ret = isp_buff_to_file(data, part->flash_size, filename); - args[0] = "0x00000000"; - snprintf(flash_size, STR_SIZE, "0x%08x", part->flash_size); /* Get count from part ID */ - args[1] = flash_size; - args[2] = filename; + /* Free memory */ + free(data); - isp_cmd_read_memory(argc, args); return ret; }