Skip to content

Commit

Permalink
Improve flashing bin files for JLink targets (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Feb 22, 2023
1 parent a33aeec commit cdac7a2
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions nanoFirmwareFlasher.Library/JLinkCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace nanoFramework.Tools.FirmwareFlasher
{
Expand Down Expand Up @@ -180,41 +179,33 @@ public ExitCodes ExecuteFlashBinFiles(
}
}

List<string> shadowFiles = new List<string>();

// 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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cdac7a2

Please sign in to comment.