Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

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?

UserRevisionLine numberNew 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 info
Pawel Zarembski 0:01f31e923fe2 22 import re
Pawel Zarembski 0:01f31e923fe2 23 import firmware
Pawel Zarembski 0:01f31e923fe2 24
Pawel Zarembski 0:01f31e923fe2 25
Pawel Zarembski 0:01f31e923fe2 26 def load_bundle_from_release(directory):
Pawel Zarembski 0:01f31e923fe2 27 """ Return a bundle representing the given build"""
Pawel Zarembski 0:01f31e923fe2 28 return ReleaseFirmwareBundle(directory)
Pawel Zarembski 0:01f31e923fe2 29
Pawel Zarembski 0:01f31e923fe2 30
Pawel Zarembski 0:01f31e923fe2 31 def load_bundle_from_project(tool='uvision'):
Pawel Zarembski 0:01f31e923fe2 32 """
Pawel Zarembski 0:01f31e923fe2 33 Return a bundle for the given tool
Pawel Zarembski 0:01f31e923fe2 34
Pawel Zarembski 0:01f31e923fe2 35 Note - This does not build the project. It only returns the
Pawel Zarembski 0:01f31e923fe2 36 firmware that has already been built.
Pawel Zarembski 0:01f31e923fe2 37 """
Pawel Zarembski 0:01f31e923fe2 38 assert (tool == 'uvision' or tool == 'mbedcli'), 'Input tool %s is not supported' % (tool)
Pawel Zarembski 0:01f31e923fe2 39
Pawel Zarembski 0:01f31e923fe2 40 self_path = os.path.abspath(__file__)
Pawel Zarembski 0:01f31e923fe2 41 test_dir = os.path.dirname(self_path)
Pawel Zarembski 0:01f31e923fe2 42 daplink_dir = os.path.dirname(test_dir)
Pawel Zarembski 0:01f31e923fe2 43 assert os.path.basename(test_dir) == 'test', 'The script "%s" must be ' \
Pawel Zarembski 0:01f31e923fe2 44 'located in the "test" directory of daplink to work correctly.'
Pawel Zarembski 0:01f31e923fe2 45
Pawel Zarembski 0:01f31e923fe2 46 if tool == 'uvision':
Pawel Zarembski 0:01f31e923fe2 47 project_dir = os.path.join(daplink_dir, 'projectfiles', tool)
Pawel Zarembski 0:01f31e923fe2 48 build_folder = 'build'
Pawel Zarembski 0:01f31e923fe2 49 elif tool == 'mbedcli':
Pawel Zarembski 0:01f31e923fe2 50 project_dir = os.path.join(daplink_dir, 'BUILD')
Pawel Zarembski 0:01f31e923fe2 51 build_folder = 'ARM-CUSTOM_PROFILE'
Pawel Zarembski 0:01f31e923fe2 52
Pawel Zarembski 0:01f31e923fe2 53 return ProjectFirmwareBundle(project_dir, build_folder)
Pawel Zarembski 0:01f31e923fe2 54
Pawel Zarembski 0:01f31e923fe2 55
Pawel Zarembski 0:01f31e923fe2 56 class ReleaseFirmwareBundle(firmware.FirmwareBundle):
Pawel Zarembski 0:01f31e923fe2 57 """Class to abstract access a formal build as a bundle"""
Pawel Zarembski 0:01f31e923fe2 58
Pawel Zarembski 0:01f31e923fe2 59 def __init__(self, directory):
Pawel Zarembski 0:01f31e923fe2 60 bundle_contents = os.listdir(directory)
Pawel Zarembski 0:01f31e923fe2 61 firmware_list = []
Pawel Zarembski 0:01f31e923fe2 62 for name in bundle_contents:
Pawel Zarembski 0:01f31e923fe2 63 path = directory + os.sep + name
Pawel Zarembski 0:01f31e923fe2 64 if os.path.isdir(path):
Pawel Zarembski 0:01f31e923fe2 65 daplink_firmware = DAPLinkFirmware(name, self, path)
Pawel Zarembski 0:01f31e923fe2 66 if daplink_firmware.valid:
Pawel Zarembski 0:01f31e923fe2 67 firmware_list.append(daplink_firmware)
Pawel Zarembski 0:01f31e923fe2 68 elif os.path.isfile(path):
Pawel Zarembski 0:01f31e923fe2 69 # Parse relevent info
Pawel Zarembski 0:01f31e923fe2 70 pass
Pawel Zarembski 0:01f31e923fe2 71 else:
Pawel Zarembski 0:01f31e923fe2 72 assert False
Pawel Zarembski 0:01f31e923fe2 73 self._firmware_list = firmware_list
Pawel Zarembski 0:01f31e923fe2 74
Pawel Zarembski 0:01f31e923fe2 75 def get_firmware_list(self):
Pawel Zarembski 0:01f31e923fe2 76 return self._firmware_list
Pawel Zarembski 0:01f31e923fe2 77
Pawel Zarembski 0:01f31e923fe2 78 @property
Pawel Zarembski 0:01f31e923fe2 79 def build_sha(self):
Pawel Zarembski 0:01f31e923fe2 80 raise NotImplementedError()
Pawel Zarembski 0:01f31e923fe2 81
Pawel Zarembski 0:01f31e923fe2 82 @property
Pawel Zarembski 0:01f31e923fe2 83 def build_local_mods(self):
Pawel Zarembski 0:01f31e923fe2 84 raise NotImplementedError()
Pawel Zarembski 0:01f31e923fe2 85
Pawel Zarembski 0:01f31e923fe2 86
Pawel Zarembski 0:01f31e923fe2 87 class ProjectFirmwareBundle(firmware.FirmwareBundle):
Pawel Zarembski 0:01f31e923fe2 88 """Class to abstract access to daplink's build directory as a bundle"""
Pawel Zarembski 0:01f31e923fe2 89
Pawel Zarembski 0:01f31e923fe2 90 def __init__(self, project_dir, build_folder):
Pawel Zarembski 0:01f31e923fe2 91
Pawel Zarembski 0:01f31e923fe2 92 if not os.path.exists(project_dir):
Pawel Zarembski 0:01f31e923fe2 93 print ("Error: DAPLink project folder %s missing" % project_dir)
Pawel Zarembski 0:01f31e923fe2 94 exit(-1)
Pawel Zarembski 0:01f31e923fe2 95
Pawel Zarembski 0:01f31e923fe2 96 project_dir_list = os.listdir(project_dir)
Pawel Zarembski 0:01f31e923fe2 97 if not project_dir_list:
Pawel Zarembski 0:01f31e923fe2 98 print ("Error: DAPLink projects not build yet at %s" % project_dir)
Pawel Zarembski 0:01f31e923fe2 99 exit(-1)
Pawel Zarembski 0:01f31e923fe2 100
Pawel Zarembski 0:01f31e923fe2 101 firmware_list = []
Pawel Zarembski 0:01f31e923fe2 102 for name in project_dir_list:
Pawel Zarembski 0:01f31e923fe2 103 build_dir = os.path.join(project_dir, name, build_folder)
Pawel Zarembski 0:01f31e923fe2 104 if os.path.isdir(build_dir):
Pawel Zarembski 0:01f31e923fe2 105 daplink_firmware = DAPLinkFirmware(name.lower(), self, build_dir)
Pawel Zarembski 0:01f31e923fe2 106 if daplink_firmware.valid:
Pawel Zarembski 0:01f31e923fe2 107 firmware_list.append(daplink_firmware)
Pawel Zarembski 0:01f31e923fe2 108 self._firmware_list = firmware_list
Pawel Zarembski 0:01f31e923fe2 109
Pawel Zarembski 0:01f31e923fe2 110 def get_firmware_list(self):
Pawel Zarembski 0:01f31e923fe2 111 return self._firmware_list
Pawel Zarembski 0:01f31e923fe2 112
Pawel Zarembski 0:01f31e923fe2 113 @property
Pawel Zarembski 0:01f31e923fe2 114 def build_sha(self):
Pawel Zarembski 0:01f31e923fe2 115 raise NotImplementedError()
Pawel Zarembski 0:01f31e923fe2 116
Pawel Zarembski 0:01f31e923fe2 117 @property
Pawel Zarembski 0:01f31e923fe2 118 def build_local_mods(self):
Pawel Zarembski 0:01f31e923fe2 119 raise NotImplementedError()
Pawel Zarembski 0:01f31e923fe2 120
Pawel Zarembski 0:01f31e923fe2 121
Pawel Zarembski 0:01f31e923fe2 122 class DAPLinkFirmware(firmware.Firmware):
Pawel Zarembski 0:01f31e923fe2 123 """Class to abstract access to a daplink firmware image"""
Pawel Zarembski 0:01f31e923fe2 124
Pawel Zarembski 0:01f31e923fe2 125 _IF_RE = re.compile("^([a-z0-9]+)([_a-z0-9]*)_if$")
Pawel Zarembski 0:01f31e923fe2 126 _BL_RE = re.compile("^([a-z0-9]+)_bl$")
Pawel Zarembski 0:01f31e923fe2 127
Pawel Zarembski 0:01f31e923fe2 128 def __init__(self, name, bundle, directory):
Pawel Zarembski 0:01f31e923fe2 129 self._name = name
Pawel Zarembski 0:01f31e923fe2 130 self._bundle = bundle
Pawel Zarembski 0:01f31e923fe2 131 self._directory = directory
Pawel Zarembski 0:01f31e923fe2 132 self._valid = False
Pawel Zarembski 0:01f31e923fe2 133
Pawel Zarembski 0:01f31e923fe2 134 # Set type
Pawel Zarembski 0:01f31e923fe2 135 self._type = None
Pawel Zarembski 0:01f31e923fe2 136 string_hic = None
Pawel Zarembski 0:01f31e923fe2 137 match = self._IF_RE.match(name)
Pawel Zarembski 0:01f31e923fe2 138 if match:
Pawel Zarembski 0:01f31e923fe2 139 string_hic = match.group(1)
Pawel Zarembski 0:01f31e923fe2 140 self._type = self.TYPE.INTERFACE
Pawel Zarembski 0:01f31e923fe2 141 match = self._BL_RE.match(name)
Pawel Zarembski 0:01f31e923fe2 142 if match:
Pawel Zarembski 0:01f31e923fe2 143 string_hic = match.group(1)
Pawel Zarembski 0:01f31e923fe2 144 self._type = self.TYPE.BOOTLOADER
Pawel Zarembski 0:01f31e923fe2 145 if self._type is None:
Pawel Zarembski 0:01f31e923fe2 146 assert False, 'Bad project name "%s"' % name
Pawel Zarembski 0:01f31e923fe2 147
Pawel Zarembski 0:01f31e923fe2 148 # Set HIC
Pawel Zarembski 0:01f31e923fe2 149 assert string_hic in info.HIC_STRING_TO_ID, 'Unknown HIC "%s" must ' \
Pawel Zarembski 0:01f31e923fe2 150 'be added to HIC_STRING_TO_ID in info.py' % string_hic
Pawel Zarembski 0:01f31e923fe2 151 self._hic_id = info.HIC_STRING_TO_ID[string_hic]
Pawel Zarembski 0:01f31e923fe2 152
Pawel Zarembski 0:01f31e923fe2 153 # Check firmware name and type
Pawel Zarembski 0:01f31e923fe2 154 assert self._type in self.TYPE, "Invalid type %s" % self._type
Pawel Zarembski 0:01f31e923fe2 155 if self._type is self.TYPE.INTERFACE:
Pawel Zarembski 0:01f31e923fe2 156 if name not in info.FIRMWARE_SET:
Pawel Zarembski 0:01f31e923fe2 157 print('Warning: board "%s" no entry in SUPPORTED_CONFIGURATIONS in info.py' % name)
Pawel Zarembski 0:01f31e923fe2 158
Pawel Zarembski 0:01f31e923fe2 159 # Set file paths
Pawel Zarembski 0:01f31e923fe2 160 self._bin_path = self._directory + os.sep + '%s_crc.bin' % name
Pawel Zarembski 0:01f31e923fe2 161 self._hex_path = self._directory + os.sep + '%s_crc.hex' % name
Pawel Zarembski 0:01f31e923fe2 162 self._bin_path = os.path.abspath(self._bin_path)
Pawel Zarembski 0:01f31e923fe2 163 self._hex_path = os.path.abspath(self._hex_path)
Pawel Zarembski 0:01f31e923fe2 164 if not os.path.isfile(self._bin_path):
Pawel Zarembski 0:01f31e923fe2 165 return # Failure
Pawel Zarembski 0:01f31e923fe2 166 if not os.path.isfile(self._hex_path):
Pawel Zarembski 0:01f31e923fe2 167 return # Failure
Pawel Zarembski 0:01f31e923fe2 168
Pawel Zarembski 0:01f31e923fe2 169 self._valid = True
Pawel Zarembski 0:01f31e923fe2 170
Pawel Zarembski 0:01f31e923fe2 171 def __str__(self):
Pawel Zarembski 0:01f31e923fe2 172 return "Name=%s" % (self.name)
Pawel Zarembski 0:01f31e923fe2 173
Pawel Zarembski 0:01f31e923fe2 174 @property
Pawel Zarembski 0:01f31e923fe2 175 def valid(self):
Pawel Zarembski 0:01f31e923fe2 176 """Set to True if the firmware is valid"""
Pawel Zarembski 0:01f31e923fe2 177 return self._valid
Pawel Zarembski 0:01f31e923fe2 178
Pawel Zarembski 0:01f31e923fe2 179 @property
Pawel Zarembski 0:01f31e923fe2 180 def name(self):
Pawel Zarembski 0:01f31e923fe2 181 return self._name
Pawel Zarembski 0:01f31e923fe2 182
Pawel Zarembski 0:01f31e923fe2 183 @property
Pawel Zarembski 0:01f31e923fe2 184 def hic_id(self):
Pawel Zarembski 0:01f31e923fe2 185 return self._hic_id
Pawel Zarembski 0:01f31e923fe2 186
Pawel Zarembski 0:01f31e923fe2 187 @property
Pawel Zarembski 0:01f31e923fe2 188 def type(self):
Pawel Zarembski 0:01f31e923fe2 189 return self._type
Pawel Zarembski 0:01f31e923fe2 190
Pawel Zarembski 0:01f31e923fe2 191 @property
Pawel Zarembski 0:01f31e923fe2 192 def bin_path(self):
Pawel Zarembski 0:01f31e923fe2 193 return self._bin_path
Pawel Zarembski 0:01f31e923fe2 194
Pawel Zarembski 0:01f31e923fe2 195 @property
Pawel Zarembski 0:01f31e923fe2 196 def hex_path(self):
Pawel Zarembski 0:01f31e923fe2 197 return self._hex_path
Pawel Zarembski 0:01f31e923fe2 198
Pawel Zarembski 0:01f31e923fe2 199 @property
Pawel Zarembski 0:01f31e923fe2 200 def elf_path(self):
Pawel Zarembski 0:01f31e923fe2 201 return self._elf_path