flash/nor/psoc4: adjust flash size limited by wounding
[openocd.git] / src / flash / nor / psoc4.c
index 1d861edc9d538cb41cab754b3b646bbb31678fbf..d4ce1fb02bae226c25ddf1437f2cb29617062c90 100644 (file)
@@ -78,6 +78,8 @@
 
  CYBL10x6x, CY8C4127_BL, CY8C4247_BL Programming Specifications
        Document No. 001-91508 Rev. *B September 22, 2014
+
+ http://dmitry.gr/index.php?r=05.Projects&proj=24.%20PSoC4%20confidential
 */
 
 /* register locations */
@@ -717,6 +719,22 @@ cleanup:
 }
 
 
+/* Due to Cypress's method of market segmentation some devices
+ * have accessible only 1/2, 1/4 or 1/8 of SPCIF described flash */
+static int psoc4_test_flash_wounding(struct target *target, uint32_t flash_size)
+{
+       int retval, i;
+       for (i = 3; i >= 1; i--) {
+               uint32_t addr = flash_size >> i;
+               uint32_t dummy;
+               retval = target_read_u32(target, addr, &dummy);
+               if (retval != ERROR_OK)
+                       return i;
+       }
+       return 0;
+}
+
+
 static int psoc4_probe(struct flash_bank *bank)
 {
        struct psoc4_flash_bank *psoc4_info = bank->driver_priv;
@@ -798,6 +816,15 @@ static int psoc4_probe(struct flash_bank *bank)
        if (num_macros != (num_rows + PSOC4_ROWS_PER_MACRO - 1) / PSOC4_ROWS_PER_MACRO)
                LOG_WARNING("Number of macros does not correspond with flash size!");
 
+       if (!psoc4_info->legacy_family) {
+               int wounding = psoc4_test_flash_wounding(target, num_rows * row_size);
+               if (wounding > 0) {
+                       flash_size_in_kb = flash_size_in_kb >> wounding;
+                       num_rows = num_rows >> wounding;
+                       LOG_INFO("WOUNDING detected: accessible flash size %" PRIu32 " kbytes", flash_size_in_kb);
+               }
+       }
+
        if (bank->sectors) {
                free(bank->sectors);
        }

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)