do this in this order now. we have already enabled prog mode
so now erase, then re-enable. this is a bit messy and may
cause a future bug if not understood.
Index: adapter-stk500v2.c
===================================================================
--- adapter-stk500v2.c (revision 119)
+++ adapter-stk500v2.c (working copy)
@@ -270,6 +270,25 @@
}
}
+static void chip_erase (stk_adapter_t *a)
+{
+ unsigned char cmd [7] = { CMD_CHIP_ERASE_ISP,
+ 0, /* eraseDelay? */
+ 0, /* pollMethod? */
+ 0, /* cmd1? */
+ 0, /* cmd2? */
+ 0, /* cmd3? */
+ 0 /* cmd4? */
+ };
+ unsigned char response [2];
+
+ if (! send_receive (a, cmd, 7, response, 2) || response[0] != cmd[0] ||
+ response[1] != STATUS_CMD_OK) {
+ fprintf (stderr, "Cannot erase chip.\n");
+ exit (-1);
+ }
+}
+
static void prog_disable (stk_adapter_t *a)
{
unsigned char cmd [3] = { CMD_LEAVE_PROGMODE_ISP,
@@ -431,7 +450,19 @@
fprintf (stderr, "stk: program word at %08x: %08x\n", addr, word);
}
+
/*
+ * Erase all flash memory.
+ */
+static void stk_erase_chip (adapter_t *adapter)
+{
+ stk_adapter_t *a = (stk_adapter_t*) adapter;
+
+ chip_erase (a);
+ prog_enable (a);
+}
+
+/*
* Verify a block of memory (1024 bytes).
*/
static void stk_verify_data (adapter_t *adapter,
@@ -612,6 +643,7 @@
a->adapter.user_start = 0x1d000000;
a->adapter.user_nbytes = 512 * 1024;
+ a->adapter.boot_nbytes = 12288;
printf (" Program area: %08x-%08x\n", a->adapter.user_start,
a->adapter.user_start + a->adapter.user_nbytes - 1);
@@ -622,5 +654,6 @@
a->adapter.verify_data = stk_verify_data;
a->adapter.program_block = stk_program_block;
a->adapter.program_word = stk_program_word;
+ a->adapter.erase_chip = stk_erase_chip;
return &a->adapter;
}