From cdac7a25ca8263fd30f9d6730bd91782db7d3794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 22 Feb 2023 16:06:50 +0000 Subject: [PATCH] Improve flashing bin files for JLink targets (#204) --- nanoFirmwareFlasher.Library/JLinkCli.cs | 45 ++++++++++--------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/nanoFirmwareFlasher.Library/JLinkCli.cs b/nanoFirmwareFlasher.Library/JLinkCli.cs index 6be0ebf5..3621424e 100644 --- a/nanoFirmwareFlasher.Library/JLinkCli.cs +++ b/nanoFirmwareFlasher.Library/JLinkCli.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; -using System.Threading; namespace nanoFramework.Tools.FirmwareFlasher { @@ -180,41 +179,33 @@ public ExitCodes ExecuteFlashBinFiles( } } + List shadowFiles = new List(); + // J-Link can't handle diacritc chars // developer note: reported to Segger (Case: 60276735) and can be removed if this is fixed/improved foreach (string binFile in files) { - if (!binFile.IsNormalized(NormalizationForm.FormD)) + if (!binFile.IsNormalized(NormalizationForm.FormD) + || binFile.Contains(' ')) { - Console.ForegroundColor = ConsoleColor.Red; - - Console.WriteLine(""); - Console.WriteLine("********************************* WARNING *********************************"); - Console.WriteLine("Diacritic chars found in the path to a binary file!"); - Console.WriteLine("J-Link can't handle those, please use a path with plain simple ASCII chars."); - Console.WriteLine("***************************************************************************"); - Console.WriteLine(""); + var tempFile = Path.Combine( + Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine), + Path.GetFileName(binFile)); - Console.ForegroundColor = ConsoleColor.White; + // copy file to shadow file + File.Copy( + binFile, + tempFile, + true); - return ExitCodes.E8003; + shadowFiles.Add(tempFile); } - - if (binFile.Contains(' ')) + else { - Console.ForegroundColor = ConsoleColor.Red; - - Console.WriteLine(""); - Console.WriteLine("************************* WARNING **************************"); - Console.WriteLine("Binary file path contains spaces!"); - Console.WriteLine("J-Link can't handle those, please use a path without spaces."); - Console.WriteLine("************************************************************"); - Console.WriteLine(""); - - Console.ForegroundColor = ConsoleColor.White; - - return ExitCodes.E8003; + // copy file to shadow list + shadowFiles.Add(binFile); } + } // erase flash @@ -244,7 +235,7 @@ public ExitCodes ExecuteFlashBinFiles( // program BIN file(s) int index = 0; - foreach (string binFile in files) + foreach (string binFile in shadowFiles) { // make sure path is absolute var binFilePath = Utilities.MakePathAbsolute(