FLASH bootloader questions (K60)

Showing results for 
Search instead for 
Did you mean: 

FLASH bootloader questions (K60)

Contributor I

I am trying to understand the limitations of erasing and writing to FLASH (on a FLASH only / no FlexNVM device) while executing from FLASH.

I have a bootloader that fills SECTOR0 (32K) on a 1MEG part.  Can I erase and write to any other sector on the device?  I saw several references in the documentation that made it sound like you could only write to a "block" that you were not executing from.  But I believe these devices only have two FLASH "blocks" (unless I misunderstand what a "block" is).  Is the read/erase exclusion sector based or block based?

Separately.... what is the easiest way to be able to overwrite my bootloader, i.e.write to Sector0 from code executing in Sector0?

- Have the bootloader copied into RAM on startup?  Then the entire FLASH device, all 1MEG, should be erasable and writable, right?



Labels (1)
0 Kudos
3 Replies

Senior Contributor III

You are correct in that these 'K' parts (but not KL!) do have two 'blocks' of Flash, and you cannot run code in the one you are erasing/writing.  To avoid dealing with any of that, in my usage I have let the IAR tools put the whole Bootloader in RAM so I am free to 'fiddle' sectors 'as necessary'.  At one point I was TRYING to use the available 'block swap' mechanism to allow me to create a guaranteed recovery during bootloader update, but that concept was thwarted by later silicon that made the swap mechanism pretty well forced to ONLY work for true ping-pong whole-half code image swaps.

0 Kudos

Contributor I

Are you using Keil by chance?  We're having a bit of trouble getting our boot-loader to run from RAM only.  We have two issues:

1) We've created a scatter file to place all of the code in RAM.  This appears to work when using the debugger (looks like the debugger programs the RAM), but fails when we run the device without the debugger (for some reason the code is not being loaded into RAM from FLASH).

2) We're not sure how to create a second vector table in RAM.  Do you know of an example for this?



0 Kudos

Senior Contributor III

Sorry, no, I have used the IAR toolchain (6.30 presently).  The best I can do is supply the '.icf' file used there, in hopes it will spark some thoughts with this key line "initialize by copy { readonly code , readwrite };".  As for the vector table, I let the Bootloader use the 'default' ROM@0 table, but the bootloader doesn't use any interrupts during flash operations.  MQX (the APPlication task) is already set to use a different vector table arrangement thru VTOR, first ROM then RAM.


/*###ICF### Section handled by ICF editor, don't touch! ****/

/*-Editor annotation file-*/

/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\a_v1_0.xml" */


define symbol __ICFEDIT_intvec_start__ = 0x00000000;

/*-Memory Regions-*/

define symbol __ICFEDIT_region_ROM_start__ = 0x00000410;

define symbol __ICFEDIT_region_ROM_end__ = 0x00003FFF;

define symbol __ICFEDIT_region_RAM_start__ = 0x1fff01b0;

define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF;


define symbol __ICFEDIT_size_cstack__ = 0x200;

define symbol __ICFEDIT_size_heap__ = 0x2000;

/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;

define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__ ];

define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];

define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };

define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };

//define block FIXED_ORDER_RAM with fixed order {section .text, section .noinit, section .data, section .bss};

define region APP = mem:[from 0x004000 to 0x7FFFF];

place in APP {section APPcode};

initialize by copy { readonly code , readwrite };

//initialize by copy { readwrite };

do not initialize { section .noinit };

place at address mem: __ICFEDIT_intvec_start__ { readonly section .intvec };

place at address mem: 0x00000100 {readonly data section STARTUP };

place at address mem: 0x00000400 {readonly data section FLSH_CONF };

place at address mem: 0x00003FBC {readonly data section METADATA };

//place at address mem: 0x0007FFBC {readwrite data section APP_METADATA };

place at address mem: 0x14000000 {readwrite section BOOTDATA };

place at end of ROM_region { readonly section .checksum };

place in ROM_region { readonly };

place in RAM_region { readwrite, /*block FIXED_ORDER_RAM,*/ block CSTACK, block HEAP };

0 Kudos