Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
test/target.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 | from __future__ import absolute_import |
Pawel Zarembski |
0:01f31e923fe2 | 20 | import os |
Pawel Zarembski |
0:01f31e923fe2 | 21 | import time |
Pawel Zarembski |
0:01f31e923fe2 | 22 | import info |
Pawel Zarembski |
0:01f31e923fe2 | 23 | import mbedapi |
Pawel Zarembski |
0:01f31e923fe2 | 24 | from test_info import TestInfoStub |
Pawel Zarembski |
0:01f31e923fe2 | 25 | from intelhex import IntelHex |
Pawel Zarembski |
0:01f31e923fe2 | 26 | |
Pawel Zarembski |
0:01f31e923fe2 | 27 | TEST_REPO = 'https://developer.mbed.org/users/c1728p9/code/daplink-validation/' |
Pawel Zarembski |
0:01f31e923fe2 | 28 | |
Pawel Zarembski |
0:01f31e923fe2 | 29 | |
Pawel Zarembski |
0:01f31e923fe2 | 30 | def load_target_bundle(directory): |
Pawel Zarembski |
0:01f31e923fe2 | 31 | return TargetBundle(directory) |
Pawel Zarembski |
0:01f31e923fe2 | 32 | |
Pawel Zarembski |
0:01f31e923fe2 | 33 | |
Pawel Zarembski |
0:01f31e923fe2 | 34 | class TargetBundle(object): |
Pawel Zarembski |
0:01f31e923fe2 | 35 | |
Pawel Zarembski |
0:01f31e923fe2 | 36 | def __init__(self, directory): |
Pawel Zarembski |
0:01f31e923fe2 | 37 | dir_contents = os.listdir(directory) |
Pawel Zarembski |
0:01f31e923fe2 | 38 | name_to_target = {} |
Pawel Zarembski |
0:01f31e923fe2 | 39 | for name in dir_contents: |
Pawel Zarembski |
0:01f31e923fe2 | 40 | base_name, extension = os.path.splitext(name) |
Pawel Zarembski |
0:01f31e923fe2 | 41 | path = directory + os.sep + name |
Pawel Zarembski |
0:01f31e923fe2 | 42 | if os.path.isdir(path): |
Pawel Zarembski |
0:01f31e923fe2 | 43 | # Directories are unused |
Pawel Zarembski |
0:01f31e923fe2 | 44 | pass |
Pawel Zarembski |
0:01f31e923fe2 | 45 | elif os.path.isfile(path): |
Pawel Zarembski |
0:01f31e923fe2 | 46 | if extension not in ('.bin', '.hex'): |
Pawel Zarembski |
0:01f31e923fe2 | 47 | continue |
Pawel Zarembski |
0:01f31e923fe2 | 48 | if base_name not in name_to_target: |
Pawel Zarembski |
0:01f31e923fe2 | 49 | name_to_target[base_name] = Target(base_name) |
Pawel Zarembski |
0:01f31e923fe2 | 50 | if extension == '.bin': |
Pawel Zarembski |
0:01f31e923fe2 | 51 | name_to_target[base_name].set_bin_path(path) |
Pawel Zarembski |
0:01f31e923fe2 | 52 | elif extension == '.hex': |
Pawel Zarembski |
0:01f31e923fe2 | 53 | name_to_target[base_name].set_hex_path(path) |
Pawel Zarembski |
0:01f31e923fe2 | 54 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 55 | # Unsupported file type |
Pawel Zarembski |
0:01f31e923fe2 | 56 | pass |
Pawel Zarembski |
0:01f31e923fe2 | 57 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 58 | assert False |
Pawel Zarembski |
0:01f31e923fe2 | 59 | all_targets = list(name_to_target.values()) |
Pawel Zarembski |
0:01f31e923fe2 | 60 | self._target_list = [target for target in all_targets if target.valid] |
Pawel Zarembski |
0:01f31e923fe2 | 61 | |
Pawel Zarembski |
0:01f31e923fe2 | 62 | def get_target_list(self): |
Pawel Zarembski |
0:01f31e923fe2 | 63 | """Return the target objects associated with this bundle""" |
Pawel Zarembski |
0:01f31e923fe2 | 64 | return self._target_list |
Pawel Zarembski |
0:01f31e923fe2 | 65 | |
Pawel Zarembski |
0:01f31e923fe2 | 66 | |
Pawel Zarembski |
0:01f31e923fe2 | 67 | def build_target_bundle(directory, username, password, parent_test=None): |
Pawel Zarembski |
0:01f31e923fe2 | 68 | """Build target firmware package""" |
Pawel Zarembski |
0:01f31e923fe2 | 69 | if parent_test is None: |
Pawel Zarembski |
0:01f31e923fe2 | 70 | parent_test = TestInfoStub() |
Pawel Zarembski |
0:01f31e923fe2 | 71 | target_names = info.TARGET_WITH_COMPILE_API_LIST |
Pawel Zarembski |
0:01f31e923fe2 | 72 | for build_name in target_names: |
Pawel Zarembski |
0:01f31e923fe2 | 73 | name_base = os.path.normpath(directory + os.sep + build_name) |
Pawel Zarembski |
0:01f31e923fe2 | 74 | target_hex_path = name_base + '.hex' |
Pawel Zarembski |
0:01f31e923fe2 | 75 | target_bin_path = name_base + '.bin' |
Pawel Zarembski |
0:01f31e923fe2 | 76 | |
Pawel Zarembski |
0:01f31e923fe2 | 77 | # Build target test image |
Pawel Zarembski |
0:01f31e923fe2 | 78 | test_info = parent_test.create_subtest('Building target %s' % |
Pawel Zarembski |
0:01f31e923fe2 | 79 | build_name) |
Pawel Zarembski |
0:01f31e923fe2 | 80 | if not os.path.isdir(directory): |
Pawel Zarembski |
0:01f31e923fe2 | 81 | os.mkdir(directory) |
Pawel Zarembski |
0:01f31e923fe2 | 82 | # Remove previous build files |
Pawel Zarembski |
0:01f31e923fe2 | 83 | if os.path.isfile(target_hex_path): |
Pawel Zarembski |
0:01f31e923fe2 | 84 | os.remove(target_hex_path) |
Pawel Zarembski |
0:01f31e923fe2 | 85 | if os.path.isfile(target_bin_path): |
Pawel Zarembski |
0:01f31e923fe2 | 86 | os.remove(target_bin_path) |
Pawel Zarembski |
0:01f31e923fe2 | 87 | test_info.info('Starting remote build') |
Pawel Zarembski |
0:01f31e923fe2 | 88 | start = time.time() |
Pawel Zarembski |
0:01f31e923fe2 | 89 | built_file = mbedapi.build_repo(username, password, |
Pawel Zarembski |
0:01f31e923fe2 | 90 | TEST_REPO, build_name, |
Pawel Zarembski |
0:01f31e923fe2 | 91 | directory) |
Pawel Zarembski |
0:01f31e923fe2 | 92 | stop = time.time() |
Pawel Zarembski |
0:01f31e923fe2 | 93 | test_info.info("Build took %s seconds" % (stop - start)) |
Pawel Zarembski |
0:01f31e923fe2 | 94 | extension = os.path.splitext(built_file)[1].lower() |
Pawel Zarembski |
0:01f31e923fe2 | 95 | assert extension == '.hex' or extension == '.bin' |
Pawel Zarembski |
0:01f31e923fe2 | 96 | if extension == '.hex': |
Pawel Zarembski |
0:01f31e923fe2 | 97 | intel_hex = IntelHex(built_file) |
Pawel Zarembski |
0:01f31e923fe2 | 98 | # Only supporting devices with the starting |
Pawel Zarembski |
0:01f31e923fe2 | 99 | # address at 0 currently |
Pawel Zarembski |
0:01f31e923fe2 | 100 | assert intel_hex.minaddr() == 0 |
Pawel Zarembski |
0:01f31e923fe2 | 101 | intel_hex.tobinfile(target_bin_path) |
Pawel Zarembski |
0:01f31e923fe2 | 102 | os.rename(built_file, target_hex_path) |
Pawel Zarembski |
0:01f31e923fe2 | 103 | if extension == '.bin': |
Pawel Zarembski |
0:01f31e923fe2 | 104 | intel_hex = IntelHex() |
Pawel Zarembski |
0:01f31e923fe2 | 105 | intel_hex.loadbin(built_file, offset=0) |
Pawel Zarembski |
0:01f31e923fe2 | 106 | intel_hex.tofile(target_hex_path, 'hex') |
Pawel Zarembski |
0:01f31e923fe2 | 107 | os.rename(built_file, target_bin_path) |
Pawel Zarembski |
0:01f31e923fe2 | 108 | |
Pawel Zarembski |
0:01f31e923fe2 | 109 | # Assert that required files are present |
Pawel Zarembski |
0:01f31e923fe2 | 110 | assert os.path.isfile(target_hex_path) |
Pawel Zarembski |
0:01f31e923fe2 | 111 | assert os.path.isfile(target_bin_path) |
Pawel Zarembski |
0:01f31e923fe2 | 112 | |
Pawel Zarembski |
0:01f31e923fe2 | 113 | |
Pawel Zarembski |
0:01f31e923fe2 | 114 | class Target(object): |
Pawel Zarembski |
0:01f31e923fe2 | 115 | |
Pawel Zarembski |
0:01f31e923fe2 | 116 | def __init__(self, name, hex_path=None, bin_path=None): |
Pawel Zarembski |
0:01f31e923fe2 | 117 | self._name = name |
Pawel Zarembski |
0:01f31e923fe2 | 118 | self._valid = False |
Pawel Zarembski |
0:01f31e923fe2 | 119 | self._hex_path = None |
Pawel Zarembski |
0:01f31e923fe2 | 120 | self._bin_path = None |
Pawel Zarembski |
0:01f31e923fe2 | 121 | if hex_path is not None: |
Pawel Zarembski |
0:01f31e923fe2 | 122 | self.set_hex_path(hex_path) |
Pawel Zarembski |
0:01f31e923fe2 | 123 | if bin_path is not None: |
Pawel Zarembski |
0:01f31e923fe2 | 124 | self.set_bin_path(bin_path) |
Pawel Zarembski |
0:01f31e923fe2 | 125 | self._valid = True |
Pawel Zarembski |
0:01f31e923fe2 | 126 | |
Pawel Zarembski |
0:01f31e923fe2 | 127 | def __str__(self): |
Pawel Zarembski |
0:01f31e923fe2 | 128 | return "Name=%s" % self.name |
Pawel Zarembski |
0:01f31e923fe2 | 129 | |
Pawel Zarembski |
0:01f31e923fe2 | 130 | def set_hex_path(self, path): |
Pawel Zarembski |
0:01f31e923fe2 | 131 | base_name = os.path.basename(path) |
Pawel Zarembski |
0:01f31e923fe2 | 132 | assert self._hex_path is None |
Pawel Zarembski |
0:01f31e923fe2 | 133 | assert base_name == self._name + '.hex' |
Pawel Zarembski |
0:01f31e923fe2 | 134 | path = os.path.abspath(path) |
Pawel Zarembski |
0:01f31e923fe2 | 135 | assert os.path.isfile(path) |
Pawel Zarembski |
0:01f31e923fe2 | 136 | self._hex_path = path |
Pawel Zarembski |
0:01f31e923fe2 | 137 | |
Pawel Zarembski |
0:01f31e923fe2 | 138 | def set_bin_path(self, path): |
Pawel Zarembski |
0:01f31e923fe2 | 139 | base_name = os.path.basename(path) |
Pawel Zarembski |
0:01f31e923fe2 | 140 | assert self._bin_path is None |
Pawel Zarembski |
0:01f31e923fe2 | 141 | assert base_name == self._name + '.bin' |
Pawel Zarembski |
0:01f31e923fe2 | 142 | path = os.path.abspath(path) |
Pawel Zarembski |
0:01f31e923fe2 | 143 | assert os.path.isfile(path) |
Pawel Zarembski |
0:01f31e923fe2 | 144 | self._bin_path = path |
Pawel Zarembski |
0:01f31e923fe2 | 145 | |
Pawel Zarembski |
0:01f31e923fe2 | 146 | @property |
Pawel Zarembski |
0:01f31e923fe2 | 147 | def valid(self): |
Pawel Zarembski |
0:01f31e923fe2 | 148 | hex_valid = self._hex_path is not None |
Pawel Zarembski |
0:01f31e923fe2 | 149 | bin_valid = self._bin_path is not None |
Pawel Zarembski |
0:01f31e923fe2 | 150 | return hex_valid and bin_valid and self._valid |
Pawel Zarembski |
0:01f31e923fe2 | 151 | |
Pawel Zarembski |
0:01f31e923fe2 | 152 | @property |
Pawel Zarembski |
0:01f31e923fe2 | 153 | def name(self): |
Pawel Zarembski |
0:01f31e923fe2 | 154 | return self._name |
Pawel Zarembski |
0:01f31e923fe2 | 155 | |
Pawel Zarembski |
0:01f31e923fe2 | 156 | @property |
Pawel Zarembski |
0:01f31e923fe2 | 157 | def hex_path(self): |
Pawel Zarembski |
0:01f31e923fe2 | 158 | return self._hex_path |
Pawel Zarembski |
0:01f31e923fe2 | 159 | |
Pawel Zarembski |
0:01f31e923fe2 | 160 | @property |
Pawel Zarembski |
0:01f31e923fe2 | 161 | def bin_path(self): |
Pawel Zarembski |
0:01f31e923fe2 | 162 | return self._bin_path |