public SendFirmwareFileMessage(FirmwareFile file) { _file = file; // Copy the file size (4 bytes) into the message starting at byte 7 Array.Copy(file.LengthBytes, 0, msg, 7, 4); }
/// <summary> /// Checks that the compiled firmware will fit on the module. /// </summary> /// <param name="filename">The path to the firmware file.</param> /// <returns>Returns a boolean indicating whehter or not the firmware size is OK.</returns> internal static bool CheckFirmwareFileSize(string filename) { // Get the file size long length = new System.IO.FileInfo(filename).Length; // Absolute max size is 128KB int maxFileSize = 128 * 1024; // If the file is larger than the max flash space we don't need any more checks if (length > maxFileSize) { MessageBox.Show("Selected firmware file is too large.", "Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // If the file is smaller we can check if it has bootloader support and do a more exact check FirmwareFile fileDetails = GetFirmwareSignature(filename); if (fileDetails == null) { // Warn that we can't accurately check the file size string sizeMessage = $"Firmware file does not have a signature - unable to validate the size accurately."; DialogResult sizeWarning = MessageBox.Show(sizeMessage, "Firmware File Size", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (sizeWarning != DialogResult.OK) { return(false); } } else { switch (fileDetails.ModuleType) { case "AVR": maxFileSize = fileDetails.BootloaderSupport ? (fileDetails.ModuleMcuFlashSizeKb * 1024) - 512 : fileDetails.ModuleMcuFlashSizeKb * 1024; break; case "STM32F1": maxFileSize = fileDetails.BootloaderSupport ? (fileDetails.ModuleMcuFlashSizeKb * 1024) - 8192 - 2048 : (fileDetails.ModuleMcuFlashSizeKb * 1024) - 2048; byte[] eePromData = Stm32EepromUtils.GetEepromDataFromBackup(filename); if (eePromData != null && Stm32EepromUtils.FindValidPage(eePromData) >= 0) { maxFileSize += 2048; } break; } } Debug.WriteLine($"Selected file is {length / 1024:n0} KB, maximum size is {maxFileSize / 1024:n0} KB."); if (length > maxFileSize) { string sizeMessage = $"Firmware file is too large.\r\n\r\nSelected file is {length / 1024:n0} KB, maximum size is {maxFileSize / 1024:n0} KB."; MessageBox.Show(sizeMessage, "Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
public FirmwarePreludeMessage(FirmwareFile file) { // Set byte 1 to the firmware file id msg[1] = file.FirmwareIDByte; // Copy the file size (4 bytes) into the message starting at byte 2 Array.Copy(file.LengthBytes, 0, msg, 2, 4); }
private void EOFMessageHandle(string message) { if (message == "EOF") { Console.WriteLine(Quartus_console.GetInstance().RunQuartusCommandAsync($"quartus_pgm -m jtag –o \"p;{FirmwareFile.Name}@1\"").Result); string FileName = FirmwareFile.Name; FirmwareFile.Close(); File.Delete(FileName); isFileStreamCreated = false; } }
static void ExtractFirmware(string filePath) { var targetDir = Path.Combine(Environment.CurrentDirectory, $"{filePath}.extracted"); var targetFsDir = Path.Combine(targetDir, "file_system"); if (!Directory.Exists(targetFsDir)) { Directory.CreateDirectory(targetFsDir); } var firmwareFile = new FirmwareFile(filePath); var fileSystemScanner = new FileSystemScanner(firmwareFile.ContiguousRomData); fileSystemScanner.ExtractFileSystem(targetFsDir); }
private void LoadFirmwareFiles() { string[] paths = File.ReadAllLines(@"C:\Users\All Users\QUALCOMM\QDLService\Options.txt"); if (paths.Length >= 2) { foreach (string path in paths) { if (path.ToLowerInvariant().Contains("amss")) { AmssFirmware = new AmssFirmwareFile(path); } else if (path.ToLowerInvariant().Contains("apps")) { AppsFirmware = new AppsFirmwareFile(path); } } if (AmssFirmware == null || AppsFirmware == null) throw new ApplicationException(@"Firmware paths in C:\Users\All Users\QUALCOMM\QDLService\Options.txt are missing or not valid"); } }
/// <summary> /// Reads and parses the firmware file signature if it is present. /// </summary> /// <param name="filename">The path to the firmware file.</param> /// <returns>A <see cref="FirmwareFile"/> object.</returns> internal static FirmwareFile GetFirmwareSignature(string filename) { string signature = string.Empty; // Read the last 24 bytes of the binary file so we can see if it contains a signature string using (var reader = new StreamReader(filename)) { if (reader.BaseStream.Length > 24) { reader.BaseStream.Seek(-24, SeekOrigin.End); } string line; while ((line = reader.ReadLine()) != null) { signature = line; } } // Handle firmware signature v1 Regex regexFirmwareSignature = new Regex(@"^multi-(avr|stm|orx)-([a-z]{5})-(\d{8}$)"); Match match = regexFirmwareSignature.Match(signature); if (match.Success) { FirmwareFile file = new FirmwareFile { Signature = signature, ModuleType = match.Groups[1].Value == "avr" ? "AVR" : match.Groups[1].Value == "stm" ? "STM32" : match.Groups[1].Value == "orx" ? "OrangeRX" : "Unkown", BootloaderSupport = match.Groups[2].Value.Substring(0, 1) == "b" ? true : false, CheckForBootloader = match.Groups[2].Value.Substring(1, 1) == "c" ? true : false, MultiTelemetryType = match.Groups[2].Value.Substring(2, 1) == "t" ? "OpenTX" : match.Groups[2].Value.Substring(2, 1) == "s" ? "erskyTx" : "Undefined", InvertTelemetry = match.Groups[2].Value.Substring(3, 1) == "i" ? true : false, DebugSerial = match.Groups[2].Value.Substring(4, 1) == "d" ? true : false, ChannelOrder = "Unknown", Version = match.Groups[3].Value.Substring(0, 2).TrimStart('0') + "." + match.Groups[3].Value.Substring(2, 2).TrimStart('0') + "." + match.Groups[3].Value.Substring(4, 2).TrimStart('0') + "." + match.Groups[3].Value.Substring(6, 2).TrimStart('0'), }; return(file); } // Handle firmware signature v2 regexFirmwareSignature = new Regex(@"^multi-x([a-z0-9]{8})-(\d{8}$)"); match = regexFirmwareSignature.Match(signature); if (match.Success) { try { // Get the hex value of the firmware flags from the regex match string flagHexString = "0x" + match.Groups[1].Value; // Convert the hex string to a number uint flagDecimal = Convert.ToUInt32(flagHexString, 16); // Get the module type from the rightmost two bits uint moduleType = flagDecimal & ModuleTypeMask; // Get the channel order from bits 3-7 uint channelOrder = (flagDecimal & ChannelOrderMask) >> 2; string channelOrderString = GetChannelOrderString(channelOrder); // Get the version from the regex string versionString = match.Groups[2].Value; // Convert the zero-padded string to a dot-separated version string string parsedVersion = versionString.Substring(0, 2).TrimStart('0') + "." + versionString.Substring(2, 2).TrimStart('0') + "." + versionString.Substring(4, 2).TrimStart('0') + "." + versionString.Substring(6, 2).TrimStart('0'); // Create the firmware file signatre and return it FirmwareFile file = new FirmwareFile { Signature = signature, ModuleType = moduleType == 0 ? "AVR" : moduleType == 1 ? "STM32" : moduleType == 3 ? "OrangeRX" : "Unknown", ChannelOrder = channelOrderString, BootloaderSupport = (flagDecimal & BootloaderSupportMask) > 0 ? true : false, CheckForBootloader = (flagDecimal & CheckForBootloaderMask) > 0 ? true : false, InvertTelemetry = (flagDecimal & InvertTelemetryMask) > 0 ? true : false, MultiTelemetryType = ((flagDecimal & MultiTelemetryTypeMask) >> 10) == 2 ? "OpenTX" : ((flagDecimal & MultiTelemetryTypeMask) >> 10) == 1 ? "erskyTx" : "Undefined", DebugSerial = (flagDecimal & SerialDebugMask) > 0 ? true : false, Version = parsedVersion, }; return(file); } catch (Exception ex) { // Throw a warning if we fail to parse the signature MessageBox.Show("Unable to read the details from the firmware file - the signature could not be parsed.", "Firmware Signature", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } // Didn't find a signature in either format, return null return(null); }
//defines a firmware file static FirmwareFile File(string hash, long size, string recommendedName, string descr, string additionalInfo = "") { string hashfix = hash.ToUpperInvariant(); var ff = new FirmwareFile { hash = hashfix, size = size, recommendedName = recommendedName, descr = descr, info = additionalInfo }; FirmwareFiles.Add(ff); FirmwareFilesByHash[hashfix] = ff; return ff; }
//adds an acceptable option for a firmware ID to the database static FirmwareOption Option(string systemId, string id, FirmwareFile ff, FirmwareOptionStatus status = FirmwareOptionStatus.Acceptable) { var fo = Option(ff.hash, ff.size, systemId, id, status); //make sure this goes in as bad if(ff.bad) fo.status = FirmwareOptionStatus.Bad; return fo; }
private void PushFile(FirmwareFile file, bool overwrite, IProgressAcceptor GlobalProgressAcceptor = null, IProgressAcceptor LocalProgressAcceptor = null) { if (LocalProgressAcceptor != null) LocalProgressAcceptor.OnProgressChanged(0); PostProgressMessage(LocalProgressAcceptor, "Файл \"" + file.RelativePath + "\" – {0:P0}"); if (overwrite) Session.DeleteFile(file.RelativePath); var pushingFile = new DevFileInfo(file.RelativePath, file.Content); Session.CreateFile(pushingFile, new FudpProgressAcceptorShell(LocalProgressAcceptor)); PostProgressMessage(LocalProgressAcceptor, ""); }
/// <summary> /// Reads and parses the firmware file signature if it is present. /// </summary> /// <param name="filename">The path to the firmware file.</param> /// <returns>A <see cref="FirmwareFile"/> object.</returns> internal static FirmwareFile GetFirmwareSignature(string filename) { string signature = string.Empty; // Get the file size long length = new System.IO.FileInfo(filename).Length; // File is too small to contain a signature if (length < 24) { return(null); } // Parse the file and find the first instance of the signature byte[] byteBuffer = File.ReadAllBytes(filename); string byteBufferAsString = System.Text.Encoding.ASCII.GetString(byteBuffer); int offset = byteBufferAsString.IndexOf("multi-"); if (offset > 0) { signature = byteBufferAsString.Substring(offset, 24); } Debug.WriteLine(signature); // Handle firmware signature v1 Regex regexFirmwareSignature = new Regex(@"^multi-(avr|stm|orx)-([a-z]{5})-(\d{8}$)"); Match match = regexFirmwareSignature.Match(signature); if (match.Success) { FirmwareFile file = new FirmwareFile { Signature = signature, ModuleType = match.Groups[1].Value == "avr" ? "AVR" : match.Groups[1].Value == "stm" ? "STM32F1" : match.Groups[1].Value == "orx" ? "OrangeRX" : "Unkown", BootloaderSupport = match.Groups[2].Value.Substring(0, 1) == "b" ? true : false, CheckForBootloader = match.Groups[2].Value.Substring(1, 1) == "c" ? true : false, MultiTelemetryType = match.Groups[2].Value.Substring(2, 1) == "t" ? "OpenTX" : match.Groups[2].Value.Substring(2, 1) == "s" ? "erskyTx" : "Undefined", InvertTelemetry = match.Groups[2].Value.Substring(3, 1) == "i" ? true : false, DebugSerial = match.Groups[2].Value.Substring(4, 1) == "d" ? true : false, ChannelOrder = "Unknown", Version = match.Groups[3].Value.Substring(0, 2).TrimStart('0') + "." + match.Groups[3].Value.Substring(2, 2).TrimStart('0') + "." + match.Groups[3].Value.Substring(4, 2).TrimStart('0') + "." + match.Groups[3].Value.Substring(6, 2).TrimStart('0'), }; return(file); } // Handle firmware signature v2 regexFirmwareSignature = new Regex(@"^multi-x([a-z0-9]{8})-(\d{8}$)"); match = regexFirmwareSignature.Match(signature); if (match.Success) { try { // Get the hex value of the firmware flags from the regex match string flagHexString = "0x" + match.Groups[1].Value; // Convert the hex string to a number uint flagDecimal = Convert.ToUInt32(flagHexString, 16); // Get the module type from the rightmost two bits uint moduleType = flagDecimal & ModuleTypeMask; // Get the module sub-type from bits 14-16 uint moduleSubType = (flagDecimal & ModuleSubTypeMask) >> 13; // Get the channel order from bits 3-7 uint channelOrder = (flagDecimal & ChannelOrderMask) >> 2; string channelOrderString = GetChannelOrderString(channelOrder); // Get the version from the regex string versionString = match.Groups[2].Value; // Convert the zero-padded string to a dot-separated version string int.TryParse(versionString.Substring(0, 2), out int versionMajor); int.TryParse(versionString.Substring(2, 2), out int versionMinor); int.TryParse(versionString.Substring(4, 2), out int versionRevision); int.TryParse(versionString.Substring(6, 2), out int versionPatch); string parsedVersion = versionMajor + "." + versionMinor + "." + versionRevision + "." + versionPatch; // Create the firmware file signature and return it FirmwareFile file = new FirmwareFile { Signature = signature, ModuleType = moduleType == 0 ? "AVR" : moduleType == 1 ? "STM32F1" : moduleType == 2 ? "OrangeRX" : "Unknown", ModuleSubType = (moduleType == 0) ? "Atmega328p" : (moduleType == 1 && moduleSubType == 0) ? "STM32F103CB" : (moduleType == 1 && moduleSubType == 1) ? "STM32F103C8" : (moduleType == 1 && moduleSubType == 2) ? "Jumper T18 5-in-1" : (moduleType == 2) ? "ATxmega32D4" : "Unknown", ModuleMcuFlashSizeKb = (moduleType == 0 || moduleType == 2) ? 32 : (moduleType == 1 && moduleSubType == 0) ? 128 : (moduleType == 1 && moduleSubType == 1) ? 64 : (moduleType == 1 && moduleSubType == 2) ? 128 : -1, ChannelOrder = channelOrderString, BootloaderSupport = (flagDecimal & BootloaderSupportMask) > 0, CheckForBootloader = (flagDecimal & CheckForBootloaderMask) > 0, InvertTelemetry = (flagDecimal & InvertTelemetryMask) > 0, MultiTelemetryType = ((flagDecimal & MultiTelemetryTypeMask) >> 10) == 2 ? "OpenTX or erSkyTx (MULTI_TELEMETRY)" : ((flagDecimal & MultiTelemetryTypeMask) >> 10) == 1 ? "erSkyTx Only (MULTI_STATUS)" : "Undefined", DebugSerial = (flagDecimal & SerialDebugMask) > 0, Version = parsedVersion, }; return(file); } catch (Exception) { // Throw a warning if we fail to parse the signature MessageBox.Show("Unable to read the details from the firmware file - the signature could not be parsed.", "Firmware Signature", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } // Didn't find a signature in either format, return null return(null); }