Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
tools/package_release_files.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-2016, 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 os |
Pawel Zarembski |
0:01f31e923fe2 | 20 | import sys |
Pawel Zarembski |
0:01f31e923fe2 | 21 | import shutil |
Pawel Zarembski |
0:01f31e923fe2 | 22 | import argparse |
Pawel Zarembski |
0:01f31e923fe2 | 23 | import yaml |
Pawel Zarembski |
0:01f31e923fe2 | 24 | import subprocess |
Pawel Zarembski |
0:01f31e923fe2 | 25 | |
Pawel Zarembski |
0:01f31e923fe2 | 26 | self_path = os.path.abspath(__file__) |
Pawel Zarembski |
0:01f31e923fe2 | 27 | tools_dir = os.path.dirname(self_path) |
Pawel Zarembski |
0:01f31e923fe2 | 28 | daplink_dir = os.path.dirname(tools_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 29 | test_dir = os.path.join(daplink_dir, "test") |
Pawel Zarembski |
0:01f31e923fe2 | 30 | sys.path.append(test_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 31 | |
Pawel Zarembski |
0:01f31e923fe2 | 32 | import info |
Pawel Zarembski |
0:01f31e923fe2 | 33 | |
Pawel Zarembski |
0:01f31e923fe2 | 34 | from make_update_yml import DefaultList |
Pawel Zarembski |
0:01f31e923fe2 | 35 | from make_update_yml import TargetList |
Pawel Zarembski |
0:01f31e923fe2 | 36 | from make_update_yml import InstructionsText |
Pawel Zarembski |
0:01f31e923fe2 | 37 | from make_update_yml import make_update_yml_file |
Pawel Zarembski |
0:01f31e923fe2 | 38 | |
Pawel Zarembski |
0:01f31e923fe2 | 39 | import zipfile |
Pawel Zarembski |
0:01f31e923fe2 | 40 | |
Pawel Zarembski |
0:01f31e923fe2 | 41 | def make_bin_zip(dir, name): |
Pawel Zarembski |
0:01f31e923fe2 | 42 | working_dir = os.getcwd() |
Pawel Zarembski |
0:01f31e923fe2 | 43 | os.chdir(dir) |
Pawel Zarembski |
0:01f31e923fe2 | 44 | with zipfile.ZipFile(name, mode='w') as zipf: |
Pawel Zarembski |
0:01f31e923fe2 | 45 | for file in os.listdir("./"): |
Pawel Zarembski |
0:01f31e923fe2 | 46 | if file.endswith(".bin") or file.endswith(".hex"): |
Pawel Zarembski |
0:01f31e923fe2 | 47 | zipf.write(os.path.join("./", file)) |
Pawel Zarembski |
0:01f31e923fe2 | 48 | #go back |
Pawel Zarembski |
0:01f31e923fe2 | 49 | os.chdir(working_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 50 | |
Pawel Zarembski |
0:01f31e923fe2 | 51 | def package_release_files(source, dest, version, toolchain): |
Pawel Zarembski |
0:01f31e923fe2 | 52 | |
Pawel Zarembski |
0:01f31e923fe2 | 53 | proj_dir = source |
Pawel Zarembski |
0:01f31e923fe2 | 54 | output_dir = dest |
Pawel Zarembski |
0:01f31e923fe2 | 55 | build_number = "%04i" % version |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | update_yml_entries = [{'default':DefaultList([ |
Pawel Zarembski |
0:01f31e923fe2 | 58 | ('website', 'http://os.mbed.com/platforms'), |
Pawel Zarembski |
0:01f31e923fe2 | 59 | ('fw_version', "'" + build_number + "'"), |
Pawel Zarembski |
0:01f31e923fe2 | 60 | ('image_format', '.bin'), |
Pawel Zarembski |
0:01f31e923fe2 | 61 | ('instructions', InstructionsText['default']) |
Pawel Zarembski |
0:01f31e923fe2 | 62 | ]) }] |
Pawel Zarembski |
0:01f31e923fe2 | 63 | |
Pawel Zarembski |
0:01f31e923fe2 | 64 | if os.path.exists(output_dir): |
Pawel Zarembski |
0:01f31e923fe2 | 65 | shutil.rmtree(output_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 66 | print (output_dir + ' existed and deleted!!') |
Pawel Zarembski |
0:01f31e923fe2 | 67 | |
Pawel Zarembski |
0:01f31e923fe2 | 68 | os.mkdir(output_dir) |
Pawel Zarembski |
0:01f31e923fe2 | 69 | |
Pawel Zarembski |
0:01f31e923fe2 | 70 | for prj_name, legacy, offset, extension in info.PROJECT_RELEASE_INFO: |
Pawel Zarembski |
0:01f31e923fe2 | 71 | legacy_str = "_legacy" if legacy else "" |
Pawel Zarembski |
0:01f31e923fe2 | 72 | source_offset_str = "_0x%04x" % offset if legacy else "" |
Pawel Zarembski |
0:01f31e923fe2 | 73 | source_name = prj_name + "_crc" + legacy_str + source_offset_str + "." + extension |
Pawel Zarembski |
0:01f31e923fe2 | 74 | source_dir_part = os.path.join(proj_dir, prj_name, toolchain).upper() |
Pawel Zarembski |
0:01f31e923fe2 | 75 | source_path = os.path.join(source_dir_part, source_name) |
Pawel Zarembski |
0:01f31e923fe2 | 76 | if not os.path.isfile(source_path): |
Pawel Zarembski |
0:01f31e923fe2 | 77 | print("Warning %s not added to release" % prj_name) |
Pawel Zarembski |
0:01f31e923fe2 | 78 | continue |
Pawel Zarembski |
0:01f31e923fe2 | 79 | items = prj_name.split('_') # "k20dx_frdmk22f_if" -> ("k20dx", "frdmk22f", "if") |
Pawel Zarembski |
0:01f31e923fe2 | 80 | assert items[-1] == "if", "Unexpected string: %s" % items[2] |
Pawel Zarembski |
0:01f31e923fe2 | 81 | host_mcu = items[0] |
Pawel Zarembski |
0:01f31e923fe2 | 82 | base_name = '_'.join(items[1:-1]) |
Pawel Zarembski |
0:01f31e923fe2 | 83 | dest_offset_str = "_0x%04x" % offset |
Pawel Zarembski |
0:01f31e923fe2 | 84 | dest_name = build_number + "_" + host_mcu + "_" + base_name + dest_offset_str + "." + extension |
Pawel Zarembski |
0:01f31e923fe2 | 85 | dest_path = os.path.join(output_dir, dest_name) |
Pawel Zarembski |
0:01f31e923fe2 | 86 | shutil.copyfile(source_path, dest_path) |
Pawel Zarembski |
0:01f31e923fe2 | 87 | |
Pawel Zarembski |
0:01f31e923fe2 | 88 | product_code = 'NOT SUPPORTED' |
Pawel Zarembski |
0:01f31e923fe2 | 89 | for board_id, family_id, fimware, bootloader, target in info.SUPPORTED_CONFIGURATIONS: |
Pawel Zarembski |
0:01f31e923fe2 | 90 | if fimware == prj_name: |
Pawel Zarembski |
0:01f31e923fe2 | 91 | product_code = board_id |
Pawel Zarembski |
0:01f31e923fe2 | 92 | if target is not None: |
Pawel Zarembski |
0:01f31e923fe2 | 93 | target_name = target |
Pawel Zarembski |
0:01f31e923fe2 | 94 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 95 | target_name = base_name.upper() |
Pawel Zarembski |
0:01f31e923fe2 | 96 | |
Pawel Zarembski |
0:01f31e923fe2 | 97 | fw_instuction = InstructionsText['default'] |
Pawel Zarembski |
0:01f31e923fe2 | 98 | for fw_name_key in InstructionsText: |
Pawel Zarembski |
0:01f31e923fe2 | 99 | if fw_name_key in dest_name.lower(): |
Pawel Zarembski |
0:01f31e923fe2 | 100 | fw_instuction = InstructionsText[fw_name_key] |
Pawel Zarembski |
0:01f31e923fe2 | 101 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | if extension == 'bin': |
Pawel Zarembski |
0:01f31e923fe2 | 104 | update_yml_entries.append({target_name:TargetList([ |
Pawel Zarembski |
0:01f31e923fe2 | 105 | ('name', target_name), |
Pawel Zarembski |
0:01f31e923fe2 | 106 | ('product_code', "'" + format(product_code, '04x') + "'"), |
Pawel Zarembski |
0:01f31e923fe2 | 107 | ('fw_name', host_mcu + "_" + base_name + dest_offset_str), |
Pawel Zarembski |
0:01f31e923fe2 | 108 | ('instructions', fw_instuction) |
Pawel Zarembski |
0:01f31e923fe2 | 109 | ])}); |
Pawel Zarembski |
0:01f31e923fe2 | 110 | |
Pawel Zarembski |
0:01f31e923fe2 | 111 | make_bin_zip(output_dir, build_number + '_release_package_' + subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip() + '.zip') |
Pawel Zarembski |
0:01f31e923fe2 | 112 | |
Pawel Zarembski |
0:01f31e923fe2 | 113 | make_update_yml_file(os.path.join(output_dir, 'update.yml'), update_yml_entries, explicit_start=True) |
Pawel Zarembski |
0:01f31e923fe2 | 114 | |
Pawel Zarembski |
0:01f31e923fe2 | 115 | if __name__ == "__main__": |
Pawel Zarembski |
0:01f31e923fe2 | 116 | parser = argparse.ArgumentParser(description='Package a release for distribution') |
Pawel Zarembski |
0:01f31e923fe2 | 117 | parser.add_argument('source', help='Release directory to grab files from') |
Pawel Zarembski |
0:01f31e923fe2 | 118 | parser.add_argument('dest', help='Directory to create and place files in') |
Pawel Zarembski |
0:01f31e923fe2 | 119 | parser.add_argument('version', type=int, help='Version number of this release') |
Pawel Zarembski |
0:01f31e923fe2 | 120 | parser.add_argument('--toolchain', type=str, default='', help='Toolchain directory if present') |
Pawel Zarembski |
0:01f31e923fe2 | 121 | args = parser.parse_args() |
Pawel Zarembski |
0:01f31e923fe2 | 122 | |
Pawel Zarembski |
0:01f31e923fe2 | 123 | print("args",args.source,args.dest,args.version,args.toolchain) |
Pawel Zarembski |
0:01f31e923fe2 | 124 | |
Pawel Zarembski |
0:01f31e923fe2 | 125 | package_release_files(args.source,args.dest,args.version,args.toolchain) |