?? dvflasher.cs
字號:
MySP.Write(cmdParams.UARTUBLExecAddr.ToString("X4")); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the BEGIN sequence if (waitForSequence(" BEGIN\0", " BOOTME\0", MySP,true)) Console.WriteLine("BEGIN commmand received. Sending CRC table..."); else goto BOOTMESEQ; // Send the 1024 byte (256 word) CRC table for (int i = 0; i < MyCRC.Length; i++) { MySP.Write(MyCRC[i].ToString("x8")); // Console.WriteLine(MyCRC[i].ToString("x8")); } Console.WriteLine("CRC table sent. Waiting for DONE..."); // Wait for the first DONE sequence if (waitForSequence(" DONE\0", " BOOTME\0", MySP)) Console.WriteLine("DONE received. Sending the UART UBL file..."); else goto BOOTMESEQ; // Send the contents of the UBL file MySP.Write(UBLsb.ToString()); // Wait for the second DONE sequence if (waitForSequence(" DONE\0", " BOOTME\0", MySP)) Console.WriteLine("DONE received. UART UBL file was accepted."); else goto BOOTMESEQ; Console.WriteLine("UART UBL Transmitted successfully.\n"); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } } /// <summary> /// Function to transmit the CMD and command over the UART (following BOOTPSP) /// </summary> private static Boolean TransmitCMDSuccessful() { try { // Clear input buffer so we can start looking for BOOTPSP MySP.DiscardInBuffer(); Console.WriteLine("\nWaiting for UBL on DVEVM..."); // Wait for the UBL on the DVEVM to send the ^BOOTPSP\0 sequence if (waitForSequence("BOOTPSP\0", "BOOTPSP\0", MySP)) Console.WriteLine("UBL's BOOTPSP commmand received. Returning CMD and command..."); else return false; // 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."); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } return true; } /// <summary> /// Send command and wait for erase response. (NOR and NAND global erase) /// </summary> private static void TransmitErase() { try { BOOTPSPSEQ1: // Send the UBL command if (!TransmitCMDSuccessful()) goto BOOTPSPSEQ1; if (!waitForSequence(" DONE\0", "BOOTPSP\0", MySP, true)) goto BOOTPSPSEQ1; } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } } /// <summary> /// Function to transmit the application code via the UBL, which is now /// running on the DM644x. This code is specific to the TI supplied UBL. /// If the the TI supplied UBL is modified or a different boot loader is /// used, this code will need to be modified. /// </summary> private static void TransmitAPP() { // Local Variables for reading APP file Byte[] APPFileData; APPFileData = GetFileData(cmdParams.APPFileName, cmdParams.APPLoadAddr, false); try { BOOTPSPSEQ3: // Send the UBL command if (!TransmitCMDSuccessful()) goto BOOTPSPSEQ3; if (waitForSequence("SENDAPP\0", "BOOTPSP\0", MySP)) { Console.WriteLine("SENDAPP received. Returning ACK and header for application data..."); } else { goto BOOTPSPSEQ3; } // Output 36 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of magic number (in this case flash the nor MySP.Write(((UInt32)cmdParams.APPMagicFlag).ToString("X8")); // 8 bytes of binary execution address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", cmdParams.APPEntryPoint)); // 8 bytes of data size = ASCII string of 8 hex characters MySP.Write(((UInt32)APPFileData.Length).ToString("X8")); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the ^^BEGIN\0 sequence if (waitForSequence(" BEGIN\0", "BOOTPSP\0", MySP)) Console.WriteLine("UBL's BEGIN commmand received. Sending the application code..."); else goto BOOTPSPSEQ3; // Send the application code (should be in S-record format) MySP.Write(APPFileData, 0, APPFileData.Length); Console.WriteLine("Application code sent. Waiting for DONE..."); // Wait for ^^^DONE\0 if (waitForSequence(" DONE\0", "BOOTPSP\0", MySP)) Console.WriteLine("DONE received. All bytes of application code received..."); else goto BOOTPSPSEQ3; // Wait for second ^^^DONE\0 to indicate the S-record decode worked if (waitForSequence(" DONE\0", "BOOTPSP\0", MySP)) Console.WriteLine("DONE received. Application S-record decoded correctly."); else goto BOOTPSPSEQ3; // Wait for third ^^^DONE that indicates booting if (!waitForSequence(" DONE\0", "BOOTPSP\0", MySP, true)) throw new Exception("Final DONE not returned. Command failed on DM644x."); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } } /// <summary> /// Function to transmit the second UBL if it is needed /// </summary> private static void TransmitFLASHUBLandAPP() { Byte[] APPFileData; Byte[] FLASHUBLData; // Get Application image data APPFileData = GetFileData(cmdParams.APPFileName, cmdParams.APPLoadAddr, false); // Get Flash UBL data (either embedded or from file) if (cmdParams.useEmbeddedUBL) FLASHUBLData = bin2srec(GetEmbeddedUBLStream(), cmdParams.FLASHUBLLoadAddr, (cmdParams.UBLFlashType == FlashType.NAND)); else FLASHUBLData = GetFileData(cmdParams.FLASHUBLFileName, cmdParams.FLASHUBLLoadAddr, (cmdParams.UBLFlashType == FlashType.NAND)); try { BOOTPSPSEQ2: // Send the UBL command if (!TransmitCMDSuccessful()) goto BOOTPSPSEQ2; if (waitForSequence("SENDUBL\0", "BOOTPSP\0", MySP)) Console.WriteLine("SENDUBL received. Returning ACK and header for UBL data..."); else goto BOOTPSPSEQ2; // Output 36 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of magic number (in this case flash the nor MySP.Write(((UInt32)cmdParams.FLASHUBLMagicFlag).ToString("X8")); // 8 bytes of binary execution address = ASCII string of 8 hex characters MySP.Write("8000"); MySP.Write(cmdParams.FLASHUBLExecAddr.ToString("X4")); // 8 bytes of data size = ASCII string of 8 hex characters MySP.Write(((UInt32)FLASHUBLData.Length).ToString("X8")); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the ^^BEGIN\0 sequence if (waitForSequence(" BEGIN\0", "BOOTPSP\0", MySP)) Console.WriteLine("UART UBL's BEGIN commmand received. Sending the Flash UBL code..."); else goto BOOTPSPSEQ2; // Send the Flash UBL code (should be in S-record format) MySP.Write(FLASHUBLData, 0, FLASHUBLData.Length); Console.WriteLine("Flash UBL code sent. Waiting for DONE..."); // Wait for ^^^DONE\0 if (waitForSequence(" DONE\0", "BOOTPSP\0", MySP)) Console.WriteLine("DONE received. All bytes of Flash UBL code received..."); else goto BOOTPSPSEQ2; // Wait for second ^^^DONE\0 to indicate the S-record decode worked if (waitForSequence(" DONE\0", "BOOTPSP\0", MySP)) Console.WriteLine("DONE received. Flash UBL S-record decoded correctly."); else goto BOOTPSPSEQ2; // Now Send the Application file that will be written to flash if (waitForSequence("SENDAPP\0", "BOOTPSP\0", MySP,true)) Console.WriteLine("SENDAPP received. Returning ACK and header for application data..."); else goto BOOTPSPSEQ2; // Output 36 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of magic number (in this case flash the nor if ( (cmdParams.CMDMagicFlag == MagicFlags.UBL_MAGIC_NAND_BIN_BURN) || (cmdParams.CMDMagicFlag == MagicFlags.UBL_MAGIC_NOR_BIN_BURN) ) MySP.Write(((UInt32)MagicFlags.UBL_MAGIC_BIN_IMG).ToString("X8")); else MySP.Write(((UInt32)MagicFlags.UBL_MAGIC_SAFE).ToString("X8")); // 8 bytes of binary execution address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", cmdParams.APPEntryPoint)); // 8 bytes of data size = ASCII string of 8 hex characters MySP.Write(((UInt32)APPFileData.Length).ToString("X8")); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the ^^BEGIN\0 sequence if (waitForSequence(" BEGIN\0", "BOOTPSP\0", MySP)) Console.WriteLine("UART UBL's BEGIN commmand received. Sending the Application code..."); else goto BOOTPSPSEQ2; // Send the application code (should be in S-record format) MySP.Write(APPFileData, 0, APPFileData.Length); Console.WriteLine("Application code sent. Waiting for DONE..."); // Wait for ^^^DONE\0 if (waitForSequence(" DONE\0", "BOOTPSP\0", MySP)) Console.WriteLine("DONE received. All bytes of Application code received..."); else goto BOOTPSPSEQ2; // Wait for second ^^^DONE\0 to indicate the S-record decode worked if (waitForSequence(" DONE\0", "BOOTPSP\0", MySP)) Console.WriteLine("DONE received. Application S-record decoded correctly."); else goto BOOTPSPSEQ2; // Wait for third ^^^DONE that indicates booting waitForSequence(" DONE\0", "BOOTPSP\0", MySP,true); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -