From 85235a82f2650676595d35a61e8563c31ab83eb1 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 16 Dec 2020 15:49:10 +0000 Subject: [PATCH] Work Flash Sector Data - Rename struct vars. - Add new constants to allow processing Block Region Attributes. - Rework DeploymentBlock to add support for ProgramAligment field. - Rework WriteMemory to process program alignment attribute on flash map. - Rework test app to test new feature. - Bump version to 1.27.0-preview. --- USB Test App WPF/MainWindow.xaml.cs | 139 +++++------------- .../Extensions/FlashSectorDataExtensions.cs | 18 ++- .../MonitorFlashSectorMapExtensions.cs | 2 +- .../Extensions/OutputExtensions.cs | 38 ++--- .../NFDevice/NanoDeviceBase.cs | 42 +++--- .../WireProtocol/Commands.cs | 15 +- .../WireProtocol/DeploymentBlock.cs | 11 +- .../WireProtocol/Engine.cs | 22 ++- version.json | 2 +- 9 files changed, 129 insertions(+), 160 deletions(-) diff --git a/USB Test App WPF/MainWindow.xaml.cs b/USB Test App WPF/MainWindow.xaml.cs index 24f98374..cbd711f5 100644 --- a/USB Test App WPF/MainWindow.xaml.cs +++ b/USB Test App WPF/MainWindow.xaml.cs @@ -388,17 +388,25 @@ private async void DeployTestButton_Click(object sender, RoutedEventArgs e) var p4Size = 752; assemblies.Add(new byte[p1Size]); - assemblies[0][0] = 0x5; - assemblies[0][1] = 0x5; + assemblies[0][0] = 0xDE; + assemblies[0][1] = 0xAD; + assemblies[0][2] = 0xBE; + assemblies[0][3] = 0xEF; assemblies.Add(new byte[p2Size]); - assemblies[1][0] = 0x6; - assemblies[1][1] = 0x6; + assemblies[1][0] = 0xDE; + assemblies[1][1] = 0xAD; + assemblies[1][2] = 0xBE; + assemblies[1][3] = 0xEF; assemblies.Add(new byte[p3Size]); - assemblies[2][0] = 0x7; - assemblies[2][1] = 0x7; + assemblies[2][0] = 0xDE; + assemblies[2][1] = 0xAD; + assemblies[2][2] = 0xBE; + assemblies[2][3] = 0xEF; assemblies.Add(new byte[p4Size]); - assemblies[3][0] = 0x8; - assemblies[3][1] = 0x8; + assemblies[3][0] = 0xDE; + assemblies[3][1] = 0xAD; + assemblies[3][0] = 0xBE; + assemblies[3][1] = 0xEF; var totalSize = p1Size + p2Size + p3Size + p4Size; @@ -424,105 +432,26 @@ private async void DeployTestButton_Click(object sender, RoutedEventArgs e) /////////////////////////////////////////////////////////////// // process replicated from VS deploy provider + /////////////////////////////////////////////////////////////// - // device needs to be in 'initialized state' for a successful and correct deployment - // meaning that is not running nor stopped - bool deviceIsInInitializeState = false; - - - // erase the target deployment area to ensure a clean deployment and execution start - if (await device.EraseAsync(EraseOptions.Deployment, CancellationToken.None)) - { - //MessageCentre.InternalErrorMessage("Erase deployment area successful."); - - // initial check - if (device.DebugEngine.IsDeviceInInitializeState()) - { - //MessageCentre.InternalErrorMessage("Device status verified as being in initialized state. Requesting to resume execution."); - - // set flag - deviceIsInInitializeState = true; - - // device is still in initialization state, try resume execution - device.DebugEngine.ResumeExecution(); - } - - // handle the workflow required to try resuming the execution on the device - // only required if device is not already there - // retry 5 times with a 500ms interval between retries - while (retryCount++ < _numberOfRetries && deviceIsInInitializeState) - { - if (!device.DebugEngine.IsDeviceInInitializeState()) - { - //MessageCentre.InternalErrorMessage("Device has completed initialization."); - - // done here - deviceIsInInitializeState = false; - break; - } - - //MessageCentre.InternalErrorMessage($"Waiting for device to report initialization completed ({retryCount}/{_numberOfRetries})."); - - // provide feedback to user on the 1st pass - if (retryCount == 0) - { - //await outputPaneWriter.WriteLineAsync(ResourceStrings.WaitingDeviceInitialization); - } - - if (device.DebugEngine.ConnectionSource == ConnectionSource.nanoBooter) - { - //MessageCentre.InternalErrorMessage("Device reported running nanoBooter. Requesting to load nanoCLR."); - - // request nanoBooter to load CLR - device.DebugEngine.ExecuteMemory(0); - } - else if (device.DebugEngine.ConnectionSource == ConnectionSource.nanoCLR) - { - //MessageCentre.InternalErrorMessage("Device reported running nanoCLR. Requesting to reboot nanoCLR."); - - await Task.Run(delegate - { - // already running nanoCLR try rebooting the CLR - device.DebugEngine.RebootDevice(RebootOptions.ClrOnly); - }); - } - - // wait before next pass - // use a back-off strategy of increasing the wait time to accommodate slower or less responsive targets (such as networked ones) - await Task.Delay(TimeSpan.FromMilliseconds(_timeoutMiliseconds * (retryCount + 1))); - - await Task.Yield(); - } - } - - // check if device is still in initialized state - if (!deviceIsInInitializeState) - { - /////////////////////////////////////////////////////////////// - - var largePackets = totalSize / (debugEngine.WireProtocolPacketSize - 8); + var largePackets = totalSize / (debugEngine.WireProtocolPacketSize - 8); - var packetSize = debugEngine.WireProtocolPacketSize == 1024 ? "1k" : $"({ debugEngine.WireProtocolPacketSize / 1024}bytes"; + var packetSize = debugEngine.WireProtocolPacketSize == 1024 ? "1k" : $"({ debugEngine.WireProtocolPacketSize / 1024}bytes"; - Debug.WriteLine($">>> Sending : {totalSize} bytes.<<<<"); - Debug.WriteLine($">>> This is {packetSize} packets plus something bytes.<<<<"); + Debug.WriteLine($">>> Sending : {totalSize} bytes.<<<<"); + Debug.WriteLine($">>> This is {packetSize} packets plus something bytes.<<<<"); - var result = (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].DebugEngine.DeploymentExecute(assemblies, true); + var result = (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].DebugEngine.DeploymentExecute(assemblies, true); - Debug.WriteLine($">>> Deployment result: {result} <<<<"); + Debug.WriteLine($">>> Deployment result: {result} <<<<"); - if (result) - { - //(DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].DebugEngine.RebootDevice(RebootOptions.ClrOnly); + if (result) + { + //(DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].DebugEngine.RebootDevice(RebootOptions.ClrOnly); - //Task.Delay(1000).Wait(); + //Task.Delay(1000).Wait(); - (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].GetDeviceInfo(true); - } - } - else - { - Debug.WriteLine($">>> Failed to initialize device. <<<<"); + (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].GetDeviceInfo(true); } })); @@ -1043,10 +972,10 @@ private async void ReadTestButton_Click(object sender, RoutedEventArgs e) var flashStartAddress = memoryMap.First(m => (m.m_flags & Commands.Monitor_MemoryMap.c_FLASH) == Commands.Monitor_MemoryMap.c_FLASH).m_address; // bootloader - if (flashSectorMap.Exists(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP)) + if (flashSectorMap.Exists(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP)) { - var startAddress = flashSectorMap.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).m_StartAddress; - var length = (uint)flashSectorMap.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock); + var startAddress = flashSectorMap.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).StartAddress; + var length = (uint)flashSectorMap.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).Sum(obj => obj.NumBlocks * obj.BytesPerBlock); var bootloaderOperation = device.DebugEngine.ReadMemory(startAddress, length); if(bootloaderOperation.Success) @@ -1064,10 +993,10 @@ private async void ReadTestButton_Click(object sender, RoutedEventArgs e) //var configSector = flashSectorMap.Where(s => ((s.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG)).Select(s => s.ToDeploymentSector()).ToList(); // CLR - if (flashSectorMap.Exists(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE)) + if (flashSectorMap.Exists(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE)) { - var startAddress = flashSectorMap.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).m_StartAddress; - var length = (uint)flashSectorMap.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock); + var startAddress = flashSectorMap.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).StartAddress; + var length = (uint)flashSectorMap.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).Sum(obj => obj.NumBlocks * obj.BytesPerBlock); var clrOperation = device.DebugEngine.ReadMemory(startAddress, length); if (clrOperation.Success) diff --git a/nanoFramework.Tools.DebugLibrary.Shared/Extensions/FlashSectorDataExtensions.cs b/nanoFramework.Tools.DebugLibrary.Shared/Extensions/FlashSectorDataExtensions.cs index 0dc2cc07..3220fd4b 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/Extensions/FlashSectorDataExtensions.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/Extensions/FlashSectorDataExtensions.cs @@ -22,9 +22,23 @@ public static DeploymentSector ToDeploymentSector(this FlashSectorData value) List blocks = new List(); - for (int i = 0; i < value.m_NumBlocks; i++) + for (int i = 0; i < value.NumBlocks; i++) { - blocks.Add(new DeploymentBlock((int)value.m_StartAddress + (i * (int)value.m_BytesPerBlock), (int)value.m_BytesPerBlock)); + int programmingAlignment = 0; + + // check alignment requirements + if ((value.Flags + & BlockRegionAttributes_MASK + & BlockRegionAttribute_ProgramWidthIs64bits) == BlockRegionAttribute_ProgramWidthIs64bits) + { + // programming width is 64bits => 8 bytes + programmingAlignment = 8; + } + + blocks.Add(new DeploymentBlock( + (int)value.StartAddress + (i * (int)value.BytesPerBlock), + (int)value.BytesPerBlock, + programmingAlignment)); } return new DeploymentSector(blocks); diff --git a/nanoFramework.Tools.DebugLibrary.Shared/Extensions/MonitorFlashSectorMapExtensions.cs b/nanoFramework.Tools.DebugLibrary.Shared/Extensions/MonitorFlashSectorMapExtensions.cs index aeb0c48a..d5f5306b 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/Extensions/MonitorFlashSectorMapExtensions.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/Extensions/MonitorFlashSectorMapExtensions.cs @@ -11,7 +11,7 @@ public static class MonitorFlashSectorMapExtensions { public static string UsageAsString(this Commands.Monitor_FlashSectorMap.FlashSectorData value) { - switch (value.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) + switch (value.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) { case Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP: return "nanoBooter"; diff --git a/nanoFramework.Tools.DebugLibrary.Shared/Extensions/OutputExtensions.cs b/nanoFramework.Tools.DebugLibrary.Shared/Extensions/OutputExtensions.cs index 74f6d647..b4f1e09d 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/Extensions/OutputExtensions.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/Extensions/OutputExtensions.cs @@ -82,7 +82,7 @@ public static string ToStringForOutput(this List (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP)) + if (range.Exists(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP)) { output.AppendLine( - $" {string.Format(" 0x{0:X08}", range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).m_StartAddress)}" + - $" {string.Format(" 0x{0:X06}", range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock))}" + - $" {range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock).ToMemorySizeFormart()}" + - $" {range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).UsageAsString()}"); + $" {string.Format(" 0x{0:X08}", range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).StartAddress)}" + + $" {string.Format(" 0x{0:X06}", range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).Sum(obj => obj.NumBlocks * obj.BytesPerBlock))}" + + $" {range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).Sum(obj => obj.NumBlocks * obj.BytesPerBlock).ToMemorySizeFormart()}" + + $" {range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP).UsageAsString()}"); } // output config line only if it's available on the target - if (range.Count(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG) > 0) + if (range.Count(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG) > 0) { output.AppendLine( - $" {string.Format(" 0x{0:X08}", range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).m_StartAddress)}" + - $" {string.Format(" 0x{0:X06}", range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock))}" + - $" {range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock).ToMemorySizeFormart()}" + - $" {range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).UsageAsString()}"); + $" {string.Format(" 0x{0:X08}", range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).StartAddress)}" + + $" {string.Format(" 0x{0:X06}", range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).Sum(obj => obj.NumBlocks * obj.BytesPerBlock))}" + + $" {range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).Sum(obj => obj.NumBlocks * obj.BytesPerBlock).ToMemorySizeFormart()}" + + $" {range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG).UsageAsString()}"); } // nanoCLR output.AppendLine( - $" {string.Format(" 0x{0:X08}", range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).m_StartAddress)}" + - $" {string.Format(" 0x{0:X06}", range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock))}" + - $" {range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock).ToMemorySizeFormart()}" + - $" {range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).UsageAsString()}"); + $" {string.Format(" 0x{0:X08}", range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).StartAddress)}" + + $" {string.Format(" 0x{0:X06}", range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).Sum(obj => obj.NumBlocks * obj.BytesPerBlock))}" + + $" {range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).Sum(obj => obj.NumBlocks * obj.BytesPerBlock).ToMemorySizeFormart()}" + + $" {range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE).UsageAsString()}"); // deployment output.AppendLine( - $" {string.Format(" 0x{0:X08}", range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).m_StartAddress)}" + - $" {string.Format(" 0x{0:X06}", range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock))}" + - $" {range.Where(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).Sum(obj => obj.m_NumBlocks * obj.m_BytesPerBlock).ToMemorySizeFormart()}" + - $" {range.First(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).UsageAsString()}"); + $" {string.Format(" 0x{0:X08}", range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).StartAddress)}" + + $" {string.Format(" 0x{0:X06}", range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).Sum(obj => obj.NumBlocks * obj.BytesPerBlock))}" + + $" {range.Where(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).Sum(obj => obj.NumBlocks * obj.BytesPerBlock).ToMemorySizeFormart()}" + + $" {range.First(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT).UsageAsString()}"); return output.ToString(); } diff --git a/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs b/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs index 264fa214..0ee875f9 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs @@ -250,8 +250,8 @@ public int GetDeploymentStartAddress() { return (int)DebugEngine.FlashSectorMap.FirstOrDefault(s => { - return (s.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; - }).m_StartAddress; + return (s.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; + }).StartAddress; } return -1; @@ -267,8 +267,8 @@ public int GetClrStartAddress() { return (int)DebugEngine.FlashSectorMap.FirstOrDefault(s => { - return (s.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE; - }).m_StartAddress; + return (s.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE; + }).StartAddress; } return -1; @@ -426,7 +426,7 @@ public async Task EraseAsync(EraseOptions options, CancellationToken cance return false; } - switch (flashSectorData.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) + switch (flashSectorData.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) { case Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT: if (EraseOptions.Deployment == (options & EraseOptions.Deployment)) @@ -491,15 +491,15 @@ public async Task EraseAsync(EraseOptions options, CancellationToken cance foreach (Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData in eraseSectors) { - for (int block = 0; block < flashSectorData.m_NumBlocks; block++) + for (int block = 0; block < flashSectorData.NumBlocks; block++) { - progress?.Report($"Erasing sector @ 0x{flashSectorData.m_StartAddress:X8}..."); + progress?.Report($"Erasing sector @ 0x{flashSectorData.StartAddress:X8}..."); - var sectorAddress = (uint)(flashSectorData.m_StartAddress + block * flashSectorData.m_BytesPerBlock); + var sectorAddress = (uint)(flashSectorData.StartAddress + block * flashSectorData.BytesPerBlock); (AccessMemoryErrorCodes ErrorCode, bool Success) = DebugEngine.EraseMemory( sectorAddress, - flashSectorData.m_BytesPerBlock); + flashSectorData.BytesPerBlock); if (!Success) { @@ -596,6 +596,7 @@ public async Task DeployBinaryFileAsync( if(!DeployFile( data, address, + 0, progress)) { return false; @@ -674,6 +675,7 @@ private async Task DeploySrecFileAsync( if (!DeployFile( data, addr, + 0, progress)) { return false; @@ -687,11 +689,13 @@ private async Task DeploySrecFileAsync( private bool DeployFile( byte[] buffer, uint address, + int programAligment = 0, IProgress progress = null) { (AccessMemoryErrorCodes ErrorCode, bool Success) = DebugEngine.WriteMemory( address, buffer, + programAligment, progress); if (!Success) @@ -1383,23 +1387,23 @@ private async Task PrepareForDeployAsync( { foreach (SRecordFile.Block bl in blocks) { - var startSector = flashSectorsMap.Find(s => s.m_StartAddress == bl.address); - if (startSector.m_NumBlocks > 0) + var startSector = flashSectorsMap.Find(s => s.StartAddress == bl.address); + if (startSector.NumBlocks > 0) { - updatesDeployment ^= (startSector.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; - 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; + updatesDeployment ^= (startSector.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; + updatesClr ^= (startSector.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE; + updatesBooter ^= (startSector.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP; } } } else { - var startSector = flashSectorsMap.Find(s => s.m_StartAddress == address); - if (startSector.m_NumBlocks > 0) + var startSector = flashSectorsMap.Find(s => s.StartAddress == address); + if (startSector.NumBlocks > 0) { - updatesDeployment = (startSector.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; - 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; + updatesDeployment = (startSector.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; + updatesClr = (startSector.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE; + updatesBooter = (startSector.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP; } } diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Commands.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Commands.cs index 9f653360..a778ff1e 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Commands.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Commands.cs @@ -94,12 +94,19 @@ public class Monitor_FlashSectorMap public const uint c_MEMORY_USAGE_STORAGE_B = 0x000000F0; public const uint c_MEMORY_USAGE_MASK = 0x000000F0; + // media attributes + public const uint BlockRegionAttributes_MASK = 0x0000FF00; + + public const uint BlockRegionAttribute_MemoryMapped = 0x0100; + // programming width is 64bits + public const uint BlockRegionAttribute_ProgramWidthIs64bits = 0x0200; + public struct FlashSectorData { - public uint m_StartAddress; - public uint m_NumBlocks; - public uint m_BytesPerBlock; - public uint m_flags; + public uint StartAddress; + public uint NumBlocks; + public uint BytesPerBlock; + public uint Flags; } public class Reply : IConverter diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/DeploymentBlock.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/DeploymentBlock.cs index ed82bf42..dfb6a91e 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/DeploymentBlock.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/DeploymentBlock.cs @@ -37,18 +37,25 @@ public int AvailableSpace } } + /// + /// Required aliment of programming word. + /// + public int ProgramAligment { get; } = 0; + /// /// Creates a new starting at with size. /// /// Start address of the block. /// Size of the block. - public DeploymentBlock(int startAddress, int size) + /// Alignment size for programming. + public DeploymentBlock(int startAddress, int size, int programAligment) { - // empty deploymentdata + // empty deployment data _deploymentData = new byte[0]; StartAddress = startAddress; Size = size; + ProgramAligment = programAligment; } internal void AddDeploymentData(byte[] buffer) diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs index 7d76aead..85f6589e 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs @@ -1417,6 +1417,7 @@ public TargetInfo GetMonitorTargetInfo() byte[] buf, int offset, int length, + int programAligment = 0, IProgress progress = null) { int count = length; @@ -1431,6 +1432,11 @@ public TargetInfo GetMonitorTargetInfo() // get packet length, either the maximum allowed size or whatever is still available to TX int packetLength = Math.Min(GetPacketMaxLength(cmd), count); + if(programAligment != 0 && packetLength % programAligment != 0) + { + packetLength -= packetLength % programAligment; + } + cmd.PrepareForSend(address, buf, position, packetLength); DebuggerEventSource.Log.EngineWriteMemory(address, packetLength); @@ -1466,7 +1472,8 @@ public TargetInfo GetMonitorTargetInfo() public (AccessMemoryErrorCodes ErrorCode, bool Success) WriteMemory( uint address, - byte[] buf, + byte[] buf, + int programAligment = 0, IProgress progress = null) { return WriteMemory( @@ -1474,6 +1481,7 @@ public TargetInfo GetMonitorTargetInfo() buf, 0, buf.Length, + programAligment, progress); } @@ -2849,7 +2857,7 @@ private bool DeploymentExecuteIncremental( // build the deployment blob from the flash sector map // apply a filter so that we take only the blocks flag for deployment - var deploymentBlob = flashSectorMap.Where(s => (s.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT) + var deploymentBlob = flashSectorMap.Where(s => (s.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT) .Select(s => s.ToDeploymentSector()) .ToList(); @@ -2945,7 +2953,7 @@ private bool DeploymentExecuteIncremental( } // block erased, write buffer - memoryOperationResult = WriteMemory((uint)block.StartAddress, block.DeploymentData); + memoryOperationResult = WriteMemory((uint)block.StartAddress, block.DeploymentData, block.ProgramAligment); if (!memoryOperationResult.Success) { progress?.Report($"Error writing to device memory @ 0x{block.StartAddress:X8} ({block.DeploymentData.Length} bytes)."); @@ -3803,18 +3811,18 @@ public bool UpdateDeviceConfiguration(DeviceConfiguration configuration) } // get configuration sector details - configSector = FlashSectorMap.FirstOrDefault(item => (item.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG); + configSector = FlashSectorMap.FirstOrDefault(item => (item.Flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG); // check if the device has a config sector - if (configSector.m_NumBlocks > 0) + if (configSector.NumBlocks > 0) { // store the current configuration in case we need to revert this for some reason - var readConfigSector = ReadMemory(configSector.m_StartAddress, configSector.m_NumBlocks * configSector.m_BytesPerBlock); + var readConfigSector = ReadMemory(configSector.StartAddress, configSector.NumBlocks * configSector.BytesPerBlock); if (readConfigSector.Success) { // start erasing the sector that holds the configuration block - var (ErrorCode, Success) = EraseMemory(configSector.m_StartAddress, 1); + var (ErrorCode, Success) = EraseMemory(configSector.StartAddress, 1); if (Success) { okToUploadConfig = true; diff --git a/version.json b/version.json index 9f00f1be..df9f6505 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.26.5-preview.{height}", + "version": "1.27.0-preview.{height}", "assemblyVersion": { "precision": "revision" },