|
1 | 1 | #!/usr/bin/python3 |
2 | 2 | # coding=utf-8 |
3 | 3 |
|
| 4 | +# MIT License |
| 5 | +# Copyright (c) 2026 github0null |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be included in all |
| 14 | +# copies or substantial portions of the Software. |
| 15 | +# |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +# SOFTWARE. |
| 23 | + |
4 | 24 | from pathlib import Path |
5 | 25 | import click |
6 | 26 | import os |
|
12 | 32 | from pyocd.core.memory_map import MemoryType |
13 | 33 | from pyocd.target.pack.cmsis_pack import (CmsisPack) |
14 | 34 |
|
| 35 | +app_version = "v0.1.9" |
15 | 36 |
|
16 | 37 | class CommentedTreeBuilder(ElementTree.TreeBuilder): |
17 | 38 | def comment(self, data): |
@@ -40,17 +61,20 @@ def pretty_xml(element, indent, newline, level=0): |
40 | 61 |
|
41 | 62 |
|
42 | 63 | @click.command() |
43 | | -@click.option('--xml-path', '-x', default=None, type=click.STRING, help='jlink xml file path') |
| 64 | +@click.option('--jlink-dir', '-j', default=None, type=click.STRING, help='jlink root dir. if not set, it will auto search in system path') |
44 | 65 | @click.argument('pack_path') |
45 | | -def main(pack_path: str, xml_path: str): |
| 66 | +def main(pack_path: str, jlink_dir: str): |
46 | 67 | """Import MCU Database From Cmsis Packages To JLink""" |
47 | 68 |
|
48 | 69 | if pack_path == None: |
49 | 70 | raise Exception('We need a cmsis .pack path !') |
50 | 71 |
|
51 | | - if xml_path == None: |
| 72 | + xml_path = None |
| 73 | + if jlink_dir == None: |
52 | 74 | p_jlink = find_exe('jlink') |
53 | 75 | xml_path = os.path.dirname(p_jlink) + '/' + 'JLinkDevices.xml' |
| 76 | + else: |
| 77 | + xml_path = jlink_dir + '/' + 'JLinkDevices.xml' |
54 | 78 |
|
55 | 79 | if not os.path.isabs(xml_path): |
56 | 80 | xml_path = os.path.abspath(xml_path) |
@@ -118,7 +142,7 @@ def main(pack_path: str, xml_path: str): |
118 | 142 | if not has_comment_header: |
119 | 143 | has_comment_header = True |
120 | 144 | xml_dom_db.append(ElementTree.Comment('')) |
121 | | - xml_dom_db.append(ElementTree.Comment(' {} ({}) (add by \'jlink-dev-addon\', author: github0null) '.format(vendor_name, dev_familys[0]))) |
| 145 | + xml_dom_db.append(ElementTree.Comment(f" {vendor_name} ({dev_familys[0]}) (add by jlink-dev-addon {app_version})")) |
122 | 146 | xml_dom_db.append(ElementTree.Comment('')) |
123 | 147 |
|
124 | 148 | n_ele = SubElement(xml_dom_db, 'Device') |
|
0 commit comments