fm3: add Fujitsu MB9Ax family support
[openocd.git] / src / flash / nor / fm3.c
index 32e81798f3a05577da6d471184148ea7d141d7fc..a9a11a311f809b3e07f7f2153210e6a8d853a10f 100644 (file)
@@ -229,7 +229,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
                return ERROR_TARGET_NOT_HALTED;
        }
 
                return ERROR_TARGET_NOT_HALTED;
        }
 
-       LOG_INFO("Fujitsu MB9Bxxx: Sector Erase ... (%d to %d)", first, last);
+       LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%d to %d)", first, last);
 
        /* FASZR = 0x01, Enables CPU Programming Mode (16-bit Flash acccess) */
        retval = target_write_u32(target, 0x40000000, 0x0001);
 
        /* FASZR = 0x01, Enables CPU Programming Mode (16-bit Flash acccess) */
        retval = target_write_u32(target, 0x40000000, 0x0001);
@@ -296,7 +296,7 @@ static int fm3_write_block(struct flash_bank *bank, uint8_t *buffer,
 {
        struct fm3_flash_bank *fm3_info = bank->driver_priv;
        struct target *target = bank->target;
 {
        struct fm3_flash_bank *fm3_info = bank->driver_priv;
        struct target *target = bank->target;
-       uint32_t buffer_size = 2048;            /* 8192 for MB9Bxx6! */
+       uint32_t buffer_size = 2048;            /* Default minimum value */
        struct working_area *write_algorithm;
        struct working_area *source;
        uint32_t address = bank->base + offset;
        struct working_area *write_algorithm;
        struct working_area *source;
        uint32_t address = bank->base + offset;
@@ -307,6 +307,10 @@ static int fm3_write_block(struct flash_bank *bank, uint8_t *buffer,
        uint32_t u32FlashSeqAddress1;
        uint32_t u32FlashSeqAddress2;
 
        uint32_t u32FlashSeqAddress1;
        uint32_t u32FlashSeqAddress2;
 
+       /* Increase buffer_size if needed */
+       if (buffer_size < (target->working_area_size / 2))
+               buffer_size = (target->working_area_size / 2);
+
        u32FlashType = (uint32_t) fm3_info->flashtype;
 
        if (u32FlashType == fm3_flash_type1) {
        u32FlashType = (uint32_t) fm3_info->flashtype;
 
        if (u32FlashType == fm3_flash_type1) {
@@ -446,13 +450,13 @@ static int fm3_write_block(struct flash_bank *bank, uint8_t *buffer,
        0x00, 0xBE,                                     /*        BKPT     #0                         */
 
        /* The following address pointers assume, that the code is running from   */
        0x00, 0xBE,                                     /*        BKPT     #0                         */
 
        /* The following address pointers assume, that the code is running from   */
-       /* address 0x1FFF8008. These address pointers will be patched, if a       */
-       /* different start address in RAM is used (e.g. for Flash type 2)!        */
-       0x00, 0x80, 0xFF, 0x1F,     /* u32DummyRead address in RAM (0x1FFF8000)   */
-       0x04, 0x80, 0xFF, 0x1F      /* u32FlashResult address in RAM (0x1FFF8004) */
+       /* SRAM basic-address(BASE_ADDR)+8.These address pointers will be patched */
+       /* if a different start address in RAM is used (e.g. for Flash type 2)!   */
+       0x00, 0x80, 0xFF, 0x1F,     /* u32DummyRead address in RAM (BASE_ADDR)    */
+       0x04, 0x80, 0xFF, 0x1F      /* u32FlashResult address in RAM (BASE_ADDR+4)*/
        };
 
        };
 
-       LOG_INFO("Fujitsu MB9B500: FLASH Write ...");
+       LOG_INFO("Fujitsu MB9[A/B]FXXX: FLASH Write ...");
 
        /* disable HW watchdog */
        retval = target_write_u32(target, 0x40011C00, 0x1ACCE551);
 
        /* disable HW watchdog */
        retval = target_write_u32(target, 0x40011C00, 0x1ACCE551);
@@ -487,8 +491,6 @@ static int fm3_write_block(struct flash_bank *bank, uint8_t *buffer,
        if (retval != ERROR_OK)
                return retval;
 
        if (retval != ERROR_OK)
                return retval;
 
-
-
        /* memory buffer */
        while (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK) {
                buffer_size /= 2;
        /* memory buffer */
        while (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK) {
                buffer_size /= 2;
@@ -522,7 +524,7 @@ static int fm3_write_block(struct flash_bank *bank, uint8_t *buffer,
                        break;
 
                /* Patching 'local variable address' for different RAM addresses */
                        break;
 
                /* Patching 'local variable address' for different RAM addresses */
-               if (write_algorithm->address != 0x1FFF8008) {
+               if (write_algorithm->address != (target->working_area_phys + 8)) {
                        /* Algorithm: u32DummyRead: */
                        retval = target_write_u32(target, (write_algorithm->address)
                                + sizeof(fm3_flash_write_code) - 8, (write_algorithm->address) - 8);
                        /* Algorithm: u32DummyRead: */
                        retval = target_write_u32(target, (write_algorithm->address)
                                + sizeof(fm3_flash_write_code) - 8, (write_algorithm->address) - 8);

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)