Author Topic: Programming issues resolved with linker file change  (Read 5817 times)

Offline mdkendall

  • Newbie
  • *
  • Posts: 4
    • View Profile
Programming issues resolved with linker file change
« on: September 22, 2014, 10:57:45 PM »
After making a small change and rebuilding the serial bootloader for the Kinetis K60 I had problems programming it in to the target (using the Flash Programmer utility from within CodeWarrior, with a P&E Micro Multilink Universal FX). I had consistent errors programming the third segment, even after a full erase:

Code: [Select]
cmdwin::fl::write
 Beginning Operation ...   
-------------------------
Using restricted address range 0x00000000 to 0x000FFFFF   
Programming file C:\Users\mdkendall.ELEMENTS\Documents\SCU-Bootloader\Applications\uTaskerSerialBoot\KinetisCodeWarrior\uTaskerSer
ialBoot_FLASH\uTaskerSerialBoot.srec   
Auto-detection is successful.   
  File is of type Motorola S-Record Format.   
 
 Downloading Flash Device Driver ...   
 Reading flash ID ...
Auto-detection is successful.   
  File is of type Motorola S-Record Format.   
 
Downloading 0x00000008 bytes to be programmed at 0x00000000   
Executing program ....   
 Program Command Succeeded   
Downloading 0x00004D4B bytes to be programmed at 0x00000400   
Executing program ....   
 Program Command Succeeded   
Downloading 0x00000023 bytes to be programmed at 0x0000514C   
Executing program ....   
Error:  Program failed.   Flash driver reports the following error(s):  Chip reported error during program. Please check that the sector you are programming is erased.

After a bit of Googling I found a post on the Freescale forums that indicates an alignment of 8 is required.
https://community.freescale.com/thread/312328

The segment that failed to program was on a 4-byte boundary. I edited the linker file (\Applications\uTaskerV1.4\KinetisCodeWarrior\Linker_Files\K_1M_128.ld) to change all the ALIGN(foo, 4) directives to ALIGN(foo, 8 ) and that has fixed my problem:

Code: [Select]
cmdwin::fl::write
 Beginning Operation ...   
-------------------------
Using restricted address range 0x00000000 to 0x000FFFFF   
Programming file C:\Users\mdkendall.ELEMENTS\Documents\SCU-Bootloader\Applications\uTaskerSerialBoot\KinetisCodeWarrior\uTaskerSer
ialBoot_FLASH\uTaskerSerialBoot.srec   
Auto-detection is successful.   
  File is of type Motorola S-Record Format.   
 
 Downloading Flash Device Driver ...   
 Reading flash ID ...
Auto-detection is successful.   
  File is of type Motorola S-Record Format.   
 
Downloading 0x00000008 bytes to be programmed at 0x00000000   
Executing program ....   
 Program Command Succeeded   
Downloading 0x0000474C bytes to be programmed at 0x00000400   
Executing program ....   
 Program Command Succeeded   
Downloading 0x000005FF bytes to be programmed at 0x00004B50   
Executing program ....   
 Program Command Succeeded   
Downloading 0x00000023 bytes to be programmed at 0x00005150   
Executing program ....   
 Program Command Succeeded   

I haven't investigated this in any detail, but it has solved my problem.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3188
    • View Profile
    • uTasker
Re: Programming issues resolved with linker file change
« Reply #1 on: September 23, 2014, 12:30:27 AM »
Hi

I think that the reason for the problem lies at the debuggers since the actual code needs 4-byte alignment and not 8-byte alignment.
If you are using a K60 with FPU all Flash programming is performed as phrase programming (8 bytes) - non FPU parts tend to use long word programming. It is possible that the debuggers in question somehow enforce this alignment when programming and so can't handle code with 4 byte alignment.

I tend to work with OpenSDA and KDS, or just the mbed boot loader for copying files to eval boards and never had an issue - eg. today I worked with FRDM-K64F, KDS and the linker scripr file K_1M_256.ld.

The 8-byte alignment therefore looks to be more a workaround for a restriction imposed by some programming tools.

Rather than modify all linker scripts to use 8 byte alignment (at the moment) I will set this thread as "sticky" so that it remains at the top of the board for a while since it may help others who suffer the same issue. If it turns out to be more widespread it may be worth ensuring 8-byte alignment as default - we'll see.

Regards

Mark