From: Nathael Pajani Date: Mon, 21 May 2012 17:12:09 +0000 (+0200) Subject: Adding erase flash support to prog X-Git-Tag: v1.0~18 X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=e4ee544d00f2da2b5ef6ad912e43a71f9c30e89d;p=soft%2Ftools%2Flpctools Adding erase flash support to prog --- diff --git a/prog_commands.c b/prog_commands.c index 782cb6b..0184321 100644 --- a/prog_commands.c +++ b/prog_commands.c @@ -27,6 +27,8 @@ #include "isp_commands.h" #include "parts.h" +#define REP_BUFSIZE 40 + extern int trace_on; @@ -73,9 +75,46 @@ int dump_to_file(struct part_desc* part, char* filename) int erase_flash(struct part_desc* part) { int ret = 0; + int i = 0; + + /* Unlock device */ + ret = isp_cmd_unlock(1); + if (ret != 0) { + printf("Unable to unlock device, aborting.\n"); + return -1; + } + for (i=0; i<(int)(part->flash_nb_sectors); i++) { + ret = isp_send_cmd_sectors("blank-check", 'I', i, i, 1); + if (ret == CMD_SUCCESS) { + /* sector already blank, preserve the flash, skip to next one :) */ + continue; + } + if (ret < 0) { + /* Error ? */ + printf("Initial blank check error (%d) at sector %d!\n", ret, i); + return ret; + } else { + /* Controller replyed with first non blank offset and data, remove it from buffer */ + char buf[REP_BUFSIZE]; + usleep( 2000 ); + isp_serial_read(buf, REP_BUFSIZE, 3); + } + /* Sector not blank, perform erase */ + ret = isp_send_cmd_sectors("prepare-for-write", 'P', i, i, 1); + if (ret != 0) { + printf("Error (%d) when trying to prepare sector %d for erase operation!\n", ret, i); + return ret; + } + ret = isp_send_cmd_sectors("erase", 'E', i, i, 1); + if (ret != 0) { + printf("Error (%d) when trying to erase sector %d!\n", ret, i); + return ret; + } + } + printf("Flash now all blank.\n"); - return ret; + return 0; } int start_prog(struct part_desc* part)