⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvflasher.cs

📁 TI DM6446 EVM 串口下载程序 使用环境:windows dos环境或者linux 使用前需安装mono
💻 CS
📖 第 1 页 / 共 5 页
字号:
                    workerThread.Abort();                }                else if (workerThread.IsAlive)                {                    Console.WriteLine("Aborting program...");                    workerThread.Abort();                }                                while ((workerThread.ThreadState & ThreadState.Stopped) != ThreadState.Stopped){}            }            catch (Exception e)            {                Console.WriteLine("Abort thread error...");                Console.WriteLine(e.GetType());                Console.WriteLine(e.Message);            }                        if (workerThreadSucceeded)            {                Console.WriteLine("\nOperation completed successfully.");                return 0;            }            else            {                Console.WriteLine("\n\nInterfacing to the DVEVM via UART failed." +                    "\nPlease reset or power-cycle the board and try again...");                return -1;            }                    }        #endregion        //**********************************************************************************                //**********************************************************************************        #region Code for UART interfacing thread        /// <summary>        /// The main fucntion of the thread where all the cool stuff happens        /// to interface with the DVEVM        /// </summary>        public static void WorkerThreadStart()        {            // Try transmitting the first stage boot-loader (UBL) via the RBL            try            {                if (cmdParams.UARTUBLUsed)                    TransmitUARTUBL();            }            catch (Exception e)            {                if (e is ThreadAbortException)                {                    Thread.Sleep(1000);                }                else                {                    Console.WriteLine(e.Message);                }                return;            }            // Sleep in case we need to abort            Thread.Sleep(200);                        // Code to perform specified command            try            {                // Wait for the bootmode to be sent                if (!waitForSequence("PSPBootMode = UART", "PSPBootMode = N", MySP, true))                {                    Console.WriteLine("\nWARNING! The DM644x is NOT in UART boot mode!");                    Console.WriteLine("Only continue if you are sure of what you are doing.");                    Console.Write("\n\tContinue (Y/N) ? ");                    if (!String.Equals(                            Console.ReadKey().Key.ToString(),                            "y",                            StringComparison.CurrentCultureIgnoreCase)                        )                    {                        Console.WriteLine("\n\nCheck your switch and jumper settings, if appropriate.");                        Thread.CurrentThread.Abort();                    }                    else                        Console.WriteLine();                }                                // Clear input buffer so we can start looking for BOOTPSP                MySP.DiscardInBuffer();                // Take appropriate action depending on command                switch (cmdParams.CMDMagicFlag)                {                    case MagicFlags.UBL_MAGIC_NAND_BIN_BURN:                        {                            TransmitFLASHUBLandAPP();                            break;                        }                    case MagicFlags.UBL_MAGIC_NAND_SREC_BURN:                        {                            TransmitFLASHUBLandAPP();                            break;                        }                    case MagicFlags.UBL_MAGIC_NOR_BIN_BURN:                        {                            TransmitFLASHUBLandAPP();                            break;                        }                    case MagicFlags.UBL_MAGIC_NOR_SREC_BURN:                        {                            TransmitFLASHUBLandAPP();                            break;                        }                    case MagicFlags.UBL_MAGIC_NOR_GLOBAL_ERASE:                        {                            TransmitErase();                            break;                        }                    case MagicFlags.UBL_MAGIC_NAND_GLOBAL_ERASE:                        {                            TransmitErase();                            break;                        }                    case MagicFlags.UBL_MAGIC_NOR_RESTORE:                        {                            TransmitAPP();                            break;                        }                    case MagicFlags.UBL_MAGIC_SAFE:                        {                            TransmitAPP();                            break;                        }                    default:                        {                            Console.WriteLine("Command not recognized!");                            break;                        }                }            }            catch (Exception e)            {                if (e is ThreadAbortException)                {                    Thread.Sleep(1000);                }                else                {                    Console.WriteLine(e.Message);                }                return;            }                        // Everything worked, so change boolean status            workerThreadSucceeded = true;        }        /// <summary>        /// Read the appropriate embedded UBL data (NAND or NOR) that        /// will be transmitted to the DM644x.        /// </summary>        /// <returns>A Stream object of the UBL data</returns>        private static Stream GetEmbeddedUBLStream()        {            String srchStr;            Stream UBLstream;            String UBLResourceName = "";            Assembly executingAssembly = Assembly.GetExecutingAssembly();            if (cmdParams.UBLFlashType == FlashType.NAND)                srchStr = "ubl_davinci_nand.bin";            else                srchStr = "ubl_davinci_nor.bin";            executingAssembly = Assembly.GetExecutingAssembly();            foreach (String s in executingAssembly.GetManifestResourceNames())            {                if (s.Contains(srchStr))                {                    UBLResourceName = s;                    break;                }            }            try            {                UBLstream = executingAssembly.GetManifestResourceStream(UBLResourceName);            }            catch (FileNotFoundException e)            {                Console.WriteLine("The embedded UBL file was not found.");                throw e;            }            return UBLstream;        }        /// <summary>        /// Function to find, read, and convert to S-record (if needed) a data file        /// </summary>        /// <param name="filename">The name of the file to load</param>        /// <param name="decAddr">The address to which the data should be loaded in memory        /// on the DM644x device.        /// </param>        /// <returns></returns>        private static Byte[] GetFileData(String filename, UInt32 decAddr, Boolean stripData)        {            FileStream fs;            Byte[] data;            if (!File.Exists(filename))            {                throw new FileNotFoundException("File " + filename + " is not present.");            }            // Open file and setup the binary stream reader            fs = File.Open(cmdParams.APPFileName, FileMode.Open, FileAccess.Read);            // Check to see if the file is an s-record file            if (isFileSrec(fs))            {                data = readSrec(fs);            }            else //Assume the file is a binary file            {                data = bin2srec(fs, decAddr, stripData);            }            return data;        }        /// <summary>        /// Function to Transmit the UBL via the DM644x ROM Serial boot        /// </summary>        private static void TransmitUARTUBL()        {            // Local Variables for reading UBL file            Stream UBLstream;            BinaryReader UBLbr;            StringBuilder UBLsb;            Byte[] UBLFileData;            UInt32 UBLcrc;            UInt32 data;                      CRC32 MyCRC;            // Access the appropriate embedded UBL            UBLstream = GetEmbeddedUBLStream();                                    // Open UBL UART stream and setup the binary stream reader            UBLbr = new BinaryReader(UBLstream);                        // Create the byte array and stringbuilder for holding UBL file data            UBLFileData = new Byte[(UBLstream.Length-256)];            UBLsb = new StringBuilder((UBLFileData.Length-256) * 2);            // Skip the first 0x100 bytes since they contain slef-copy stuff            // This is required to mimic the SDI flashwriter programs (Ugh!)            UBLbr.BaseStream.Seek(256, SeekOrigin.Begin);                        // Read the data from the UBL file into the appropriate structures            for (int i = 0; i < ((UBLstream.Length-256) / sizeof(UInt32)); i++)            {                data = UBLbr.ReadUInt32();                System.BitConverter.GetBytes(data).CopyTo(UBLFileData, i * sizeof(UInt32));                UBLsb.AppendFormat("{0:X8}", data);            }            // Create CRC object and use it to calculate the UBL file's CRC            // Not that this CRC is not quite the standard CRC-32 algorithm            // commonly is use since the final register value is not XOR'd            // with 0xFFFFFFFF.  As a result the CRC value returned here            // will be the bitwise inverse of the standard CRC-32 value.            MyCRC = new CRC32(0x04C11DB7, 0xFFFFFFFF, 0x00000000, true, 1);            UBLcrc = MyCRC.CalculateCRC(UBLFileData);            try            {            BOOTMESEQ:                Console.WriteLine("\nWaiting for DVEVM...");                // Wait for the DVEVM to send the ^BOOTME/0 sequence                if (waitForSequence(" BOOTME\0", " BOOTME\0", MySP))                    Console.WriteLine("BOOTME commmand received. Returning ACK and header...");                else                    goto BOOTMESEQ;                // Output 28 Bytes for the ACK sequence and header                // 8 bytes acknowledge sequence = "    ACK\0"                MySP.Write("    ACK\0");                                // 8 bytes of CRC data = ASCII string of 8 hex characters                MySP.Write(UBLcrc.ToString("X8"));                                // 4 bytes of UBL data size = ASCII string of 4 hex characters (3800h = 14336d)                MySP.Write((UBLstream.Length-256).ToString("X4"));                                // 4 bytes of start address = ASCII string of 4 hex characters (>=0100h)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -