aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Kilgour <techie@whiterocker.com>2013-04-22 19:08:15 -0700
committerFreddie Chopin <freddie.chopin@gmail.com>2013-04-28 07:37:03 +0000
commit392fe709275d830b0da79b46a6b1447264178c52 (patch)
treec7f6b245a7c7365dd668bda120108b5b1ce44172
parentece28927017614a20b80fdc203584ca919f81878 (diff)
kinetis: fix "SF1" parts to limit FlexRAM usage
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>
-rw-r--r--src/flash/nor/kinetis.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index 494c266c..fe18451c 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -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);