Skip to content

Commit 2545fad

Browse files
authored
Rework DeploymentExecuteIncremental to fully erase deployment region (#365)
1 parent 6c8b64a commit 2545fad

File tree

1 file changed

+36
-22
lines changed
  • nanoFramework.Tools.DebugLibrary.Shared/WireProtocol

1 file changed

+36
-22
lines changed

nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,9 +3081,10 @@ private bool DeploymentExecuteIncremental(
30813081

30823082
// build the deployment blob from the flash sector map
30833083
// apply a filter so that we take only the blocks flag for deployment
3084-
List<DeploymentSector> deploymentBlob = FlashSectorMap.Where(s => (s.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT)
3085-
.Select(s => s.ToDeploymentSector())
3086-
.ToList();
3084+
List<DeploymentSector> deploymentBlob = FlashSectorMap.Where(s => (s.Flags
3085+
& Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT)
3086+
.Select(s => s.ToDeploymentSector())
3087+
.ToList();
30873088

30883089
// rough check if there is enough room to deploy
30893090
if (deploymentBlob.ToDeploymentBlockList().Sum(b => b.Size) < deployLength)
@@ -3093,6 +3094,7 @@ private bool DeploymentExecuteIncremental(
30933094

30943095
log?.Report(errorMessage);
30953096
progress?.Report(new MessageWithProgress(""));
3097+
30963098
return false;
30973099
}
30983100

@@ -3105,6 +3107,7 @@ private bool DeploymentExecuteIncremental(
31053107
{
31063108
log?.Report($"It's only possible to deploy word aligned assemblies. Failed to deploy assembly with {assemblies.First().Length} bytes.");
31073109
progress?.Report(new MessageWithProgress(""));
3110+
31083111
return false;
31093112
}
31103113

@@ -3145,26 +3148,25 @@ private bool DeploymentExecuteIncremental(
31453148
}
31463149
else
31473150
{
3148-
// shouldn't happen, but couldn't find enough space to deploy all the assemblies!!
3151+
// shouldn't happen!
3152+
// if got here that's because couldn't find enough space to deploy all the assemblies!!
31493153
string errorMessage = $"Couldn't find a free deployment block to complete the deployment (remaining: {remainingBytes} bytes).";
31503154

31513155
log?.Report(errorMessage);
31523156
progress?.Report(new MessageWithProgress(""));
3157+
31533158
return false;
31543159
}
31553160
}
31563161

3157-
// get the block list to deploy (not empty)
3158-
List<DeploymentBlock> blocksToDeploy = deploymentBlob.ToDeploymentBlockList().FindAll(b => b.DeploymentData.Length > 0);
3159-
int deploymentSize = blocksToDeploy.Sum(b => b.DeploymentData.Length);
3160-
int deployedBytes = 0;
3161-
3162-
foreach (DeploymentBlock block in blocksToDeploy)
3162+
if (!skipErase)
31633163
{
3164-
// check if skip erase step was requested
3165-
if (!skipErase)
3164+
int deploymentRegionSize = deploymentBlob.ToDeploymentBlockList().Sum(b => b.DeploymentData.Length);
3165+
int erasedBytes = 0;
3166+
3167+
foreach (DeploymentBlock block in deploymentBlob.ToDeploymentBlockList())
31663168
{
3167-
progress?.Report(new MessageWithProgress($"Erasing block @ 0x{block.StartAddress:X8}...", (uint)deployedBytes, (uint)deploymentSize));
3169+
progress?.Report(new MessageWithProgress($"Erasing block @ 0x{block.StartAddress:X8}...", (uint)erasedBytes, (uint)deploymentRegionSize));
31683170
log?.Report($"Erasing block @ 0x{block.StartAddress:X8}...");
31693171

31703172
// erase memory sector
@@ -3178,16 +3180,26 @@ private bool DeploymentExecuteIncremental(
31783180

31793181
return false;
31803182
}
3183+
31813184
// check the error code returned
31823185
if (eraseMemoryResult.ErrorCode != AccessMemoryErrorCodes.NoError)
31833186
{
31843187
log?.Report($"Error erasing device memory @ 0x{block.StartAddress:X8}. Error code: {eraseMemoryResult.ErrorCode}.");
31853188
progress?.Report(new MessageWithProgress(""));
3189+
31863190
return false;
31873191
}
31883192
}
3193+
}
31893194

3190-
// block erased, write buffer
3195+
// get the block list to deploy (not empty)
3196+
List<DeploymentBlock> blocksToDeploy = deploymentBlob.ToDeploymentBlockList().FindAll(b => b.DeploymentData.Length > 0);
3197+
int deploymentSize = blocksToDeploy.Sum(b => b.DeploymentData.Length);
3198+
int deployedBytes = 0;
3199+
3200+
foreach (DeploymentBlock block in blocksToDeploy)
3201+
{
3202+
// write buffer
31913203
AccessMemoryErrorCodes writeOpResult = WriteMemory(
31923204
(uint)block.StartAddress,
31933205
block.DeploymentData,
@@ -3303,11 +3315,16 @@ private bool DeploymentExecuteFull(List<byte[]> assemblies, IProgress<string> pr
33033315
return writeResult2 == AccessMemoryErrorCodes.NoError;
33043316
}
33053317

3306-
//public bool Deployment_Execute(ArrayList assemblies)
3307-
//{
3308-
// return Deployment_Execute(assemblies, true, null);
3309-
//}
3310-
3318+
/// <summary>
3319+
/// Deploy a list of assemblies to the device and optionally reboot it.
3320+
/// </summary>
3321+
/// <param name="assemblies">A collection of assemblies to deploy.</param>
3322+
/// <param name="rebootAfterDeploy"><see langword="true"/> to reboot device after a successfull deployment.</param>
3323+
/// <param name="skipErase"><see langword="true"/> to skip erasing the storage block before writting to it.</param>
3324+
/// <param name="progress">An <see cref="IProgress&lt;MessageWithProgress&gt;"/> object to track the progress of the deploy operation.</param>
3325+
/// <param name="log">An <see cref="IProgress&lt;String&gt;"/> object to log the progress of the deploy operation.</param>
3326+
/// <returns><see langword="true"/> upon a successfull deployment operation. <see langword="false"/> otherwise.</returns>
3327+
/// <exception cref="NotSupportedException">In case the connected device doesn't have support for incremental deployment.</exception>
33113328
public bool DeploymentExecute(
33123329
List<byte[]> assemblies,
33133330
bool rebootAfterDeploy = true,
@@ -3347,9 +3364,6 @@ public bool DeploymentExecute(
33473364
else
33483365
{
33493366
throw new NotSupportedException("Current version only supports incremental deployment. Check the image source code for Debugging_Execution_QueryCLRCapabilities. The capabilities list has to include c_CapabilityFlags_IncrementalDeployment.");
3350-
//progress?.Report("Deploying assemblies to device");
3351-
3352-
//fDeployedOK = await DeploymentExecuteFullAsync(assemblies, progress);
33533367
}
33543368

33553369
if (!deployedOK)

0 commit comments

Comments
 (0)