[tools] feat: auto-select Keil/IAR target by Kconfig linker script - #11743
Open
nxp-ran wants to merge 1 commit into
Open
[tools] feat: auto-select Keil/IAR target by Kconfig linker script#11743nxp-ran wants to merge 1 commit into
nxp-ran wants to merge 1 commit into
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(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