public static retType InsertSecureAISCommandViaINI(AISGen devAISGen, IniSection sec) { #region Handle Input Binary and Object Files if (sec.sectionName.Equals("INPUTFILE", StringComparison.OrdinalIgnoreCase)) { String fileName = null; Boolean useEntryPoint = false, encryptSections = false; UInt32 loadAddr = 0x00000000; UInt32 entryPointAddr = 0x00000000; foreach (DictionaryEntry de in sec.sectionValues) { // File name for binary section data if (((String)de.Key).Equals("FILENAME", StringComparison.OrdinalIgnoreCase)) { fileName = (String) sec.sectionValues["FILENAME"]; } // Binary section's load address in the memory map if (((String)de.Key).Equals("LOADADDRESS", StringComparison.OrdinalIgnoreCase)) { loadAddr = (UInt32) sec.sectionValues["LOADADDRESS"]; } // Binary section's entry point address in the memory map if (((String)de.Key).Equals("ENTRYPOINTADDRESS", StringComparison.OrdinalIgnoreCase)) { entryPointAddr = (UInt32) sec.sectionValues["ENTRYPOINTADDRESS"]; } // Option to specify that this entry point should be used for AIS if (((String)de.Key).Equals("USEENTRYPOINT", StringComparison.OrdinalIgnoreCase)) { if (((String)sec.sectionValues["USEENTRYPOINT"]).Equals("YES", StringComparison.OrdinalIgnoreCase)) useEntryPoint = true; if (((String)sec.sectionValues["USEENTRYPOINT"]).Equals("TRUE", StringComparison.OrdinalIgnoreCase)) useEntryPoint = true; } // Binary section's entry point address in the memory map if (((String)de.Key).Equals("ENCRYPT", StringComparison.OrdinalIgnoreCase)) { if (((String)sec.sectionValues["ENCRYPT"]).Equals("YES", StringComparison.OrdinalIgnoreCase)) encryptSections = true; if (((String)sec.sectionValues["ENCRYPT"]).Equals("TRUE", StringComparison.OrdinalIgnoreCase)) encryptSections = true; } } if (fileName == null) { Console.WriteLine("ERROR: File name must be provided in INPUTFILE section."); return retType.FAIL; } // Insert the file into the AIS image if ( loadAddr != 0x00000000) { // binary image if ( entryPointAddr != 0x00000000) { devAISGen.InsertAISSecureObjectFile(fileName, loadAddr, entryPointAddr, encryptSections); } else { devAISGen.InsertAISSecureObjectFile(fileName, loadAddr, encryptSections); } } else { devAISGen.InsertAISSecureObjectFile(fileName, useEntryPoint, encryptSections); } } #endregion #region Handle ROM and AIS Extra Functions // Handle ROM functions if (devAISGen.ROMFunc != null) { for (UInt32 j = 0; j < devAISGen.ROMFunc.Length; j++) { if (sec.sectionName.Equals(devAISGen.ROMFunc[j].iniSectionName, StringComparison.OrdinalIgnoreCase)) { UInt32 funcIndex = j; UInt32[] args = new UInt32[ (UInt32)devAISGen.ROMFunc[funcIndex].numParams ]; for (Int32 k = 0; k < devAISGen.ROMFunc[funcIndex].numParams; k++) { //FIXME Debug.DebugMSG("\tParam name: {0}, Param num: {1}, Value: {2}\n", devAISGen.ROMFunc[funcIndex].paramNames[k], k, sec.sectionValues[devAISGen.ROMFunc[funcIndex].paramNames[k].ToUpper()]); args[k] = (UInt32) sec.sectionValues[devAISGen.ROMFunc[funcIndex].paramNames[k].ToUpper()]; } devAISGen.InsertAISFunctionExecute((UInt16) funcIndex, (UInt16) devAISGen.ROMFunc[funcIndex].numParams, args); // Insert signature InsertAISSecureSignature(devAISGen); } } } // Handle AISExtras functions if (devAISGen.AISExtraFunc != null) { for (UInt32 j = 0; j < devAISGen.AISExtraFunc.Length; j++) { if (sec.sectionName.Equals(devAISGen.AISExtraFunc[j].iniSectionName, StringComparison.OrdinalIgnoreCase)) { UInt32 funcIndex = j; // Load the AIS extras file if needed { IniSection tempSec = new IniSection(); tempSec.sectionName = "INPUTFILE"; tempSec.sectionValues = new Hashtable(); tempSec.sectionValues["FILENAME"] = devAISGen.AISExtraFunc[funcIndex].aisExtraFileName; EmbeddedFileIO.ExtractFile(Assembly.GetExecutingAssembly(), devAISGen.AISExtraFunc[funcIndex].aisExtraFileName, true); InsertAISCommandViaINI(devAISGen, tempSec); // Use symbols to get address for AISExtra functions and parameters for (Int32 k = 0; k < devAISGen.AISExtraFunc.Length; k++) { ObjectFile tempFile = FindFileWithSymbol(devAISGen, devAISGen.AISExtraFunc[funcIndex].funcName); if (tempFile == null) { // Try looking for underscore version tempFile = FindFileWithSymbol(devAISGen, "_" + devAISGen.AISExtraFunc[funcIndex].funcName); } if (tempFile != null) { ObjectSymbol tempSym = tempFile.symFind(devAISGen.AISExtraFunc[funcIndex].funcName); if (tempSym == null) { // Try looking for underscore version tempSym = tempFile.symFind("_"+devAISGen.AISExtraFunc[funcIndex].funcName); } devAISGen.AISExtraFunc[funcIndex].funcAddr = (UInt32) tempSym.value; tempSym = tempFile.symFind(".params"); devAISGen.AISExtraFunc[funcIndex].paramAddr = (UInt32) tempSym.value; } else { // The function name was not found - that's a big problem with our // device specific AISGen class. Console.WriteLine("AIS extra function, {0}, not found in file {1}.", devAISGen.AISExtraFunc[funcIndex].funcName, devAISGen.AISExtraFunc[funcIndex].aisExtraFileName); return retType.FAIL; } } } for (Int32 k = 0; k < devAISGen.AISExtraFunc[funcIndex].numParams; k++) { // Write SET command devAISGen.InsertAISSet( (UInt32)0x3, // Write type field (32-bit only) (UInt32) (devAISGen.AISExtraFunc[funcIndex].paramAddr + (k * 4)), (UInt32)sec.sectionValues[devAISGen.AISExtraFunc[funcIndex].paramNames[k].ToString()], (UInt32)0x0 ); // Write Sleep value (should always be zero) // Insert signature InsertAISSecureSignature(devAISGen); } // Now that params are set, Jump to function devAISGen.InsertAISJump(devAISGen.AISExtraFunc[funcIndex].funcAddr); // Insert signature InsertAISSecureSignature(devAISGen); } } } #endregion #region Handle AIS Command Sections if (sec.sectionName.Equals("AIS_EnableCRC", StringComparison.OrdinalIgnoreCase)) { devAISGen.InsertAISEnableCRC(); } if (sec.sectionName.Equals("AIS_DisableCRC", StringComparison.OrdinalIgnoreCase)) { devAISGen.InsertAISDisableCRC(); } if (sec.sectionName.Equals("AIS_RequestCRC", StringComparison.OrdinalIgnoreCase)) { UInt32 crcValue = 0x00000000; Int32 seekValue = -12; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("CRCValue", StringComparison.OrdinalIgnoreCase)) { crcValue = (UInt32)sec.sectionValues["CRCVALUE"]; } if (((String)de.Key).Equals("SEEKValue", StringComparison.OrdinalIgnoreCase)) { seekValue = (Int32)sec.sectionValues["SEEKVALUE"]; } } if (devAISGen.InsertAISRequestCRC(crcValue, seekValue) != retType.SUCCESS) { Console.WriteLine("WARNING: Final function register AIS command failed."); } } if (sec.sectionName.Equals("AIS_Jump", StringComparison.OrdinalIgnoreCase)) { String symbolName = ""; UInt32 address = 0x00000000; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("LOCATION", StringComparison.OrdinalIgnoreCase)) { symbolName = (String)sec.sectionValues["LOCATION"]; } } // See if string is number (address) if (UInt32.TryParse(symbolName, out address)) { if (devAISGen.InsertAISJump(address) != retType.SUCCESS) { Console.WriteLine("WARNING: AIS Jump to {0} was not inserted.",symbolName); } } else { if (devAISGen.InsertAISJump(symbolName) != retType.SUCCESS) { Console.WriteLine("WARNING: AIS Jump to {0} was not inserted.",symbolName); } } // Insert signature InsertAISSecureSignature(devAISGen); } if (sec.sectionName.Equals("AIS_JumpClose", StringComparison.OrdinalIgnoreCase)) { String symbolName = ""; UInt32 address = 0x00000000; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("ENTRYPOINT", StringComparison.OrdinalIgnoreCase)) { symbolName = (String)sec.sectionValues["ENTRYPOINT"]; } } if (symbolName == "") { devAISGen.InsertAISJumpClose(devAISGen.entryPoint); } else { // See if string is number (address) if (UInt32.TryParse(symbolName, out address)) { if (devAISGen.InsertAISJumpClose(address) != retType.SUCCESS) { Console.WriteLine("WARNING: AIS Jump to {0} was not inserted.",symbolName); } } else { if (devAISGen.InsertAISJumpClose(symbolName) != retType.SUCCESS) { Console.WriteLine("WARNING: AIS Jump to {0} was not inserted.",symbolName); } } } // Insert signature InsertAISSecureSignature(devAISGen); } if (sec.sectionName.Equals("AIS_Set", StringComparison.OrdinalIgnoreCase)) { UInt32 type = 0x00000000; UInt32 address = 0x00000000; UInt32 data = 0x00000000; UInt32 sleep = 0x00000000; foreach (DictionaryEntry de in sec.sectionValues) { if (sec.sectionValues["TYPE"].GetType() == typeof(String)) { if (((String)de.Key).Equals("TYPE", StringComparison.OrdinalIgnoreCase)) { if (! UInt32.TryParse((String)sec.sectionValues["TYPE"], out type)) { try { type = (UInt32)Enum.Parse(typeof(AisSetType),(String)sec.sectionValues["TYPE"]); } catch (ArgumentException e) { Console.WriteLine((String)sec.sectionValues["TYPE"] + " is not allowed specifier for SET type."); Console.WriteLine(e.Message); return retType.FAIL; } } } } else { type = (UInt32)sec.sectionValues["TYPE"]; } if (((String)de.Key).Equals("ADDRESS", StringComparison.OrdinalIgnoreCase)) { address = (UInt32)sec.sectionValues["ADDRESS"]; } if (((String)de.Key).Equals("DATA", StringComparison.OrdinalIgnoreCase)) { data = (UInt32)sec.sectionValues["DATA"]; } if (((String)de.Key).Equals("SLEEP", StringComparison.OrdinalIgnoreCase)) { sleep = (UInt32)sec.sectionValues["SLEEP"]; } } devAISGen.InsertAISSet(type, address, data, sleep); // Insert signature InsertAISSecureSignature(devAISGen); } if (sec.sectionName.Equals("AIS_SectionFill", StringComparison.OrdinalIgnoreCase)) { UInt32 address = 0x00000000; UInt32 size = 0x00000000; UInt32 type = 0x00000000; UInt32 pattern = 0x00000000; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("ADDRESS", StringComparison.OrdinalIgnoreCase)) { address = (UInt32)sec.sectionValues["ADDRESS"]; } if (((String)de.Key).Equals("SIZE", StringComparison.OrdinalIgnoreCase)) { size = (UInt32)sec.sectionValues["SIZE"]; } if (((String)de.Key).Equals("TYPE", StringComparison.OrdinalIgnoreCase)) { type = (UInt32)sec.sectionValues["TYPE"]; } if (((String)de.Key).Equals("PATTERN", StringComparison.OrdinalIgnoreCase)) { pattern = (UInt32)sec.sectionValues["PATTERN"]; } } devAISGen.InsertAISSectionFill( address, size, type, pattern); } if (sec.sectionName.Equals("AIS_FastBoot", StringComparison.OrdinalIgnoreCase)) { devAISGen.InsertAISFastBoot(); } if (sec.sectionName.Equals("AIS_ReadWait", StringComparison.OrdinalIgnoreCase)) { UInt32 address = 0x00000000; UInt32 mask = 0xFFFFFFFF; UInt32 data = 0xFFFFFFFF; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("ADDRESS", StringComparison.OrdinalIgnoreCase)) { address = (UInt32)sec.sectionValues["ADDRESS"]; } if (((String)de.Key).Equals("MASK", StringComparison.OrdinalIgnoreCase)) { mask = (UInt32)sec.sectionValues["MASK"]; } if (((String)de.Key).Equals("DATA", StringComparison.OrdinalIgnoreCase)) { data = (UInt32)sec.sectionValues["DATA"]; } } devAISGen.InsertAISReadWait(address, mask, data); // Insert signature InsertAISSecureSignature(devAISGen); } if (sec.sectionName.Equals("AIS_SeqReadEnable", StringComparison.OrdinalIgnoreCase)) { devAISGen.InsertAISSeqReadEnable(); } if (sec.sectionName.Equals("AIS_FinalFunctionReg", StringComparison.OrdinalIgnoreCase)) { String finalFxnName = ""; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("FINALFXNSYMBOLNAME", StringComparison.OrdinalIgnoreCase)) { finalFxnName = (String)sec.sectionValues["FINALFXNSYMBOLNAME"]; } } if (devAISGen.InsertAISFinalFxnReg(finalFxnName) != retType.SUCCESS) { Console.WriteLine("WARNING: Final function register AIS command failed."); } } if (sec.sectionName.Equals("AIS_SetDelegateKey", StringComparison.OrdinalIgnoreCase)) { String rsaKeyFileName = null; String keyString = null; foreach (DictionaryEntry de in sec.sectionValues) { if (((String)de.Key).Equals("RSAKEYFILENAME", StringComparison.OrdinalIgnoreCase)) { rsaKeyFileName = (String)sec.sectionValues["RSAKEYFILENAME"]; } if (((String)de.Key).Equals("ENCRYPTIONKEY", StringComparison.OrdinalIgnoreCase)) { keyString = (String)sec.sectionValues["ENCRYPTIONKEY"]; } } if ((rsaKeyFileName == null) || (keyString == null)) { Console.WriteLine("ERROR: Key file name and encryption key must be given."); return retType.FAIL; } if (devAISGen.InsertAISSetDelegateKey(rsaKeyFileName, keyString) != retType.SUCCESS) { Console.WriteLine("WARNING: Set Delegate Key AIS command failed."); } } if (sec.sectionName.Equals("AIS_RemoveDelegateKey", StringComparison.OrdinalIgnoreCase)) { devAISGen.InsertAISRemDelegateKey(); } #endregion return retType.SUCCESS; }