Report each region of same-size sectors separately, instead
of incorrectly reporting that every sector has the same size.
This fixes a longstanding bug, exposed by other recent bugfixes
in flash handling.
---
Sanity tested with: single and dual bank with uniform sectors;
dual bank CFI with non-uniform sectors (top boot).
src/server/gdb_server.c | 81 ++++++++++++++++++++++++++++------------------
1 file changed, 50 insertions(+), 31 deletions(-)
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1613,22 +1613,6 @@ static int decode_xfer_read(char *buf, c
return 0;
}
-static int gdb_calc_blocksize(struct flash_bank *bank)
-{
- uint32_t i;
- uint32_t block_size = 0xffffffff;
-
- /* loop through all sectors and return smallest sector size */
-
- for (i = 0; i < (uint32_t)bank->num_sectors; i++)
- {
- if (bank->sectors[i].size < block_size)
- block_size = bank->sectors[i].size;
- }
-
- return block_size;
-}
-
static int compare_bank (const void * a, const void * b)
{
struct flash_bank *b1, *b2;
@@ -1666,7 +1650,6 @@ static int gdb_memory_map(struct connect
int offset;
int length;
char *separator;
- int blocksize;
uint32_t ram_start = 0;
int i;
@@ -1701,29 +1684,65 @@ static int gdb_memory_map(struct connect
compare_bank);
for (i = 0; i < flash_get_bank_count(); i++) {
+ int j;
+ unsigned sector_size = 0;
+ uint32_t start, end;
+
p = banks[i];
+ start = p->base;
+ end = p->base + p->size;
if (ram_start < p->base)
xml_printf(&retval, &xml, &pos, &size,
"<memory type=\"ram\" start=\"0x%x\" "
"length=\"0x%x\"/>\n",
- ram_start, p->base-ram_start);
+ ram_start, p->base - ram_start);
- /* If device has uneven sector sizes, eg. str7, lpc
- * we pass the smallest sector size to gdb memory map
- *
- * FIXME Don't lie about flash regions with different
- * sector sizes; just tell GDB about each region as
- * if it were a separate flash device.
+ /* Report adjacent groups of same-size sectors. So for
+ * example top boot CFI flash will list an initial region
+ * with several large sectors (maybe 128KB) and several
+ * smaller ones at the end (maybe 32KB). STR7 will have
+ * regions with 8KB, 32KB, and 64KB sectors; etc.
*/
- blocksize = gdb_calc_blocksize(p);
+ for (j = 0; j < p->num_sectors; j++) {
+
+ /* start a new group of sectors */
+ if (sector_size == 0) {
+ start = p->base + p->sectors[j].offset;
+ xml_printf(&retval, &xml, &pos, &size,
+ "<memory type=\"flash\" "
+ "start=\"0x%x\" ",
+ start);
+ sector_size = p->sectors[j].size;
+ continue;
+ }
+
+ /* finish a group of sectors */
+ if (p->sectors[j].size != sector_size) {
+ xml_printf(&retval, &xml, &pos, &size,
+ "length=\"0x%x\">\n"
+ "<property name=\"blocksize\">"
+ "0x%x</property>\n"
+ "</memory>\n",
+ p->sectors[j].offset - start,
+ sector_size);
+ sector_size = 0;
+ }
+
+ /* else we continue a group we started */
+ }
+
+ /* terminate the last group of sectors */
+ if (sector_size) {
+ xml_printf(&retval, &xml, &pos, &size,
+ "length=\"0x%x\">\n"
+ "<property name=\"blocksize\">"
+ "0x%x</property>\n"
+ "</memory>\n",
+ p->size - start,
+ sector_size);
+ }
- xml_printf(&retval, &xml, &pos, &size,
- "<memory type=\"flash\" start=\"0x%x\" "
- "length=\"0x%x\">\n" \
- "<property name=\"blocksize\">0x%x</property>\n" \
- "</memory>\n", \
- p->base, p->size, blocksize);
ram_start = p->base + p->size;
}
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development