十一、从0开始卷出一个新项目之瑞萨RZN2Lrzn2l_coremark_fsp200工程构建和gcc .ld链接文件的修改方法

目录

一、概述

二、rzn2l_fsp2.0.0_coremark工程构建

2.1 目录结构

2.2 项目一览

三、代码优化的问题

四、gcc .ld链接文件修改方法

4.1 .ld文件的构成

4.1.1 包含另一个ld文件

4.1.2 符号/变量

4.1.3 MEMORY 定义内存区域

4.1.4 SECTIONS 定义段到内存的映射

4.1.5 ENTRY VERSIONS等

4.2 .ld文件的重要语法

4.3 ram执行:fsp_ram_execution.ld

4.4 flash启动:fsp_xspi0_boot.ld

4.5 app全部运行在sram:fsp_xspi0_boot_sram_all.ld

4.6 仅text使用sram:fsp_xspi0_boot_sram_text.ld

4.7 优先使用sram特殊使用atcm:fsp_xspi0_boot_sram_atcm.ld

4.8 参考separating-loader-and-application

五、gcc -fno-strict-aliasing(禁用严格别名规则)

六、测试结果


一、概述

二、rzn2l_fsp2.0.0_coremark工程构建

2.1 目录结构

  • coremark文件夹(用户代码)放在项目根目录下,需要增加源文件夹;

图片

图片

图片

2.2 项目一览

图片

三、代码优化的问题

  • rzn-fsp v1.2.0版本及之前版本,可以选择多种优化等级,并且可以通过coremark看到优化和结果,优化等级越高结果越高;

  • rzn-fsp v1.3.0版本及之后版本,优化等级只能选择-O1和-Og,其他等级无法运行;

图片

图片

四、gcc .ld链接文件修改方法

4.1 .ld文件的构成

4.1.1 包含另一个ld文件

例如:
INCLUDE memory_regions.ld

4.1.2 符号/变量

例如:
ATCM_START = 0x00000000;
ATCM_LENGTH = 0x20000;
ATCM_PRV_START = DEFINED(ATCM_START) ? ATCM_START : 0;
ATCM_PRV_LENGTH = DEFINED(ATCM_LENGTH) ? ATCM_LENGTH : 0;

4.1.3 MEMORY 定义内存区域

例如:
MEMORY
{
    ATCM : ORIGIN = ATCM_PRV_START, LENGTH = ATCM_PRV_LENGTH
    BTCM : ORIGIN = BTCM_PRV_START, LENGTH = BTCM_PRV_LENGTH
    SYSTEM_RAM : ORIGIN = SYSTEM_RAM_PRV_START, LENGTH = SYSTEM_RAM_PRV_LENGTH
    ....
}

4.1.4 SECTIONS 定义段到内存的映射

例如:
SECTIONS
{
    .loader_param LOADER_PARAM_ADDRESS : AT (LOADER_PARAM_ADDRESS)
    {
        KEEP(*(.loader_param))
    } > xSPI0_CS0_SPACE
    ....
    .text TEXT_ADDRESS : AT (_mtext)
    {
        _text_start = .;
        *(.text*)

        KEEP(*(.reset_handler))
        KEEP(*(.init))
        KEEP(*(.fini))

        /* .ctors */
        *crtbegin.o(.ctors)
        *crtbegin?.o(.ctors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
        *(SORT(.ctors.*))
        *(.ctors)
        _ctor_end = .;

        /* .dtors */
        *crtbegin.o(.dtors)
        *crtbegin?.o(.dtors)
        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
        *(SORT(.dtors.*))
        *(.dtors)
        _dtor_end = .;

        KEEP(*(.eh_frame*))
    } > RAM
    ....
}

4.1.5 ENTRY VERSIONS等

4.2 .ld文件的重要语法

  • VERSIONS:定义符号版本。

  • ORIGIN:定义内存区域的起始地址。

  • LENGTH:定义内存区域的长度。

  • AT:指定加载地址(对于非连续内存模型)。

  • FILL:用于填充未使用的内存空间。

  • SORT:用于对段进行排序。

  • ALIGN:用于对齐段的起始地址。

  • PROVIDE:为链接器提供一个符号定义,但不创建实际的代码或数据。

  • ASSERT:用于在链接时检查条件是否满足。

  • 通配符

4.3 ram执行:fsp_ram_execution.ld

  • fsp-BSP-Board-(RAM execution without flash memory)

  • 未下载到flash,掉电/复位无法继续执行;boot+app

  • btcm(loader&stack)+atcm(text&data&stack&heap)

4.4 flash启动:fsp_xspi0_boot.ld

  • fsp-BSP-Board-(xSPI0 x1 boot mode)

  • 下载到flash,掉电/复位可执行,需等待写flash

  • btcm(loader&stack)+atcm(text&data&stack&heap)

4.5 app全部运行在sram:fsp_xspi0_boot_sram_all.ld

  • fsp-BSP-Board-(xSPI0 x1 boot mode)

  • 下载到flash,掉电/复位可执行,需等待写flash

  • btcm(loader&stack)+sram(text&data&stack&heap)

  • dma、usb等需要注意处理,使用nocache

4.6 仅text使用sram:fsp_xspi0_boot_sram_text.ld

  • fsp-BSP-Board-(xSPI0 x1 boot mode)

  • 下载到flash,掉电/复位可执行,需等待写flash

  • btcm(loader&stack)+sram(text)+atcm(data、stack、heap)

4.7 优先使用sram特殊使用atcm:fsp_xspi0_boot_sram_atcm.ld

  • fsp-BSP-Board-(xSPI0 x1 boot mode)

  • 下载到flash,掉电/复位可执行,需等待写flash

  • btcm(loader&stack)+sram(优先使用-text&data&stack&heap)+atcm(*/coremark文件夹-text&data)

  • 不改变原有分区结构,只增加单独文件夹使用atcm

  • 需要修改system.c,增加复制过程。通过宏控制FSP_XSPI0_BOOT_SRAM_ATCM

图片

4.8 参考separating-loader-and-application

五、gcc -fno-strict-aliasing(禁用严格别名规则)

  • -fno-strict-aliasing 是一个 GCC(GNU Compiler Collection)的编译选项,用于禁用严格别名规则(strict aliasing rules)

  • https://so.youkuaiyun.com/so/search?spm=1001.2101.3001.4498&q=-fno-strict-aliasing&t=&u=

  • rzn-fsp新版本开始使用,什么作用?

图片

六、测试结果

-Og
hello word!
date:Jun 20 2024
time:11:16:16
file:../src/hal_entry.c
func:hal_entry,line:81
hello world!
PI=3.141593
start coremain!!!

[11:17:14.072]收←◆2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 24856
Total time (secs): 24.856000
Iterations/Sec   : 804.634696
Iterations       : 20000
Compiler version : GCC12.2.1 20230214
Compiler flags   : Please put compiler flags here (e.g. -o3)
Memory location  : STACK
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x382f
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 804.634696 / GCC12.2.1 20230214 Please put compiler flags here (e.g. -o3) / STACK
FSP_PRIV_CLOCK_CPU0=400000000
running!!!
-O1
hello word!
date:Jun 20 2024
time:11:10:55
file:../src/hal_entry.c
func:hal_entry,line:81
hello world!
PI=3.141593
start coremain!!!

[11:11:59.520]收←◆2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 19502
Total time (secs): 19.502000
Iterations/Sec   : 1025.535842
Iterations       : 20000
Compiler version : GCC12.2.1 20230214
Compiler flags   : Please put compiler flags here (e.g. -o3)
Memory location  : STACK
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x382f
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 1025.535842 / GCC12.2.1 20230214 Please put compiler flags here (e.g. -o3) / STACK
FSP_PRIV_CLOCK_CPU0=400000000
running!!!
-Ofast
hello word!
date:Jun 20 2024
time:10:23:02
file:../src/hal_entry.c
func:hal_entry,line:81
hello world!
PI=3.141593
start coremain!!!

[11:08:26.840]收←◆2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 15781
Total time (secs): 15.781000
Iterations/Sec   : 1267.346809
Iterations       : 20000
Compiler version : GCC12.2.1 20230214
Compiler flags   : Please put compiler flags here (e.g. -o3)
Memory location  : STACK
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x382f
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 1267.346809 / GCC12.2.1 20230214 Please put compiler flags here (e.g. -o3) / STACK
FSP_PRIV_CLOCK_CPU0=400000000
running!!!
-O3
hello word!
date:Jun 20 2024
time:11:13:40
file:../src/hal_entry.c
func:hal_entry,line:81
hello world!
PI=3.141593
start coremain!!!

[11:14:34.311]收←◆2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 15781
Total time (secs): 15.781000
Iterations/Sec   : 1267.346809
Iterations       : 20000
Compiler version : GCC12.2.1 20230214
Compiler flags   : Please put compiler flags here (e.g. -o3)
Memory location  : STACK
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x382f
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 1267.346809 / GCC12.2.1 20230214 Please put compiler flags here (e.g. -o3) / STACK
FSP_PRIV_CLOCK_CPU0=400000000
running!!!

图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值