public ImportedExternalSDK GenerateBSPForSDK(ImportedSDKLocation location, ISDKImportHost host) { var bsp = ParseKSDKManifest(location.Directory, host.WarningSink); bsp.Save(location.Directory); return(new ImportedExternalSDK { BSPID = bsp.BSP.PackageID }); }
public ParsedSDK ParseKSDKManifest(ISDKImportHost host) { LoadDevicesAndFamilies(); _GlobalDefines = _Manifest.DocumentElement.SelectNodes("defines/define").OfType <XmlElement>().Select(e => new ParsedDefine(e)).ToArray(); _Components = _Manifest.DocumentElement.SelectNodes($"components/component").OfType <XmlElement>() .Select(n => new ParsedComponent(n)) .Where(c => !c.SkipUnconditionally) .ToArray(); AttachSVDFilesAndLinkerScriptsToDevices(host); Dictionary <string, FileCondition> fileConditions = new Dictionary <string, FileCondition>(); var frameworks = TranslateComponentsToFrameworks(fileConditions); var vendorSamples = TranslateSampleProjects(); var version = _Manifest.DocumentElement.GetAttribute("version"); if (string.IsNullOrEmpty(version)) { version = _Manifest.DocumentElement.SelectSingleNode("ksdk/@version")?.InnerText; } if (string.IsNullOrEmpty(version)) { version = "unknown"; } var allFamilies = _SpecializedDevices.Select(d => d.BuildMCUFamily()).ToArray(); return(new ParsedSDK { BSP = new BoardSupportPackage { PackageID = "com.sysprogs.imported.ksdk2x." + allFamilies[0].ID, PackageDescription = "Imported MCUXpresso SDK for " + allFamilies[0].ID, PackageVersion = version, GNUTargetID = "arm-eabi", Frameworks = frameworks, MCUFamilies = allFamilies.ToArray(), SupportedMCUs = _SpecializedDevices.SelectMany(d => d.Complete(_GlobalDefines)).ToArray(), FileConditions = fileConditions.Values.ToArray(), VendorSampleCatalogName = "MCUXpresso Samples", BSPImporterID = ID, }, VendorSampleDirectory = new VendorSampleDirectory { Samples = vendorSamples.ToArray() } }); }
public ImportedExternalSDK GenerateBSPForSDK(ImportedSDKLocation location, ISDKImportHost host) { string[] manifestFiles = Directory.GetFiles(location.Directory, "*manifest*.xml"); if (manifestFiles.Length < 1) { throw new Exception($"No manifest files in {location.Directory}"); } string manifestFile = Directory.GetFiles(location.Directory, "*manifest*.xml")[0]; XmlDocument doc = new XmlDocument(); doc.Load(manifestFile); var bsp = new ParserImpl(location.Directory, doc, host.WarningSink).ParseKSDKManifest(host); bsp.Save(location.Directory); return(new ImportedExternalSDK { BSPID = bsp.BSP.PackageID, Directory = location.Directory }); }
public ImportedExternalSDK GenerateBSPForSDK(ImportedSDKLocation location, ISDKImportHost host) { string temporaryDir = Path.Combine(host.GetDefaultDirectoryForImportedSDKs("arm-eabi"), Guid.NewGuid().ToString()); Directory.CreateDirectory(temporaryDir); try { host.ExtractZIPFile(location.OriginallySelectedFile, temporaryDir); var bsp = GenerateBSPForSTARTProject(temporaryDir, host.WarningSink); string newDir = Path.Combine(Path.GetDirectoryName(temporaryDir), bsp.PackageID); if (Directory.Exists(newDir)) { if (!host.AskWarn($"{newDir} already exists. Overwrite?")) { throw new OperationCanceledException(); } host.DeleteDirectoryRecursively(newDir); } Directory.Move(temporaryDir, newDir); return(new ImportedExternalSDK { BSPID = bsp.PackageID, Directory = newDir }); } catch { try { host.DeleteDirectoryRecursively(temporaryDir); } catch { } throw; } }
void AttachSVDFilesAndLinkerScriptsToDevices(ISDKImportHost host) { foreach (var sd in _SpecializedDevices) { if (_Components.FirstOrDefault(c => c.Type == ComponentType.SVDFile && c.Filter.MatchesDevice(sd)) is ParsedComponent svdComponent) { var svdFiles = svdComponent.LocateAllFiles(sd, _Directory).ToArray(); Debug.Assert(svdFiles.Length <= 1); //If we get multiple matching SVD files, we might have skipped some conditions. if (svdFiles.Length > 0) { try { var fullPath = svdFiles[0].GetLocalPath(_Directory); var mcuDef = host?.TryParseSVDFile(fullPath, sd.Device.DeviceName) ?? SVDParser.ParseSVDFile(fullPath, sd.Device.DeviceName); var convertedFile = new FileReference(Path.ChangeExtension(svdFiles[0].RelativePath, ".vgdbdevice"), svdFiles[0].Type); XmlSerializer ser = new XmlSerializer(typeof(MCUDefinition)); using (var fs = File.Create(Path.ChangeExtension(convertedFile.GetLocalPath(_Directory), ".vgdbdevice.gz"))) using (var gs = new GZipStream(fs, CompressionMode.Compress, true)) ser.Serialize(gs, new MCUDefinition(mcuDef)); sd.ConvertedSVDFile = convertedFile; } catch (Exception ex) { _Sink.LogWarning($"Failed to process {svdFiles[0]}: {ex.Message}"); } } } sd.DiscoveredLinkerScripts = _Components.Where(c => c.Type == ComponentType.LinkerScript && c.Filter.MatchesDevice(sd)) .SelectMany(c => c.LocateAllFiles(sd, _Directory)).ToArray(); } }