Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
tools/mbedcli_compile.py@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | # |
Pawel Zarembski |
0:01f31e923fe2 | 2 | # DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 3 | # Copyright (c) 2009-2018, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 4 | # SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 5 | # |
Pawel Zarembski |
0:01f31e923fe2 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 7 | # not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 8 | # You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 9 | # |
Pawel Zarembski |
0:01f31e923fe2 | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 11 | # |
Pawel Zarembski |
0:01f31e923fe2 | 12 | # Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | # See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 16 | # limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | # |
Pawel Zarembski |
0:01f31e923fe2 | 18 | |
Pawel Zarembski |
0:01f31e923fe2 | 19 | import argparse |
Pawel Zarembski |
0:01f31e923fe2 | 20 | import os |
Pawel Zarembski |
0:01f31e923fe2 | 21 | import sys |
Pawel Zarembski |
0:01f31e923fe2 | 22 | import shutil |
Pawel Zarembski |
0:01f31e923fe2 | 23 | import yaml |
Pawel Zarembski |
0:01f31e923fe2 | 24 | import mbedcli_tools |
Pawel Zarembski |
0:01f31e923fe2 | 25 | from pre_build_script import generate_version_file |
Pawel Zarembski |
0:01f31e923fe2 | 26 | from package_release_files import package_release_files |
Pawel Zarembski |
0:01f31e923fe2 | 27 | from post_build_script import post_build_script |
Pawel Zarembski |
0:01f31e923fe2 | 28 | |
Pawel Zarembski |
0:01f31e923fe2 | 29 | self_path = os.path.abspath(__file__) |
Pawel Zarembski |
0:01f31e923fe2 | 30 | tools_dir = os.path.dirname(self_path) |
Pawel Zarembski |
0:01f31e923fe2 | 31 | daplink_dir = os.path.dirname(tools_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 32 | test_dir = os.path.join(daplink_dir, "test") |
Pawel Zarembski |
0:01f31e923fe2 | 33 | sys.path.append(test_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 34 | |
Pawel Zarembski |
0:01f31e923fe2 | 35 | import info |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | PROJECTS_YAML = "projects.yaml" |
Pawel Zarembski |
0:01f31e923fe2 | 38 | VERSION_YAML = "version.yaml" |
Pawel Zarembski |
0:01f31e923fe2 | 39 | |
Pawel Zarembski |
0:01f31e923fe2 | 40 | def main(): |
Pawel Zarembski |
0:01f31e923fe2 | 41 | """python -u tools/mbedcli_compile.py kl26z_microbit_if kl26z_bl --clean""" |
Pawel Zarembski |
0:01f31e923fe2 | 42 | #parse project yaml file for project list |
Pawel Zarembski |
0:01f31e923fe2 | 43 | project_list = [] |
Pawel Zarembski |
0:01f31e923fe2 | 44 | with open(PROJECTS_YAML, 'r') as top_yaml: |
Pawel Zarembski |
0:01f31e923fe2 | 45 | try: |
Pawel Zarembski |
0:01f31e923fe2 | 46 | topdict = yaml.load(top_yaml) |
Pawel Zarembski |
0:01f31e923fe2 | 47 | for dict_key in topdict: |
Pawel Zarembski |
0:01f31e923fe2 | 48 | if dict_key == 'projects': |
Pawel Zarembski |
0:01f31e923fe2 | 49 | for project in topdict[dict_key]: |
Pawel Zarembski |
0:01f31e923fe2 | 50 | project_list.append(project) |
Pawel Zarembski |
0:01f31e923fe2 | 51 | break |
Pawel Zarembski |
0:01f31e923fe2 | 52 | except yaml.YAMLError as ex: |
Pawel Zarembski |
0:01f31e923fe2 | 53 | print("Found yaml parse error", ex) |
Pawel Zarembski |
0:01f31e923fe2 | 54 | #parse the arguments |
Pawel Zarembski |
0:01f31e923fe2 | 55 | projects = "List of supported projects\n\n" + ", ".join(project_list) # |
Pawel Zarembski |
0:01f31e923fe2 | 56 | parser = argparse.ArgumentParser(description='mbedcli compile support for DAPLink', epilog=projects, formatter_class=argparse.RawDescriptionHelpFormatter) |
Pawel Zarembski |
0:01f31e923fe2 | 57 | parser.add_argument('projects', help='Selectively compile only the firmware specified otherwise all projects', |
Pawel Zarembski |
0:01f31e923fe2 | 58 | nargs='*', type=str, default=[]) |
Pawel Zarembski |
0:01f31e923fe2 | 59 | parser.add_argument("--board-id", type=str, help="board id to for the target in hex") |
Pawel Zarembski |
0:01f31e923fe2 | 60 | parser.add_argument("--family-id", type=str, help="family id to for the target in hex") |
Pawel Zarembski |
0:01f31e923fe2 | 61 | parser.add_argument("--bin-offset", type=str, help="binary offset in hex") |
Pawel Zarembski |
0:01f31e923fe2 | 62 | parser.add_argument('--release', dest='release', action='store_true', help='Create a release with the yaml version file') |
Pawel Zarembski |
0:01f31e923fe2 | 63 | parser.add_argument('--build-folder', type=str, default='BUILD', help='Release directory to grab files from') |
Pawel Zarembski |
0:01f31e923fe2 | 64 | parser.add_argument('--release-folder', type=str, default='firmware', help='Directory to create and place files in') |
Pawel Zarembski |
0:01f31e923fe2 | 65 | parser.add_argument('--toolchain', type=str, default='ARM', help='Toolchain directory if present') |
Pawel Zarembski |
0:01f31e923fe2 | 66 | parser.add_argument('--clean', dest='clean', action='store_true', help='Rebuild or delete build folder before compile') |
Pawel Zarembski |
0:01f31e923fe2 | 67 | parser.add_argument('-v', dest='verbosity', action='count', help='Pass verbosity level to mbed compile -vv for more') |
Pawel Zarembski |
0:01f31e923fe2 | 68 | parser.set_defaults(clean=False) |
Pawel Zarembski |
0:01f31e923fe2 | 69 | parser.set_defaults(release=False) |
Pawel Zarembski |
0:01f31e923fe2 | 70 | args = parser.parse_args() |
Pawel Zarembski |
0:01f31e923fe2 | 71 | self_path = os.path.abspath(__file__) |
Pawel Zarembski |
0:01f31e923fe2 | 72 | tools_dir = os.path.dirname(self_path) |
Pawel Zarembski |
0:01f31e923fe2 | 73 | daplink_dir = os.path.dirname(tools_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 74 | if os.path.basename(tools_dir) != "tools": |
Pawel Zarembski |
0:01f31e923fe2 | 75 | print("Error - this script must be run from the tools directory") |
Pawel Zarembski |
0:01f31e923fe2 | 76 | exit(-1) |
Pawel Zarembski |
0:01f31e923fe2 | 77 | version_git_dir = os.path.join(daplink_dir, "source", "daplink") |
Pawel Zarembski |
0:01f31e923fe2 | 78 | generate_version_file(version_git_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 79 | if not args.projects == []: |
Pawel Zarembski |
0:01f31e923fe2 | 80 | for project in args.projects: |
Pawel Zarembski |
0:01f31e923fe2 | 81 | print("Compiling %s" % project) |
Pawel Zarembski |
0:01f31e923fe2 | 82 | (cli_hex_output,crc_file_output) = mbedcli_tools.mbedcli_run(daplink_dir, args.build_folder, project, args.toolchain, args.clean, args.verbosity) |
Pawel Zarembski |
0:01f31e923fe2 | 83 | print("Creating crc padded binaries %s" % os.path.basename(cli_hex_output)) |
Pawel Zarembski |
0:01f31e923fe2 | 84 | post_build_script(cli_hex_output, crc_file_output, args.board_id, args.family_id, args.bin_offset) |
Pawel Zarembski |
0:01f31e923fe2 | 85 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 86 | print("compiling all firmware") |
Pawel Zarembski |
0:01f31e923fe2 | 87 | #generate a dictionary of board ID, and family ID |
Pawel Zarembski |
0:01f31e923fe2 | 88 | id_map = {} |
Pawel Zarembski |
0:01f31e923fe2 | 89 | for board_id, family_id, firmware, bootloader, target in info.SUPPORTED_CONFIGURATIONS: |
Pawel Zarembski |
0:01f31e923fe2 | 90 | if firmware in id_map: |
Pawel Zarembski |
0:01f31e923fe2 | 91 | id_map[firmware].append((hex(board_id), hex(family_id))) |
Pawel Zarembski |
0:01f31e923fe2 | 92 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 93 | id_map[firmware] = [(hex(board_id), hex(family_id))] |
Pawel Zarembski |
0:01f31e923fe2 | 94 | for project in project_list: |
Pawel Zarembski |
0:01f31e923fe2 | 95 | print("Compiling %s" % project) |
Pawel Zarembski |
0:01f31e923fe2 | 96 | (cli_hex_output,crc_file_output) = mbedcli_tools.mbedcli_run(daplink_dir, args.build_folder, project, args.toolchain, args.clean, args.verbosity) |
Pawel Zarembski |
0:01f31e923fe2 | 97 | print("Creating crc padded binaries %s" % os.path.basename(cli_hex_output)) |
Pawel Zarembski |
0:01f31e923fe2 | 98 | #can be a legacy build or 0 board_id and family_id |
Pawel Zarembski |
0:01f31e923fe2 | 99 | post_build_script(cli_hex_output, crc_file_output) |
Pawel Zarembski |
0:01f31e923fe2 | 100 | #do a build with board_id and family_id |
Pawel Zarembski |
0:01f31e923fe2 | 101 | if project in id_map: |
Pawel Zarembski |
0:01f31e923fe2 | 102 | for (boardid, familyid) in id_map[project]: |
Pawel Zarembski |
0:01f31e923fe2 | 103 | print(project, boardid, familyid) |
Pawel Zarembski |
0:01f31e923fe2 | 104 | post_build_script(cli_hex_output, crc_file_output, boardid, familyid) |
Pawel Zarembski |
0:01f31e923fe2 | 105 | if args.release is True: |
Pawel Zarembski |
0:01f31e923fe2 | 106 | release_version = 0 |
Pawel Zarembski |
0:01f31e923fe2 | 107 | with open(os.path.join("records","tools", VERSION_YAML), 'r') as ver_yaml: |
Pawel Zarembski |
0:01f31e923fe2 | 108 | try: |
Pawel Zarembski |
0:01f31e923fe2 | 109 | verdict = yaml.load(ver_yaml) |
Pawel Zarembski |
0:01f31e923fe2 | 110 | release_version = int(verdict['common']['macros'][0].split('=')[1]) |
Pawel Zarembski |
0:01f31e923fe2 | 111 | except yaml.YAMLError as ex: |
Pawel Zarembski |
0:01f31e923fe2 | 112 | print("Found yaml parse error", ex) |
Pawel Zarembski |
0:01f31e923fe2 | 113 | |
Pawel Zarembski |
0:01f31e923fe2 | 114 | release_dir = args.release_folder + "_%04i" % release_version |
Pawel Zarembski |
0:01f31e923fe2 | 115 | if os.path.exists(release_dir): |
Pawel Zarembski |
0:01f31e923fe2 | 116 | print("Deleting %s" % release_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 117 | shutil.rmtree(release_dir, ignore_errors=True) |
Pawel Zarembski |
0:01f31e923fe2 | 118 | print("Releasing directory: " + release_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 119 | toolchain_dir = args.toolchain+"-CUSTOM_PROFILE" |
Pawel Zarembski |
0:01f31e923fe2 | 120 | package_release_files(args.build_folder, release_dir, release_version, toolchain_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 121 | |
Pawel Zarembski |
0:01f31e923fe2 | 122 | main() |