Repository navigation
[tools] feat: auto-select Keil/IAR target by Kconfig linker script #11743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d4a86fc
410951e
0268caf
66b15aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,11 +231,15 @@ def MDK45Project(env, tree, target, script): | |
| CFLAGS = '' | ||
| ProjectFiles = [] | ||
|
|
||
| # add group | ||
| groups = tree.find('Targets/Target/Groups') | ||
| import copy | ||
|
|
||
| # add groups to the first target; they will be copied to all other targets afterward | ||
| first_target = tree.find('Targets/Target') | ||
| groups = first_target.find('Groups') | ||
| if groups is None: | ||
| groups = SubElement(tree.find('Targets/Target'), 'Groups') | ||
| groups = SubElement(first_target, 'Groups') | ||
| groups.clear() # clean old groups | ||
|
|
||
| for group in script: | ||
| group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path, group) | ||
|
|
||
|
|
@@ -290,19 +294,23 @@ def MDK45Project(env, tree, target, script): | |
| paths = [_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH] | ||
| IncludePath.text = ';'.join(dict.fromkeys(paths)) | ||
|
|
||
| Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') | ||
| Define.text = ', '.join(set(CPPDEFINES)) | ||
| dfn = target_node.find('TargetOption/TargetArmAds/Cads/VariousControls/Define') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里保留了循环体,却缺失循环和 define_text 初始化,单纯调整缩进仍会引用未定义变量。由于 targets/init.py 无条件导入 keil,IAR、CMake、Eclipse 等工程生成也会被阻断。应恢复完整循环及初始化。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 但是在292行和293行已经加上了如下代码: 所以这个地方没有问题吧? |
||
| if dfn is not None: | ||
| dfn.text = define_text | ||
|
|
||
| if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS: | ||
| uC99 = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uC99') | ||
| uC99.text = '1' | ||
| if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS: | ||
| uC99 = target_node.find('TargetOption/TargetArmAds/Cads/uC99') | ||
| if uC99 is not None: | ||
| uC99.text = '1' | ||
|
|
||
| if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS: | ||
| uGnu = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uGnu') | ||
| uGnu.text = '1' | ||
| if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS: | ||
| uGnu = target_node.find('TargetOption/TargetArmAds/Cads/uGnu') | ||
| if uGnu is not None: | ||
| uGnu.text = '1' | ||
|
|
||
| Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') | ||
| Misc.text = LINKFLAGS | ||
| misc = target_node.find('TargetOption/TargetArmAds/LDads/Misc') | ||
| if misc is not None: | ||
| misc.text = LINKFLAGS | ||
|
|
||
| xml_indent(root) | ||
| out.write(etree.tostring(root, encoding='utf-8').decode()) | ||
|
|
@@ -364,18 +372,37 @@ def MDK5Project(env, target, script): | |
| # copy uvopt file | ||
| if os.path.exists('template.uvoptx'): | ||
| import shutil | ||
| shutil.copy2('template.uvoptx', '{}.uvoptx'.format(os.path.splitext(target)[0])) | ||
| # build with UV4.exe | ||
| project_uvoptx = '{}.uvoptx'.format(os.path.splitext(target)[0]) | ||
| shutil.copy2('template.uvoptx', project_uvoptx) | ||
|
|
||
| # Set the active target from the BSP via an optional board-specific hook. | ||
| # The hook returns the active target name so we build the matching target. | ||
| active_target_name = None | ||
| try: | ||
| import rtconfig | ||
| if hasattr(rtconfig, 'update_keil_active_target'): | ||
| active_target_name = rtconfig.update_keil_active_target(project_uvoptx) | ||
| except Exception as e: | ||
| print('Warning: could not set Keil active target: %s' % e) | ||
|
|
||
| # build with UV4.exe | ||
| if shutil.which('UV4.exe') is not None: | ||
| target_name = template_tree.find('Targets/Target/TargetName') | ||
| print('target_name:', target_name.text) | ||
| # Prefer the active target reported by the BSP hook; fall back to the | ||
| # template's first target only when no hook is available. | ||
| if not active_target_name: | ||
| target_name = template_tree.find('Targets/Target/TargetName') | ||
| active_target_name = target_name.text | ||
| print('target_name:', active_target_name) | ||
|
|
||
| # Use the actual generated project file name (honors --project-name). | ||
| uvprojx_name = os.path.basename(target) | ||
|
|
||
| log_file_path = 'keil.log' | ||
| if os.path.exists(log_file_path): | ||
| os.remove(log_file_path) | ||
| log_thread = threading.Thread(target=monitor_log_file, args=(log_file_path,)) | ||
| log_thread.start() | ||
| cmd = 'UV4.exe -b project.uvprojx -q -j0 -t '+ target_name.text +' -o '+log_file_path | ||
| cmd = 'UV4.exe -b '+ uvprojx_name +' -q -j0 -t '+ active_target_name +' -o '+log_file_path | ||
| print('Start to build keil project') | ||
| print(cmd) | ||
| os.system(cmd) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当 group 的 LINKFLAGS 包含 --keep=Reset_Handler 或 --config_def APP_OFFSET=0x1000 时,所有 token 都会进入 IlinkConfigDefines。已验证生成结果包含独立的 --config_def 等无效符号项;该字段只接受 symbol=value。应单独提取配置符号,或使用专用字段。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以LINKFLAGS 里是不是就不应该有 --config_def 这些内容,而应该只是想要添加的宏?
就像现在bsp\nxp\imx\imxrt\imxrt1180-nxp-evk\cm33\board\SConscript中,关于LINKFLAGS的使用是如下实现的:
而不是:
--keep=Reset_Handler 这些内容,是不是就不应该出现在 LINKFLAGS 中? 而是属于LFLAGS?出现在LINKFLAGS 本身就错误使用,而不是应该iar.py 应该处理的事务?
keil.py 的做法极其简单——不解析,整串透传:
而IAR这边因为没类似KEIL有misc这种灵活的方式。所以这边关于ILINK的配置,应该怎么处理更好?我只需要判断symbol=value这种情况,然后其他的都直接不处理吗?