public void Parse(Firmware firmware) { StreamReader sr = new StreamReader(mPath, Encoding.Default); Console.WriteLine("Parsing file: {0}...", mPath); while (sr.EndOfStream == false) { string line = sr.ReadLine(); // Parse line like: C:00000040 32 char[] split = { ':', ' ' }; string[] parts = line.Split(split); Char type = Convert.ToChar(parts[0]); UInt32 address = UInt32.Parse(parts[1], System.Globalization.NumberStyles.HexNumber); Byte value = Byte.Parse(parts[2], System.Globalization.NumberStyles.HexNumber); //Console.WriteLine("Parse a line: type={0}, address={1}, value={2}", type, address, value); //Console.ReadKey(); if (type.Equals('C')) { firmware.AddCode(address, value); } else { firmware.AddData(address, value); } } }
public static Firmware parse(string configFile) { Firmware firmware = null; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configFile); string fwNodePath = ConfigXml.NODE_ROOT + "/" + ConfigXml.NODE_FIRMWARE; XmlNodeList nodeList = xmlDoc.SelectNodes(fwNodePath); // Just support one firmware in ConfigXml firmware = Firmware.CreateFromXml(nodeList.Item(0)); return(firmware); }
public static Firmware CreateFromXml(XmlNode fwNode) { Firmware firmware = new Firmware(); // Parse firmware information in ConfigXml string version = fwNode.SelectSingleNode(ConfigXml.ATTR_VERSION).InnerText.Trim(); string compatiable = fwNode.SelectSingleNode(ConfigXml.ATTR_COMPATIBLE).InnerText.Trim(); string exeFilePath = fwNode.SelectSingleNode(ConfigXml.ATTR_EXEFILE).InnerText.Trim(); UInt32 maxCodeSize = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_MAX_CSIZE).InnerText.Trim(), 16); UInt32 maxDataSize = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_MAX_DSIZE).InnerText.Trim(), 16); UInt32 codeLoadableStart = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_LOADABLE_CSTART).InnerText.Trim(), 16); UInt32 codeLoadableSize = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_LOADABLE_CSIZE).InnerText.Trim(), 16); UInt32 dataLoadableStart = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_LOADABLE_DSTART).InnerText.Trim(), 16); UInt32 dataLoadableSize = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_LOADABLE_DSIZE).InnerText.Trim(), 16); UInt32 externalCodeStart = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_EXTCMEM_START).InnerText.Trim(), 16); UInt32 externalCodeEnd = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_EXTCMEM_END).InnerText.Trim(), 16); UInt32 externalDataStart = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_EXTDMEM_START).InnerText.Trim(), 16); UInt32 externalDataEnd = (UInt32)Convert.ToInt32(fwNode.SelectSingleNode(ConfigXml.ATTR_EXTDMEM_END).InnerText.Trim(), 16); firmware.SetVersion(version); firmware.SetCompatible(compatiable); firmware.SetExecutableFile(new ExecutableFile(exeFilePath)); firmware.SetMaxCodeSize(maxCodeSize); firmware.SetMaxDataSize(maxDataSize); firmware.SetCodeLoadableStart(codeLoadableStart); firmware.SetCodeLoadableSize(codeLoadableSize); firmware.SetDataLoadableStart(dataLoadableStart); firmware.SetDataLoadableSize(dataLoadableSize); XmlNodeList nodeList = fwNode.SelectNodes(ConfigXml.NODE_IMAGE); if (nodeList.Count < 1) { Console.WriteLine("At least one image in firmware node"); return(null); } foreach (XmlNode node in nodeList) { Image image = null; int id = int.Parse(node.SelectSingleNode(ConfigXml.ATTR_ID).InnerText.Trim()); string name = node.SelectSingleNode(ConfigXml.ATTR_NAME).InnerText.Trim(); string type = node.SelectSingleNode(ConfigXml.ATTR_TYPE).InnerText.Trim(); if (type.Equals(ImageType.LOADABLE_STRING)) { image = LoadableImage.CreateFromXml(node, id, name); image.SetInternalCodeRange(codeLoadableStart, codeLoadableStart + codeLoadableSize); image.SetInternalDataRange(dataLoadableStart, dataLoadableStart + dataLoadableSize); } else if (type.Equals(ImageType.PERMANENT_STRING)) { image = PermanentImage.CreateFromXml(node, id, name); image.SetInternalCodeRange(0, maxCodeSize); image.SetInternalDataRange(0, maxDataSize); image.SetExternalCodeRange(externalCodeStart, externalCodeEnd); image.SetExternalDataRange(externalDataStart, externalDataEnd); } firmware.AddImage(image); } return(firmware); }
public FirmwareGenerator(Firmware firmware, string path, string name) { mPath = path; mName = name; mFirmware = firmware; }