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 Monitor_TargetInfo command #263

Merged
merged 1 commit into from
Nov 23, 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
2 changes: 1 addition & 1 deletion USB Test App WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Button Content="Set Device Config" HorizontalAlignment="Left" Margin="378,313,0,0" VerticalAlignment="Top" Width="121" Click="SetDeviceConfigButton_Click" />
<Button Content="ReScan devices" HorizontalAlignment="Left" Margin="250,157,0,0" VerticalAlignment="Top" Width="98" Click="ReScanDevices_Click" />
<Button Content="Read Test" HorizontalAlignment="Left" Margin="250,313,0,0" VerticalAlignment="Top" Width="98" Click="ReadTestButton_Click" />
<Button Content="OEM Info" HorizontalAlignment="Left" Margin="39,313,0,0" VerticalAlignment="Top" Width="110" Click="OemInfoButton_Click" />
<Button Content="Target Info" HorizontalAlignment="Left" Margin="39,313,0,0" VerticalAlignment="Top" Width="110" Click="TargetInfoButton_Click" />
<Button Content="Reboot to nanoBooter" HorizontalAlignment="Left" Margin="378,157,0,0" VerticalAlignment="Top" Width="121" Click="RebootToNanoBooterButton_Click"/>
<Button Content="Deploy File" HorizontalAlignment="Left" Margin="162,313,0,0" VerticalAlignment="Top" Width="75" Click="DeployFileTestButton_Click" />

Expand Down
10 changes: 4 additions & 6 deletions USB Test App WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ private async void ConnectDeviceButton_ClickAsync(object sender, RoutedEventArgs

var di = (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].GetDeviceInfo();

var clrAddress = (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex].ClrStartAddress;

Debug.WriteLine("");
Debug.WriteLine("");
Debug.WriteLine(di.ToString());
Expand Down Expand Up @@ -1105,7 +1103,7 @@ private async void ReadTestButton_Click(object sender, RoutedEventArgs e)
(sender as Button).IsEnabled = true;
}

private async void OemInfoButton_Click(object sender, RoutedEventArgs e)
private async void TargetInfoButton_Click(object sender, RoutedEventArgs e)
{
// disable button
(sender as Button).IsEnabled = false;
Expand All @@ -1116,13 +1114,13 @@ private async void OemInfoButton_Click(object sender, RoutedEventArgs e)
var device = (DataContext as MainViewModel).AvailableDevices[DeviceGrid.SelectedIndex];


var oemInfo = device.DebugEngine.GetMonitorOemInfo();
var targetInfo = device.DebugEngine.GetMonitorTargetInfo();

if (oemInfo != null)
if (targetInfo != null)
{
Debug.WriteLine("");
Debug.WriteLine("");
Debug.WriteLine($"{oemInfo.ToString()}");
Debug.WriteLine($"{targetInfo.ToString()}");
Debug.WriteLine("");
Debug.WriteLine("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,26 @@ public override string ToString()
output.AppendLine($" Platform: {Platform?.ToString()}");
output.AppendLine();
output.AppendLine($"Firmware build Info:");
output.AppendLine($" Date: {ImageBuildDate ?? "unknown"}");
output.AppendLine($" Type: {VendorInfo ?? "unknown"}");
output.AppendLine($" Version: {SolutionBuildVersion}");
output.AppendLine($" Compiler: {ImageCompilerInfo ?? "unknown"} v{ImageCompilerVersion?.ToString()}");
output.AppendLine($" Date: {ImageBuildDate ?? "unknown"}");
output.AppendLine($" Type: {VendorInfo ?? "unknown"}");
output.AppendLine($" CLR Version: {SolutionBuildVersion}");
output.AppendLine($" Compiler: {ImageCompilerInfo ?? "unknown"} v{ImageCompilerVersion?.ToString()}");
output.AppendLine();
output.AppendLine($"OEM Product codes (vendor, model, SKU): {OEM.ToString()}, {Model.ToString()}, {SKU.ToString()}");
output.AppendLine();
output.AppendLine("Serial Numbers (module, system):");
output.AppendLine(" " + ModuleSerialNumber);
output.AppendLine(" " + SystemSerialNumber);
output.AppendLine();
output.AppendLine("Target capabilities:");
output.AppendLine(" Has nanoBooter: " + (Dbg.HasNanoBooter? "YES" : "NO"));
if (Dbg.TargetInfo != null &&
Dbg.HasNanoBooter)
{
output.AppendLine($" nanoBooter: v{Dbg.TargetInfo.BooterVersion}");
}
output.AppendLine(" IFU capable: " + (Dbg.IsIFUCapable ? "YES" : "NO"));
output.AppendLine(" Has proprietary bootloader: " + (Dbg.HasProprietaryBooter ? "YES" : "NO"));

output.AppendLine();
output.AppendLine("AppDomains:");
Expand Down
215 changes: 131 additions & 84 deletions nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,78 +66,76 @@ public void CreateDebugEngine()
public string SerialNumber { get; internal set; }

/// <summary>
/// Detailed info about the NanoFramework device hardware, solution and CLR.
/// </summary>
public INanoFrameworkDeviceInfo DeviceInfo { get; internal set; }

/// <summary>
/// This indicates if the device has a proprietary bootloader.
/// Version of nanoBooter.
/// </summary>
public bool HasProprietaryBooter
public Version BooterVersion
{
get
{
return DebugEngine != null && DebugEngine.HasProprietaryBooter;
try
{
return DebugEngine?.TargetInfo?.BooterVersion;
}
catch
{
return new Version();
}
}
}

/// <summary>
/// This indicates if the target device has nanoBooter.
/// Version of nanoCLR.
/// </summary>
public bool HasNanoBooter
public Version ClrVersion
{
get
{
return DebugEngine != null && DebugEngine.HasNanoBooter;
try
{
return DebugEngine?.TargetInfo?.ClrVersion;
}
catch
{
return new Version();
}
}
}

/// <summary>
/// This indicates if the target device is IFU capable.
/// Detailed info about the NanoFramework device hardware, solution and CLR.
/// </summary>
public bool IsIFUCapable
public INanoFrameworkDeviceInfo DeviceInfo { get; internal set; }

/// <summary>
/// This indicates if the device has a proprietary bootloader.
/// </summary>
public bool HasProprietaryBooter
{
get
{
return DebugEngine != null && DebugEngine.IsIFUCapable;
return DebugEngine != null && DebugEngine.HasProprietaryBooter;
}
}

/// <summary>
/// Start address of the deployment block.
/// This indicates if the target device has nanoBooter.
/// </summary>
public uint DeploymentStartAddress
public bool HasNanoBooter
{
get
{
if(DebugEngine != null)
{
return 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 0;
return DebugEngine != null && DebugEngine.HasNanoBooter;
}
}

/// <summary>
/// Start address of the CLR block.
/// This indicates if the target device is IFU capable.
/// </summary>
public uint ClrStartAddress
public bool IsIFUCapable
{
get
{
if (DebugEngine != null)
{
return 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 0;
return DebugEngine != null && DebugEngine.IsIFUCapable;
}
}

Expand Down Expand Up @@ -230,6 +228,40 @@ public PingConnectionType Ping()
return PingConnectionType.NoConnection;
}

/// <summary>
/// Start address of the deployment block.
/// Returns (-1) as invalid value if the address can't be retrieved from the device properties.
/// </summary>
public int GetDeploymentStartAddress()
{
if (DebugEngine != null)
{
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 -1;
}

/// <summary>
/// Start address of the CLR block.
/// Returns (-1) as invalid value if the address can't be retrieved from the device properties.
/// </summary>
public int GetClrStartAddress()
{
if (DebugEngine != null)
{
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 -1;
}

/// <summary>
/// Attempt to establish a connection with nanoBooter (with reboot if necessary)
/// </summary>
Expand All @@ -244,62 +276,70 @@ public async Task<bool> ConnectToNanoBooterAsync(CancellationToken cancellationT
{
if (DebugEngine.ConnectionSource == ConnectionSource.nanoBooter) return true;

DebugEngine.RebootDevice(RebootOptions.EnterNanoBooter);

/////////////////////////////////////////
// FIXME
/////////////////////////////////////////
//// nanoBooter is only com port so
//if (Transport == TransportType.TcpIp)
//{
// _DBG.PortDefinition pdTmp = m_port;

// Disconnect();

// try
// {
// m_port = m_portNanoBooter;

// // digi takes forever to reset
// if (!Connect(60000, true))
// {
// Console.WriteLine(Properties.Resources.ErrorUnableToConnectToNanoBooterSerial);
// return false;
// }
// }
// finally
// {
// m_port = pdTmp;
// }
//}

bool fConnected = false;

for (int i = 0; i < 40; i++)
try
{
// check if cancellation was requested
if (cancellationToken.IsCancellationRequested) return false;

if(DebugEngine == null)
DebugEngine.RebootDevice(RebootOptions.EnterNanoBooter);

/////////////////////////////////////////
// FIXME
/////////////////////////////////////////
//// nanoBooter is only com port so
//if (Transport == TransportType.TcpIp)
//{
// _DBG.PortDefinition pdTmp = m_port;

// Disconnect();

// try
// {
// m_port = m_portNanoBooter;

// // digi takes forever to reset
// if (!Connect(60000, true))
// {
// Console.WriteLine(Properties.Resources.ErrorUnableToConnectToNanoBooterSerial);
// return false;
// }
// }
// finally
// {
// m_port = pdTmp;
// }
//}

bool fConnected = false;

for (int i = 0; i < 40; i++)
{
CreateDebugEngine();
}
// check if cancellation was requested
if (cancellationToken.IsCancellationRequested) return false;

if (fConnected = await DebugEngine.ConnectAsync(1000, true, ConnectionSource.Unknown))
{
Commands.Monitor_Ping.Reply reply = DebugEngine.GetConnectionSource();
if (DebugEngine == null)
{
CreateDebugEngine();
}

ret = (reply.Source == Commands.Monitor_Ping.c_Ping_Source_NanoBooter);
if (fConnected = await DebugEngine.ConnectAsync(1000, true, ConnectionSource.Unknown))
{
Commands.Monitor_Ping.Reply reply = DebugEngine.GetConnectionSource();

break;
ret = (reply.Source == Commands.Monitor_Ping.c_Ping_Source_NanoBooter);

break;
}
}
}

if (!fConnected)
if (!fConnected)
{
//Debug.WriteLine("Unable to connect to NanoBooter");
}
}
catch
{
//Debug.WriteLine("Unable to connect to NanoBooter");
// need a catch all here because some targets re-enumerate the USB device and that makes it impossible to catch them here
}
}

return ret;
}

Expand Down Expand Up @@ -1267,11 +1307,18 @@ private async Task<bool> PrepareForDeployAsync(
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.Count == 0 ? DebugEngine.GetFlashSectorMap() : DebugEngine.FlashSectorMap;
List<Commands.Monitor_FlashSectorMap.FlashSectorData> flashSectorsMap = DebugEngine.FlashSectorMap;

// sanity check
if (flashSectorsMap.Count == 0)
if (flashSectorsMap == null ||
flashSectorsMap.Count == 0)
{
return false;
}
Expand Down
Loading