Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
daplink_firmware.py
00001 # 00002 # DAPLink Interface Firmware 00003 # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 00004 # SPDX-License-Identifier: Apache-2.0 00005 # 00006 # Licensed under the Apache License, Version 2.0 (the "License"); you may 00007 # not use this file except in compliance with the License. 00008 # You may obtain a copy of the License at 00009 # 00010 # http://www.apache.org/licenses/LICENSE-2.0 00011 # 00012 # Unless required by applicable law or agreed to in writing, software 00013 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00014 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 # See the License for the specific language governing permissions and 00016 # limitations under the License. 00017 # 00018 00019 from __future__ import absolute_import 00020 import os 00021 import info 00022 import re 00023 import firmware 00024 00025 00026 def load_bundle_from_release(directory): 00027 """ Return a bundle representing the given build""" 00028 return ReleaseFirmwareBundle(directory) 00029 00030 00031 def load_bundle_from_project(tool='uvision'): 00032 """ 00033 Return a bundle for the given tool 00034 00035 Note - This does not build the project. It only returns the 00036 firmware that has already been built. 00037 """ 00038 assert (tool == 'uvision' or tool == 'mbedcli'), 'Input tool %s is not supported' % (tool) 00039 00040 self_path = os.path.abspath(__file__) 00041 test_dir = os.path.dirname(self_path) 00042 daplink_dir = os.path.dirname(test_dir) 00043 assert os.path.basename(test_dir) == 'test', 'The script "%s" must be ' \ 00044 'located in the "test" directory of daplink to work correctly.' 00045 00046 if tool == 'uvision': 00047 project_dir = os.path.join(daplink_dir, 'projectfiles', tool) 00048 build_folder = 'build' 00049 elif tool == 'mbedcli': 00050 project_dir = os.path.join(daplink_dir, 'BUILD') 00051 build_folder = 'ARM-CUSTOM_PROFILE' 00052 00053 return ProjectFirmwareBundle(project_dir, build_folder) 00054 00055 00056 class ReleaseFirmwareBundle (firmware.FirmwareBundle): 00057 """Class to abstract access a formal build as a bundle""" 00058 00059 def __init__(self, directory): 00060 bundle_contents = os.listdir(directory) 00061 firmware_list = [] 00062 for name in bundle_contents: 00063 path = directory + os.sep + name 00064 if os.path.isdir(path): 00065 daplink_firmware = DAPLinkFirmware(name, self, path) 00066 if daplink_firmware.valid: 00067 firmware_list.append(daplink_firmware) 00068 elif os.path.isfile(path): 00069 # Parse relevent info 00070 pass 00071 else: 00072 assert False 00073 self._firmware_list = firmware_list 00074 00075 def get_firmware_list(self): 00076 return self._firmware_list 00077 00078 @property 00079 def build_sha(self): 00080 raise NotImplementedError() 00081 00082 @property 00083 def build_local_mods(self): 00084 raise NotImplementedError() 00085 00086 00087 class ProjectFirmwareBundle (firmware.FirmwareBundle): 00088 """Class to abstract access to daplink's build directory as a bundle""" 00089 00090 def __init__(self, project_dir, build_folder): 00091 00092 if not os.path.exists(project_dir): 00093 print ("Error: DAPLink project folder %s missing" % project_dir) 00094 exit(-1) 00095 00096 project_dir_list = os.listdir(project_dir) 00097 if not project_dir_list: 00098 print ("Error: DAPLink projects not build yet at %s" % project_dir) 00099 exit(-1) 00100 00101 firmware_list = [] 00102 for name in project_dir_list: 00103 build_dir = os.path.join(project_dir, name, build_folder) 00104 if os.path.isdir(build_dir): 00105 daplink_firmware = DAPLinkFirmware(name.lower(), self, build_dir) 00106 if daplink_firmware.valid: 00107 firmware_list.append(daplink_firmware) 00108 self._firmware_list = firmware_list 00109 00110 def get_firmware_list(self): 00111 return self._firmware_list 00112 00113 @property 00114 def build_sha(self): 00115 raise NotImplementedError() 00116 00117 @property 00118 def build_local_mods(self): 00119 raise NotImplementedError() 00120 00121 00122 class DAPLinkFirmware (firmware.Firmware): 00123 """Class to abstract access to a daplink firmware image""" 00124 00125 _IF_RE = re.compile("^([a-z0-9]+)([_a-z0-9]*)_if$") 00126 _BL_RE = re.compile("^([a-z0-9]+)_bl$") 00127 00128 def __init__(self, name, bundle, directory): 00129 self._name = name 00130 self._bundle = bundle 00131 self._directory = directory 00132 self._valid = False 00133 00134 # Set type 00135 self._type = None 00136 string_hic = None 00137 match = self._IF_RE .match(name) 00138 if match: 00139 string_hic = match.group(1) 00140 self._type = self.TYPE.INTERFACE 00141 match = self._BL_RE .match(name) 00142 if match: 00143 string_hic = match.group(1) 00144 self._type = self.TYPE.BOOTLOADER 00145 if self._type is None: 00146 assert False, 'Bad project name "%s"' % name 00147 00148 # Set HIC 00149 assert string_hic in info.HIC_STRING_TO_ID, 'Unknown HIC "%s" must ' \ 00150 'be added to HIC_STRING_TO_ID in info.py' % string_hic 00151 self._hic_id = info.HIC_STRING_TO_ID[string_hic] 00152 00153 # Check firmware name and type 00154 assert self._type in self.TYPE, "Invalid type %s" % self._type 00155 if self._type is self.TYPE.INTERFACE: 00156 if name not in info.FIRMWARE_SET: 00157 print('Warning: board "%s" no entry in SUPPORTED_CONFIGURATIONS in info.py' % name) 00158 00159 # Set file paths 00160 self._bin_path = self._directory + os.sep + '%s_crc.bin' % name 00161 self._hex_path = self._directory + os.sep + '%s_crc.hex' % name 00162 self._bin_path = os.path.abspath(self._bin_path ) 00163 self._hex_path = os.path.abspath(self._hex_path ) 00164 if not os.path.isfile(self._bin_path ): 00165 return # Failure 00166 if not os.path.isfile(self._hex_path ): 00167 return # Failure 00168 00169 self._valid = True 00170 00171 def __str__ (self): 00172 return "Name=%s" % (self.name ) 00173 00174 @property 00175 def valid (self): 00176 """Set to True if the firmware is valid""" 00177 return self._valid 00178 00179 @property 00180 def name (self): 00181 return self._name 00182 00183 @property 00184 def hic_id (self): 00185 return self._hic_id 00186 00187 @property 00188 def type (self): 00189 return self._type 00190 00191 @property 00192 def bin_path (self): 00193 return self._bin_path 00194 00195 @property 00196 def hex_path (self): 00197 return self._hex_path 00198 00199 @property 00200 def elf_path (self): 00201 return self._elf_path
Generated on Tue Jul 12 2022 15:37:15 by
1.7.2