jlink: fix flashing behavior on Windows

The object returned by NamedTemporaryFile cannot be opened a second
time while the file is still open on Windows. This is exactly what the
JLink commander needs to do with the resulting file, however, breaking
jlink flash on that platform.

Fix this by using a temporary directory instead, and creating a file
inside it. The resulting directory still gets cleaned up, but the
resulting file can be read by the commander.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
This commit is contained in:
Marti Bolivar 2018-04-06 16:00:23 -04:00 committed by Maureen Helm
parent bdda369580
commit e32ed18076

View file

@ -124,15 +124,18 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
lines.append('g') # Start the CPU
lines.append('q') # Close the connection and quit
with tempfile.NamedTemporaryFile(suffix='.jlink') as f:
f.writelines(bytes(line + '\n', 'utf-8') for line in lines)
f.flush()
# Don't use NamedTemporaryFile: the resulting file can't be
# opened again on Windows.
with tempfile.TemporaryDirectory(suffix='jlink') as d:
fname = os.path.join(d, 'runner.jlink')
with open(fname, 'wb') as f:
f.writelines(bytes(line + '\n', 'utf-8') for line in lines)
cmd = ([self.commander] +
['-if', self.iface,
'-speed', self.speed,
'-device', self.device,
'-CommanderScript', f.name])
'-CommanderScript', fname])
print('Flashing Target Device')
self.check_call(cmd)