Skip to content

Commit ae84997

Browse files
Merge pull request #386 from bridadan/always_check_for_daplink_files
Always checking daplink files to catch older devices
2 parents b98d08d + 07babc1 commit ae84997

File tree

21 files changed

+359
-5
lines changed

21 files changed

+359
-5
lines changed

mbed_lstools/lstools_base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ def _update_device_from_fs(self, device, read_details_txt):
223223
device['directory_entries'] = directory_entries
224224
device['target_id'] = device['target_id_usb_id']
225225

226-
{
227-
'daplink': self._update_device_details_daplink_compatible,
228-
'stlink': self._update_device_details_daplink_compatible,
229-
'jlink': self._update_device_details_jlink
230-
}[device['device_type'] or 'daplink'](device, read_details_txt)
226+
# Always try to update using daplink compatible boards processself.
227+
# This is done for backwards compatibility.
228+
self._update_device_details_daplink_compatible(device, read_details_txt)
229+
230+
if device.get('device_type') == 'jlink':
231+
self._update_device_details_jlink(device, read_details_txt)
232+
231233
except (OSError, IOError) as e:
232234
logger.warning(
233235
'Marking device with mount point "%s" as unmounted due to the '

test/platform_detection.py

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#!/usr/bin/env python
2+
"""
3+
mbed SDK
4+
Copyright (c) 2011-2015 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
import unittest
20+
import os
21+
import copy
22+
from mock import patch, mock_open, DEFAULT
23+
24+
from mbed_lstools.lstools_base import MbedLsToolsBase
25+
26+
TEST_DATA_PATH = 'test_data'
27+
28+
class DummyLsTools(MbedLsToolsBase):
29+
return_value = []
30+
def find_candidates(self):
31+
return self.return_value
32+
33+
try:
34+
basestring
35+
except NameError:
36+
# Python 3
37+
basestring = str
38+
39+
40+
def get_case_insensitive_path(path, file_name):
41+
for entry in os.listdir(path):
42+
if entry.lower() == file_name.lower():
43+
return os.path.join(path, entry)
44+
45+
raise Exception('No matching file for %s found in $s' % (file_name, path))
46+
47+
48+
class PlatformDetectionTestCase(unittest.TestCase):
49+
""" Basic test cases checking trivial asserts
50+
"""
51+
52+
def setUp(self):
53+
self.base = DummyLsTools()
54+
55+
def tearDown(self):
56+
pass
57+
58+
def run_test(self, test_data_case, candidate_data, expected_data):
59+
# Add necessary candidate data
60+
candidate_data['mount_point'] = 'dummy_mount_point'
61+
62+
# Find the test data in the test_data folder
63+
test_script_path = os.path.dirname(os.path.abspath(__file__))
64+
test_data_path = os.path.join(test_script_path, TEST_DATA_PATH)
65+
test_data_cases = os.listdir(test_data_path)
66+
self.assertTrue(test_data_case in test_data_cases, 'Expected %s to be present in %s folder' % (test_data_case, test_data_path))
67+
test_data_case_path = os.path.join(test_data_path, test_data_case)
68+
69+
# NOTE a limitation of this mocked test is that it only allows mocking of one directory level.
70+
# This is enough at the moment because all firmwares seem to use a flat file structure.
71+
# If this changes in the future, this mocking framework can be extended to support this.
72+
73+
test_data_case_file_names = os.listdir(test_data_case_path)
74+
mocked_open_file_paths = [os.path.join(candidate_data['mount_point'], file_name ) for file_name in test_data_case_file_names]
75+
76+
# Setup all the mocks
77+
self.base.return_value = [candidate_data]
78+
79+
def do_open(path, mode='r'):
80+
file_name = os.path.basename(path)
81+
try:
82+
with open(get_case_insensitive_path(test_data_case_path, file_name), 'r') as test_data_file:
83+
test_data_file_data = test_data_file.read()
84+
except OSError:
85+
raise OSError("(mocked open) No such file or directory: '%s'" % (path))
86+
87+
file_object = mock_open(read_data=test_data_file_data).return_value
88+
file_object.__iter__.return_value = test_data_file_data.splitlines(True)
89+
return file_object
90+
91+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
92+
patch('mbed_lstools.lstools_base.open', do_open) as _,\
93+
patch('os.listdir') as _listdir:
94+
_mpr.return_value = True
95+
_listdir.return_value = test_data_case_file_names
96+
results = self.base.list_mbeds(read_details_txt=True)
97+
98+
# There should only ever be one result
99+
self.assertEqual(len(results), 1)
100+
actual = results[0]
101+
102+
expected_keys = list(expected_data.keys())
103+
actual_keys = list(actual.keys())
104+
differing_map = {}
105+
for key in expected_keys:
106+
actual_value = actual.get(key)
107+
if actual_value != expected_data[key]:
108+
differing_map[key] = (actual_value, expected_data[key])
109+
110+
111+
if differing_map:
112+
differing_string = ''
113+
for differing_key in sorted(list(differing_map.keys())):
114+
actual, expected = differing_map[differing_key]
115+
differing_string += ' "%s": "%s" (expected "%s")\n' % (differing_key, actual, expected)
116+
117+
assert_string = 'Expected data mismatch:\n\n{\n%s}' % (differing_string)
118+
self.assertTrue(False, assert_string)
119+
120+
121+
122+
def test_efm32pg_stk3401_jlink(self):
123+
self.run_test('efm32pg_stk3401_jlink', {
124+
'target_id_usb_id': u'000440074453',
125+
'vendor_id': '1366',
126+
'product_id': '1015'
127+
}, {
128+
'platform_name': 'EFM32PG_STK3401',
129+
'device_type': 'jlink',
130+
'target_id': '2035022D000122D5D475113A',
131+
'target_id_usb_id': '000440074453',
132+
'target_id_mbed_htm': '2035022D000122D5D475113A'
133+
})
134+
135+
def test_lpc1768(self):
136+
self.run_test('lpc1768', {
137+
'target_id_usb_id': u'101000000000000000000002F7F20DF3',
138+
'vendor_id': '0d28',
139+
'product_id': '0204'
140+
}, {
141+
'platform_name': 'LPC1768',
142+
'device_type': 'daplink',
143+
'target_id': '101000000000000000000002F7F20DF3d51e6be5ac41795761dc44148e3b7000',
144+
'target_id_usb_id': '101000000000000000000002F7F20DF3',
145+
'target_id_mbed_htm': '101000000000000000000002F7F20DF3d51e6be5ac41795761dc44148e3b7000'
146+
})
147+
148+
def test_nucleo_f411re_stlink(self):
149+
self.run_test('nucleo_f411re_stlink', {
150+
'target_id_usb_id': u'0671FF554856805087112815',
151+
'vendor_id': '0483',
152+
'product_id': '374b'
153+
}, {
154+
'platform_name': 'NUCLEO_F411RE',
155+
'device_type': 'stlink',
156+
'target_id': '07400221076061193824F764',
157+
'target_id_usb_id': '0671FF554856805087112815',
158+
'target_id_mbed_htm': '07400221076061193824F764'
159+
})
160+
161+
def test_nrf51_microbit(self):
162+
self.run_test('nrf51_microbit', {
163+
'target_id_usb_id': u'9900007031324e45000f9019000000340000000097969901',
164+
'vendor_id': '0d28',
165+
'product_id': '0204'
166+
}, {
167+
'platform_name': 'NRF51_MICROBIT',
168+
'device_type': 'daplink',
169+
'target_id': '9900007031324e45000f9019000000340000000097969901',
170+
'target_id_usb_id': '9900007031324e45000f9019000000340000000097969901'
171+
})
172+
173+
def test_k64f_daplink(self):
174+
self.run_test('k64f_daplink', {
175+
'target_id_usb_id': u'0240000032044e45000a700a997b00356781000097969900',
176+
'vendor_id': '0d28',
177+
'product_id': '0204'
178+
}, {
179+
'platform_name': 'K64F',
180+
'device_type': 'daplink',
181+
'target_id': '0240000032044e45000a700a997b00356781000097969900',
182+
'target_id_usb_id': '0240000032044e45000a700a997b00356781000097969900',
183+
'target_id_mbed_htm': '0240000032044e45000a700a997b00356781000097969900'
184+
})
185+
186+
def test_nrf52_dk_daplink(self):
187+
self.run_test('nrf52_dk_daplink', {
188+
'target_id_usb_id': u'110100004420312043574641323032203233303397969903',
189+
'vendor_id': '0d28',
190+
'product_id': '0204'
191+
}, {
192+
'platform_name': 'NRF52_DK',
193+
'device_type': 'daplink',
194+
'target_id': '110100004420312043574641323032203233303397969903',
195+
'target_id_usb_id': '110100004420312043574641323032203233303397969903',
196+
'target_id_mbed_htm': '110100004420312043574641323032203233303397969903'
197+
})
198+
199+
def test_nrf52_dk_jlink(self):
200+
self.run_test('nrf52_dk_jlink', {
201+
'target_id_usb_id': u'000682546728',
202+
'vendor_id': '1366',
203+
'product_id': '1015'
204+
}, {
205+
'platform_name': 'NRF52_DK',
206+
'device_type': 'jlink',
207+
'target_id': '000682546728',
208+
'target_id_usb_id': '000682546728'
209+
})
210+
211+
212+
213+
if __name__ == '__main__':
214+
unittest.main()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- mbed website redirect -->
2+
<!-- Version: 0.14.3. build 557 -->
3+
<html>
4+
<head>
5+
<meta http-equiv="refresh" content="0; url=http://mbed.org/device/?code=2035022D000122D5D475113A"/>
6+
<title>mbed Website Shortcut</title>
7+
</head>
8+
<body></body>
9+
</html>
10+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Silicon Labs J-Link MSD volume.
2+
3+
Copying a binary file here will flash it to the MCU.
4+
5+
Supported binary file formats:
6+
- Intel Hex (.hex)
7+
- Motorola s-records (.mot)
8+
- Binary (.bin/.par/.crd)
9+
10+
Known limitations:
11+
- Virtual COM port speed is currently fixed at 115200 bps
12+
- Using other kit functionality such as energy profiling or debugger while flashing is
13+
not supported.
14+
Workaround: Pause any energy profiling and disconnect any connected debug sessions
15+
before flashing.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="refresh" content="0; url=https://www.silabs.com/products/mcu/32-bit/efm32-pearl-gecko/Pages/efm32-pearl-gecko-starter-kit.aspx"/>
4+
<title>EFM32PG-STK3401 - Pearl Gecko STK</title>
5+
</head>
6+
<body>
7+
</body>
8+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html><head><meta http-equiv="refresh" content="0; url=http://www.silabs.com/simplicity"/><title>Simplicity Studio Shortcut</title></head><body></body></html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# DAPLink Firmware - see https://mbed.com/daplink
2+
Unique ID: 0240000032044e45000a700a997b00356781000097969900
3+
HIC ID: 97969900
4+
Auto Reset: 0
5+
Automation allowed: 0
6+
Overflow detection: 0
7+
Daplink Mode: Interface
8+
Interface Version: 0244
9+
Git SHA: 363abb00ee17ad50cb407c6d2e299407332e3c85
10+
Local Mods: 1
11+
USB Interfaces: MSD, CDC, HID
12+
Interface CRC: 0xc44e96e1
13+
Remount count: 0
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<!-- mbed Platform Website and Authentication Shortcut -->
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<title>mbed Website Shortcut</title>
7+
</head>
8+
<body>
9+
<script>
10+
window.location.replace("https://mbed.org/device/?code=0240000032044e45000a700a997b00356781000097969900?version=0244?target_id=00000000000000000000000000000000");
11+
</script>
12+
</body>
13+
</html>

test/test_data/lpc1768/MBED.HTM

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- mbed Microcontroller Website and Authentication Shortcut -->
2+
<html>
3+
<head>
4+
<meta http-equiv="refresh" content="0; url=http://mbed.org/start?auth=101000000000000000000002F7F20DF3d51e6be5ac41795761dc44148e3b7000&loader=11972&firmware=16457&configuration=4" />
5+
<title>mbed Website Shortcut</title>
6+
</head>
7+
<body></body>
8+
</html>
9+

test/test_data/lpc1768/basic.bin

111 KB
Binary file not shown.

0 commit comments

Comments
 (0)