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

Add VerifyMemory method #271

Merged
merged 1 commit into from
Nov 24, 2020
Merged
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
47 changes: 45 additions & 2 deletions nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,25 @@ public async Task<bool> DeployBinaryFileAsync(

progress?.Report($"Writing to device @ 0x{address:X8}...");

return DeployFile(
if(!DeployFile(
data,
address,
progress);
progress))
{
return false;
}

//progress?.Report($"Verifying image...");

//if (!VerifyMemory(
// data,
// address,
// progress))
//{
// return false;
//}

return true;
}

/// <summary>
Expand Down Expand Up @@ -663,6 +678,34 @@ private bool DeployFile(
return true;
}

private bool VerifyMemory(
byte[] buffer,
uint address,
IProgress<string> progress = null)
{
(byte[] ReadBuffer, uint ErrorCode, bool Success) = DebugEngine.ReadMemory(address, (uint)buffer.Length);
if (!Success)
{
progress?.Report($"Error reading from device memory, error {ErrorCode}.");

return false;
}

int index = 0;

foreach(var b in buffer)
{
if(ReadBuffer[index] != b)
{
progress?.Report($"Verification error @ 0x{(address + index):X8}.");
return false;
}
}

return true;
}


/// <summary>
/// Starts execution on the connected nanoDevice at the supplied address (parameter entrypoint).
/// This method is generally used after the Deploy method to jump into the code that was deployed.
Expand Down