Flash memory size not aligned to address
authorKevin Buettner <kevinb@redhat.com>
Wed, 11 Oct 2017 05:47:01 +0000 (22:47 -0700)
committerKevin Buettner <kevinb@redhat.com>
Wed, 11 Oct 2017 07:50:29 +0000 (00:50 -0700)
(This patch is from Mark Rages <markrages@gmail.com>.)

The Nordic nRF52 memory map, reported from black magic probe:

Num Enb Low Addr High Addr Attrs
0 y 0x00000000 0x00080000 flash blocksize 0x1000 nocache
1 y 0x10001000 0x10001210 flash blocksize 0x210 nocache
2 y 0x20000000 0x20010000 rw nocache

The region at 0x10001000 is "UICR" and it is a section of flash that is
erased all at once.

Notice the odd size: 0x210 is the size of the region defined in the
datasheet.

But because the block size was listed as 0x210, gdb was insisting on
issuing two erase commands divisible by 0x210, starting below 0x10001000.

This patch fixes it by doing the alignment computation from the start of
the region, not from address 0.

gdb/ChangeLog:

* target-memory.c (block_boundaries): Fix for block address not
aligned on block size.

gdb/ChangeLog
gdb/target-memory.c

index 4f9fac2..459f0ff 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-11  Mark Rages  <markrages@gmail.com>
+
+       * target-memory.c (block_boundaries): Fix for block address not
+       aligned on block size.
+
 2017-10-10  Pedro Alves <palves@redhat.com>
            Tom Tromey  <tom@tromey.com>
 
index 1c8faa8..7f048de 100644 (file)
@@ -138,14 +138,18 @@ block_boundaries (CORE_ADDR address, CORE_ADDR *begin, CORE_ADDR *end)
 {
   struct mem_region *region;
   unsigned blocksize;
+  CORE_ADDR offset_in_region;
 
   region = lookup_mem_region (address);
   gdb_assert (region->attrib.mode == MEM_FLASH);
   blocksize = region->attrib.blocksize;
+
+  offset_in_region = address - region->lo;
+
   if (begin)
-    *begin = address / blocksize * blocksize;
+    *begin = region->lo + offset_in_region / blocksize * blocksize;
   if (end)
-    *end = (address + blocksize - 1) / blocksize * blocksize;
+    *end = region->lo + (offset_in_region + blocksize - 1) / blocksize * blocksize;
 }
 
 /* Given the list of memory requests to be WRITTEN, this function