1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
python do_flash_usb() {
import subprocess
return_code = subprocess.call("which dfu-util", shell=True)
if return_code != 0:
bb.error("ERROR: dfu-util binary not in PATH")
sys.exit(1)
board = d.getVar('BOARD', True)
if board == 'arduino_101_sss':
iface = 'sensor_core'
elif board == 'arduino_101':
iface = 'x86_app'
elif board == 'arduino_101_ble':
iface = 'ble_core'
else:
bb.error(" Unsupported board %s" % board)
sys.exit(2)
# We need to serialize flashing of separate images (when using multiconfig)
lock = bb.utils.lockfile(os.path.join(d.getVar('TOPDIR', True),"flash-dfu.lock"), False, True)
image = "%s/%s.elf" % (d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('PN', True))
statement = 'dfu-util -v -a ' + iface + ' -d 8087:0aba -D ' + image.replace('elf','bin')
bb.note("command: %s" % statement)
bb.plain("Attempting to flash board: %s" % board)
# Arduino-101 needs to be reset in order to enter "flash mode".
# The flash window is about 5 seconds.
# However, if the device is flashed, it remains in the "flash mode"
# until it is reset again, so it needs to enter the flash mode via reset
# only once even if we flash images for multiple cores. So we only prompt
# for reset once.
timeout = 5
promptneeded = True
while (timeout > 0):
time.sleep(0.5)
timeout = timeout - 0.5
return_code = subprocess.call(statement, shell=True)
if return_code == 0:
break
if promptneeded:
bb.warn("\n\n *** Failed to flash %s. *** \n Press reset, will retry for five seconds...\n" % board)
promptneeded = False
if return_code != 0:
bb.error("Error flashing %s [%d]" % (board,return_code))
else:
bb.plain("Success (return code %d)" % return_code)
bb.utils.unlockfile(lock)
}
addtask do_flash_usb
do_flash_usb[nostamp] = "1"
|