//********************************************************************************** //********************************************************************************** #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; }
/// <summary> /// Function used to handle the -load2DDR command-line option private static void TransmitSLTAndApp() { // Local Variables for holding file data Byte[] imageData; UARTBOOT_Header ackHeader = new UARTBOOT_Header(); // Extract the embedded SLT EmbeddedFileIO.ExtractFile(System.Reflection.Assembly.GetExecutingAssembly(), "slt_" + devString + ".bin", true); // Read the extracted embedded SLT data that we will transmit imageData = FileIO.GetFileData("slt_" + devString + ".bin"); ackHeader.startAddr = 0x0100; // Default for SLT ackHeader.byteCnt = (UInt32)imageData.Length; ackHeader.loadAddr = 0x0020; // Not used here, but this what the RBL uses TransmitUBL(imageData, ackHeader); // Sleep in case we need to abort Thread.Sleep(200); // Code to perform specified command try { BOOTUBLSEQ1: // Send the UBL command // Clear input buffer so we can start looking for BOOTUBL MySP.DiscardInBuffer(); Console.WriteLine("\nWaiting for SLT on the " + devString + "..."); // Wait for the UBL 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..."); // Wait for ^^^DONE letting us know the command was accepted if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { goto BOOTUBLSEQ1; } Console.WriteLine("DONE received. Command was accepted."); // Local Variables for reading APP file imageData = FileIO.GetFileData(cmdParams.APPFileName); ackHeader.startAddr = cmdParams.APPStartAddr; // App entry point ackHeader.loadAddr = cmdParams.APPLoadAddr; // App load address ackHeader.byteCnt = (UInt32)imageData.Length; // App byte cnt if (!TransmitImage(imageData, ackHeader)) { goto BOOTUBLSEQ1; } } catch (Exception e) { if (e is ThreadAbortException) { Thread.Sleep(1000); } else { Console.WriteLine(e.Message); } return; } }
//********************************************************************************** //********************************************************************************** #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; }