Kinetis: give a reasonable default for max_flash_prog_size 58/2958/4
authorTomas Vanek <vanekt@fbl.cz>
Thu, 24 Sep 2015 08:29:12 +0000 (10:29 +0200)
committerPaul Fertser <fercerpav@gmail.com>
Fri, 9 Oct 2015 12:44:05 +0000 (13:44 +0100)
max_flash_prog_size euals to pflash_sector_size_bytes for most of devices.
There is no point setting max_flash_prog_size for devices without
FS_PROGRAM_SECTOR capability.
Check for zero sector_size to avoid div by zero exception in case of
device has FlexNVM but the driver does not define nvm_sector_size_bytes

Change-Id: Iaf4e007fb1ec3d24c373350410e4bebe504a4c3e
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/2958
Tested-by: jenkins
Reviewed-by: Thomas Schmid <thomas@rfranging.com>
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-by: Patrick Stewart <patstew@gmail.com>
src/flash/nor/kinetis.c

index 6485bc3fa3171de67d599dbab751903269f8598a..46591e9e2cd5dc520d455a9b56749382c1698f52 100644 (file)
@@ -1072,7 +1072,6 @@ static int kinetis_read_part_info(struct flash_bank *bank)
                        nvm_sector_size_bytes = 1<<10;
                        num_blocks = 2;
                        kinfo->flash_support = FS_PROGRAM_LONGWORD | FS_PROGRAM_SECTOR;
-                       kinfo->max_flash_prog_size = 1<<10;
                        break;
                case KINETIS_K_SDID_K10_M72:
                case KINETIS_K_SDID_K20_M72:
@@ -1102,7 +1101,6 @@ static int kinetis_read_part_info(struct flash_bank *bank)
                        nvm_sector_size_bytes = 2<<10;
                        num_blocks = 2;
                        kinfo->flash_support = FS_PROGRAM_LONGWORD | FS_PROGRAM_SECTOR;
-                       kinfo->max_flash_prog_size = 2<<10;
                        break;
                case KINETIS_K_SDID_K10_M120:
                case KINETIS_K_SDID_K20_M120:
@@ -1115,7 +1113,6 @@ static int kinetis_read_part_info(struct flash_bank *bank)
                        nvm_sector_size_bytes = 4<<10;
                        num_blocks = 4;
                        kinfo->flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR;
-                       kinfo->max_flash_prog_size = 4<<10;
                        break;
                default:
                        LOG_ERROR("Unsupported K-family FAMID");
@@ -1151,7 +1148,6 @@ static int kinetis_read_part_info(struct flash_bank *bank)
                                pflash_sector_size_bytes = 4<<10;
                                num_blocks = 1;
                                kinfo->flash_support = FS_PROGRAM_LONGWORD;
-                               kinfo->max_flash_prog_size = 1<<10;
                                break;
                        default:
                                break;
@@ -1163,7 +1159,6 @@ static int kinetis_read_part_info(struct flash_bank *bank)
                        nvm_sector_size_bytes = 1<<10;
                        num_blocks = 1;
                        kinfo->flash_support = FS_PROGRAM_LONGWORD;
-                       kinfo->max_flash_prog_size = 1<<10;
                        break;
                default:
                        break;
@@ -1372,6 +1367,17 @@ static int kinetis_read_part_info(struct flash_bank *bank)
                bank->sectors = NULL;
        }
 
+       if (kinfo->sector_size == 0) {
+               LOG_ERROR("Unknown sector size for bank %d", bank->bank_number);
+               return ERROR_FLASH_BANK_INVALID;
+       }
+
+       if (kinfo->flash_support & FS_PROGRAM_SECTOR
+                        && kinfo->max_flash_prog_size == 0) {
+               kinfo->max_flash_prog_size = kinfo->sector_size;
+               /* Program section size is equal to sector size by default */
+       }
+
        bank->num_sectors = bank->size / kinfo->sector_size;
        assert(bank->num_sectors > 0);
        bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_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)