[tools] feat: auto-select Keil/IAR target by Kconfig linker script - #11743
[tools] feat: auto-select Keil/IAR target by Kconfig linker script#11743nxp-ran wants to merge 3 commits into
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
| ewd_template = target.replace('.ewp', '.ewd').replace('project', 'template') | ||
| ewd_target = target.replace('.ewp', '.ewd') | ||
| if not os.path.exists(ewd_template): | ||
| ewd_template = 'template.ewd' | ||
| if os.path.exists(ewd_template): | ||
| shutil.copy2(ewd_template, ewd_target) | ||
|
|
||
| ewt_template = target.replace('.ewp', '.ewt').replace('project', 'template') | ||
| ewt_target = target.replace('.ewp', '.ewt') | ||
| if not os.path.exists(ewt_template): | ||
| ewt_template = 'template.ewt' | ||
| if os.path.exists(ewt_template): | ||
| shutil.copy2(ewt_template, ewt_target) |
There was a problem hiding this comment.
新增逻辑从输出工程名推导模板路径。使用 --project-name=foo 时,第一次生成 foo.ewd,第二次会执行同文件复制并触发 SameFileError。模板源应固定解析为目标目录下的 template.ewd/template.ewt。
There was a problem hiding this comment.
钩子虽然正确更新了 project.uvoptx,但检测到 UV4.exe 后,构建逻辑仍固定读取模板中的第一个 Target。选择 FLEXSPI_NOR 时活动目标是 rtthread_flexspi_nor,实际传给 UV4.exe -t 的却仍是 rtthread_ram,可能生成错误镜像。
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
i.MX RT1180 EVK BSP 通过 Kconfig 选择不同的链接脚本(RAM / FLEXSPI_NOR / HYPERRAM / FLEXSPI_NOR_HYPERRAM),并在 Keil/IAR 工程中对应不同的 target/configuration。此前生成的工程无法自动选中与所选链接脚本匹配的 target/配置,需要手动切换。本 PR 通过在通用工具中引入"可选板级钩子",让 BSP 自行决定激活哪个 target/配置,对不定义钩子的其他芯片零影响。
你的解决方案是什么 (what is your solution)
hasattr(rtconfig, ...)探测并调用可选钩子,用 try/except 守卫。tools/targets/iar.py 改动详解
1. 工作区模板占位符改造
改动前:
改动后:
说明:把匿名占位符
%s改为命名占位符,新增%(active_config)s用于插入<activeConfig>段。无激活配置时active_elem为空串,渲染结果与旧版逐字节一致,保证对其他板子无影响。2. IARWorkspace 增加 active_config 参数
说明:新增可选参数(默认
None,向后兼容)。有配置时在.eww中写入<activeConfig><name>项目名/配置名</name></activeConfig>,声明工程默认激活哪个 configuration。3. 新增 _update_iar_wsdt() 函数
说明:
.wsdt是 IAR 的会话文件,其<CurrentConfigs><Project>决定 IDE 实际选中的配置。只更新.eww不够,需同步.wsdt。函数分"文件不存在则新建"和"文件存在则改/补节点"两种情况,出错只警告不中断。4. IlinkConfigDefines 处理块(新增)
说明:这是更新 IAR 工程的
IlinkConfigDefines选项(对应 IDE 中 Linker -> Config -> Configuration file symbol definitions)。作用是把 SCons 收集到的 LINKFLAGS 里的链接器符号定义(如symbol=value这类给链接脚本用的宏)用re.findall(r'\S+', ...)按空白拆分成一个个 token,写成<state>子节点注入到该 option 下,使链接脚本依赖的符号能正确传给 ilinkarm。注意:此块不受
active_config守卫,对所有 IAR 板子生效;但仅当模板.ewp中存在IlinkConfigDefines选项且 LINKFLAGS 非空时才写入,多数板子该项为空、行为基本不变。5. IARProject 中的钩子调用与文件复制(新增)
说明:
hasattr+try/except守卫,其他芯片没有iar_get_active_config则active_config保持None,.wsdt更新整段跳过,行为不变。.ewd/.ewt复制:把调试器设置和构建设置从模板复制到实际工程文件,均有os.path.exists保护,模板不存在则安全跳过。此段不受active_config守卫,对所有 IAR 板子生效。tools/targets/keil.py 改动详解
1. MDK45Project:多 Target 支持
改动前(只处理第一个 Target):
改动后(遍历所有 Target):
说明:
copy.deepcopy复制到所有其它 target,并对每个 target 分别写入 IncludePath、Define、uC99、uGnu、Misc(链接选项)。if ... is not None空值保护,比旧版直接.text =更健壮。findall只返回一个节点,target_node is first_target恒为真,跳过 deepcopy,行为与旧版等价。2. MDK5Project:复制 uvoptx 后调用可选钩子
改动前:
改动后:
说明:复制得到
project.uvoptx后,若 BSP 定义了update_keil_active_target钩子则调用它,把.uvoptx里匹配所选 linker script 的 target 的<IsCurrentTarget>置 1、其余置 0。用hasattr+try/except守卫,其他芯片跳过,行为不变。bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/rtconfig.py(cm7 同步)中的实现
1. linker script -> target/配置名映射表
2. Keil 钩子:设置激活 target
3. IAR 钩子:返回激活 configuration 名
说明:cm7/rtconfig.py 做同样改动,仅 target 映射表多一个 HYPERRAM 条目(cm7 特有)。原 cm7 里的
_LINKER_SCRIPT_TO_KEIL_TARGET已统一重命名为_LINKER_SCRIPT_TO_PROJECT_TARGET,并抽出_get_active_project_target()供两个钩子复用。CONFIG_BSP_LINKER_SCRIPT_RAM
CONFIG_BSP_LINKER_SCRIPT_HYPERRAM
CONFIG_BSP_LINKER_SCRIPT_FLEXSPI_NOR
CONFIG_BSP_LINKER_SCRIPT_FLEXSPI_NOR_HYPERRAM
新增的功能也初步测试了其他项目生成IAR和KEIL工程的兼容性,包括bsp\nxp\imx\imxrt\imxrt1060-nxp-evk, bsp\nxp\mcx\mcxn\frdm-mcxn947 和 bsp\stm32\stm32h743-st-nucleo
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up