flash/nor/psoc4: fix protection on devices with 256k flash 25/4425/2
authorTomas Vanek <vanekt@fbl.cz>
Wed, 21 Feb 2018 12:54:44 +0000 (13:54 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Sat, 3 Mar 2018 09:41:52 +0000 (09:41 +0000)
Protection read and setting of the second flash macro did not work.
Tested on CY8CKIT-046

Change-Id: I67789399ad1e89bbfc23a95547ecca7753130701
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4425
Tested-by: jenkins
src/flash/nor/psoc4.c

index 62b904ed12663673e9614bc286f8798729897362..a0240091dc1e99e112c7ed45a5f60daee6d5bad9 100644 (file)
@@ -99,7 +99,7 @@
 
 
 /* constants */
-#define PSOC4_SFLASH_MACRO_SIZE                0x400
+#define PSOC4_SFLASH_MACRO_SIZE                0x800
 #define PSOC4_ROWS_PER_MACRO           512
 
 #define PSOC4_SROM_KEY1                        0xb6
@@ -567,7 +567,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
        uint32_t *sysrq_buffer = NULL;
        const int param_sz = 8;
        int chip_prot = PSOC4_CHIP_PROT_OPEN;
-       int i, m;
+       int i, m, sect;
        int num_bits = bank->num_sectors;
 
        if (num_bits > PSOC4_ROWS_PER_MACRO)
@@ -575,7 +575,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
 
        int prot_sz = num_bits / 8;
 
-       sysrq_buffer = calloc(1, param_sz + prot_sz);
+       sysrq_buffer = malloc(param_sz + prot_sz);
        if (sysrq_buffer == NULL) {
                LOG_ERROR("no memory for row buffer");
                return ERROR_FAIL;
@@ -584,10 +584,11 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
        for (i = first; i <= last && i < bank->num_sectors; i++)
                bank->sectors[i].is_protected = set;
 
-       for (m = 0; m < psoc4_info->num_macros; m++) {
+       for (m = 0, sect = 0; m < psoc4_info->num_macros; m++) {
                uint8_t *p = (uint8_t *)(sysrq_buffer + 2);
-               for (i = 0; i < num_bits && i < bank->num_sectors; i++) {
-                       if (bank->sectors[i].is_protected)
+               memset(p, 0, prot_sz);
+               for (i = 0; i < num_bits && sect < bank->num_sectors; i++, sect++) {
+                       if (bank->sectors[sect].is_protected)
                                p[i/8] |= 1 << (i%8);
                }
 
@@ -597,7 +598,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
                retval = psoc4_sysreq(bank, PSOC4_CMD_LOAD_LATCH,
                        0       /* Byte number in latch from what to write */
                          | (m << 8), /* flash macro index */
-                       sysrq_buffer, param_sz + psoc4_info->row_size,
+                       sysrq_buffer, param_sz + prot_sz,
                        NULL);
                if (retval != ERROR_OK)
                        break;

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)