contrib: add source to the cfi flash loaders
[openocd.git] / src / flash / nor / cfi.c
index 7f2d0a5b906312c20b2f7733430d0617cfb638ee..74362c4f78809dc01e8dad6452f9ade4880f15e2 100644 (file)
@@ -46,9 +46,10 @@ static struct cfi_unlock_addresses cfi_unlock_addresses[] =
 };
 
 /* CFI fixups foward declarations */
-static void cfi_fixup_0002_erase_regions(struct flash_bank *flash, void *param);
-static void cfi_fixup_0002_unlock_addresses(struct flash_bank *flash, void *param);
-static void cfi_fixup_reversed_erase_regions(struct flash_bank *flash, void *param);
+static void cfi_fixup_0002_erase_regions(struct flash_bank *bank, void *param);
+static void cfi_fixup_0002_unlock_addresses(struct flash_bank *bank, void *param);
+static void cfi_fixup_reversed_erase_regions(struct flash_bank *bank, void *param);
+static void cfi_fixup_0002_write_buffer(struct flash_bank *bank, void *param);
 
 /* fixup after reading cmdset 0002 primary query table */
 static const struct cfi_fixup cfi_0002_fixups[] = {
@@ -59,13 +60,14 @@ static const struct cfi_fixup cfi_0002_fixups[] = {
        {CFI_MFR_SST, 0x2780, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_5555_2AAA]},
        {CFI_MFR_SST, 0x236d, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_555_2AA]},
        {CFI_MFR_ATMEL, 0x00C8, cfi_fixup_reversed_erase_regions, NULL},
-       {CFI_MFR_ST,  0x22C4, cfi_fixup_reversed_erase_regions, NULL}, /* M29W160ET */
+       {CFI_MFR_ST, 0x22C4, cfi_fixup_reversed_erase_regions, NULL}, /* M29W160ET */
        {CFI_MFR_FUJITSU, 0x22ea, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_555_2AA]},
        {CFI_MFR_FUJITSU, 0x226b, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_5555_2AAA]},
        {CFI_MFR_AMIC, 0xb31a, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_555_2AA]},
        {CFI_MFR_MX, 0x225b, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_555_2AA]},
        {CFI_MFR_AMD, 0x225b, cfi_fixup_0002_unlock_addresses, &cfi_unlock_addresses[CFI_UNLOCK_555_2AA]},
        {CFI_MFR_ANY, CFI_ID_ANY, cfi_fixup_0002_erase_regions, NULL},
+       {CFI_MFR_ST, 0x227E, cfi_fixup_0002_write_buffer, NULL}, /* M29W128G */
        {0, 0, NULL, NULL}
 };
 
@@ -1224,6 +1226,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, uint8_t *buffer,
         * r6: error test pattern
         */
 
+       /* see contib/loaders/flash/armv4_5_cfi_intel_32.s for src */
        static const uint32_t word_32_code[] = {
                0xe4904004,   /* loop:  ldr r4, [r0], #4 */
                0xe5813000,   /*                str r3, [r1] */
@@ -1241,6 +1244,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, uint8_t *buffer,
                0xeafffffe    /* done:  b -2 */
        };
 
+       /* see contib/loaders/flash/armv4_5_cfi_intel_16.s for src */
        static const uint32_t word_16_code[] = {
                0xe0d040b2,   /* loop:  ldrh r4, [r0], #2 */
                0xe1c130b0,   /*                strh r3, [r1] */
@@ -1258,6 +1262,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, uint8_t *buffer,
                0xeafffffe    /* done:  b -2 */
        };
 
+       /* see contib/loaders/flash/armv4_5_cfi_intel_8.s for src */
        static const uint32_t word_8_code[] = {
                0xe4d04001,   /* loop:  ldrb r4, [r0], #1 */
                0xe5c13000,   /*                strb r3, [r1] */
@@ -1485,6 +1490,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, uint8_t *buffer,
        /*  R10 = unlock2_addr */
        /*  R11 = unlock2_cmd */
 
+       /* see contib/loaders/flash/armv4_5_cfi_span_32.s for src */
        static const uint32_t word_32_code[] = {
                                                /* 00008100 <sp_32_code>:               */
                0xe4905004,             /* ldr  r5, [r0], #4                    */
@@ -1517,9 +1523,10 @@ static int cfi_spansion_write_block(struct flash_bank *bank, uint8_t *buffer,
                                                /*                                                              */
                                                /* 00008154 <sp_32_done>:               */
                0xeafffffe              /* b    8154 <sp_32_done>               */
-               };
+       };
 
-               static const uint32_t word_16_code[] = {
+       /* see contib/loaders/flash/armv4_5_cfi_span_16.s for src */
+       static const uint32_t word_16_code[] = {
                                                /* 00008158 <sp_16_code>:               */
                0xe0d050b2,             /* ldrh r5, [r0], #2                    */
                0xe1c890b0,             /* strh r9, [r8]                                */
@@ -1551,9 +1558,10 @@ static int cfi_spansion_write_block(struct flash_bank *bank, uint8_t *buffer,
                                                /*                                                              */
                                                /* 000081ac <sp_16_done>:               */
                0xeafffffe              /* b    81ac <sp_16_done>               */
-               };
+       };
 
-               static const uint32_t word_16_code_dq7only[] = {
+       /* see contib/loaders/flash/armv4_5_cfi_span_16_dq7.s for src */
+       static const uint32_t word_16_code_dq7only[] = {
                                                /* <sp_16_code>:                                */
                0xe0d050b2,             /* ldrh r5, [r0], #2                    */
                0xe1c890b0,             /* strh r9, [r8]                                */
@@ -1576,9 +1584,10 @@ static int cfi_spansion_write_block(struct flash_bank *bank, uint8_t *buffer,
                                                /*                                                              */
                                                /* 000081ac <sp_16_done>:               */
                0xeafffffe              /* b    81ac <sp_16_done>               */
-               };
+       };
 
-               static const uint32_t word_8_code[] = {
+       /* see contib/loaders/flash/armv4_5_cfi_span_8.s for src */
+       static const uint32_t word_8_code[] = {
                                                /* 000081b0 <sp_16_code_end>:   */
                0xe4d05001,             /* ldrb r5, [r0], #1                    */
                0xe5c89000,             /* strb r9, [r8]                                */
@@ -2051,6 +2060,13 @@ static int cfi_write_words(struct flash_bank *bank, uint8_t *word,
 {
        struct cfi_flash_bank *cfi_info = bank->driver_priv;
 
+       if (cfi_info->buf_write_timeout_typ == 0)
+       {
+               /* buffer writes are not supported */
+               LOG_DEBUG("Buffer Writes Not Supported");
+               return ERROR_FLASH_OPER_UNSUPPORTED;
+       }
+
        switch (cfi_info->pri_id)
        {
                case 1:
@@ -2241,6 +2257,8 @@ static int cfi_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset,
                                                count -= buffersize;
                                                fallback = 0;
                                        }
+                                       else if (retval != ERROR_FLASH_OPER_UNSUPPORTED)
+                                               return retval;
                                }
                                /* try the slow way? */
                                if (fallback)
@@ -2519,6 +2537,7 @@ static int cfi_probe(struct flash_bank *bank)
                retval = cfi_query_u8(bank, 0, 0x1e, &cfi_info->vpp_max);
                if (retval != ERROR_OK)
                        return retval;
+
                retval = cfi_query_u8(bank, 0, 0x1f, &cfi_info->word_write_timeout_typ);
                if (retval != ERROR_OK)
                        return retval;
@@ -2915,6 +2934,14 @@ static int get_cfi_info(struct flash_bank *bank, char *buf, int buf_size)
        return ERROR_OK;
 }
 
+static void cfi_fixup_0002_write_buffer(struct flash_bank *bank, void *param)
+{
+       struct cfi_flash_bank *cfi_info = bank->driver_priv;
+
+       /* disable write buffer for M29W128G */
+       cfi_info->buf_write_timeout_typ = 0;
+}
+
 struct flash_driver cfi_flash = {
        .name = "cfi",
        .flash_bank_command = cfi_flash_bank_command,

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)