IAR环境中Kinetis的“0x40C -0x40F”加密位无法真正写入的原因和解决方法 (The way to solve the write-acess of Kinetis' security byte “0x40C -0x40F” in IAR6.6)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IAR环境中Kinetis的“0x40C -0x40F”加密位无法真正写入的原因和解决方法 (The way to solve the write-acess of Kinetis' security byte “0x40C -0x40F” in IAR6.6)

IAR环境中Kinetis的“0x40C -0x40F”加密位无法真正写入的原因和解决方法 (The way to solve the write-acess of Kinetis' security byte “0x40C -0x40F” in IAR6.6)

最近,有客户反映在IAR6.6 环境中,即便在程序中配置了Kinetis的加密字段“0x40C -0x40F”,但在实际程序运行中发现这些加密位并没有被真正的写进去。现根据Colleagues的分析,结合个人的理解总结如下,描述不清楚之处希望能提出宝贵意见。


原因:新版本的IAR 6.6 为了防止用户在使用Kinetis过程中误操作导致芯片被锁死,默认将加密位Disable了,在烧录Flash的时候设了最后一道闸门,将0x40C -0x40F的值统一成0xFFFFFFFE (解密模式) 如果要完成加密, 可以修改其Flash Loader配置。


证据:在C:\Program Files\IAR Systems\Embedded Workbench 6.5_2\arm\config\flashloader\Freescale文件夹中,查看FlashK60Dxxx128K.board文件可以看到如下描述,其中<args_doc>与</args_doc>可以理解为一些注释,需要按解决方法的步骤设置。

<args_doc>.....--enable_config_write - allow programming of 0x40C - 0x40F with user supplied data, in other case flashloader after erase of block 0 will write 0xFFFFFFFE (unsecure state).</args_doc>


解决方法:

1) 打开IAR的Options配置框,选择Debuger的Download 标签,勾选如下图所示的选项,可以看到此项目中对应的.board文件;

QQ截图5.png

2) 点击edit按钮, 显示如下对话框,两处分别对应包含不同Flash Memory的器件设备;

QQ截图6.png

3) 对于不包含FlexNVM的器件,选择0x0-0xfffffff对应的条目,然后选择Edit;

4) 在下面的对话框中的extra edit 项目中填写 --enable_config_write , 它意味着打开了在烧录Flash的时候设置的最后一道闸门,使能了用户对加密字段“0x40C -0x40F”的配置。关于此参数选项含义,可以查看下面框中parameters description的描述。

QQ截图7.png

5) 选择OK , 回到上级对话框,如下图可以看到“--enable_config_write”作为一个Extra Parameters显示出来;

QQ截图8.png

6)再次选择OK,回到上层对话框。 此处不用担心OK后修改的配置会替换Flash Loader中的默认配置,因为系统自动保存刚才的修改到一个新的board文件,并存储到当前工程的文件目录中;

QQ截图9.png

7) 选择“save 保存;

8) 选择"OK”然后开始下载。

QQ截图10.png

9) 如果以后需要加密的时候, 可以使用新的board文件, 不需要加密的时候,选择使用IAR下面的board文件。

     至此,完成整个配置过程。

关于在J_flash中选择使用加密:

1)在Jflash中选择project settings;

QQ图片1.jpg

QQ图片2.jpg

2)在Project settings栏选择CPU标签,勾选Device选项,并点击Freescale MKL25Z128xxx4后面的方框;

QQ截图3.png

3)在如下窗口Manufacturer中选择Freescale,找到对应的Device,选择带有"allow security"的选项,就可以支持加密了。否则即便在程序中Kinetis的加密字节设置了加密,代码也不会实     际的运行。

QQ截图4.png

Comments

It’s a good practice. Is it verified and tested?

Best Regards,

Gang Chen

Yes, the case has been verified by Derek last week, I also make a general test just now.

good, I have a customer encountering this problem.

It looks like the new version IAR may presents this issue, and another things need to note is that it may arise an  error saying "Missing or malformed flash loader specification file: C:\Program Files\IAR Systems\arm\config\flashloader\Freescale\FlashK60Xxxx.board"  when we build the old K60/K40/K53's demo code in flash using the new version IAR6.6, That's because in the new version IAR it names the different device by its RAM size, which is not like the old version IAR.

 

To solve this subject, As K60DN512 Only need to setup Options-> Debugger->Download->use Flash Loader-> Override default .board file, then check the "override default .board file" tab, and select FlashK60Dxxx_128K.board instead of default FlashK60Xxxx.board. Then the demo will work well.

How to do it  with  KDS?

There should be no such issue in KDS,in KDS you just need to make the configuration in startup_MKXXX.S file like below. it's very similar with CW.

/* Flash Configuration */

    .section .FlashConfig, "a"

    .long 0xFFFFFFFF

    .long 0xFFFFFFFF

    .long 0xFFFFFFFF

    .long 0xFFFFFFFE

    .text

    .thumb

/* Reset Handler */

No ratings
Version history
Last update:
‎09-03-2013 02:13 AM
Updated by: