/// <summary> /// Main entry point of application /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code //Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI EMIF2.x Hamming ECC Parity Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Create ECC object HammingECC h = new HammingECC(512); // Create binary writer for saving ECC data to output file BinaryWriter bw = new BinaryWriter(new FileStream(cmdParams.outputFileName, FileMode.Create, FileAccess.Write)); // Read input data from file Byte[] fileData = FileIO.GetFileData(cmdParams.inputfileName); Byte[] subArray = new Byte[512]; for (int i = 0; i < fileData.Length; i += 512) { for (int j = 0; j < 512; j++) { subArray[j] = (Byte)(((i + j) >= fileData.Length) ? (0xFF) : fileData[i + j]); } // Calculate parity of the message data Int32 parity = h.GenerateParity(subArray); // Prep the parity data and output it to file if (cmdParams.verbose) { Console.WriteLine("NAND operation #{0}", (i / 512) + 1); Console.WriteLine("\tNANDFxECC = 0x{0:X8}", parity); } bw.Write(parity); } return(0); }
/// <summary> /// Main program. /// </summary> /// <param name="args">Input commandline arguments</param> /// <returns>Return code</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI NOR AIS File Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Now proceed with main program FileStream tempAIS_fs = null; Byte[] AISData; // Create a new C642x AIS generator object AISGen_C642x generator = new AISGen_C642x(); generator.CRCType = CRCCheckType.SECTION_CRC; // Do the AIS generation try { AISData = AISGen.GenAIS(cmdParams.inputfileName, "emifa", generator); tempAIS_fs = new FileStream(cmdParams.outFileName, FileMode.Create, FileAccess.Write); tempAIS_fs.Write(AISData, 0, (int)AISData.Length); tempAIS_fs.Close(); } catch (Exception e) { Console.WriteLine(e.StackTrace); Console.WriteLine("Unhandled Exception!!! Application will now exit."); return(-1); } Console.WriteLine("AIS generation is complete."); return(0); }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; UInt32 numUnhandledArgs, numHandledArgs = 0; String s; // Check for no argumnents if (args.Length == 0) { myCmdParams.valid = false; return(myCmdParams); } // Set Defaults myCmdParams.valid = true; myCmdParams.outFileName = null; myCmdParams.iniFileName = null; myCmdParams.inputfileName = null; myCmdParams.convType = ConvType.COFF2Hex; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "coff2hex": myCmdParams.convType = ConvType.COFF2Hex; break; case "ais2hex": myCmdParams.convType = ConvType.AIS2Hex; break; case "ini": myCmdParams.iniFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "o": myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; } } numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); // Check to make sure we are still valid if ((!myCmdParams.valid) || (numUnhandledArgs != 1) || (argsHandled[args.Length - 1])) { myCmdParams.valid = false; return(myCmdParams); } // Get input file FileInfo fi = new FileInfo(args[args.Length - 1]); if (fi.Exists) { //myCmdParams.inputfileName = fi.Name; myCmdParams.inputfileName = args[args.Length - 1]; String extension = Path.GetExtension(fi.Name); if (myCmdParams.outFileName == null) { myCmdParams.outFileName = Path.GetFileNameWithoutExtension(fi.Name) + ".hex"; } if ((myCmdParams.convType == ConvType.COFF2Hex) && (!extension.Equals(".out", StringComparison.OrdinalIgnoreCase))) { Console.WriteLine("Warning: Input filename does not have .out extension!"); Console.WriteLine("\tIt may not be a valid COFF file."); } if ((myCmdParams.convType == ConvType.AIS2Hex) && (!extension.Equals(".ais", StringComparison.OrdinalIgnoreCase))) { Console.WriteLine("Warning: Input filename does not have .ais extension!"); Console.WriteLine("\tIt may not be a valid binary AIS file."); } } else { Console.WriteLine("File not found."); myCmdParams.valid = false; return(myCmdParams); } return(myCmdParams); }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; UInt32 numUnhandledArgs, numHandledArgs = 0; String s, defaultExtension; // Check for no argumnents if (args.Length == 0) { myCmdParams.valid = false; return(myCmdParams); } // Set Defaults myCmdParams.valid = true; myCmdParams.outFileName = null; myCmdParams.iniFileName = null; myCmdParams.inputfileName = null; myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "otype": String temp = args[i + 1]; if (temp.ToLower().Equals("binary")) { myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; } else if (temp.ToLower().Equals("carray")) { myCmdParams.convType = ConvType.Exec2CArray; defaultExtension = ".c"; } else if (temp.ToLower().Equals("srecord")) { myCmdParams.convType = ConvType.Exec2Srec; defaultExtension = ".srec"; } else if (temp.ToLower().Equals("text")) { myCmdParams.convType = ConvType.Exec2Text; defaultExtension = ".txt"; } else { myCmdParams.valid = false; } argsHandled[i + 1] = true; numHandledArgs++; break; case "ini": myCmdParams.iniFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "o": myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; } } numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); // Check to make sure we are still valid if ((!myCmdParams.valid)) { return(myCmdParams); } // Check to see if one last arg is still left - if so it is input object filename if ((numUnhandledArgs == 1) && (!argsHandled[args.Length - 1])) { // Get input file FileInfo fi = new FileInfo(args[args.Length - 1]); if (fi.Exists) { myCmdParams.inputfileName = args[args.Length - 1]; String extension = Path.GetExtension(fi.Name); if (myCmdParams.outFileName == null) { myCmdParams.outFileName = Path.GetFileNameWithoutExtension(fi.Name) + defaultExtension; } } } if (myCmdParams.outFileName == null) { myCmdParams.outFileName = devString + "_boot_image.ais"; } return(myCmdParams); }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs,numHandledArgs=0; String s; if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++ ) argsHandled[i] = false; // Set Defualts for application myCmdParams.UBLFlashType = FlashType.NONE; myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.SerialPortName = null; myCmdParams.SerialPortBaudRate = 115200; myCmdParams.APPMagicFlag = MagicFlags.UBL_MAGIC_SAFE; myCmdParams.APPFileName = null; myCmdParams.APPLoadAddr = 0xFFFFFFFF; myCmdParams.APPStartAddr = 0xFFFFFFFF; #if DM35X_STANDARD myCmdParams.UBLMagicFlag = MagicFlags.UBL_MAGIC_SAFE_DM35x_REVC; #else myCmdParams.UBLMagicFlag = MagicFlags.UBL_MAGIC_SAFE; #endif myCmdParams.UBLFileName = null; myCmdParams.UBLStartAddr = 0xFFFFFFFF; // For loop for required command type for(int i = 0; i<args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "norflash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NOR_FLASH; else myCmdParams.valid = false; numFiles = 2; myCmdParams.UBLFlashType = FlashType.NOR; cmdString = "Flashing NOR with "; break; case "norflash_noubl": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NOR_FLASH_NO_UBL; else myCmdParams.valid = false; numFiles = 1; myCmdParams.UBLFlashType = FlashType.NOR; cmdString = "Flashing NOR with "; break; case "sdflash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_SDMMC_FLASH; else myCmdParams.valid = false; numFiles = 2; myCmdParams.UBLFlashType = FlashType.SD_MMC; cmdString = "Flashing SD/MMC with "; break; case "nandflash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NAND_FLASH; else myCmdParams.valid = false; numFiles = 2; myCmdParams.UBLFlashType = FlashType.NAND; cmdString = "Flashing NAND with "; break; case "norerase": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NOR_ERASE; else myCmdParams.valid = false; numFiles = 0; myCmdParams.UBLFlashType = FlashType.NOR; cmdString = "Globally erasing NOR flash."; break; case "nanderase": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NAND_ERASE; else myCmdParams.valid = false; numFiles = 0; myCmdParams.UBLFlashType = FlashType.NAND; cmdString = "Globally erasing NAND flash."; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params // Check to make sure a command was selected if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.valid = false; return myCmdParams; } // For loop for all other dash options try { for(int i = 0; i<args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "appstartaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPStartAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "apploadaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPLoadAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "ublstartaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.UBLStartAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "p": myCmdParams.SerialPortName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "baud": myCmdParams.SerialPortBaudRate = System.Int32.Parse(args[i + 1]); argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params } catch(Exception e) { Console.WriteLine(e.Message); myCmdParams.valid = false; return myCmdParams; } // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32) (args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return myCmdParams; } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += myCmdParams.APPFileName + "."; } else myCmdParams.valid = false; break; case 2: if (myCmdParams.UBLFileName == null) { myCmdParams.UBLFileName = args[i]; cmdString += myCmdParams.UBLFileName + " and "; } else if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += myCmdParams.APPFileName + "."; } else myCmdParams.valid = false; break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; if (!myCmdParams.valid) return myCmdParams; } // end of for loop for handling dash params // Set default binary execution address on target device if (myCmdParams.APPLoadAddr == 0xFFFFFFFF) myCmdParams.APPLoadAddr = 0x81080000; if (myCmdParams.APPStartAddr == 0xFFFFFFFF) myCmdParams.APPStartAddr = 0x81080000; if (myCmdParams.UBLStartAddr == 0xFFFFFFFF) myCmdParams.UBLStartAddr = 0x00000100; //Setup default serial port name if (myCmdParams.SerialPortName == null) { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) //Check for unix/linux { Console.WriteLine("Platform is Unix/Linux."); myCmdParams.SerialPortName = "/dev/ttyS0"; } else { Console.WriteLine("Platform is Windows."); myCmdParams.SerialPortName = "COM1"; } } return myCmdParams; }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs, numHandledArgs = 0; String s; if (args.Length == 0) { myCmdParams.valid = false; return(myCmdParams); } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // Set Defualts for application myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.SerialPortName = null; myCmdParams.APPFileName = null; myCmdParams.APPLoadAddr = 0xFFFFFFFF; myCmdParams.APPStartAddr = 0xFFFFFFFF; // For loop for required load type for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "load2iram": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.SLT_MAGIC_LOADIMAGE_IRAM; } else { myCmdParams.valid = false; } myCmdParams.APPLoadAddr = 0x0020; myCmdParams.APPStartAddr = 0x0100; numFiles = 1; cmdString = "Loading image to ARM IRAM "; break; case "load2ddr": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.SLT_MAGIC_LOADIMAGE_DDR; } else { myCmdParams.valid = false; } myCmdParams.APPLoadAddr = 0x80000000; myCmdParams.APPStartAddr = 0x80000000; numFiles = 1; cmdString = "Loading image to DDR"; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } } if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.valid = false; return(myCmdParams); } // For loop for all other dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "startaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.APPStartAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "loadaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.APPLoadAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "p": myCmdParams.SerialPortName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } } // end of for loop for handling dash params // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return(myCmdParams); } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; } else { myCmdParams.valid = false; } break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } // end of for loop handling file name inputs //Setup default serial port name if (myCmdParams.SerialPortName == null) { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) //Check for unix/linux { Console.WriteLine("Platform is Unix/Linux."); myCmdParams.SerialPortName = "/dev/ttyS0"; } else { Console.WriteLine("Platform is Windows."); myCmdParams.SerialPortName = "COM1"; } } return(myCmdParams); }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; UInt32 numUnhandledArgs, numHandledArgs = 0; String s; // Check for no argumnents if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Set Defaults myCmdParams.valid = true; myCmdParams.outFileName = null; myCmdParams.iniFileName = null; myCmdParams.inputfileName = null; myCmdParams.convType = ConvType.COFF2Hex; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) argsHandled[i] = false; // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "coff2hex": myCmdParams.convType = ConvType.COFF2Hex; break; case "ais2hex": myCmdParams.convType = ConvType.AIS2Hex; break; case "ini": myCmdParams.iniFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "o": myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; } } numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); // Check to make sure we are still valid if ( (!myCmdParams.valid) || (numUnhandledArgs != 1) || (argsHandled[args.Length-1])) { myCmdParams.valid = false; return myCmdParams; } // Get input file FileInfo fi = new FileInfo(args[args.Length-1]); if (fi.Exists) { //myCmdParams.inputfileName = fi.Name; myCmdParams.inputfileName = args[args.Length - 1]; String extension = Path.GetExtension(fi.Name); if (myCmdParams.outFileName == null) { myCmdParams.outFileName = Path.GetFileNameWithoutExtension(fi.Name) + ".hex"; } if ( (myCmdParams.convType == ConvType.COFF2Hex) && (!extension.Equals(".out",StringComparison.OrdinalIgnoreCase)) ) { Console.WriteLine("Warning: Input filename does not have .out extension!"); Console.WriteLine("\tIt may not be a valid COFF file."); } if ( (myCmdParams.convType == ConvType.AIS2Hex) && (!extension.Equals(".ais",StringComparison.OrdinalIgnoreCase)) ) { Console.WriteLine("Warning: Input filename does not have .ais extension!"); Console.WriteLine("\tIt may not be a valid binary AIS file."); } } else { Console.WriteLine("File not found."); myCmdParams.valid = false; return myCmdParams; } return myCmdParams; }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs,numHandledArgs=0; String s; if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++ ) argsHandled[i] = false; // Set Defualts for application myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.SerialPortName = null; myCmdParams.APPFileName = null; // For loop for required load type myCmdParams.CMDMagicFlag = MagicFlags.SLT_MAGIC_LOADIMAGE; numFiles = 1; if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.valid = false; return myCmdParams; } // For loop for all other dash options for(int i = 0; i<args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "p": myCmdParams.SerialPortName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; case "waitfordevice": myCmdParams.waitForBOOTME = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32) (args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return myCmdParams; } // This for loop handles all other params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; } else myCmdParams.valid = false; break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } // end of for loop handling file name inputs //Setup default serial port name if (myCmdParams.SerialPortName == null) { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) //Check for unix/linux { Console.WriteLine("Platform is Unix/Linux."); myCmdParams.SerialPortName = "/dev/ttyS0"; } else { Console.WriteLine("Platform is Windows."); myCmdParams.SerialPortName = "COM1"; } } return myCmdParams; }
/// <summary> /// Main program. /// </summary> /// <param name="args">Input commandline arguments</param> /// <returns>Return code</returns> static Int32 Main(String[] args) { IniFile myIniFile; // From Common/AIS/HexAIS_version.cs System.Version v = GetVersion(); // From Common/AIS/HexAIS_version.cs Int32 buildYear = GetBuildYear(); // Begin main code Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI AIS Hex File Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Now proceed with main program FileStream tempAIS_fs = null; Byte[] AISData, convertedData; AISGen_OMAP_L137 generator = new AISGen_OMAP_L137(); // Update the default INI file name to the one supplied on the command line if (cmdParams.iniFileName == null) { Console.WriteLine("No ini file provided. Using default, {0}", generator.DeviceNameShort + ".ini"); cmdParams.iniFileName = generator.DeviceNameShort + ".ini"; } // Read the INI data from file if (File.Exists(cmdParams.iniFileName)) { myIniFile = new IniFile(new FileStream(cmdParams.iniFileName, FileMode.Open, FileAccess.Read), cmdParams.iniFileName); } else { Console.WriteLine("File {0} not found.", cmdParams.iniFileName); return(-1); } // Put entryPoint in General Ini section (may be overridden by INI InputFile sections) myIniFile.InsertValue("General", "EntryPoint", "0x" + cmdParams.entryPoint.ToString("X8")); // Force section-by-section CRC checks (may be overridden in INI file) generator.AISCRCType = AisCRCCheckType.SECTION_CRC; // Do the AIS generation try { AISData = AISGen.GenAIS(generator, cmdParams.inputFileName, myIniFile); } catch (Exception e) { System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true); Console.WriteLine(e.StackTrace); Console.WriteLine(e.Message); Console.WriteLine("Unhandled Exception!!! Application will now exit."); return(-1); } // Check if SecureAISGen completed successfully if (AISData == null) { Console.WriteLine("AIS generation failed."); return(-1); } using (tempAIS_fs = new FileStream(cmdParams.outFileName, FileMode.Create, FileAccess.Write)) { // Convert the AIS data to the correct output format switch (cmdParams.convType) { case ConvType.Exec2Bin: tempAIS_fs.Write(AISData, 0, (int)AISData.Length); Console.WriteLine("Wrote {0} bytes to file {1}.", AISData.Length, cmdParams.outFileName); break; case ConvType.Exec2CArray: convertedData = CArray.bin2CArray(cmdParams.cArrayName, AISData, 4); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); Console.WriteLine("Wrote {0} bytes to file {1}.", convertedData.Length, cmdParams.outFileName); break; case ConvType.Exec2Srec: convertedData = SRecord.bin2srec(AISData, (UInt32)cmdParams.srecAddr, 32); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); Console.WriteLine("Wrote {0} bytes to file {1}.", convertedData.Length, cmdParams.outFileName); break; case ConvType.Exec2Text: Console.WriteLine("Mode Not supported."); break; } } Console.WriteLine("Conversion is complete."); return(0); }
/// <summary> /// Main program. /// </summary> /// <param name="args">Input commandline arguments</param> /// <returns>Return code</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI AIS Hex File Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Now proceed with main program FileStream tempAIS_fs = null; Byte[] AISData, convertedData; AISGen_OMAP_L138 generator = new AISGen_OMAP_L138(); // Update the default INI file name to the one supplied on the command line if (cmdParams.iniFileName == null) { cmdParams.iniFileName = generator.DeviceNameShort + ".ini"; } // Read the INI data from file INISection[] iniSecs = INI.Parse(new FileStream(cmdParams.iniFileName, FileMode.Open, FileAccess.Read)); // Force section-by-section CRC checks (may be overridden in INI file) generator.CRCType = CRCCheckType.SECTION_CRC; // Do the AIS generation try { AISData = AISGen.GenAIS(cmdParams.inputfileName, generator, iniSecs); } catch (Exception e) { System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true); Console.WriteLine(e.StackTrace); Console.WriteLine("Unhandled Exception!!! Application will now exit."); return(-1); } tempAIS_fs = new FileStream(cmdParams.outFileName, FileMode.Create, FileAccess.Write); switch (cmdParams.convType) { case ConvType.Exec2Bin: tempAIS_fs.Write(AISData, 0, (int)AISData.Length); break; case ConvType.Exec2CArray: convertedData = CArray.bin2CArray(AISData, 4); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); break; case ConvType.Exec2Srec: convertedData = SRecord.bin2srec(AISData, 0x60000000, 32); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); break; case ConvType.Exec2Text: Console.WriteLine("Mode Not supported."); //Byte[] val = SRecord.bin2srec(aisData, 0x60000000, 32); break; } tempAIS_fs.Close(); Console.WriteLine("Conversion is complete."); return(0); }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numUnhandledArgs, numHandledArgs = 0; String defaultExtension; // Set Defaults myCmdParams.valid = true; myCmdParams.outFileName = null; myCmdParams.iniFileName = null; myCmdParams.inputFileName = null; myCmdParams.srecAddr = 0xFFFFFFFF; myCmdParams.entryPoint = 0xFFFFFFFF; myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("-")) { switch (args[i].Substring(1).ToLower()) { case "entrypoint": { UInt32 temp; if (args[i + 1].StartsWith("0x") || args[i + 1].StartsWith("0X")) { if (!UInt32.TryParse(args[i + 1].Replace("0x", ""), NumberStyles.HexNumber, null, out temp)) { Console.WriteLine("WARNING: Invalid entrypoint address, {0}. Ignoring...", args[i + 1]); } else { myCmdParams.entryPoint = temp; } } else if (UInt32.TryParse(args[i + 1], out temp)) { myCmdParams.entryPoint = temp; } else { Console.WriteLine("WARNING: Invalid entrypoint address, {0}. Ignoring...", args[i + 1]); } argsHandled[i + 1] = true; numHandledArgs++; break; } case "otype": { // Handle possible srecord@addr, carray:name case String[] otype = args[i + 1].Split(new Char [] { '@', ':' }); if (otype[0].ToLower().Equals("binary")) { myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; } else if (otype[0].ToLower().Equals("carray")) { myCmdParams.convType = ConvType.Exec2CArray; defaultExtension = ".c"; if (otype.Length == 1) { myCmdParams.cArrayName = "data_array"; } else if (otype.Length == 2) { myCmdParams.cArrayName = otype[1]; } else { myCmdParams.valid = false; } } else if (otype[0].ToLower().Equals("text")) { myCmdParams.convType = ConvType.Exec2Text; defaultExtension = ".txt"; } else if (otype[0].ToLower().Equals("srecord")) { if (otype.Length == 2) { UInt32 temp; otype[1] = otype[1].ToLower(); if (otype[1].StartsWith("0x")) { if (!UInt32.TryParse(otype[1].Replace("0x", ""), NumberStyles.HexNumber, null, out temp)) { Console.WriteLine("ERROR: Invalid S-record address, {0}. Aborting...", otype[1]); myCmdParams.valid = false; } else { myCmdParams.srecAddr = temp; } } else if (UInt32.TryParse(otype[1], out temp)) { myCmdParams.srecAddr = temp; } else { Console.WriteLine("ERROR: Invalid S-record address, {0}. Aborting...", otype[1]); myCmdParams.valid = false; } myCmdParams.convType = ConvType.Exec2Srec; defaultExtension = ".srec"; } else { myCmdParams.valid = false; } } else { myCmdParams.valid = false; } argsHandled[i + 1] = true; numHandledArgs++; break; } case "ini": { myCmdParams.iniFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; } case "o": { myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; } default: { myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; // If we've seen any error, bug out if (!myCmdParams.valid) { break; } } } numUnhandledArgs = args.Length - numHandledArgs; // Check to make sure we are still valid if (!myCmdParams.valid) { return(myCmdParams); } // Get optional input files in order (all unhandled args, if any, are input files) if (numUnhandledArgs != 0) { myCmdParams.inputFileName = new List <String>(numUnhandledArgs); } for (int i = numUnhandledArgs; i > 0; i--) { String[] file = args[args.Length - i].Split('@'); myCmdParams.inputFileName.Add(args[args.Length - i]); } // Set output filename to match input filename, if needed if (myCmdParams.outFileName == null) { if (myCmdParams.inputFileName != null) { String lastFileName = ((String)myCmdParams.inputFileName[myCmdParams.inputFileName.Count - 1]).Split('@')[0]; myCmdParams.outFileName = Path.GetFileNameWithoutExtension(lastFileName) + defaultExtension; } else { myCmdParams.outFileName = "ais_output" + defaultExtension; } } return(myCmdParams); }
/// <summary> /// Main program. /// </summary> /// <param name="args">Input commandline arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code //Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI EMIF2.5 ECC Parity Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Create Reed Solomon ECC Object // Usage: ReedSolomonECC(Int32 msgSymbolCnt, Int32 maxCorrectibleErrorCnt, Byte symbolBitWidth) ReedSolomonECC rs = new ReedSolomonECC(512, 4, 10); // Create binary writer for saving ECC data to output file BinaryWriter bw = new BinaryWriter(new FileStream(cmdParams.outputFileName, FileMode.Create, FileAccess.Write)); // Read input data from file Byte[] fileData = FileIO.GetFileData(cmdParams.inputfileName); Int32[] subArray = new Int32[512]; Int32[] parityArray; for (int i = 0; i < fileData.Length; i += 512) { for (int j = 0; j < 512; j++) { // Swap order of message data since this is apparently what the hardware does // for its RS calculations subArray[511 - j] = ((i + j) >= fileData.Length) ? (0xFF) : ((Int32)fileData[i + j]); } // Calculate parity of the message data parityArray = rs.GenerateParity(subArray); // Prep the parity data and output it to file if (cmdParams.verbose) { Console.WriteLine("NAND operation #{0}", (i / 512) + 1); } for (int j = 0; j < 8; j += 2) { if (cmdParams.verbose) { Console.WriteLine("\tNAND4BITECC{0} = {1:X8}", (j / 2 + 1), ((parityArray[j + 1] & 0x3FF) << 16) | (parityArray[j] & 0x3FF)); } bw.Write(((parityArray[j + 1] & 0x3FF) << 16) | (parityArray[j] & 0x3FF)); } } return(0); }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numUnhandledArgs, numHandledArgs = 0; String defaultExtension; // Set Defaults myCmdParams.valid = true; myCmdParams.outFileName = null; myCmdParams.iniFileName = null; myCmdParams.inputFileName = null; myCmdParams.srecAddr = 0xFFFFFFFF; myCmdParams.entryPoint = 0xFFFFFFFF; myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("-")) { switch (args[i].Substring(1).ToLower()) { case "entrypoint": { UInt32 temp; if (args[i + 1].StartsWith("0x") || args[i + 1].StartsWith("0X")) { if (!UInt32.TryParse(args[i + 1].Replace("0x", ""), NumberStyles.HexNumber, null, out temp)) { Console.WriteLine("WARNING: Invalid entrypoint address, {0}. Ignoring...", args[i + 1]); } else { myCmdParams.entryPoint = temp; } } else if (UInt32.TryParse(args[i + 1], out temp)) { myCmdParams.entryPoint = temp; } else { Console.WriteLine("WARNING: Invalid entrypoint address, {0}. Ignoring...", args[i + 1]); } argsHandled[i + 1] = true; numHandledArgs++; break; } case "otype": { // Handle possible srecord@addr, carray:name case String[] otype = args[i + 1].Split(new Char [] {'@',':'}); if (otype[0].ToLower().Equals("binary")) { myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; } else if (otype[0].ToLower().Equals("carray")) { myCmdParams.convType = ConvType.Exec2CArray; defaultExtension = ".c"; if (otype.Length == 1) { myCmdParams.cArrayName = "data_array"; } else if (otype.Length == 2) { myCmdParams.cArrayName = otype[1]; } else { myCmdParams.valid = false; } } else if (otype[0].ToLower().Equals("text")) { myCmdParams.convType = ConvType.Exec2Text; defaultExtension = ".txt"; } else if (otype[0].ToLower().Equals("srecord")) { if (otype.Length == 2) { UInt32 temp; otype[1] = otype[1].ToLower(); if (otype[1].StartsWith("0x")) { if (!UInt32.TryParse(otype[1].Replace("0x", ""), NumberStyles.HexNumber, null, out temp)) { Console.WriteLine("ERROR: Invalid S-record address, {0}. Aborting...", otype[1]); myCmdParams.valid = false; } else { myCmdParams.srecAddr = temp; } } else if (UInt32.TryParse(otype[1], out temp)) { myCmdParams.srecAddr = temp; } else { Console.WriteLine("ERROR: Invalid S-record address, {0}. Aborting...", otype[1]); myCmdParams.valid = false; } myCmdParams.convType = ConvType.Exec2Srec; defaultExtension = ".srec"; } else { myCmdParams.valid = false; } } else { myCmdParams.valid = false; } argsHandled[i + 1] = true; numHandledArgs++; break; } case "ini": { myCmdParams.iniFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; } case "o": { myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; } default: { myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; // If we've seen any error, bug out if (!myCmdParams.valid) { break; } } } numUnhandledArgs = args.Length - numHandledArgs; // Check to make sure we are still valid if (!myCmdParams.valid) { return myCmdParams; } // Get optional input files in order (all unhandled args, if any, are input files) if (numUnhandledArgs != 0) { myCmdParams.inputFileName = new List<String>(numUnhandledArgs); } for (int i=numUnhandledArgs; i>0; i--) { String[] file = args[args.Length-i].Split('@'); myCmdParams.inputFileName.Add(args[args.Length-i]); } // Set output filename to match input filename, if needed if (myCmdParams.outFileName == null) { if (myCmdParams.inputFileName != null) { String lastFileName = ((String) myCmdParams.inputFileName[myCmdParams.inputFileName.Count - 1]).Split('@')[0]; myCmdParams.outFileName = Path.GetFileNameWithoutExtension(lastFileName) + defaultExtension; } else { myCmdParams.outFileName = "ais_output" + defaultExtension; } } return myCmdParams; }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs,numHandledArgs=0; String s; if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++ ) argsHandled[i] = false; // Set Defualts for parsing myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.inFileName = null; myCmdParams.outFileName = null; myCmdParams.loadAddr = 0xFFFFFFFF; myCmdParams.startAddr = 0xFFFFFFFF; // For loop for required options for(int i = 0; i<args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "pagesize": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); myCmdParams.pageSize = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); } else { myCmdParams.pageSize = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.Number); } argsHandled[i + 1] = true; numHandledArgs++; break; case "blocknum": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); myCmdParams.blockNum = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); } else { myCmdParams.blockNum = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.Number); } argsHandled[i + 1] = true; numHandledArgs++; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // Must have received pageSize, blockNum, and their values if (numHandledArgs != 4) { myCmdParams.valid = false; return myCmdParams; } // For loop for all other dash options for(int i = 0; i<args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "uboot": myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_UBOOT; myCmdParams.valid = true; break; case "startaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.startAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "loadaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.loadAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "o": myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params // We should always expect 1 binary file for input numFiles = 1; // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32) (args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return myCmdParams; } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.inFileName == null) { myCmdParams.inFileName = args[i]; } else { myCmdParams.valid = false; } break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } // end of for loop handling file name inputs // default to UBL usage if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_UBL; // Set output file name to default if (myCmdParams.outFileName == null) { myCmdParams.outFileName = Path.GetFileNameWithoutExtension(myCmdParams.inFileName) + "_withNANDHeader" + Path.GetExtension(myCmdParams.inFileName); } // Set start and load addresses to default if not provided if (myCmdParams.startAddr == 0xFFFFFFFF) { if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_UBL) myCmdParams.startAddr = 0x00000100; else myCmdParams.startAddr = 0x81080000; } if (myCmdParams.loadAddr == 0xFFFFFFFF) { if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_UBL) myCmdParams.loadAddr = 0x00000020; // Not used for UBL, but this is the value the RBL uses else myCmdParams.loadAddr = 0x81080000; } return myCmdParams; }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs,numHandledArgs=0; String s; if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++ ) argsHandled[i] = false; // Set Defualts for application myCmdParams.UBLFlashType = FlashType.NONE; myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.SerialPortName = null; myCmdParams.SerialPortBaudRate = 115200; myCmdParams.deviceType = null; myCmdParams.flashType = null; myCmdParams.APPMagicFlag = MagicFlags.UBL_MAGIC_BINARY_BOOT; myCmdParams.APPMagicFlagLeg = MagicFlags.UBL_MAGIC_BINARY_BOOT_LEG; myCmdParams.APPFileName = null; myCmdParams.APPLoadAddr = 0xFFFFFFFF; myCmdParams.APPStartAddr = 0xFFFFFFFF; myCmdParams.APPFlashAddr = 0xFFFFFFFF; myCmdParams.APPFlashBlock = 0xFFFFFFFF; myCmdParams.UBLMagicFlag = MagicFlags.UBL_MAGIC_BINARY_BOOT; myCmdParams.DSPUBLMagicFlag = MagicFlags.UBL_MAGIC_BINARY_BOOT; myCmdParams.ARMUBLMagicFlag = MagicFlags.UBL_MAGIC_BINARY_BOOT; myCmdParams.UBLFileName = null; myCmdParams.DSPUBLFileName = null; myCmdParams.ARMUBLFileName = null; myCmdParams.UBLStartAddr = 0xFFFFFFFF; // For loop for required command-line params for(int i = 0; i<args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "flash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_FLASH; } else { myCmdParams.valid = false; } numFiles = 2; cmdString += " [TYPE] UBL and application image\n"; break; case "flash_noubl": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_FLASH_NO_UBL; } else { myCmdParams.valid = false; } numFiles = 1; cmdString += " [TYPE] Single boot image\n"; break; case "flash_dsp": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_FLASH_DSP; } else { myCmdParams.valid = false; } numFiles = 3; cmdString += " [TYPE] DSP UBL, ARM UBL, and application image\n"; break; case "erase": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_ERASE; } else { myCmdParams.valid = false; } cmdString += " [TYPE] Global erase\n"; numFiles = 0; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params // Check to make sure a command was selected if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.valid = false; return myCmdParams; } // For loop for optional command-line params try { for(int i = 0; i<args.Length; i++) { Int32 index; s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "targettype": index = Array.IndexOf<String>(deviceTypes,args[i + 1]); myCmdParams.deviceType = (index < 0)?deviceTypes[0]:deviceTypes[index]; if (index < 0) { Console.WriteLine("Target type not recongnized"); myCmdParams.valid = false; } argsHandled[i + 1] = true; numHandledArgs++; break; case "flashtype": index = Array.IndexOf<String>(flashTypes,args[i + 1]); myCmdParams.flashType = (index < 0)?flashTypes[0]:flashTypes[index]; if (index < 0) { Console.WriteLine("Flash type not recongnized, using default ({0}).",myCmdParams.flashType); } argsHandled[i + 1] = true; numHandledArgs++; break; case "appstartaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPStartAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "apploadaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPLoadAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "appflashblock": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPFlashBlock = System.UInt32.Parse(args[i + 1]); argsHandled[i + 1] = true; numHandledArgs++; break; case "ublstartaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.UBLStartAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "p": myCmdParams.SerialPortName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "baud": myCmdParams.SerialPortBaudRate = System.Int32.Parse(args[i + 1]); argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params } catch(Exception e) { Console.WriteLine(e.Message); myCmdParams.valid = false; return myCmdParams; } // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32) (args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return myCmdParams; } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += "[BOOT IMAGE] " + myCmdParams.APPFileName + "\n" ; } else myCmdParams.valid = false; break; case 2: if (myCmdParams.UBLFileName == null) { myCmdParams.UBLFileName = args[i]; cmdString += " [UBL] "+ myCmdParams.UBLFileName + "\n"; } else if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += " [APP IMAGE] " + myCmdParams.APPFileName + "\n"; } else myCmdParams.valid = false; break; case 3: if (myCmdParams.DSPUBLFileName == null) { myCmdParams.DSPUBLFileName = args[i]; cmdString += " [DSP UBL] "+ myCmdParams.DSPUBLFileName + "\n"; } else if (myCmdParams.ARMUBLFileName == null) { myCmdParams.ARMUBLFileName = args[i]; cmdString += " [ARM UBL] "+ myCmdParams.ARMUBLFileName + "\n"; } else if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += " [APP IMAGE] " + myCmdParams.APPFileName + "\n"; } else myCmdParams.valid = false; break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; if (!myCmdParams.valid) return myCmdParams; } // end of for loop for handling dash params // Set default binary execution address on target device if (myCmdParams.APPLoadAddr == 0xFFFFFFFF) { myCmdParams.APPLoadAddr = externalRAMStart + 0x01080000; } if (myCmdParams.APPStartAddr == 0xFFFFFFFF) { myCmdParams.APPStartAddr = externalRAMStart + 0x01080000; } if (myCmdParams.UBLStartAddr == 0xFFFFFFFF) myCmdParams.UBLStartAddr = 0x00000100; myCmdParams.ARMUBLStartAddr = 0x80000000; if (myCmdParams.deviceType == null) { myCmdParams.deviceType = deviceTypes[0]; } if (myCmdParams.flashType == null) { myCmdParams.flashType = flashTypes[0]; } if (myCmdParams.APPFlashBlock == 0xFFFFFFFF) { if(myCmdParams.flashType == "NAND") { myCmdParams.APPFlashBlock = 1; } else { myCmdParams.APPFlashBlock = 0; } } //Setup default serial port name if (myCmdParams.SerialPortName == null) { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) //Check for unix/linux { Console.WriteLine("Platform is Unix/Linux."); myCmdParams.SerialPortName = "/dev/ttyS0"; } else { Console.WriteLine("Platform is Windows."); myCmdParams.SerialPortName = "COM1"; } } // Prep command string cmdString += " [TARGET] " + myCmdParams.deviceType + "\n"; cmdString = cmdString + " [DEVICE] " + myCmdParams.flashType+ "\n"; if(myCmdParams.flashType == "SPI_MEM") { cmdString = cmdString + " [SPI Block] " + myCmdParams.APPFlashBlock + "\n"; } else if(myCmdParams.flashType =="NAND") { cmdString = cmdString + " [NAND Block] " + myCmdParams.APPFlashBlock; } else if(myCmdParams.flashType =="NOR") { cmdString = cmdString + " [NOR Block] " + myCmdParams.APPFlashBlock; } else cmdString = cmdString + " [UNKNOWN Flash Address] " + myCmdParams.APPFlashBlock; return myCmdParams; }
/// <summary> /// Main entry point of application /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime( v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2 ).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI Binary Creator for " + devString ); Console.WriteLine(" (C) "+buildYear+", Texas Instruments, Inc." ); Console.WriteLine(" Ver. "+v.Major+"."+v.Minor.ToString("D2") ); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse command line cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return -1; } Console.WriteLine("Preparing binary image with header prepended...\n"); Console.WriteLine(" Intended NAND device has {0} byte pages.",cmdParams.pageSize); Console.WriteLine(" Image intended for block {0}.",cmdParams.blockNum); Console.WriteLine(" Image entry point is 0x{0:X8}.",cmdParams.startAddr); Console.WriteLine(" Image load address is 0x{0:X8}.",cmdParams.loadAddr); // Setup the thread that will actually do all the work of interfacing to // the Device boot ROM. Start that thread. workerThread = new Thread(new ThreadStart(Program.WorkerThreadStart)); workerThread.Start(); // Wait for a key to terminate the program while ((workerThread.IsAlive) && (!Console.KeyAvailable)) { Thread.Sleep(1000); } // If a key is pressed then abort the worker thread and close the serial port try { if (Console.KeyAvailable) { Console.ReadKey(); Console.WriteLine("Aborting program..."); 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("\nOperation did NOT complete successfully."); return -1; } }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> private static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; UInt32 numUnhandledArgs, numHandledArgs = 0; String s,defaultExtension; // Check for no argumnents if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Set Defaults myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.outputFileName = null; myCmdParams.inputfileName = null; defaultExtension = "_eccdata.bin"; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) argsHandled[i] = false; // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "o": myCmdParams.outputFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; } } numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); // Check to make sure we are still valid if ( (!myCmdParams.valid) || (numUnhandledArgs != 1) || (argsHandled[args.Length-1])) { myCmdParams.valid = false; return myCmdParams; } // Get input file FileInfo fi = new FileInfo(args[args.Length-1]); if (fi.Exists) { myCmdParams.inputfileName = args[args.Length - 1]; String extension = Path.GetExtension(fi.Name); if (myCmdParams.outputFileName == null) { myCmdParams.outputFileName = Path.GetFileNameWithoutExtension(fi.Name) + defaultExtension; } } else { Console.WriteLine("File not found."); myCmdParams.valid = false; return myCmdParams; } return myCmdParams; }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> private static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; UInt32 numUnhandledArgs, numHandledArgs = 0; String s, defaultExtension; // Check for no argumnents if (args.Length == 0) { myCmdParams.valid = false; return(myCmdParams); } // Set Defaults myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.outputFileName = null; myCmdParams.inputfileName = null; defaultExtension = "_eccdata.bin"; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "o": myCmdParams.outputFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; } } numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); // Check to make sure we are still valid if ((!myCmdParams.valid) || (numUnhandledArgs != 1) || (argsHandled[args.Length - 1])) { myCmdParams.valid = false; return(myCmdParams); } // Get input file FileInfo fi = new FileInfo(args[args.Length - 1]); if (fi.Exists) { myCmdParams.inputfileName = args[args.Length - 1]; String extension = Path.GetExtension(fi.Name); if (myCmdParams.outputFileName == null) { myCmdParams.outputFileName = Path.GetFileNameWithoutExtension(fi.Name) + defaultExtension; } } else { Console.WriteLine("File not found."); myCmdParams.valid = false; return(myCmdParams); } return(myCmdParams); }
/// <summary> /// Function to parse the command line /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Struct of the filled in program arguments</returns> static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; UInt32 numUnhandledArgs, numHandledArgs = 0; String s,defaultExtension; // Check for no argumnents if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Set Defaults myCmdParams.valid = true; myCmdParams.outFileName = null; myCmdParams.iniFileName = null; myCmdParams.inputfileName = null; myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) argsHandled[i] = false; // For loop to check for all dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "otype": String temp = args[i + 1]; if (temp.ToLower().Equals("binary")) { myCmdParams.convType = ConvType.Exec2Bin; defaultExtension = ".bin"; } else if (temp.ToLower().Equals("carray")) { myCmdParams.convType = ConvType.Exec2CArray; defaultExtension = ".c"; } else if (temp.ToLower().Equals("srecord")) { myCmdParams.convType = ConvType.Exec2Srec; defaultExtension = ".srec"; } else if (temp.ToLower().Equals("text")) { myCmdParams.convType = ConvType.Exec2Text; defaultExtension = ".txt"; } else { myCmdParams.valid = false; } argsHandled[i + 1] = true; numHandledArgs++; break; case "ini": myCmdParams.iniFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "o": myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; } } numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); // Check to make sure we are still valid if ( (!myCmdParams.valid)) { return myCmdParams; } // Check to see if one last arg is still left - if so it is input object filename if ((numUnhandledArgs == 1) && (!argsHandled[args.Length-1])) { // Get input file FileInfo fi = new FileInfo(args[args.Length-1]); if (fi.Exists) { myCmdParams.inputfileName = args[args.Length - 1]; String extension = Path.GetExtension(fi.Name); if (myCmdParams.outFileName == null) { myCmdParams.outFileName = Path.GetFileNameWithoutExtension(fi.Name) + defaultExtension; } } } if (myCmdParams.outFileName == null) { myCmdParams.outFileName = devString + "_boot_image.ais"; } return myCmdParams; }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs, numHandledArgs = 0; String s; if (args.Length == 0) { myCmdParams.valid = false; return(myCmdParams); } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // Set Defualts for application myCmdParams.UBLFlashType = FlashType.NONE; myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.SerialPortName = null; myCmdParams.SerialPortBaudRate = 115200; myCmdParams.APPMagicFlag = MagicFlags.UBL_MAGIC_SAFE; myCmdParams.APPFileName = null; myCmdParams.APPLoadAddr = 0xFFFFFFFF; myCmdParams.APPStartAddr = 0xFFFFFFFF; #if DM35x_REVC myCmdParams.UBLMagicFlag = MagicFlags.UBL_MAGIC_SAFE_DM35x_REVC; #else myCmdParams.UBLMagicFlag = MagicFlags.UBL_MAGIC_SAFE; #endif myCmdParams.UBLFileName = null; myCmdParams.UBLStartAddr = 0xFFFFFFFF; // For loop for required command type for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "norflash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NOR_FLASH; } else { myCmdParams.valid = false; } numFiles = 2; myCmdParams.UBLFlashType = FlashType.NOR; cmdString = "Flashing NOR with "; break; case "norflash_noubl": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NOR_FLASH_NO_UBL; } else { myCmdParams.valid = false; } numFiles = 1; myCmdParams.UBLFlashType = FlashType.NOR; cmdString = "Flashing NOR with "; break; case "sdflash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_SDMMC_FLASH; } else { myCmdParams.valid = false; } numFiles = 2; myCmdParams.UBLFlashType = FlashType.SD_MMC; cmdString = "Flashing SD/MMC with "; break; case "nandflash": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NAND_FLASH; } else { myCmdParams.valid = false; } numFiles = 2; myCmdParams.UBLFlashType = FlashType.NAND; cmdString = "Flashing NAND with "; break; case "norerase": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NOR_ERASE; } else { myCmdParams.valid = false; } numFiles = 0; myCmdParams.UBLFlashType = FlashType.NOR; cmdString = "Globally erasing NOR flash."; break; case "nanderase": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.UBL_MAGIC_NAND_ERASE; } else { myCmdParams.valid = false; } numFiles = 0; myCmdParams.UBLFlashType = FlashType.NAND; cmdString = "Globally erasing NAND flash."; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } } // end of for loop for handling dash params // Check to make sure a command was selected if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.valid = false; return(myCmdParams); } // For loop for all other dash options try { for (int i = 0; i < args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "appstartaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.APPStartAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "apploadaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.APPLoadAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "ublstartaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.UBLStartAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "p": myCmdParams.SerialPortName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "baud": myCmdParams.SerialPortBaudRate = System.Int32.Parse(args[i + 1]); argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } } // end of for loop for handling dash params } catch (Exception e) { Console.WriteLine(e.Message); myCmdParams.valid = false; return(myCmdParams); } // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return(myCmdParams); } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += myCmdParams.APPFileName + "."; } else { myCmdParams.valid = false; } break; case 2: if (myCmdParams.UBLFileName == null) { myCmdParams.UBLFileName = args[i]; cmdString += myCmdParams.UBLFileName + " and "; } else if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; cmdString += myCmdParams.APPFileName + "."; } else { myCmdParams.valid = false; } break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; if (!myCmdParams.valid) { return(myCmdParams); } } // end of for loop for handling dash params // Set default binary execution address on target device if (myCmdParams.APPLoadAddr == 0xFFFFFFFF) { myCmdParams.APPLoadAddr = 0x81080000; } if (myCmdParams.APPStartAddr == 0xFFFFFFFF) { myCmdParams.APPStartAddr = 0x81080000; } if (myCmdParams.UBLStartAddr == 0xFFFFFFFF) { myCmdParams.UBLStartAddr = 0x00000100; } //Setup default serial port name if (myCmdParams.SerialPortName == null) { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) //Check for unix/linux { Console.WriteLine("Platform is Unix/Linux."); myCmdParams.SerialPortName = "/dev/ttyS0"; } else { Console.WriteLine("Platform is Windows."); myCmdParams.SerialPortName = "COM1"; } } return(myCmdParams); }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs, numHandledArgs = 0; String s; if (args.Length == 0) { myCmdParams.valid = false; return(myCmdParams); } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++) { argsHandled[i] = false; } // Set Defualts for parsing myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.inFileName = null; myCmdParams.outFileName = null; myCmdParams.loadAddr = 0xFFFFFFFF; myCmdParams.startAddr = 0xFFFFFFFF; // For loop for required options for (int i = 0; i < args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "pagesize": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); myCmdParams.pageSize = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); } else { myCmdParams.pageSize = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.Number); } argsHandled[i + 1] = true; numHandledArgs++; break; case "blocknum": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); myCmdParams.blockNum = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); } else { myCmdParams.blockNum = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.Number); } argsHandled[i + 1] = true; numHandledArgs++; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } } // Must have received pageSize, blockNum, and their values if (numHandledArgs != 4) { myCmdParams.valid = false; return(myCmdParams); } // For loop for all other dash options for (int i = 0; i < args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "uboot": myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_UBOOT; myCmdParams.valid = true; break; case "startaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.startAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "loadaddr": if (args[i + 1].StartsWith("0x")) { args[i + 1] = args[i + 1].Substring(2); } myCmdParams.loadAddr = System.UInt32.Parse(args[i + 1], System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "o": myCmdParams.outFileName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } } // end of for loop for handling dash params // We should always expect 1 binary file for input numFiles = 1; // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32)(args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return(myCmdParams); } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.inFileName == null) { myCmdParams.inFileName = args[i]; } else { myCmdParams.valid = false; } break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) { return(myCmdParams); } } // end of for loop handling file name inputs // default to UBL usage if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_UBL; } // Set output file name to default if (myCmdParams.outFileName == null) { myCmdParams.outFileName = Path.GetFileNameWithoutExtension(myCmdParams.inFileName) + "_withNANDHeader" + Path.GetExtension(myCmdParams.inFileName); } // Set start and load addresses to default if not provided if (myCmdParams.startAddr == 0xFFFFFFFF) { if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_UBL) { myCmdParams.startAddr = 0x00000100; } else { myCmdParams.startAddr = 0x81080000; } } if (myCmdParams.loadAddr == 0xFFFFFFFF) { if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_UBL) { myCmdParams.loadAddr = 0x00000020; // Not used for UBL, but this is the value the RBL uses } else { myCmdParams.loadAddr = 0x81080000; } } return(myCmdParams); }
/// <summary> /// Main entry point of application /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI Serial Loader Host Program for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse command line cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } else { Console.Write(cmdString + "\n\n\n"); } try { Console.WriteLine("Attempting to connect to device " + cmdParams.SerialPortName + "..."); MySP = new SerialPort(cmdParams.SerialPortName, 115200, Parity.None, 8, StopBits.One); MySP.Encoding = Encoding.ASCII; MySP.Open(); } catch (Exception e) { if (e is UnauthorizedAccessException) { Console.WriteLine(e.Message); Console.WriteLine("This application failed to open the COM port."); Console.WriteLine("Most likely it is in use by some other application."); return(-1); } Console.WriteLine(e.Message); return(-1); } Console.WriteLine("Press any key to end this program at any time.\n"); // Setup the thread that will actually do all the work of interfacing to // the Device boot ROM. Start that thread. workerThread = new Thread(new ThreadStart(Program.WorkerThreadStart)); workerThread.Start(); // Wait for a key to terminate the program while ((workerThread.IsAlive) && (!Console.KeyAvailable)) { Thread.Sleep(1000); } // If a key is pressed then abort the worker thread and close the serial port try { if (Console.KeyAvailable) { Console.ReadKey(); Console.WriteLine("Aborting program..."); 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 " + devString + " via UART failed." + "\nPlease reset or power-cycle the board and try again..."); return(-1); } }
/// <summary> /// Main entry point of application /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI Binary Creator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse command line cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } Console.WriteLine("Preparing binary image with header prepended...\n"); Console.WriteLine(" Intended NAND device has {0} byte pages.", cmdParams.pageSize); Console.WriteLine(" Image intended for block {0}.", cmdParams.blockNum); Console.WriteLine(" Image entry point is 0x{0:X8}.", cmdParams.startAddr); Console.WriteLine(" Image load address is 0x{0:X8}.", cmdParams.loadAddr); // Setup the thread that will actually do all the work of interfacing to // the Device boot ROM. Start that thread. workerThread = new Thread(new ThreadStart(Program.WorkerThreadStart)); workerThread.Start(); // Wait for a key to terminate the program while ((workerThread.IsAlive) && (!Console.KeyAvailable)) { Thread.Sleep(1000); } // If a key is pressed then abort the worker thread and close the serial port try { if (Console.KeyAvailable) { Console.ReadKey(); Console.WriteLine("Aborting program..."); 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("\nOperation did NOT complete successfully."); return(-1); } }
/// <summary> /// Main entry point of application /// </summary> /// <param name="args">Array of command-line arguments</param> /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime( v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2 ).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI Serial Flasher Host Program for " + devString ); Console.WriteLine(" (C) "+buildYear+", Texas Instruments, Inc." ); Console.WriteLine(" Ver. "+v.Major+"."+v.Minor.ToString("D2") ); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse command line cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return -1; } else { Console.Write(cmdString + "\n\n\n"); } try { Console.WriteLine("Attempting to connect to device " + cmdParams.SerialPortName + "..."); MySP = new SerialPort(cmdParams.SerialPortName, cmdParams.SerialPortBaudRate, Parity.None, 8, StopBits.One); MySP.Encoding = Encoding.ASCII; MySP.Open(); } catch(Exception e) { if (e is UnauthorizedAccessException) { Console.WriteLine(e.Message); Console.WriteLine("This application failed to open the COM port."); Console.WriteLine("Most likely it is in use by some other application."); return -1; } Console.WriteLine(e.Message); return -1; } Console.WriteLine("Press any key to end this program at any time.\n"); // Setup the thread that will actually do all the work of interfacing to // the Device boot ROM. Start that thread. workerThread = new Thread(new ThreadStart(Program.WorkerThreadStart)); workerThread.Start(); // Wait for a key to terminate the program while ((workerThread.IsAlive) && (!Console.KeyAvailable)) { Thread.Sleep(1000); } // If a key is pressed then abort the worker thread and close the serial port try { if (Console.KeyAvailable) { Console.ReadKey(); Console.WriteLine("Aborting program..."); 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 "+devString+" via UART failed." + "\nPlease reset or power-cycle the board and try again..."); return -1; } }
/// <summary> /// Parse the command line into the appropriate internal command structure /// </summary> /// <param name="args">The array of strings passed to the command line.</param> public static ProgramCmdParams ParseCmdLine(String[] args) { ProgramCmdParams myCmdParams = new ProgramCmdParams(); Boolean[] argsHandled = new Boolean[args.Length]; Int32 numFiles = -1; UInt32 numUnhandledArgs,numHandledArgs=0; String s; if (args.Length == 0) { myCmdParams.valid = false; return myCmdParams; } // Initialize array of handled argument booleans to false for (int i = 0; i < argsHandled.Length; i++ ) argsHandled[i] = false; // Set Defualts for application myCmdParams.CMDMagicFlag = MagicFlags.MAGIC_NUMBER_INVALID; myCmdParams.valid = true; myCmdParams.verbose = false; myCmdParams.SerialPortName = null; myCmdParams.APPFileName = null; myCmdParams.APPLoadAddr = 0xFFFFFFFF; myCmdParams.APPStartAddr = 0xFFFFFFFF; // For loop for required load type for(int i = 0; i<args.Length; i++) { s = args[i]; if (s.StartsWith("-")) { switch (s.Substring(1).ToLower()) { case "load2iram": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.SLT_MAGIC_LOADIMAGE_IRAM; else myCmdParams.valid = false; myCmdParams.APPLoadAddr = 0x0020; myCmdParams.APPStartAddr = 0x0100; numFiles = 1; cmdString = "Loading image to ARM IRAM "; break; case "load2ddr": if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) myCmdParams.CMDMagicFlag = MagicFlags.SLT_MAGIC_LOADIMAGE_DDR; else myCmdParams.valid = false; myCmdParams.APPLoadAddr = 0x80000000; myCmdParams.APPStartAddr = 0x80000000; numFiles = 1; cmdString = "Loading image to DDR"; break; default: continue; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } if (myCmdParams.CMDMagicFlag == MagicFlags.MAGIC_NUMBER_INVALID) { myCmdParams.valid = false; return myCmdParams; } // For loop for all other dash options for(int i = 0; i<args.Length; i++) { s = args[i]; if ((s.StartsWith("-")) && (argsHandled[i] != true)) { switch (s.Substring(1).ToLower()) { case "startaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPStartAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "loadaddr": if (args[i + 1].StartsWith("0x")) args[i + 1] = args[i + 1].Substring(2); myCmdParams.APPLoadAddr = System.UInt32.Parse(args[i + 1],System.Globalization.NumberStyles.AllowHexSpecifier); argsHandled[i + 1] = true; numHandledArgs++; break; case "p": myCmdParams.SerialPortName = args[i + 1]; argsHandled[i + 1] = true; numHandledArgs++; break; case "v": myCmdParams.verbose = true; break; default: myCmdParams.valid = false; break; } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } } // end of for loop for handling dash params // Verify that the number of unhandled arguments is equal to numFiles // If not, then there is a problem. numUnhandledArgs = (UInt32) (args.Length - numHandledArgs); if (numUnhandledArgs != numFiles) { myCmdParams.valid = false; return myCmdParams; } // This for loop handles all othe params (namely filenames) for (int i = 0; i < args.Length; i++) { if (!argsHandled[i]) { switch (numFiles) { case 1: if (myCmdParams.APPFileName == null) { myCmdParams.APPFileName = args[i]; } else myCmdParams.valid = false; break; default: myCmdParams.valid = false; break; } } argsHandled[i] = true; numHandledArgs++; if (!myCmdParams.valid) return myCmdParams; } // end of for loop handling file name inputs //Setup default serial port name if (myCmdParams.SerialPortName == null) { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) //Check for unix/linux { Console.WriteLine("Platform is Unix/Linux."); myCmdParams.SerialPortName = "/dev/ttyS0"; } else { Console.WriteLine("Platform is Windows."); myCmdParams.SerialPortName = "COM1"; } } return myCmdParams; }