This is an automated email from Gerrit.

Tomas Vanek (van...@fbl.cz) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/5106

-- gerrit

commit dd34cefc09ed2bcd8f540f5fbcbece508d5ee344
Author: Tomas Vanek <van...@fbl.cz>
Date:   Thu Apr 11 08:29:15 2019 +0200

    flash: ROM support
    
    The only reason to define a read-only region is that gdb needs
    a complete memory map to choose hard or soft breakpoints properly.
    
    Change-Id: I9d05cb6b91f054ad5cc9333af6b14eb433dbdc99
    Signed-off-by: Tomas Vanek <van...@fbl.cz>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index a5037b2..cec1fb4 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -5147,6 +5147,16 @@ flash bank vbank1 virtual 0x9fc00000 0 0 0 \
 @end example
 @end deffn
 
+@deffn {Flash Driver} read_only
+A stub driver without write and erase.
+Use to define a ROM region for the gdb memory map.
+
+@example
+flash bank $_CHIPNAME.sysrom read_only 0x1ff00000 0xedc0 0 0 \
+           $_TARGETNAME
+@end example
+@end deffn
+
 @subsection External Flash
 
 @deffn {Flash Driver} cfi
diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am
index 135128e..bb97a4f 100644
--- a/src/flash/nor/Makefile.am
+++ b/src/flash/nor/Makefile.am
@@ -51,6 +51,7 @@ NOR_DRIVERS = \
        %D%/psoc4.c \
        %D%/psoc5lp.c \
        %D%/psoc6.c \
+       %D%/read_only.c \
        %D%/sim3x.c \
        %D%/spi.c \
        %D%/stmsmi.c \
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index 043ff13..2d750f0 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -53,6 +53,11 @@ int flash_driver_protect(struct flash_bank *bank, int set, 
int first, int last)
        int retval;
        int num_blocks;
 
+       if (bank->driver->protect == NULL) {
+               LOG_ERROR("Flash protection is not supported.");
+               return ERROR_FLASH_OPER_UNSUPPORTED;
+       }
+
        if (bank->num_prot_blocks)
                num_blocks = bank->num_prot_blocks;
        else
@@ -68,11 +73,6 @@ int flash_driver_protect(struct flash_bank *bank, int set, 
int first, int last)
        /* force "set" to 0/1 */
        set = !!set;
 
-       if (bank->driver->protect == NULL) {
-               LOG_ERROR("Flash protection is not supported.");
-               return ERROR_FLASH_OPER_UNSUPPORTED;
-       }
-
        /* DANGER!
         *
         * We must not use any cached information about protection state!!!!
diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h
index a8edb2d..b31f7ad 100644
--- a/src/flash/nor/core.h
+++ b/src/flash/nor/core.h
@@ -97,6 +97,8 @@ struct flash_bank {
        target_addr_t base; /**< The base address of this bank */
        uint32_t size; /**< The size of this chip bank, in bytes */
 
+       bool read_only; /**< a ROM region - mainly to list in gdb memory map */
+
        int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */
        int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */
 
diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c
index 955d149..ad322a0 100644
--- a/src/flash/nor/drivers.c
+++ b/src/flash/nor/drivers.c
@@ -66,6 +66,7 @@ extern const struct flash_driver psoc5lp_flash;
 extern const struct flash_driver psoc5lp_eeprom_flash;
 extern const struct flash_driver psoc5lp_nvl_flash;
 extern const struct flash_driver psoc6_flash;
+extern const struct flash_driver read_only_flash;
 extern const struct flash_driver sim3x_flash;
 extern const struct flash_driver stellaris_flash;
 extern const struct flash_driver stm32f1x_flash;
@@ -135,6 +136,7 @@ static const struct flash_driver * const flash_drivers[] = {
        &psoc5lp_eeprom_flash,
        &psoc5lp_nvl_flash,
        &psoc6_flash,
+       &read_only_flash,
        &sim3x_flash,
        &stellaris_flash,
        &stm32f1x_flash,
diff --git a/src/flash/nor/read_only.c b/src/flash/nor/read_only.c
new file mode 100644
index 0000000..77e8b81
--- /dev/null
+++ b/src/flash/nor/read_only.c
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *   Copyright (C) 2019 by Tomas Vanek                                     *
+ *   van...@fbl.cz                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "imp.h"
+
+FLASH_BANK_COMMAND_HANDLER(rom_bank_command)
+{
+       bank->read_only = true;
+       return ERROR_OK;
+}
+
+static int rom_erase(struct flash_bank *bank, int first, int last)
+{
+       LOG_ERROR("Erase of read-only memory refused");
+       return ERROR_FAIL;
+}
+
+static int rom_write(struct flash_bank *bank, const uint8_t *buffer,
+               uint32_t offset, uint32_t count)
+{
+       LOG_ERROR("Write to read-only memory refused");
+       return ERROR_FAIL;
+}
+
+static int rom_probe(struct flash_bank *bank)
+{
+       return ERROR_OK;
+}
+
+const struct flash_driver read_only_flash = {
+       .name = "read_only",
+       .flash_bank_command = rom_bank_command,
+       .erase = rom_erase,
+       .write = rom_write,
+       .read = default_flash_read,
+       .probe = rom_probe,
+       .auto_probe = rom_probe,
+       .erase_check = default_flash_blank_check,
+
+       /* ROM driver doesn't set driver_priv, free(NULL) makes no harm */
+       .free_driver_priv = default_flash_free_driver_priv,
+};
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 95e6c04..3e92429 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1867,52 +1867,59 @@ static int gdb_memory_map(struct connection *connection,
                                "length=\"0x%x\"/>\n",
                                ram_start, p->base - ram_start);
 
-               /* 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.
-                */
-               for (j = 0; j < p->num_sectors; j++) {
-
-                       /* Maybe start a new group of sectors. */
-                       if (sector_size == 0) {
-                               if (p->sectors[j].offset + p->sectors[j].size > 
p->size) {
-                                       LOG_WARNING("The flash sector at offset 
0x%08" PRIx32
-                                               " overflows the end of %s 
bank.",
-                                               p->sectors[j].offset, p->name);
-                                       LOG_WARNING("The rest of bank will not 
show in gdb memory map.");
-                                       break;
+               if (p->read_only) {
+                       xml_printf(&retval, &xml, &pos, &size,
+                               "<memory type=\"rom\" start=\"" TARGET_ADDR_FMT 
"\" "
+                               "length=\"0x%x\"/>\n",
+                               p->base, p->size);
+               } else {
+                       /* 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.
+                        */
+                       for (j = 0; j < p->num_sectors; j++) {
+
+                               /* Maybe start a new group of sectors. */
+                               if (sector_size == 0) {
+                                       if (p->sectors[j].offset + 
p->sectors[j].size > p->size) {
+                                               LOG_WARNING("The flash sector 
at offset 0x%08" PRIx32
+                                                       " overflows the end of 
%s bank.",
+                                                       p->sectors[j].offset, 
p->name);
+                                               LOG_WARNING("The rest of bank 
will not show in gdb memory map.");
+                                               break;
+                                       }
+                                       target_addr_t start;
+                                       start = p->base + p->sectors[j].offset;
+                                       xml_printf(&retval, &xml, &pos, &size,
+                                               "<memory type=\"flash\" "
+                                               "start=\"" TARGET_ADDR_FMT "\" 
",
+                                               start);
+                                       sector_size = p->sectors[j].size;
+                                       group_len = sector_size;
+                               } else {
+                                       group_len += sector_size; /* equal to 
p->sectors[j].size */
                                }
-                               target_addr_t start;
-                               start = p->base + p->sectors[j].offset;
-                               xml_printf(&retval, &xml, &pos, &size,
-                                       "<memory type=\"flash\" "
-                                       "start=\"" TARGET_ADDR_FMT "\" ",
-                                       start);
-                               sector_size = p->sectors[j].size;
-                               group_len = sector_size;
-                       } else {
-                               group_len += sector_size; /* equal to 
p->sectors[j].size */
-                       }
 
-                       /* Does this finish a group of sectors?
-                        * If not, continue an already-started group.
-                        */
-                       if (j < p->num_sectors - 1
-                                       && p->sectors[j + 1].size == sector_size
-                                       && p->sectors[j + 1].offset == 
p->sectors[j].offset + sector_size
-                                       && p->sectors[j + 1].offset + 
p->sectors[j + 1].size <= p->size)
-                               continue;
+                               /* Does this finish a group of sectors?
+                                * If not, continue an already-started group.
+                                */
+                               if (j < p->num_sectors - 1
+                                               && p->sectors[j + 1].size == 
sector_size
+                                               && p->sectors[j + 1].offset == 
p->sectors[j].offset + sector_size
+                                               && p->sectors[j + 1].offset + 
p->sectors[j + 1].size <= p->size)
+                                       continue;
 
-                       xml_printf(&retval, &xml, &pos, &size,
-                               "length=\"0x%x\">\n"
-                               "<property name=\"blocksize\">"
-                               "0x%x</property>\n"
-                               "</memory>\n",
-                               group_len,
-                               sector_size);
-                       sector_size = 0;
+                               xml_printf(&retval, &xml, &pos, &size,
+                                       "length=\"0x%x\">\n"
+                                       "<property name=\"blocksize\">"
+                                       "0x%x</property>\n"
+                                       "</memory>\n",
+                                       group_len,
+                                       sector_size);
+                               sector_size = 0;
+                       }
                }
 
                ram_start = p->base + p->size;

-- 


_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to