at91smad: Fixes to 'samd_protect'
[openocd.git] / src / flash / nor / at91sam4l.c
index bb84185205b5834ae91745911f138e46fe629b33..0139f61c87b84dc5797301c20abe8f415341af0f 100644 (file)
@@ -82,7 +82,7 @@ struct sam4l_chip_info {
 };
 
 /* These are taken from Table 9-1 in 42023E-SAM-07/2013 */
-static struct sam4l_chip_info sam4l_known_chips[] = {
+static const struct sam4l_chip_info sam4l_known_chips[] = {
        { 0xAB0B0AE0, 0x1400000F, "ATSAM4LC8C" },
        { 0xAB0A09E0, 0x0400000F, "ATSAM4LC4C" },
        { 0xAB0A07E0, 0x0400000F, "ATSAM4LC2C" },
@@ -104,13 +104,13 @@ static struct sam4l_chip_info sam4l_known_chips[] = {
 };
 
 /* Meaning of SRAMSIZ field in CHIPID, see 9.3.1 in 42023E-SAM-07/2013 */
-static uint16_t sam4l_ram_sizes[16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 };
+static const uint16_t sam4l_ram_sizes[16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 };
 
 /* Meaning of PSZ field in FPR, see 14.10.4 in 42023E-SAM-07/2013 */
 static const uint16_t sam4l_page_sizes[8] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 };
 
 struct sam4l_info {
-       struct sam4l_chip_info *details;
+       const struct sam4l_chip_info *details;
 
        uint32_t flash_kb;
        uint32_t ram_kb;
@@ -230,7 +230,7 @@ FLASH_BANK_COMMAND_HANDLER(sam4l_flash_bank_command)
        return ERROR_OK;
 }
 
-static struct sam4l_chip_info *sam4l_find_chip_name(uint32_t id, uint32_t exid)
+static const struct sam4l_chip_info *sam4l_find_chip_name(uint32_t id, uint32_t exid)
 {
        unsigned int i;
 
@@ -495,10 +495,12 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
 /* Write an entire page from host buffer 'buf' to page-aligned 'address' in the
  * Flash. */
 static int sam4l_write_page(struct sam4l_info *chip, struct target *target,
-               uint32_t address, uint8_t *buf)
+               uint32_t address, const uint8_t *buf)
 {
        int res;
 
+       LOG_DEBUG("sam4l_write_page address=%08" PRIx32, address);
+
        /* Clear the page buffer before we write to it */
        res = sam4l_flash_command(target, SAM4L_FCMD_CPB, -1);
        if (res != ERROR_OK) {
@@ -527,7 +529,7 @@ static int sam4l_write_page(struct sam4l_info *chip, struct target *target,
 /* Write partial contents into page-aligned 'address' on the Flash from host
  * buffer 'buf' by writing 'nb' of 'buf' at 'offset' into the Flash page. */
 static int sam4l_write_page_partial(struct sam4l_info *chip,
-               struct flash_bank *bank, uint32_t address, uint8_t *buf,
+               struct flash_bank *bank, uint32_t address, const uint8_t *buf,
                uint32_t page_offset, uint32_t nb)
 {
        int res;
@@ -535,6 +537,8 @@ static int sam4l_write_page_partial(struct sam4l_info *chip,
        if (!pg)
                return ERROR_FAIL;
 
+       LOG_DEBUG("sam4l_write_page_partial address=%08" PRIx32 " nb=%08" PRIx32, address, nb);
+
        assert(page_offset + nb < chip->page_size);
        assert((address % chip->page_size) == 0);
 
@@ -556,13 +560,15 @@ static int sam4l_write_page_partial(struct sam4l_info *chip,
        return res;
 }
 
-static int sam4l_write(struct flash_bank *bank, uint8_t *buffer,
+static int sam4l_write(struct flash_bank *bank, const uint8_t *buffer,
                uint32_t offset, uint32_t count)
 {
        int res;
        uint32_t nb = 0;
        struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
 
+       LOG_DEBUG("sam4l_write offset=%08" PRIx32 " count=%08" PRIx32, offset, count);
+
        if (bank->target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
 
@@ -605,14 +611,14 @@ static int sam4l_write(struct flash_bank *bank, uint8_t *buffer,
                for (int i = 0; i < np; i++) {
                        if (count >= chip->page_size) {
                                res = sam4l_write_page(chip, bank->target,
-                                               bank->base + (i * chip->page_size),
+                                               bank->base + offset,
                                                buffer + (i * chip->page_size));
                                /* Advance one page */
                                offset += chip->page_size;
                                count -= chip->page_size;
                        } else {
                                res = sam4l_write_page_partial(chip, bank,
-                                               bank->base + (i * chip->page_size),
+                                               bank->base + offset,
                                                buffer + (i * chip->page_size), 0, count);
                                /* We're done after this. */
                                offset += count;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)