mirror of https://github.com/ARMmbed/mbed-os.git
Using mbedls for smartcopy
parent
1eacabd7c3
commit
19978dd9a8
|
@ -17,11 +17,12 @@ limitations under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from os.path import join, basename, exists
|
import mbed_lstools
|
||||||
|
import ctypes
|
||||||
|
from os.path import join, basename, exists, abspath, dirname
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from host_test_plugins import HostTestPluginBase
|
from host_test_plugins import HostTestPluginBase
|
||||||
|
|
||||||
|
|
||||||
class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
|
class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
|
||||||
|
|
||||||
# Plugin interface
|
# Plugin interface
|
||||||
|
@ -58,17 +59,47 @@ class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
|
||||||
|
|
||||||
cmd = ['sync']
|
cmd = ['sync']
|
||||||
result = self.run_command(cmd, shell=False)
|
result = self.run_command(cmd, shell=False)
|
||||||
|
elif os.name == 'nt':
|
||||||
|
cmd = ['copy', image_path, destination_path]
|
||||||
|
result = self.run_command(cmd, shell=True)
|
||||||
|
|
||||||
# Give the OS and filesystem time to settle down
|
# Give the OS and filesystem time to settle down
|
||||||
sleep(3)
|
sleep(3)
|
||||||
|
|
||||||
if not target_mcu == 'LPC1768':
|
platform_name_filter = [target_mcu]
|
||||||
|
muts_list = {}
|
||||||
|
|
||||||
remount_complete = False
|
remount_complete = False
|
||||||
|
|
||||||
for i in range(0, 60):
|
for i in range(0, 60):
|
||||||
|
oldError = None
|
||||||
|
if os.name == 'nt':
|
||||||
|
# Disable Windows error box temporarily
|
||||||
|
oldError = ctypes.windll.kernel32.SetErrorMode(1) #note that SEM_FAILCRITICALERRORS = 1
|
||||||
|
|
||||||
|
print('Looking for %s with MBEDLS' % target_mcu)
|
||||||
|
mbeds = mbed_lstools.create()
|
||||||
|
detect_muts_list = mbeds.list_mbeds()
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
ctypes.windll.kernel32.SetErrorMode(oldError)
|
||||||
|
|
||||||
|
muts_list = get_autodetected_MUTS(detect_muts_list, platform_name_filter=platform_name_filter)
|
||||||
|
|
||||||
|
if 1 in muts_list:
|
||||||
|
mut = muts_list[1]
|
||||||
|
destination_disk = mut['disk']
|
||||||
|
destination_path = join(destination_disk, image_base_name)
|
||||||
|
|
||||||
|
if mut['mcu'] == 'LPC1768' or mut['mcu'] == 'LPC11U24':
|
||||||
|
if exists(destination_disk) and exists(destination_path):
|
||||||
|
remount_complete = True
|
||||||
|
break;
|
||||||
|
else:
|
||||||
if exists(destination_disk) and not exists(destination_path):
|
if exists(destination_disk) and not exists(destination_path):
|
||||||
remount_complete = True
|
remount_complete = True
|
||||||
break
|
break;
|
||||||
else:
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
if remount_complete:
|
if remount_complete:
|
||||||
|
@ -88,10 +119,44 @@ class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def load_plugin():
|
def load_plugin():
|
||||||
""" Returns plugin available in this module
|
""" Returns plugin available in this module
|
||||||
"""
|
"""
|
||||||
return HostTestPluginCopyMethod_Smart()
|
return HostTestPluginCopyMethod_Smart()
|
||||||
|
|
||||||
|
def get_autodetected_MUTS(mbeds_list, platform_name_filter=None):
|
||||||
|
""" Function detects all connected to host mbed-enabled devices and generates artificial MUTS file.
|
||||||
|
If function fails to auto-detect devices it will return empty dictionary.
|
||||||
|
|
||||||
|
if get_module_avail('mbed_lstools'):
|
||||||
|
mbeds = mbed_lstools.create()
|
||||||
|
mbeds_list = mbeds.list_mbeds()
|
||||||
|
|
||||||
|
@param mbeds_list list of mbeds captured from mbed_lstools
|
||||||
|
@param platform_name You can filter 'platform_name' with list of filtered targets from 'platform_name_filter'
|
||||||
|
"""
|
||||||
|
result = {} # Should be in muts_all.json format
|
||||||
|
# Align mbeds_list from mbed_lstools to MUT file format (JSON dictionary with muts)
|
||||||
|
# mbeds_list = [{'platform_name': 'NUCLEO_F302R8', 'mount_point': 'E:', 'target_id': '07050200623B61125D5EF72A', 'serial_port': u'COM34'}]
|
||||||
|
index = 1
|
||||||
|
for mut in mbeds_list:
|
||||||
|
# Filter the MUTS if a filter is specified
|
||||||
|
|
||||||
|
if platform_name_filter and not mut['platform_name'] in platform_name_filter:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# For mcu_unique - we are assigning 'platform_name_unique' value from mbedls output (if its existing)
|
||||||
|
# if not we are creating our own unique value (last few chars from platform's target_id).
|
||||||
|
m = {'mcu': mut['platform_name'],
|
||||||
|
'mcu_unique' : mut['platform_name_unique'] if 'platform_name_unique' in mut else "%s[%s]" % (mut['platform_name'], mut['target_id'][-4:]),
|
||||||
|
'port': mut['serial_port'],
|
||||||
|
'disk': mut['mount_point'],
|
||||||
|
'peripherals': [] # No peripheral detection
|
||||||
|
}
|
||||||
|
if index not in result:
|
||||||
|
result[index] = {}
|
||||||
|
result[index] = m
|
||||||
|
index += 1
|
||||||
|
return result
|
||||||
|
|
Loading…
Reference in New Issue