示例#1
0
 public MfTargetDevice(MFPortDefinition port, MFDevice device)
 {
     _port = port;
     _device = device;
     _tc = App.Kernel.Get<TelemetryClient>();
     Task.Run(() => InitializeAsync());
 }
示例#2
0
            public MFDeviceInfoImpl(MFDevice dev)
            {
                m_self = dev;

                if (!Dbg.IsConnectedToTinyCLR)
                {
                    return;
                }

                m_self.DoForEachAppDomain(
                    delegate(IAppDomainInfo adi)
                {
                    m_Domains.Add(adi);
                }
                    );

                m_self.DoForEachAssembly(
                    delegate(MFDevice.IAssemblyInfo ai)
                {
                    m_AssemblyInfos.Add(ai);
                }
                    );

                m_fValid = true;
            }
 public DeploymentStatusDialog(MFDevice dev, params EraseOptions[] eraseBlocks)
     : this(dev, null, null)
 {
     m_fEraseCmd = true;
     m_eraseBlocks = eraseBlocks;
     this.Text = Properties.Resources.DeploymentStatusTitleErase;
 }
        public MFUsbConfigDialog( MFDevice device )
        {
            m_cfgHelper = new MFConfigHelper(device);
            m_cfg = new MFUsbConfiguration(device);

            InitializeComponent();
        }
示例#5
0
		/// <summary>
		/// Connects to the device at the specified port
		/// </summary>
		/// <param name="port"></param>
		public void Connect(MFPortDefinition port)
		{
			this._device = new MFDeploy().Connect(port);
			this._device.OnDebugText += new EventHandler<DebugOutputEventArgs>(Device_OnDebugText);

			this.Connected(this, EventArgs.Empty);
		}
        public DeploymentStatusDialog(MFDevice dev, ReadOnlyCollection<string> files, string[] sig_files)
        {
            m_dev       = dev;
            m_files     = files;
            m_sigFiles  = sig_files;

            InitializeComponent();
        }
示例#7
0
        public MFNetworkConfigDialog(MFDevice device)
        {
            m_cfg = new MFNetworkConfiguration(device);
            m_cfgHelper = new MFConfigHelper(device);
            m_wirelessCfg = new MFWirelessConfiguration(device);

            InitializeComponent();
        }
示例#8
0
 public override void Dispose()
 {
     if (_device != null)
     {
         _device.Dispose();
         _device = null;
     }
 }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (form == null || device == null) return;

                _DBG.Engine engine = device.DbgEngine;

                ReadOnlyCollection<string> files = form.Files;
                if (files.Count == 0) return;

                uint address = uint.MaxValue;

                _DBG.PortBooter fl = new _DBG.PortBooter(engine);
                fl.OnProgress += new _DBG.PortBooter.ProgressEventHandler(OnProgress);
                fl.Start();

                try
                {
                    foreach (string file in files)
                    {
                        if (!File.Exists(file))
                        {
                            form.DumpToOutput(string.Format("Error: File doesn't exist {0}", file));
                            continue;
                        }

                        ArrayList blocks = new ArrayList();

                        uint tmp = _DBG.SRecordFile.Parse(file, blocks, null);

                        m_form = form;

                        fl.Program(blocks);

                        if (address == uint.MaxValue)
                        {
                            if (tmp != 0)
                            {
                                address = tmp;
                            }
                        }
                    }

                    if (address == uint.MaxValue) address = 0;

                    m_form.DumpToOutput(string.Format("Executing address 0x{0:x08}", address));
                    fl.Execute(address);
                    System.Threading.Thread.Sleep(200);
                }
                finally
                {
                    if (fl != null)
                    {
                        fl.OnProgress -= new _DBG.PortBooter.ProgressEventHandler(OnProgress);
                        fl.Stop();
                        fl.Dispose();
                    }
                }
            }
        internal void CreateDeploymentData(BackgroundWorker backgroundWorker, DoWorkEventArgs doWorkEventArgs)
        {
            MFDevice device = doWorkEventArgs.Argument as MFDevice;

            _DBG.Engine eng = device.DbgEngine;

            Commands.Monitor_FlashSectorMap.Reply flashMap = eng.GetFlashSectorMap();

            //find deployment sectors.
            uint addressStart = 0;
            uint cBytes       = 0;

            //First, find out where the deployment sectors are
            for (int iSector = flashMap.m_map.Length - 1; iSector >= 0; iSector--)
            {
                Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData = flashMap.m_map[iSector];
                if ((flashSectorData.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT)
                {
                    addressStart = flashSectorData.m_address;
                    cBytes      += flashSectorData.m_size;
                }
            }

            if (cBytes == 0)
            {
                throw new ApplicationException("Could not find deployment sectorsd");
            }

            byte[] deploymentData = new byte[cBytes];

            //Read deployment data
            if (!CreateDeploymentReadHelper(backgroundWorker, doWorkEventArgs, eng, addressStart, deploymentData))
            {
                return;
            }

            //create deployment stream
            MemoryStream deploymentStream = new MemoryStream();

            deploymentStream.Write(deploymentData, 0, deploymentData.Length);

            //convert to srec
            MFApplicationDeploymentData data = new MFApplicationDeploymentData();
            MemoryStream streamSrec          = new MemoryStream();

            data.BinaryData = deploymentData;
            deploymentStream.Seek(0, SeekOrigin.Begin);
            new BinToSrec().DoConversion(deploymentStream, streamSrec, addressStart);

            //Get bytes
            long pos = streamSrec.Seek(0, SeekOrigin.Current);

            data.HexData = new byte[(int)pos];
            streamSrec.Seek(0, SeekOrigin.Begin);
            streamSrec.Read(data.HexData, 0, (int)pos);

            doWorkEventArgs.Result = data;
        }
示例#11
0
        public MFConfigHelper(MFDevice device)
        {
            m_device = device;

            if (device.DbgEngine.ConnectionSource == Microsoft.SPOT.Debugger.ConnectionSource.TinyBooter)
            {
                m_fRestartClr = false;
            }
        }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (form == null || device == null) return;

                _DBG.Engine engine = device.DbgEngine;

                engine.RebootDevice(Microsoft.SPOT.Debugger.Engine.RebootOption.EnterBootloader);

                device.ConnectToTinyBooter();
            }
示例#13
0
        public MFNetworkConfigurationExtended(MFDevice dev)
        {
            /* load default settings, in case extended settinsg are not available */
            m_cfg.flags                 = c_SOCK_NETWORKCONFIGURATION_FLAGS_IPV4_SUPPORTED; // default setting for backwards compatibility
            this.IPv6IpAddress          = new IPAddress(new byte[16]);
            this.IPv6Gateway            = new IPAddress(new byte[16]);
            this.IPv6SubnetPrefixLength = 0;
            this.IPv6PrimaryDns         = new IPAddress(new byte[16]);
            this.IPv6SecondaryDns       = new IPAddress(new byte[16]);

            m_cfgHelper = new MFConfigHelper(dev);
        }
示例#14
0
        public MFAppDeployConfigDialog(MFDevice device, ConfigDialogCommand command)
        {
            if (device != null)
            {
                m_cfgHelper = new MFConfigHelper(device);
                m_appDeploy = new MFApplicationDeployment(device);
            }
            m_command = command;
            m_device = device;

            InitializeComponent();
        }
示例#15
0
        public MFConfigHelper(MFDevice device)
        {
            m_device = device;

            Microsoft.SPOT.Debugger.ConnectionSource src = device.DbgEngine.ConnectionSource;

            if (src == _DBG.ConnectionSource.Unknown)
            {
                device.Connect(500, true);
            }

            m_fRestartClr = device.DbgEngine.ConnectionSource == Microsoft.SPOT.Debugger.ConnectionSource.TinyCLR;
        }
示例#16
0
        public void UpdateDeviceKey(MFDevice device, PublicKeyUpdateInfo.KeyIndex index, byte[] publicKey, byte[] publicKeySignature)
        {
            MFConfigHelper cfg = new MFConfigHelper(device);

            PublicKeyUpdateInfo pku = new PublicKeyUpdateInfo();

            pku.NewPublicKey          = publicKey;
            pku.NewPublicKeySignature = publicKeySignature;
            pku.PublicKeyIndex        = index;

            cfg.UpdatePublicKey(pku);

            cfg.Dispose();
            cfg = null;
        }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (form == null || device == null) return;

                _DBG.Engine engine = device.DbgEngine;

                _DBG.WireProtocol.Commands.Monitor_DeploymentMap.Reply reply = engine.DeploymentMap();

                if (reply != null)
                {
                    for (int i = 0; i < reply.m_count; i++)
                    {
                        _DBG.WireProtocol.Commands.Monitor_DeploymentMap.DeploymentData dd = reply.m_map[i];

                        form.DumpToOutput("Assembly " + i.ToString());
                        form.DumpToOutput("  Address: " + dd.m_address.ToString());
                        form.DumpToOutput("  Size   : " + dd.m_size.ToString());
                        form.DumpToOutput("  CRC    : " + dd.m_CRC.ToString());
                    }

                    if (reply.m_count == 0)
                    {
                        form.DumpToOutput("No deployed assemblies");
                    }
                }
                else
                {
                    form.DumpToOutput("Command Not Supported by Device");
                }
            }
        public MFConfigHelper(MFDevice device)
        {
            m_device = device;

            Microsoft.SPOT.Debugger.ConnectionSource src = device.DbgEngine.ConnectionSource;

            if(src == _DBG.ConnectionSource.Unknown)
            {
                device.Connect(500, true);
            }

            m_fRestartClr = device.DbgEngine.ConnectionSource == Microsoft.SPOT.Debugger.ConnectionSource.TinyCLR;
        }
 public MFUsbConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }
示例#20
0
            public MFDeviceInfoImpl(MFDevice dev)
            {
                m_self = dev;

                if ( !Dbg.IsConnectedToTinyCLR ) return;

                m_self.DoForEachAppDomain(
                    delegate(IAppDomainInfo adi)
                    {
                        m_Domains.Add(adi);
                    }
                );
               
                m_self.DoForEachAssembly(
                    delegate(MFDevice.IAssemblyInfo ai) 
                    {
                        m_AssemblyInfos.Add(ai);
                    }
                );                
                
                m_fValid = true;
            }
 public MFApplicationDeployment(MFDevice device)
 {
     m_device = device;
 }
 public MFApplicationDeployment(MFDevice device)
 {
     m_device = device;
 }
 public override void OnAction(IMFDeployForm form, MFDevice device)
 {
     device.Reboot(false);
 }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.DefaultExt = "*.key";
                sfd.CheckPathExists = true;
                sfd.Filter = "Key File (*.key)|*.key|All Files (*.*)|*.*";
                sfd.FilterIndex = 0;
                sfd.AddExtension = true;
                sfd.OverwritePrompt = true;
                sfd.Title = "Create Empty Key";

                if (System.Windows.Forms.DialogResult.OK == sfd.ShowDialog())
                {
                    MFKeyConfig cfg = new MFKeyConfig();
                    KeyPair emptyKey = cfg.CreateEmptyKeyPair();
                    cfg.SaveKeyPair(emptyKey, sfd.FileName);
                }
            }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (device == null || form == null) return;

                _DBG.Engine engine = device.DbgEngine;

                _DBG.WireProtocol.Commands.Monitor_MemoryMap.Range[] range = engine.MemoryMap();

                if (range != null && range.Length > 0)
                {
                    form.DumpToOutput("Type     Start       Size");
                    form.DumpToOutput("--------------------------------");
                    for (int i = 0; i < range.Length; i++)
                    {
                        string mem = "";
                        switch (range[i].m_flags)
                        {
                            case _DBG.WireProtocol.Commands.Monitor_MemoryMap.c_FLASH:
                                mem = "FLASH";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_MemoryMap.c_RAM:
                                mem = "RAM";
                                break;
                        }
                        form.DumpToOutput(string.Format("{0,-6} 0x{1:x08}  0x{2:x08}", mem, range[i].m_address, range[i].m_length));
                    }
                }
            }
示例#26
0
 public void UpdateDeviceKey(MFDevice device, PublicKeyUpdateInfo.KeyIndex index, byte[] publicKey)
 {
     UpdateDeviceKey(device, index, publicKey, null);
 }
示例#27
0
        private MFDevice InitializePorts(MFPortDefinition portDefinitionMain, MFPortDefinition portDefinitionTinyBooter)
        {
            MFDevice device = null;
            MFPortDefinition[] portDefs = new MFPortDefinition[2] { portDefinitionMain, portDefinitionTinyBooter };
            _DBG.PortDefinition[] pds = new Microsoft.SPOT.Debugger.PortDefinition[2];

            for (int i = 0;i < portDefs.Length;i++)
            {
                MFPortDefinition portDefinition = portDefs[i];
                if (portDefinition == null) continue;

                if (portDefinition.Transport == TransportType.TCPIP)
                {
                    System.Net.IPAddress[] addr = System.Net.Dns.GetHostAddresses(portDefinition.Port);

                    pds[i] = new Microsoft.SPOT.Debugger.PortDefinition_Tcp(addr[0]);
                }
                else
                {
                    ArrayList list = _DBG.PortDefinition.Enumerate(_DBG.PortFilter.Usb, _DBG.PortFilter.Serial);
                    foreach (_DBG.PortDefinition pd in list)
                    {
                        if (portDefinition.Port.Length > 0)
                        {
                            if (string.Equals(portDefinition.Port, pd.UniqueId.ToString()))
                            {
                                pds[i] = pd;
                                break;
                            }
                        }
                        if (string.Equals(portDefinition.Name, pd.DisplayName))
                        {
                            pds[i] = pd;
                            break;
                        }
                    }
                }
            }

            if (pds[0] == null && pds[1] != null)
            {
                pds[0] = pds[1];
                pds[1] = null;
            }

            if (pds[0] != null || pds[1] != null)
            {
                device = new MFDevice(pds[0], pds[1]);

                if (!device.Connect(2000, m_tryConnect))
                {
                    throw new MFDeviceNoResponseException();
                }
            }
            else
            {
                throw new MFDeviceUnknownDeviceException();
            }

            return device;
        }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (form == null || device == null) return;

                _DBG.Engine engine = device.DbgEngine;

                _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply reply = engine.GetFlashSectorMap();

                if (reply != null)
                {
                    form.DumpToOutput(" Sector    Start       Size        Usage");
                    form.DumpToOutput("-----------------------------------------------");
                    for (int i = 0; i < reply.m_map.Length; i++)
                    {
                        _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.FlashSectorData fsd = reply.m_map[i];

                        string usage = "";
                        switch (fsd.m_flags & _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK)
                        {
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_APPLICATION:
                                usage = "Application";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_BOOTSTRAP:
                                usage = "Bootstrap";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE:
                                usage = "Code";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG:
                                usage = "Configuration";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT:
                                usage = "Deployment";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_JITTER:
                                usage = "Jitter";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_FS:
                                usage = "File System";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_RESERVED:
                                usage = "Reserved";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_STORAGE_A:
                                usage = "Storage (A)";
                                break;
                            case _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_STORAGE_B:
                                usage = "Storage (B)";
                                break;
                        }

                        form.DumpToOutput(string.Format("{0,5}  {1,12}{2,12}   {3}", i, string.Format("0x{0:x08}", fsd.m_address), string.Format("0x{0:x08}", fsd.m_size), usage));
                    }
                }
            }
 public DeploymentStatusDialog(MFDevice dev, ReadOnlyCollection<string> files, string[] sig_files)
     : this(dev, files, sig_files, "")
 {
 }
示例#30
0
        private void Form1_FormClosing(System.Object sender, FormClosingEventArgs e)
        {
            m_fShuttingDown = true;

            if (m_pluginThread != null && m_pluginThread.IsAlive)
            {
                m_pluginThread.Abort();
            }

            if (m_device != null)
            {
                m_device.Dispose();
                m_device = null;
            }

            if (m_deploy != null)
            {
                m_deploy.Dispose();
                m_deploy = null;
            }
        }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                _DBG.Engine engine = device.DbgEngine;

                if (device.ConnectToTinyBooter())
                {
                    // ExecuteMemory at address 0 performs an enumerate and execute, which
                    // will clear the bootloader entry flag
                    engine.ExecuteMemory(0);
                }
                else
                {
                    form.DumpToOutput("Unable to connect to TinyBooter!");
                }
            }
 public MFWirelessConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                if (device.ConnectToTinyBooter())
                {
                    _WP.Commands.Monitor_FlashSectorMap.Reply reply = device.DbgEngine.GetFlashSectorMap();

                    if (reply != null)
                    {
                        foreach (_WP.Commands.Monitor_FlashSectorMap.FlashSectorData sector in reply.m_map)
                        {
                            if (0 != (sector.m_flags & _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CODE) ||
                                0 != (sector.m_flags & _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_CONFIG))
                            {
                                device.DbgEngine.EraseMemory(sector.m_address, sector.m_size);
                            }
                        }
                    }
                }
            }
 public DeploymentStatusDialog(MFDevice dev) : this( dev, null, null)
 {
     m_fEraseCmd = true;
     this.Text = Properties.Resources.DeploymentStatusTitleErase;
 }
            public override void OnAction(IMFDeployForm form, MFDevice device)
            {
                MFDevice.IMFDeviceInfo info = device.MFDeviceInfo;
                
                if ( !info.Valid )
                {
                    form.DumpToOutput("DeviceInfo is not valid!");
                }
                else
                {
                    form.DumpToOutput("DeviceInfo:");
                    form.DumpToOutput(String.Format("  HAL build info: {0}, {1}", info.HalBuildVersion.ToString(), info.HalBuildInfo));
                    form.DumpToOutput(String.Format("  OEM Product codes (vendor, model, SKU): {0}, {1}, {2}", info.OEM.ToString(), info.Model.ToString(), info.SKU.ToString()));
                    form.DumpToOutput("  Serial Numbers (module, system):");
                    form.DumpToOutput("    " + info.ModuleSerialNumber);
                    form.DumpToOutput("    " + info.SystemSerialNumber);
                    form.DumpToOutput(String.Format("  Solution Build Info: {0}, {1}", info.SolutionBuildVersion.ToString(), info.SolutionBuildInfo));
                    
                    form.DumpToOutput("  AppDomains:");
                    foreach (MFDevice.IAppDomainInfo adi in info.AppDomains)
                    {
                    form.DumpToOutput(String.Format("    {0}, id={1}", adi.Name, adi.ID));
                    }

                    form.DumpToOutput("  Assemblies:");
                    foreach (MFDevice.IAssemblyInfo ai in info.Assemblies)
                    {
                    form.DumpToOutput(String.Format("    {0},{1}", ai.Name, ai.Version));
                    }
                }
            }
示例#36
0
 public virtual void    OnAction(IMFDeployForm form, MFDevice device) { }
示例#37
0
 public MFSslKeyConfig(MFDevice dev)
 {
     m_dev = dev;
 }
示例#38
0
        public MFConfigHelper(MFDevice device)
        {
            m_device = device;

            if (device.DbgEngine.ConnectionSource == Microsoft.SPOT.Debugger.ConnectionSource.TinyBooter)
            {
                m_fRestartClr = false;
            }
        }
        public MFNetworkConfiguration(MFDevice dev)
        {
            m_cfg.networkInterfaceType = c_SOCK_NETWORKCONFIGURATION_INTERFACETYPE_ETHERNET;

            m_cfgHelper = new MFConfigHelper(dev);
        }
        internal void CreateDeploymentData(BackgroundWorker backgroundWorker, DoWorkEventArgs doWorkEventArgs)
        {
            MFDevice device = doWorkEventArgs.Argument as MFDevice;

            _DBG.Engine eng = device.DbgEngine;

            Commands.Monitor_FlashSectorMap.Reply flashMap = eng.GetFlashSectorMap();

            //find deployment sectors.
            MemoryStream deploymentStream = new MemoryStream();

            //this duplicates LoadDeploymentAssemblies logic, as how to find assemblies in the deployment sectors
            int  iSectorStart = -1, iSectorEnd = 0;
            uint address, addressAssemblyStart, addressStart = 0, addressEnd = 0;
            int  iSector;

            //First, find out where the deployment sectors are
            for (iSector = 0; iSector < flashMap.m_map.Length; iSector++)
            {
                Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData = flashMap.m_map[iSector];
                if ((flashSectorData.m_flags & Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) == Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT)
                {
                    if (iSectorStart < 0)
                    {
                        iSectorStart = iSector;
                        addressStart = flashSectorData.m_address;
                    }

                    iSectorEnd = iSector;
                    addressEnd = flashSectorData.m_address + flashSectorData.m_size;
                }
            }

            if (iSectorStart < 0)
            {
                throw new ApplicationException("Could not find deployment sectors");
            }

            address = addressStart;
            iSector = iSectorStart;

            while (true)
            {
                if (backgroundWorker.WorkerReportsProgress)
                {
                    int progress = (int)(100.0 * (double)address / (double)addressEnd);
                    backgroundWorker.ReportProgress(progress);
                }

                //read assembly header
                uint   assemblyHeaderSize  = (uint)Marshal.SizeOf(typeof(CLR_RECORD_ASSEMBLY));
                byte[] assemblyHeaderBytes = null;
                byte[] assemblyDataBytes   = null;

                if (address + assemblyHeaderSize >= addressEnd)
                {
                    break;
                }

                addressAssemblyStart = address;

                if (!CreateDeploymentReadHelper(backgroundWorker, doWorkEventArgs, eng, ref address, addressStart, addressEnd, assemblyHeaderSize, out assemblyHeaderBytes))
                {
                    return;
                }

                GCHandle            gch            = GCHandle.Alloc(assemblyHeaderBytes, GCHandleType.Pinned);
                CLR_RECORD_ASSEMBLY assemblyHeader = (CLR_RECORD_ASSEMBLY)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(CLR_RECORD_ASSEMBLY));
                gch.Free();

                //check if valid header
                //check marker
                bool fValidAssembly = assemblyHeader.marker == CLR_RECORD_ASSEMBLY.MARKER_ASSEMBLY_V1;

                if (fValidAssembly)
                {
                    //check header crc
                    uint crcHeader = assemblyHeader.headerCRC;

                    //clear headerCRC
                    int headerCRCOffset = 8;
                    int headerCRCSize   = 4;

                    Array.Clear(assemblyHeaderBytes, headerCRCOffset, headerCRCSize);

                    uint crc = _DBG.CRC.ComputeCRC(assemblyHeaderBytes, 0);

                    //Reset headerCRC
                    Array.Copy(BitConverter.GetBytes(crcHeader), 0, assemblyHeaderBytes, headerCRCOffset, headerCRCSize);

                    fValidAssembly = (crcHeader == crc);
                }

                if (fValidAssembly)
                {
                    uint assemblyTotalSize = assemblyHeader.startOfTables[CLR_RECORD_ASSEMBLY.TBL_EndOfAssembly];
                    uint assemblyDataSize  = assemblyTotalSize - assemblyHeaderSize;

                    if (address + assemblyDataSize >= addressEnd)
                    {
                        break;
                    }

                    //read body
                    if (!CreateDeploymentReadHelper(backgroundWorker, doWorkEventArgs, eng, ref address, addressStart, addressEnd, assemblyDataSize, out assemblyDataBytes))
                    {
                        return;
                    }

                    //check if valid body (crc)
                    uint crc = _DBG.CRC.ComputeCRC(assemblyDataBytes, 0);

                    fValidAssembly = (crc == assemblyHeader.assemblyCRC);
                }

                if (fValidAssembly)
                {
                    // add to compact stream
                    deploymentStream.Write(assemblyHeaderBytes, 0, assemblyHeaderBytes.Length);
                    deploymentStream.Write(assemblyDataBytes, 0, assemblyDataBytes.Length);

                    // make sure we are on 4 byte boundary
                    if (0 != (address % sizeof(UInt32)))
                    {
                        byte[] buff = new byte[sizeof(UInt32) - (address % sizeof(UInt32))];
                        deploymentStream.Write(buff, 0, buff.Length);
                        address += sizeof(UInt32) - (address % sizeof(UInt32));
                    }
                }
                else
                {
                    //if no, clear assemblyData, jump to next sector (if in middle of sector), or finish (if at beginning of sector)
                    while (iSector < iSectorEnd)
                    {
                        Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData = flashMap.m_map[iSector];

                        if (addressAssemblyStart >= flashSectorData.m_address && addressAssemblyStart < flashSectorData.m_address + flashSectorData.m_size)
                        {
                            // jump to next sector
                            address = flashSectorData.m_address + flashSectorData.m_size;

                            System.Diagnostics.Debug.Assert(address == flashMap.m_map[iSector + 1].m_address);

                            break;
                        }

                        iSector++;
                    }
                }
            }

            //Finished reading

            //convert to srec
            MFApplicationDeploymentData data = new MFApplicationDeploymentData();
            long deploymentLength            = deploymentStream.Seek(0, SeekOrigin.Current);

            MemoryStream streamSrec = new MemoryStream();

            deploymentStream.Seek(0, SeekOrigin.Begin);
            data.BinaryData = new byte[(int)deploymentLength];
            deploymentStream.Read(data.BinaryData, 0, (int)deploymentLength);
            deploymentStream.Seek(0, SeekOrigin.Begin);
            new BinToSrec().DoConversion(deploymentStream, streamSrec, flashMap.m_map[iSectorStart].m_address);

            //add zero bytes to all other deployment sectors?

            //Get bytes
            long pos = streamSrec.Seek(0, SeekOrigin.Current);

            data.HexData = new byte[pos];
            streamSrec.Seek(0, SeekOrigin.Begin);
            streamSrec.Read(data.HexData, 0, (int)pos);

            doWorkEventArgs.Result = data;
        }
示例#41
0
        private MFDevice InitializePorts(MFPortDefinition portDefinitionMain, MFPortDefinition portDefinitionTinyBooter)
        {
            MFDevice device = null;

            MFPortDefinition[] portDefs = new MFPortDefinition[2] {
                portDefinitionMain, portDefinitionTinyBooter
            };
            _DBG.PortDefinition[] pds = new Microsoft.SPOT.Debugger.PortDefinition[2];

            for (int i = 0; i < portDefs.Length; i++)
            {
                MFPortDefinition portDefinition = portDefs[i];
                if (portDefinition == null)
                {
                    continue;
                }

                if (portDefinition.Transport == TransportType.TCPIP)
                {
                    System.Net.IPAddress[] addr = System.Net.Dns.GetHostAddresses(portDefinition.Port);

                    pds[i] = new Microsoft.SPOT.Debugger.PortDefinition_Tcp(addr[0]);
                }
                else
                {
                    ArrayList list = _DBG.PortDefinition.Enumerate(_DBG.PortFilter.Usb, _DBG.PortFilter.Serial);
                    foreach (_DBG.PortDefinition pd in list)
                    {
                        if (portDefinition.Port.Length > 0)
                        {
                            if (string.Equals(portDefinition.Port, pd.UniqueId.ToString()))
                            {
                                pds[i] = pd;
                                break;
                            }
                        }
                        if (string.Equals(portDefinition.Name, pd.DisplayName))
                        {
                            pds[i] = pd;
                            break;
                        }
                    }
                }
            }

            if (pds[0] == null && pds[1] != null)
            {
                pds[0] = pds[1];
                pds[1] = null;
            }

            if (pds[0] != null || pds[1] != null)
            {
                device = new MFDevice(pds[0], pds[1]);

                if (!device.Connect(2000, m_tryConnect))
                {
                    throw new MFDeviceNoResponseException();
                }
            }
            else
            {
                throw new MFDeviceUnknownDeviceException();
            }

            return(device);
        }
示例#42
0
        public MFNetworkConfiguration(MFDevice dev)
        {
            m_cfg.networkInterfaceType = c_SOCK_NETWORKCONFIGURATION_INTERFACETYPE_ETHERNET;

            m_cfgHelper = new MFConfigHelper(dev);
        }
示例#43
0
        public EraseDialog(MFDevice dev)
        {
            InitializeComponent();

            m_device = dev;
        }
示例#44
0
 public MFWirelessConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }