kinetis: fix "SF1" parts to limit FlexRAM usage 58/1358/2
authorChristopher Kilgour <techie@whiterocker.com>
Tue, 23 Apr 2013 02:08:15 +0000 (19:08 -0700)
committerFreddie Chopin <freddie.chopin@gmail.com>
Sun, 28 Apr 2013 07:37:03 +0000 (07:37 +0000)
Ensure FlexRAM usage is limited to half the FlexRAM size when programming.
Assume the FlexNVM sector size is equal to half the FlexRAM.
Fix sector erase checking which had an error introduced when the
  kinetis_ftfx_command( ) signature was changed.

Change-Id: I88edd9c7d4a4ba474cad7b00052feaeedfa8ced8
Signed-off-by: Christopher Kilgour <techie@whiterocker.com>
Reviewed-on: http://openocd.zylin.com/1358
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
src/flash/nor/kinetis.c

index 494c266cfeb6aed54d2021b12b2e69fe697a7029..fe18451c92710280f0bff4e27728eed4eb4821cb 100644 (file)
@@ -365,23 +365,27 @@ static int kinetis_write(struct flash_bank *bank, uint8_t *buffer,
 
        /* program section command */
        if (fallback == 0) {
-               unsigned prog_section_bytes = kinfo->sector_size >> 8;
-               for (i = 0; i < count; i += kinfo->sector_size) {
-                       /*
-                        * The largest possible Kinetis "section" is
-                        * 16 bytes.  A full Kinetis sector is always
-                        * 256 "section"s.
-                        */
+               /*
+                * Kinetis uses different terms for the granularity of
+                * sector writes, e.g. "phrase" or "128 bits".  We use
+                * the generic term "chunk". The largest possible
+                * Kinetis "chunk" is 16 bytes (128 bits).
+                */
+               unsigned prog_section_chunk_bytes = kinfo->sector_size >> 8;
+               /* assume the NVM sector size is half the FlexRAM size */
+               unsigned prog_size_bytes = MIN(kinfo->sector_size,
+                                              kinetis_flash_params[kinfo->granularity].nvm_sector_size_bytes);
+               for (i = 0; i < count; i += prog_size_bytes) {
                        uint8_t residual_buffer[16];
                        uint8_t ftfx_fstat;
-                       uint32_t section_count = 256;
+                       uint32_t section_count = prog_size_bytes / prog_section_chunk_bytes;
                        uint32_t residual_wc = 0;
 
                        /*
                         * Assume the word count covers an entire
                         * sector.
                         */
-                       wc = kinfo->sector_size / 4;
+                       wc = prog_size_bytes / 4;
 
                        /*
                         * If bytes to be programmed are less than the
@@ -390,21 +394,21 @@ static int kinetis_write(struct flash_bank *bank, uint8_t *buffer,
                         * residual buffer so that a full "section"
                         * may always be programmed.
                         */
-                       if ((count - i) < kinfo->sector_size) {
+                       if ((count - i) < prog_size_bytes) {
                                /* number of bytes to program beyond full section */
-                               unsigned residual_bc = (count-i) % prog_section_bytes;
+                               unsigned residual_bc = (count-i) % prog_section_chunk_bytes;
 
                                /* number of complete words to copy directly from buffer */
                                wc = (count - i) / 4;
 
                                /* number of total sections to write, including residual */
-                               section_count = DIV_ROUND_UP((count-i), prog_section_bytes);
+                               section_count = DIV_ROUND_UP((count-i), prog_section_chunk_bytes);
 
                                /* any residual bytes delivers a whole residual section */
-                               residual_wc = (residual_bc ? prog_section_bytes : 0)/4;
+                               residual_wc = (residual_bc ? prog_section_chunk_bytes : 0)/4;
 
                                /* clear residual buffer then populate residual bytes */
-                               (void) memset(residual_buffer, 0xff, prog_section_bytes);
+                               (void) memset(residual_buffer, 0xff, prog_section_chunk_bytes);
                                (void) memcpy(residual_buffer, &buffer[i+4*wc], residual_bc);
                        }
 
@@ -770,7 +774,7 @@ static int kinetis_blank_check(struct flash_bank *bank)
                        for (i = 0; i < bank->num_sectors; i++) {
                                /* normal margin */
                                result = kinetis_ftfx_command(bank, FTFx_CMD_SECTSTAT, bank->base + bank->sectors[i].offset,
-                                               0, 0, 0, 1,  0, 0, 0, 0, &ftfx_fstat);
+                                               1, 0, 0, 0,  0, 0, 0, 0, &ftfx_fstat);
 
                                if (result == ERROR_OK) {
                                        bank->sectors[i].is_erased = !(ftfx_fstat & 0x01);

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)