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.
module_copy_mps2.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2011-2013 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 from __future__ import print_function 00018 00019 import re 00020 import os, shutil 00021 from os.path import join 00022 from time import sleep 00023 from .host_test_plugins import HostTestPluginBase 00024 00025 00026 class HostTestPluginCopyMethod_MPS2(HostTestPluginBase): 00027 00028 # MPS2 specific flashing / binary setup funcitons 00029 def mps2_set_board_image_file(self, disk, images_cfg_path, image0file_path, image_name='images.txt'): 00030 """ This function will alter image cfg file. 00031 Main goal of this function is to change number of images to 1, comment all 00032 existing image entries and append at the end of file new entry with test path. 00033 @return True when all steps succeed. 00034 """ 00035 MBED_SDK_TEST_STAMP = 'test suite entry' 00036 image_path = join(disk, images_cfg_path, image_name) 00037 new_file_lines = [] # New configuration file lines (entries) 00038 00039 # Check each line of the image configuration file 00040 try: 00041 with open(image_path, 'r') as file: 00042 for line in file: 00043 if re.search('^TOTALIMAGES', line): 00044 # Check number of total images, should be 1 00045 new_file_lines.append(re.sub('^TOTALIMAGES:[\t ]*[\d]+', 'TOTALIMAGES: 1', line)) 00046 elif re.search('; - %s[\n\r]*$'% MBED_SDK_TEST_STAMP, line): 00047 # Look for test suite entries and remove them 00048 pass # Omit all test suite entries 00049 elif re.search('^IMAGE[\d]+FILE', line): 00050 # Check all image entries and mark the ';' 00051 new_file_lines.append(';' + line) # Comment non test suite lines 00052 else: 00053 # Append line to new file 00054 new_file_lines.append(line) 00055 except IOError as e: 00056 return False 00057 00058 # Add new image entry with proper commented stamp 00059 new_file_lines.append('IMAGE0FILE: %s ; - %s\r\n'% (image0file_path, MBED_SDK_TEST_STAMP)) 00060 00061 # Write all lines to file 00062 try: 00063 with open(image_path, 'w') as file: 00064 for line in new_file_lines: 00065 file.write(line), 00066 except IOError: 00067 return False 00068 00069 return True 00070 00071 def mps2_select_core(self, disk, mobo_config_name=""): 00072 """ Function selects actual core 00073 """ 00074 # TODO: implement core selection 00075 pass 00076 00077 def mps2_switch_usb_auto_mounting_after_restart(self, disk, usb_config_name=""): 00078 """ Function alters configuration to allow USB MSD to be mounted after restarts 00079 """ 00080 # TODO: implement USB MSD restart detection 00081 pass 00082 00083 def copy_file(self, file, disk): 00084 if not file: 00085 return 00086 00087 _, ext = os.path.splitext(file) 00088 ext = ext.lower() 00089 dfile = disk + "/SOFTWARE/mbed" + ext 00090 00091 if os.path.isfile(dfile): 00092 print('Remove old binary %s' % dfile) 00093 os.remove(dfile) 00094 00095 shutil.copy(file, dfile) 00096 return True 00097 00098 def touch_file(self, file): 00099 """ Touch file and set timestamp to items 00100 """ 00101 tfile = file+'.tmp' 00102 fhandle = open(tfile, 'a') 00103 try: 00104 fhandle.close() 00105 finally: 00106 os.rename(tfile, file) 00107 return True 00108 00109 # Plugin interface 00110 name = 'HostTestPluginCopyMethod_MPS2' 00111 type = 'CopyMethod' 00112 capabilities = ['mps2-copy'] 00113 required_parameters = ['image_path', 'destination_disk'] 00114 00115 def setup(self, *args, **kwargs): 00116 """ Configure plugin, this function should be called before plugin execute() method is used. 00117 """ 00118 return True 00119 00120 def execute(self, capabilitity, *args, **kwargs): 00121 """ Executes capability by name. 00122 Each capability may directly just call some command line 00123 program or execute building pythonic function 00124 """ 00125 result = False 00126 if self.check_parameters(capabilitity, *args, **kwargs) is True: 00127 file = kwargs['image_path'] 00128 disk = kwargs['destination_disk'] 00129 00130 """ Add a delay in case there a test just finished 00131 Prevents interface firmware hiccups 00132 """ 00133 sleep(20) 00134 if capabilitity == 'mps2-copy' and self.copy_file(file, disk): 00135 sleep(3) 00136 if self.touch_file(disk + 'reboot.txt'): 00137 """ Add a delay after the board was rebooted. 00138 The actual reboot time is 20 seconds, but using 15 seconds 00139 allows us to open the COM port and save a board reset. 00140 This also prevents interface firmware hiccups. 00141 """ 00142 sleep(7) 00143 result = True 00144 00145 return result 00146 00147 00148 def load_plugin (): 00149 """ Returns plugin available in this module 00150 """ 00151 return HostTestPluginCopyMethod_MPS2()
Generated on Tue Jul 12 2022 14:24:28 by
