Skip to content

Commit cdac7a2

Browse files
authored
Improve flashing bin files for JLink targets (#204)
1 parent a33aeec commit cdac7a2

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

nanoFirmwareFlasher.Library/JLinkCli.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Linq;
1111
using System.Runtime.InteropServices;
1212
using System.Text;
13-
using System.Threading;
1413

1514
namespace nanoFramework.Tools.FirmwareFlasher
1615
{
@@ -180,41 +179,33 @@ public ExitCodes ExecuteFlashBinFiles(
180179
}
181180
}
182181

182+
List<string> shadowFiles = new List<string>();
183+
183184
// J-Link can't handle diacritc chars
184185
// developer note: reported to Segger (Case: 60276735) and can be removed if this is fixed/improved
185186
foreach (string binFile in files)
186187
{
187-
if (!binFile.IsNormalized(NormalizationForm.FormD))
188+
if (!binFile.IsNormalized(NormalizationForm.FormD)
189+
|| binFile.Contains(' '))
188190
{
189-
Console.ForegroundColor = ConsoleColor.Red;
190-
191-
Console.WriteLine("");
192-
Console.WriteLine("********************************* WARNING *********************************");
193-
Console.WriteLine("Diacritic chars found in the path to a binary file!");
194-
Console.WriteLine("J-Link can't handle those, please use a path with plain simple ASCII chars.");
195-
Console.WriteLine("***************************************************************************");
196-
Console.WriteLine("");
191+
var tempFile = Path.Combine(
192+
Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine),
193+
Path.GetFileName(binFile));
197194

198-
Console.ForegroundColor = ConsoleColor.White;
195+
// copy file to shadow file
196+
File.Copy(
197+
binFile,
198+
tempFile,
199+
true);
199200

200-
return ExitCodes.E8003;
201+
shadowFiles.Add(tempFile);
201202
}
202-
203-
if (binFile.Contains(' '))
203+
else
204204
{
205-
Console.ForegroundColor = ConsoleColor.Red;
206-
207-
Console.WriteLine("");
208-
Console.WriteLine("************************* WARNING **************************");
209-
Console.WriteLine("Binary file path contains spaces!");
210-
Console.WriteLine("J-Link can't handle those, please use a path without spaces.");
211-
Console.WriteLine("************************************************************");
212-
Console.WriteLine("");
213-
214-
Console.ForegroundColor = ConsoleColor.White;
215-
216-
return ExitCodes.E8003;
205+
// copy file to shadow list
206+
shadowFiles.Add(binFile);
217207
}
208+
218209
}
219210

220211
// erase flash
@@ -244,7 +235,7 @@ public ExitCodes ExecuteFlashBinFiles(
244235

245236
// program BIN file(s)
246237
int index = 0;
247-
foreach (string binFile in files)
238+
foreach (string binFile in shadowFiles)
248239
{
249240
// make sure path is absolute
250241
var binFilePath = Utilities.MakePathAbsolute(

0 commit comments

Comments
 (0)