Tasking LSL(Linker Script Language)速览版
🧭 Tasking 链接脚本(LSL)快速掌握指南
适用于 Infineon AURIX / TriCore 平台的 Tasking 编译器
LSL = Linker Script Language
🧱 总体结构
Tasking 的 LSL 文件分为 三层:
1┌─────────────────────────────┐
2│ memory → 定义物理内存 │ ← 硬件层(哪有RAM、FLASH)
3├─────────────────────────────┤
4│ section_layout → 定义布局 │ ← 逻辑层(代码/数据放哪)
5├─────────────────────────────┤
6│ symbol / group → 实际放置段 │ ← 组织层(组织和符号定义)
7└─────────────────────────────┘可类比 GNU .ld 文件中的:
1MEMORY { ... }
2SECTIONS { ... }⚙️ memory —— 定义物理内存区
1memory psram0
2{
3 mau = 8; // memory access unit (bit)
4 size = 64K; // 容量
5 type = ram; // 类型:ram / rom / flash
6 map (dest=bus:tc0:fpi_bus, dest_offset=0xC0000000, size=64K);
7}📘 说明:
- 只定义“有哪些物理存储器”,不放代码;
- 可定义多个 memory:
psram0,dsram0,pflash0,dflash0; - 地址用
map()指定。
🧩 section_layout —— 定义逻辑布局
1section_layout :vtc:linear
2{
3 group
4 {
5 group code_psram0 (ordered, attributes=rwx, copy, run_addr=mem:psram0)
6 {
7 select "(.text.cpu0_psram|.text.cpu0_psram.*)";
8 }
9 }
10}📘 说明:
section_layout= “整体布局定义区”;:vtc:linear= layout 模式(线性分布);- 内含若干
group; select语句指定哪些输入节放进去。
🧱 group —— 放置具体段(section)
1group flash_driver (align=4, attributes=rx, run_addr=mem:psram0[64K-0x800])
2{
3 section ".flash_driver_header";
4 section ".flash_driver_body";
5}📘 关键属性:
| 关键字 | 含义 |
|---|---|
align=4 | 地址对齐 |
attributes=rx | 区域属性:r=read, w=write, x=execute |
run_addr=mem:xxx[offset] | 指定运行地址 |
load_addr=mem:xxx[...] | 指定加载地址(拷贝用) |
copy | 从加载区拷贝到运行区(RAM 运行的代码用) |
ordered | 按定义顺序排列 |
reserved | 保留一块空间(不放 section) |
📦 select —— 选择输入节 (input sections)
1select "(.text.cpu0_psram|.text.cpu0_psram.*)";📘 匹配规则与正则类似:
| 示例 | 匹配 | |
|---|---|---|
"(.text)" | 仅匹配 .text | |
"(.text.*)" | 匹配所有 .text.xxx | |
| `"(.data | .data.*)"` | 匹配 .data 及子段 |
C 代码中用 __attribute__((section(".text.cpu0_psram"))) 与之对应。
🧩 符号定义与引用
LSL 可定义或绑定符号:
1"__USTACK0" := "_lc_ue_ustack_tc0";
2"__FLASH_DRIVER_ADDR__" := "_lc_gb_flash_driver";📘 含义:
:=表示符号赋值;_lc_gb_*/_lc_ge_*是链接器自动生成的段首尾符号;- C 代码可直接引用这些符号(例如堆栈初始化)。
💾 特殊关键字和属性
| 关键字 | 说明 |
|---|---|
mau | memory access unit,通常 8 bit |
size | 定义区域大小 |
map() | 定义物理地址映射 |
type | 内存类型(ram / rom / flash) |
run_addr | 代码运行地址 |
load_addr | 加载地址(如从 Flash 拷贝到 RAM) |
attributes | 权限属性(rwx) |
align | 对齐要求 |
ordered | 保持顺序 |
reserved | 保留空间不放 section |
copy | 拷贝标记,用于代码搬运 |
fill | 用固定值填充空隙 |
group | 创建逻辑分组 |
section | 放置具体 section |
select | 匹配输入 section |
:= | 定义符号 |
sizeof(group:xxx) | 获取组大小 |
_lc_gb_xxx, _lc_ge_xxx, _lc_ub_xxx, _lc_ue_xxx | 链接器自动符号(begin/end) |
🧠 常见模式总结
| 目标 | 典型写法 |
|---|---|
| 定义 RAM / FLASH | memory psram0 { ... } |
| 代码放入特定内存 | group code_psram0 (run_addr=mem:psram0) { select "(.text.*)" } |
| 定义栈/堆/CSA 区 | group (align=8, run_addr=mem:dsram0[offset]) stack "ustack" (size=2k); |
| 定义常量符号 | "__STACK_END__" := "_lc_ue_ustack"; |
| 保留空间 | reserved "heap0" (size=8k); |
| 分核布局 | code_psram0, code_psram1, code_psram2… 对应各 CPU |
🧩 与 GNU LD Script 对照表
| GNU LD | Tasking LSL |
|---|---|
MEMORY {} | memory {} |
SECTIONS {} | section_layout {} |
.text : { *(.text) } > FLASH | group code (run_addr=mem:pflash0) { select "(.text)" } |
__start_xxx | _lc_gb_xxx |
__end_xxx | _lc_ge_xxx |
🧱 典型结构模板(完整)
1memory pflash0 { mau=8; size=2M; type=rom; map(dest=bus:sri, dest_offset=0x80000000, size=2M); }
2memory psram0 { mau=8; size=64K; type=ram; map(dest=bus:tc0:fpi_bus, dest_offset=0xC0000000, size=64K); }
3memory dsram0 { mau=8; size=240K; type=ram; map(dest=bus:tc0:fpi_bus, dest_offset=0xD0000000, size=240K); }
4// memory dsram0 { mau=8; size=240K; type=ram; map(dest=bus:tc0:fpi_bus, dest_offset=0xD0000000, reserved, size=240K); }
5
6section_layout :vtc:linear
7{
8 group
9 {
10 /* Flash code */
11 group code_flash (attributes=rx, run_addr=mem:pflash0)
12 {
13 select "(.text|.text.*)";
14 }
15
16 /* RAM code */
17 group code_psram0 (attributes=rwx, copy, run_addr=mem:psram0)
18 {
19 select "(.text.cpu0_psram|.text.cpu0_psram.*)";
20 }
21
22 /* Flash driver in psram0 tail */
23 group flash_driver (align=4, attributes=rx, run_addr=mem:psram0[64K-0x800])
24 {
25 section ".flash_driver_header";
26 section ".flash_driver_body";
27 }
28
29 /* Stack and CSA */
30 group (align=8, run_addr=mem:dsram0[200K]) stack "ustack_tc0" (size=2k);
31 group (align=8, run_addr=mem:dsram0[210K]) reserved "csa_tc0" (size=8k);
32
33 "__FLASH_DRIVER_ADDR__" := "_lc_gb_flash_driver";
34 }
35}✅ 总结一句话
memory定义“硬件内存”,section_layout定义“代码布局”,group组织“逻辑段”,select匹配“输入 section”。 调试技巧:可以使用WARNING, ERROR输出一些调试信息
评论