1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
5 * Copyright (C) 2011 sleep(5) ltd *
6 * tomas@sleepfive.com *
8 * Copyright (C) 2012 by Christopher D. Kilgour *
9 * techie at whiterocker.com *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 ***************************************************************************/
32 #include "helper/binarybuffer.h"
35 * Implementation Notes
37 * The persistent memories in the Kinetis chip families K10 through
38 * K70 are all manipulated with the Flash Memory Module. Some
39 * variants call this module the FTFE, others call it the FTFL. To
40 * indicate that both are considered here, we use FTFX.
42 * Within the module, according to the chip variant, the persistent
43 * memory is divided into what Freescale terms Program Flash, FlexNVM,
44 * and FlexRAM. All chip variants have Program Flash. Some chip
45 * variants also have FlexNVM and FlexRAM, which always appear
48 * A given Kinetis chip may have 2 or 4 blocks of flash. Here we map
49 * each block to a separate bank. Each block size varies by chip and
50 * may be determined by the read-only SIM_FCFG1 register. The sector
51 * size within each bank/block varies by the chip granularity as
54 * Kinetis offers four different of flash granularities applicable
55 * across the chip families. The granularity is apparently reflected
56 * by at least the reference manual suffix. For example, for chip
57 * MK60FN1M0VLQ12, reference manual K60P144M150SF3RM ends in "SF3RM",
58 * where the "3" indicates there are four flash blocks with 4kiB
59 * sectors. All possible granularities are indicated below.
61 * The first half of the flash (1 or 2 blocks, depending on the
62 * granularity) is always Program Flash and always starts at address
63 * 0x00000000. The "PFLSH" flag, bit 23 of the read-only SIM_FCFG2
64 * register, determines whether the second half of the flash is also
65 * Program Flash or FlexNVM+FlexRAM. When PFLSH is set, the second
66 * half of flash is Program Flash and is contiguous in the memory map
67 * from the first half. When PFLSH is clear, the second half of flash
68 * is FlexNVM and always starts at address 0x10000000. FlexRAM, which
69 * is also present when PFLSH is clear, always starts at address
72 * The Flash Memory Module provides a register set where flash
73 * commands are loaded to perform flash operations like erase and
74 * program. Different commands are available depending on whether
75 * Program Flash or FlexNVM/FlexRAM is being manipulated. Although
76 * the commands used are quite consistent between flash blocks, the
77 * parameters they accept differ according to the flash granularity.
78 * Some Kinetis chips have different granularity between Program Flash
79 * and FlexNVM/FlexRAM, so flash command arguments may differ between
80 * blocks in the same chip.
82 * Although not documented as such by Freescale, it appears that bits
83 * 8:7 of the read-only SIM_SDID register reflect the granularity
84 * settings 0..3, so sector sizes and block counts are applicable
85 * according to the following table.
88 unsigned pflash_sector_size_bytes
;
89 unsigned nvm_sector_size_bytes
;
91 } kinetis_flash_params
[4] = {
99 #define FLEXRAM 0x14000000
100 #define FTFx_FSTAT 0x40020000
101 #define FTFx_FCNFG 0x40020001
102 #define FTFx_FCCOB3 0x40020004
103 #define FTFx_FPROT3 0x40020010
104 #define SIM_SDID 0x40048024
105 #define SIM_FCFG1 0x4004804c
106 #define SIM_FCFG2 0x40048050
109 #define FTFx_CMD_BLOCKSTAT 0x00
110 #define FTFx_CMD_SECTSTAT 0x01
111 #define FTFx_CMD_LWORDPROG 0x06
112 #define FTFx_CMD_SECTERASE 0x09
113 #define FTFx_CMD_SECTWRITE 0x0b
114 #define FTFx_CMD_SETFLEXRAM 0x81
116 struct kinetis_flash_bank
{
117 unsigned granularity
;
118 unsigned bank_ordinal
;
119 uint32_t sector_size
;
120 uint32_t protection_size
;
134 FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command
)
136 struct kinetis_flash_bank
*bank_info
;
139 return ERROR_COMMAND_SYNTAX_ERROR
;
141 LOG_INFO("add flash_bank kinetis %s", bank
->name
);
143 bank_info
= malloc(sizeof(struct kinetis_flash_bank
));
145 memset(bank_info
, 0, sizeof(struct kinetis_flash_bank
));
147 bank
->driver_priv
= bank_info
;
152 static int kinetis_protect(struct flash_bank
*bank
, int set
, int first
,
155 LOG_WARNING("kinetis_protect not supported yet");
158 if (bank
->target
->state
!= TARGET_HALTED
) {
159 LOG_ERROR("Target not halted");
160 return ERROR_TARGET_NOT_HALTED
;
163 return ERROR_FLASH_BANK_INVALID
;
166 static int kinetis_protect_check(struct flash_bank
*bank
)
168 struct kinetis_flash_bank
*kinfo
= bank
->driver_priv
;
170 if (bank
->target
->state
!= TARGET_HALTED
) {
171 LOG_ERROR("Target not halted");
172 return ERROR_TARGET_NOT_HALTED
;
175 if (kinfo
->flash_class
== FC_PFLASH
) {
178 uint32_t fprot
, psec
;
181 /* read protection register */
182 result
= target_read_memory(bank
->target
, FTFx_FPROT3
, 1, 4, buffer
);
184 if (result
!= ERROR_OK
)
187 fprot
= target_buffer_get_u32(bank
->target
, buffer
);
190 * Every bit protects 1/32 of the full flash (not necessarily
191 * just this bank), but we enforce the bank ordinals for
192 * PFlash to start at zero.
194 b
= kinfo
->bank_ordinal
* (bank
->size
/ kinfo
->protection_size
);
195 for (psec
= 0, i
= 0; i
< bank
->num_sectors
; i
++) {
196 if ((fprot
>> b
) & 1)
197 bank
->sectors
[i
].is_protected
= 0;
199 bank
->sectors
[i
].is_protected
= 1;
201 psec
+= bank
->sectors
[i
].size
;
203 if (psec
>= kinfo
->protection_size
) {
209 LOG_ERROR("Protection checks for FlexNVM not yet supported");
210 return ERROR_FLASH_BANK_INVALID
;
216 static int kinetis_ftfx_command(struct flash_bank
*bank
, uint8_t fcmd
, uint32_t faddr
,
217 uint8_t fccob4
, uint8_t fccob5
, uint8_t fccob6
, uint8_t fccob7
,
218 uint8_t fccob8
, uint8_t fccob9
, uint8_t fccoba
, uint8_t fccobb
,
221 uint8_t command
[12] = {faddr
& 0xff, (faddr
>> 8) & 0xff, (faddr
>> 16) & 0xff, fcmd
,
222 fccob7
, fccob6
, fccob5
, fccob4
,
223 fccobb
, fccoba
, fccob9
, fccob8
};
228 for (i
= 0; i
< 50; i
++) {
230 target_read_memory(bank
->target
, FTFx_FSTAT
, 1, 1, &buffer
);
232 if (result
!= ERROR_OK
)
241 if (buffer
!= 0x80) {
242 /* reset error flags */
245 target_write_memory(bank
->target
, FTFx_FSTAT
, 1, 1, &buffer
);
246 if (result
!= ERROR_OK
)
250 result
= target_write_memory(bank
->target
, FTFx_FCCOB3
, 4, 3, command
);
252 if (result
!= ERROR_OK
)
257 result
= target_write_memory(bank
->target
, FTFx_FSTAT
, 1, 1, &buffer
);
258 if (result
!= ERROR_OK
)
262 for (i
= 0; i
< 50; i
++) {
264 target_read_memory(bank
->target
, FTFx_FSTAT
, 1, 1, ftfx_fstat
);
266 if (result
!= ERROR_OK
)
269 if (*ftfx_fstat
& 0x80)
273 if ((*ftfx_fstat
& 0xf0) != 0x80) {
275 ("ftfx command failed FSTAT: %02X FCCOB: %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X",
276 *ftfx_fstat
, command
[3], command
[2], command
[1], command
[0],
277 command
[7], command
[6], command
[5], command
[4],
278 command
[11], command
[10], command
[9], command
[8]);
279 return ERROR_FLASH_OPERATION_FAILED
;
285 static int kinetis_erase(struct flash_bank
*bank
, int first
, int last
)
289 if (bank
->target
->state
!= TARGET_HALTED
) {
290 LOG_ERROR("Target not halted");
291 return ERROR_TARGET_NOT_HALTED
;
294 if ((first
> bank
->num_sectors
) || (last
> bank
->num_sectors
))
295 return ERROR_FLASH_OPERATION_FAILED
;
298 * FIXME: TODO: use the 'Erase Flash Block' command if the
299 * requested erase is PFlash or NVM and encompasses the entire
300 * block. Should be quicker.
302 for (i
= first
; i
<= last
; i
++) {
304 /* set command and sector address */
305 result
= kinetis_ftfx_command(bank
, FTFx_CMD_SECTERASE
, bank
->base
+ bank
->sectors
[i
].offset
,
306 0, 0, 0, 0, 0, 0, 0, 0, &ftfx_fstat
);
308 if (result
!= ERROR_OK
) {
309 LOG_WARNING("erase sector %d failed", i
);
310 return ERROR_FLASH_OPERATION_FAILED
;
313 bank
->sectors
[i
].is_erased
= 1;
318 ("flash configuration field erased, please reset the device");
324 static int kinetis_write(struct flash_bank
*bank
, uint8_t *buffer
,
325 uint32_t offset
, uint32_t count
)
327 unsigned int i
, result
, fallback
= 0;
330 struct kinetis_flash_bank
*kinfo
= bank
->driver_priv
;
332 if (bank
->target
->state
!= TARGET_HALTED
) {
333 LOG_ERROR("Target not halted");
334 return ERROR_TARGET_NOT_HALTED
;
337 if (kinfo
->flash_class
== FC_FLEX_NVM
) {
340 LOG_DEBUG("flash write into FlexNVM @%08X", offset
);
342 /* make flex ram available */
343 result
= kinetis_ftfx_command(bank
, FTFx_CMD_SETFLEXRAM
, 0x00ff0000, 0, 0, 0, 0, 0, 0, 0, 0, &ftfx_fstat
);
345 if (result
!= ERROR_OK
)
346 return ERROR_FLASH_OPERATION_FAILED
;
348 /* check if ram ready */
349 result
= target_read_memory(bank
->target
, FTFx_FCNFG
, 1, 1, buf
);
351 if (result
!= ERROR_OK
)
354 if (!(buf
[0] & (1 << 1))) {
355 /* fallback to longword write */
358 LOG_WARNING("ram not ready, fallback to slow longword write (FCNFG: %02X)",
362 LOG_DEBUG("flash write into PFLASH @08%X", offset
);
366 /* program section command */
368 unsigned prog_section_bytes
= kinfo
->sector_size
>> 8;
369 for (i
= 0; i
< count
; i
+= kinfo
->sector_size
) {
371 * The largest possible Kinetis "section" is
372 * 16 bytes. A full Kinetis sector is always
375 uint8_t residual_buffer
[16];
377 uint32_t section_count
= 256;
378 uint32_t residual_wc
= 0;
381 * Assume the word count covers an entire
384 wc
= kinfo
->sector_size
/ 4;
387 * If bytes to be programmed are less than the
388 * full sector, then determine the number of
389 * full-words to program, and put together the
390 * residual buffer so that a full "section"
391 * may always be programmed.
393 if ((count
- i
) < kinfo
->sector_size
) {
394 /* number of bytes to program beyond full section */
395 unsigned residual_bc
= (count
-i
) % prog_section_bytes
;
397 /* number of complete words to copy directly from buffer */
398 wc
= (count
- i
) / 4;
400 /* number of total sections to write, including residual */
401 section_count
= DIV_ROUND_UP((count
-i
), prog_section_bytes
);
403 /* any residual bytes delivers a whole residual section */
404 residual_wc
= (residual_bc
? prog_section_bytes
: 0)/4;
406 /* clear residual buffer then populate residual bytes */
407 (void) memset(residual_buffer
, 0xff, prog_section_bytes
);
408 (void) memcpy(residual_buffer
, &buffer
[i
+4*wc
], residual_bc
);
411 LOG_DEBUG("write section @ %08X with length %d bytes",
414 /* write data to flexram as whole-words */
415 result
= target_write_memory(bank
->target
, FLEXRAM
, 4, wc
,
418 if (result
!= ERROR_OK
) {
419 LOG_ERROR("target_write_memory failed");
423 /* write the residual words to the flexram */
425 result
= target_write_memory(bank
->target
,
430 if (result
!= ERROR_OK
) {
431 LOG_ERROR("target_write_memory failed");
436 /* execute section-write command */
437 result
= kinetis_ftfx_command(bank
, FTFx_CMD_SECTWRITE
, bank
->base
+ offset
+ i
,
438 section_count
>>8, section_count
, 0, 0,
439 0, 0, 0, 0, &ftfx_fstat
);
441 if (result
!= ERROR_OK
)
442 return ERROR_FLASH_OPERATION_FAILED
;
445 /* program longword command, not supported in "SF3" devices */
446 else if (kinfo
->granularity
!= 3) {
447 for (i
= 0; i
< count
; i
+= 4) {
450 LOG_DEBUG("write longword @ %08X", offset
+ i
);
452 uint8_t padding
[4] = {0xff, 0xff, 0xff, 0xff};
453 memcpy(padding
, buffer
+ i
, MIN(4, count
-i
));
454 result
= kinetis_ftfx_command(bank
, FTFx_CMD_LWORDPROG
, bank
->base
+ offset
+ i
,
455 padding
[3], padding
[2], padding
[1], padding
[0],
456 0, 0, 0, 0, &ftfx_fstat
);
458 if (result
!= ERROR_OK
)
459 return ERROR_FLASH_OPERATION_FAILED
;
462 LOG_ERROR("Flash write strategy not implemented");
463 return ERROR_FLASH_OPERATION_FAILED
;
469 static int kinetis_read_part_info(struct flash_bank
*bank
)
474 uint8_t fcfg1_nvmsize
, fcfg1_pfsize
, fcfg1_eesize
, fcfg2_pflsh
;
475 uint32_t nvm_size
= 0, pf_size
= 0, ee_size
= 0;
476 unsigned granularity
, num_blocks
= 0, num_pflash_blocks
= 0, num_nvm_blocks
= 0,
477 first_nvm_bank
= 0, reassign
= 0;
478 struct kinetis_flash_bank
*kinfo
= bank
->driver_priv
;
480 result
= target_read_memory(bank
->target
, SIM_SDID
, 1, 4, buf
);
481 if (result
!= ERROR_OK
)
483 kinfo
->sim_sdid
= target_buffer_get_u32(bank
->target
, buf
);
484 granularity
= (kinfo
->sim_sdid
>> 7) & 0x03;
486 result
= target_read_memory(bank
->target
, SIM_FCFG1
, 1, 4, buf
);
487 if (result
!= ERROR_OK
)
489 kinfo
->sim_fcfg1
= target_buffer_get_u32(bank
->target
, buf
);
491 result
= target_read_memory(bank
->target
, SIM_FCFG2
, 1, 4, buf
);
492 if (result
!= ERROR_OK
)
494 kinfo
->sim_fcfg2
= target_buffer_get_u32(bank
->target
, buf
);
495 fcfg2_pflsh
= (kinfo
->sim_fcfg2
>> 23) & 0x01;
497 LOG_DEBUG("SDID: %08X FCFG1: %08X FCFG2: %08X", kinfo
->sim_sdid
,
498 kinfo
->sim_fcfg1
, kinfo
->sim_fcfg2
);
500 fcfg1_nvmsize
= (uint8_t)((kinfo
->sim_fcfg1
>> 28) & 0x0f);
501 fcfg1_pfsize
= (uint8_t)((kinfo
->sim_fcfg1
>> 24) & 0x0f);
502 fcfg1_eesize
= (uint8_t)((kinfo
->sim_fcfg1
>> 16) & 0x0f);
504 /* when the PFLSH bit is set, there is no FlexNVM/FlexRAM */
506 switch (fcfg1_nvmsize
) {
511 nvm_size
= 1 << (14 + (fcfg1_nvmsize
>> 1));
514 if (granularity
== 3)
524 switch (fcfg1_eesize
) {
535 ee_size
= (16 << (10 - fcfg1_eesize
));
543 switch (fcfg1_pfsize
) {
550 pf_size
= 1 << (14 + (fcfg1_pfsize
>> 1));
553 if (granularity
== 3)
555 else if (fcfg2_pflsh
)
565 LOG_DEBUG("FlexNVM: %d PFlash: %d FlexRAM: %d PFLSH: %d",
566 nvm_size
, pf_size
, ee_size
, fcfg2_pflsh
);
568 num_blocks
= kinetis_flash_params
[granularity
].num_blocks
;
569 num_pflash_blocks
= num_blocks
/ (2 - fcfg2_pflsh
);
570 first_nvm_bank
= num_pflash_blocks
;
571 num_nvm_blocks
= num_blocks
- num_pflash_blocks
;
573 LOG_DEBUG("%d blocks total: %d PFlash, %d FlexNVM",
574 num_blocks
, num_pflash_blocks
, num_nvm_blocks
);
577 * If the flash class is already assigned, verify the
580 if (kinfo
->flash_class
!= FC_AUTO
) {
581 if (kinfo
->bank_ordinal
!= (unsigned) bank
->bank_number
) {
582 LOG_WARNING("Flash ordinal/bank number mismatch");
584 } else if (kinfo
->granularity
!= granularity
) {
585 LOG_WARNING("Flash granularity mismatch");
588 switch (kinfo
->flash_class
) {
590 if (kinfo
->bank_ordinal
>= first_nvm_bank
) {
591 LOG_WARNING("Class mismatch, bank %d is not PFlash",
594 } else if (bank
->size
!= (pf_size
/ num_pflash_blocks
)) {
595 LOG_WARNING("PFlash size mismatch");
597 } else if (bank
->base
!=
598 (0x00000000 + bank
->size
* kinfo
->bank_ordinal
)) {
599 LOG_WARNING("PFlash address range mismatch");
601 } else if (kinfo
->sector_size
!=
602 kinetis_flash_params
[granularity
].pflash_sector_size_bytes
) {
603 LOG_WARNING("PFlash sector size mismatch");
606 LOG_DEBUG("PFlash bank %d already configured okay",
607 kinfo
->bank_ordinal
);
611 if ((kinfo
->bank_ordinal
>= num_blocks
) ||
612 (kinfo
->bank_ordinal
< first_nvm_bank
)) {
613 LOG_WARNING("Class mismatch, bank %d is not FlexNVM",
616 } else if (bank
->size
!= (nvm_size
/ num_nvm_blocks
)) {
617 LOG_WARNING("FlexNVM size mismatch");
619 } else if (bank
->base
!=
620 (0x10000000 + bank
->size
* kinfo
->bank_ordinal
)) {
621 LOG_WARNING("FlexNVM address range mismatch");
623 } else if (kinfo
->sector_size
!=
624 kinetis_flash_params
[granularity
].nvm_sector_size_bytes
) {
625 LOG_WARNING("FlexNVM sector size mismatch");
628 LOG_DEBUG("FlexNVM bank %d already configured okay",
629 kinfo
->bank_ordinal
);
633 if (kinfo
->bank_ordinal
!= num_blocks
) {
634 LOG_WARNING("Class mismatch, bank %d is not FlexRAM",
637 } else if (bank
->size
!= ee_size
) {
638 LOG_WARNING("FlexRAM size mismatch");
640 } else if (bank
->base
!= FLEXRAM
) {
641 LOG_WARNING("FlexRAM address mismatch");
643 } else if (kinfo
->sector_size
!=
644 kinetis_flash_params
[granularity
].nvm_sector_size_bytes
) {
645 LOG_WARNING("FlexRAM sector size mismatch");
648 LOG_DEBUG("FlexRAM bank %d already configured okay",
649 kinfo
->bank_ordinal
);
654 LOG_WARNING("Unknown or inconsistent flash class");
660 LOG_INFO("Probing flash info for bank %d", bank
->bank_number
);
667 kinfo
->granularity
= granularity
;
669 if ((unsigned)bank
->bank_number
< num_pflash_blocks
) {
670 /* pflash, banks start at address zero */
671 kinfo
->flash_class
= FC_PFLASH
;
672 bank
->size
= (pf_size
/ num_pflash_blocks
);
673 bank
->base
= 0x00000000 + bank
->size
* bank
->bank_number
;
674 kinfo
->sector_size
= kinetis_flash_params
[granularity
].pflash_sector_size_bytes
;
675 kinfo
->protection_size
= pf_size
/ 32;
676 } else if ((unsigned)bank
->bank_number
< num_blocks
) {
677 /* nvm, banks start at address 0x10000000 */
678 kinfo
->flash_class
= FC_FLEX_NVM
;
679 bank
->size
= (nvm_size
/ num_nvm_blocks
);
680 bank
->base
= 0x10000000 + bank
->size
* (bank
->bank_number
- first_nvm_bank
);
681 kinfo
->sector_size
= kinetis_flash_params
[granularity
].nvm_sector_size_bytes
;
682 kinfo
->protection_size
= 0; /* FIXME: TODO: depends on DEPART bits, chip */
683 } else if ((unsigned)bank
->bank_number
== num_blocks
) {
684 LOG_ERROR("FlexRAM support not yet implemented");
685 return ERROR_FLASH_OPER_UNSUPPORTED
;
687 LOG_ERROR("Cannot determine parameters for bank %d, only %d banks on device",
688 bank
->bank_number
, num_blocks
);
689 return ERROR_FLASH_BANK_INVALID
;
694 bank
->sectors
= NULL
;
697 bank
->num_sectors
= bank
->size
/ kinfo
->sector_size
;
698 assert(bank
->num_sectors
> 0);
699 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
701 for (i
= 0; i
< bank
->num_sectors
; i
++) {
702 bank
->sectors
[i
].offset
= offset
;
703 bank
->sectors
[i
].size
= kinfo
->sector_size
;
704 offset
+= kinfo
->sector_size
;
705 bank
->sectors
[i
].is_erased
= -1;
706 bank
->sectors
[i
].is_protected
= 1;
712 static int kinetis_probe(struct flash_bank
*bank
)
714 if (bank
->target
->state
!= TARGET_HALTED
) {
715 LOG_WARNING("Cannot communicate... target not halted.");
716 return ERROR_TARGET_NOT_HALTED
;
719 return kinetis_read_part_info(bank
);
722 static int kinetis_auto_probe(struct flash_bank
*bank
)
724 struct kinetis_flash_bank
*kinfo
= bank
->driver_priv
;
729 return kinetis_probe(bank
);
732 static int kinetis_info(struct flash_bank
*bank
, char *buf
, int buf_size
)
734 const char *bank_class_names
[] = {
735 "(ANY)", "PFlash", "FlexNVM", "FlexRAM"
738 struct kinetis_flash_bank
*kinfo
= bank
->driver_priv
;
740 (void) snprintf(buf
, buf_size
,
741 "%s driver for %s flash bank %s at 0x%8.8" PRIx32
"",
742 bank
->driver
->name
, bank_class_names
[kinfo
->flash_class
],
743 bank
->name
, bank
->base
);
748 static int kinetis_blank_check(struct flash_bank
*bank
)
750 struct kinetis_flash_bank
*kinfo
= bank
->driver_priv
;
752 if (bank
->target
->state
!= TARGET_HALTED
) {
753 LOG_ERROR("Target not halted");
754 return ERROR_TARGET_NOT_HALTED
;
757 if (kinfo
->flash_class
== FC_PFLASH
) {
761 /* check if whole bank is blank */
762 result
= kinetis_ftfx_command(bank
, FTFx_CMD_BLOCKSTAT
, bank
->base
, 0, 0, 0, 0, 0, 0, 0, 0, &ftfx_fstat
);
764 if (result
!= ERROR_OK
)
767 if (ftfx_fstat
& 0x01) {
768 /* the whole bank is not erased, check sector-by-sector */
770 for (i
= 0; i
< bank
->num_sectors
; i
++) {
772 result
= kinetis_ftfx_command(bank
, FTFx_CMD_SECTSTAT
, bank
->base
+ bank
->sectors
[i
].offset
,
773 0, 0, 0, 1, 0, 0, 0, 0, &ftfx_fstat
);
775 if (result
== ERROR_OK
) {
776 bank
->sectors
[i
].is_erased
= !(ftfx_fstat
& 0x01);
778 LOG_DEBUG("Ignoring errored PFlash sector blank-check");
779 bank
->sectors
[i
].is_erased
= -1;
783 /* the whole bank is erased, update all sectors */
785 for (i
= 0; i
< bank
->num_sectors
; i
++)
786 bank
->sectors
[i
].is_erased
= 1;
789 LOG_WARNING("kinetis_blank_check not supported yet for FlexNVM");
790 return ERROR_FLASH_OPERATION_FAILED
;
796 static int kinetis_flash_read(struct flash_bank
*bank
,
797 uint8_t *buffer
, uint32_t offset
, uint32_t count
)
799 LOG_WARNING("kinetis_flash_read not supported yet");
801 if (bank
->target
->state
!= TARGET_HALTED
) {
802 LOG_ERROR("Target not halted");
803 return ERROR_TARGET_NOT_HALTED
;
806 return ERROR_FLASH_OPERATION_FAILED
;
809 struct flash_driver kinetis_flash
= {
811 .flash_bank_command
= kinetis_flash_bank_command
,
812 .erase
= kinetis_erase
,
813 .protect
= kinetis_protect
,
814 .write
= kinetis_write
,
815 .read
= kinetis_flash_read
,
816 .probe
= kinetis_probe
,
817 .auto_probe
= kinetis_auto_probe
,
818 .erase_check
= kinetis_blank_check
,
819 .protect_check
= kinetis_protect_check
,
820 .info
= kinetis_info
,
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)