Пример #1
0
        //**********************************************************************************


        //**********************************************************************************
        #region Code for UART interfacing thread

        /// <summary>
        /// The main function of the thread where all the cool stuff happens
        /// to interface with the device
        /// </summary>
        public static void WorkerThreadStart()
        {
            switch (cmdParams.CMDMagicFlag)
            {
            case MagicFlags.SLT_MAGIC_LOADIMAGE_IRAM:
            {
                TransmitAppToIRAM();
                break;
            }

            case MagicFlags.SLT_MAGIC_LOADIMAGE_DDR:
            {
                // Send SLT and the app to DDR
                TransmitSLTAndApp();

                // Wait for second ^^^DONE that indicates SLT is done
                if (!SerialIO.waitForSequence("   DONE\0", "BOOTUBL\0", MySP, true))
                {
                    throw new Exception("Final DONE not returned.  Operation failed.");
                }

                break;
            }

            default:
            {
                Console.WriteLine("Command not recognized!");
                break;
            }
            }

            // Clean up any embedded files we extracted
            EmbeddedFileIO.CleanUpEmbeddedFiles();

            // Everything worked, so change boolean status
            workerThreadSucceeded = true;
        }
Пример #2
0
Файл: sfh.cs Проект: gxk/dm6467
        //**********************************************************************************


        //**********************************************************************************
        #region Code for UART interfacing thread

        /// <summary>
        /// The main function of the thread where all the cool stuff happens
        /// to interface with the device
        /// </summary>
        public static void WorkerThreadStart()
        {
            Boolean status;

            // Try transmitting the first stage boot-loader (UBL) via the RBL
            try
            {
                String          srchStr;
                Byte[]          imageData;
                UARTBOOT_Header ackHeader = new UARTBOOT_Header();

                if (cmdParams.UBLFlashType == FlashType.NAND)
                {
                    srchStr = "sft_" + devString + "_nand.bin";
                }
                else
                {
                    srchStr = "sft_" + devString + "_nor.bin";
                }

                // Extract the embedded SLT
                EmbeddedFileIO.ExtractFile(System.Reflection.Assembly.GetExecutingAssembly(), srchStr, true);

                // Read the extracted embedded SFT data that we will transmit
                imageData           = FileIO.GetFileData(srchStr);
                ackHeader.startAddr = 0x0100; // Default for SFT
                ackHeader.loadAddr  = 0x0020; // Not used here, but this what the RBL uses
                ackHeader.byteCnt   = (UInt32)imageData.Length;

                TransmitUBL(imageData, ackHeader);
            }
            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
            {
BOOTUBLSEQ1:
                // Clear input buffer so we can start looking for BOOTUBL
                MySP.DiscardInBuffer();

                Console.WriteLine("\nWaiting for SFT on the " + devString + "...");

                // Wait for the SFT on the device to send the ^BOOTUBL\0 sequence
                if (!SerialIO.waitForSequence("BOOTUBL\0", "BOOTUBL\0", MySP, true))
                {
                    goto BOOTUBLSEQ1;
                }

                Console.WriteLine("BOOTUBL commmand received. Returning CMD and command...");

                // 8 bytes acknowledge sequence = "    CMD\0"
                MySP.Write("    CMD\0");
                // 8 bytes of magic number
                MySP.Write(((UInt32)cmdParams.CMDMagicFlag).ToString("X8"));

                Console.WriteLine("CMD value sent.  Waiting for DONE...");

                if (!SerialIO.waitForSequence("   DONE\0", "BOOTUBL\0", MySP, true))
                {
                    goto BOOTUBLSEQ1;
                }

                Console.WriteLine("DONE received. Command was accepted.");

                // Take appropriate action depending on command
                switch (cmdParams.CMDMagicFlag)
                {
                case MagicFlags.UBL_MAGIC_NAND_FLASH:
                {
                    status = TransmitUBLandAPP();
                    break;
                }

                case MagicFlags.UBL_MAGIC_NOR_FLASH:
                {
                    status = TransmitUBLandAPP();
                    break;
                }

                case MagicFlags.UBL_MAGIC_NOR_FLASH_NO_UBL:
                {
                    status = TransmitAPP();
                    break;
                }

                case MagicFlags.UBL_MAGIC_NOR_ERASE:
                {
                    status = TransmitErase();
                    break;
                }

                case MagicFlags.UBL_MAGIC_NAND_ERASE:
                {
                    status = TransmitErase();
                    break;
                }

                default:
                {
                    Console.WriteLine("Command not recognized!");
                    status = false;
                    break;
                }
                }
                if (!status)
                {
                    goto BOOTUBLSEQ1;
                }
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    Console.WriteLine(e.Message);
                }
                return;
            }

            // Wait for ^^^DONE that indicates SFT is exiting and so can this host program
            if (!SerialIO.waitForSequence("   DONE\0", "BOOTUBL\0", MySP, true))
            {
                throw new Exception("Final DONE not returned.  Operation failed.");
            }

            // Clean up any embedded files we extracted
            EmbeddedFileIO.CleanUpEmbeddedFiles();

            // Everything worked, so change boolean status
            workerThreadSucceeded = true;
        }