Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework DeployFile inner methods #279

Merged
merged 1 commit into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ public async Task<bool> DeployUpdateAsync(StorageFile comprFilePath, Cancellatio
/// <param name="address">Address to write to.</param>
/// <returns>Returns false if the deployment fails, true otherwise.
/// </returns>
/// <remarks>
/// To perform the update the device has to be running:
/// - nanoCLR if this is meant to update the deployment region.
/// - nanoBooter if this is meant to update nanoCLR
/// Failing to meet this condition will abort the operation.
/// </remarks>
public async Task<bool> DeployBinaryFileAsync(
string binFile,
uint address,
Expand All @@ -576,7 +582,6 @@ public async Task<bool> DeployBinaryFileAsync(
var data = File.ReadAllBytes(binFile);

if (!await PrepareForDeployAsync(
data,
address,
cancellationToken,
progress))
Expand Down Expand Up @@ -684,6 +689,7 @@ private bool DeployFile(
address,
buffer,
progress);

if (!Success)
{
progress?.Report($"Error writing to device memory @ 0x{address:X8}, error {ErrorCode}.");
Expand Down Expand Up @@ -1325,13 +1331,11 @@ private async Task<bool> PreProcesSrecAsync(StorageFile srecFile)
}

private async Task<bool> PrepareForDeployAsync(
byte[] buffer,
uint address,
CancellationToken cancellationToken,
IProgress<string> progress = null)
{
return await PrepareForDeployAsync(
buffer,
address,
null,
cancellationToken,
Expand All @@ -1344,26 +1348,18 @@ private async Task<bool> PrepareForDeployAsync(
IProgress<string> progress = null)
{
return await PrepareForDeployAsync(
null,
0,
blocks,
cancellationToken,
progress);
}

private async Task<bool> PrepareForDeployAsync(
byte[] buffer,
uint address,
List<SRecordFile.Block> blocks,
CancellationToken cancellationToken,
IProgress<string> progress = null)
{
// make sure we are connected
if(!await DebugEngine.ConnectAsync(5000, true))
{
return false;
}

// get flash sector map, only if needed
List<Commands.Monitor_FlashSectorMap.FlashSectorData> flashSectorsMap = DebugEngine.FlashSectorMap;

Expand All @@ -1379,8 +1375,6 @@ private async Task<bool> PrepareForDeployAsync(
bool updatesClr = false;
bool updatesBooter = false;

long totalLength;

if (blocks != null)
{
foreach (SRecordFile.Block bl in blocks)
Expand All @@ -1393,8 +1387,6 @@ private async Task<bool> PrepareForDeployAsync(
updatesBooter ^= (startSector.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP;
}
}

totalLength = blocks.Sum(b => b.data.Length);
}
else
{
Expand All @@ -1405,14 +1397,15 @@ private async Task<bool> PrepareForDeployAsync(
updatesClr = (startSector.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE;
updatesBooter = (startSector.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP;
}

totalLength = buffer.Length;
}

// sanity check
if (updatesBooter)
{
// can't handle this update because it touches nanoBooter

progress?.Report("Can't deploy file because it updates nanoBooter.");

return false;
}

Expand All @@ -1425,11 +1418,15 @@ private async Task<bool> PrepareForDeployAsync(
return false;
}

if (updatesClr &&
DebugEngine.ConnectionSource != ConnectionSource.nanoBooter)
if (updatesClr)
{
// if this is updating the CLR need to launch nanoBooter
await ConnectToNanoBooterAsync(cancellationToken);
if (DebugEngine.ConnectionSource != ConnectionSource.nanoBooter)
{
progress?.Report("Need to launch nanoBooter before updating the firmware.");

return false;
}
}

// erase whatever blocks are required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);NU1603;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -79,7 +79,7 @@
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);NU1603;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -101,7 +101,7 @@
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);NU1603;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand Down Expand Up @@ -140,6 +140,9 @@
<PackageReference Include="Polly">
<Version>7.2.1</Version>
</PackageReference>
<PackageReference Include="Polly.Contrib.WaitAndRetry">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>2.6.1</Version>
</PackageReference>
Expand Down