static Memory AddMemory(MemoryLayout layout, string name, MemoryType type, string[] data, int baseIndex, bool required) { if (data[baseIndex] == "") { if (required) throw new Exception(name + " not defined!"); return null; } layout.Memories.Add(new Memory { Name = name, Access = MemoryAccess.Undefined, Type = type, Start = ParseHex(data[baseIndex]), Size = uint.Parse(data[baseIndex + 1]) * 1024 }); return layout.Memories[layout.Memories.Count - 1]; }
public LdsFileGenerator(LinkerScriptTemplate scriptTemplate, MemoryLayout memoryTemplate) { _ScriptTemplate = scriptTemplate; _MemoryTemplate = memoryTemplate; if (memoryTemplate.Memories == null) throw new Exception("Memory list cannot be empty"); foreach (var mem in memoryTemplate.Memories) { _Memories[mem.Name] = mem; if (mem.Type == MemoryType.FLASH) { if (_MainFLASH == null) _MainFLASH = mem; if (mem.Access == MemoryAccess.Undefined) mem.Access = MemoryAccess.Readable | MemoryAccess.Executable; } if (mem.Type == MemoryType.RAM) { if (_MainRAM == null) _MainRAM = mem; if (mem.Access == MemoryAccess.Undefined) mem.Access = MemoryAccess.Readable | MemoryAccess.Writable | MemoryAccess.Executable; } // Main flash can be 0! if (mem.Size == 0 && ((_MainFLASH == null) || (mem.MemoryDefinitionString != _MainFLASH.MemoryDefinitionString))) throw new Exception("Memory size cannot be 0"); } if (_MainRAM == null) throw new Exception("Cannot find the primary RAM memory. At least one memory with Type = RAM should be defined."); if (_MainFLASH == null) { _MainFLASH = _MainRAM; //throw new Exception("Cannot find the primary FLASH memory. At least one memory with Type = FLASH should be defined."); } }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes. MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = FindMemories(mcu.Name) }; layout.Memories.Insert(0, new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = FLASHBase, Size = (uint)mcu.FlashSize }); if (mcu.Name.StartsWith("LPC4", StringComparison.CurrentCultureIgnoreCase)) { int sram = mcu.RAMSize / 1024; if ((sram == 24) || (sram == 40) || (sram == 80) || (sram == 96) || (sram == 104) || (sram == 136) || (sram == 168) || (sram == 200) || (sram == 264) || (sram == 282)) { if ((layout.Memories[0].Size / 1024) == 0) layout.Memories[0].Size = 64 * 1024; } else throw new Exception("Unknown LPC43xx memory configuration"); } if (mcu.FlashSize == 0) layout.Memories[0].Size = 65536; return layout; }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes. MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() }; layout.Memories.Add(new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = SRAMBase, Size = (uint)mcu.RAMSize, }); return layout; }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes. MemoryLayout layout = new MemoryLayout(); layout.Memories = new List<Memory>(); layout.DeviceName = mcu.Name; string shName = mcu.Name; string aDirSam; if (mcu.Name.StartsWith("AT")) shName = mcu.Name.Substring(2, mcu.Name.Length - 2); if (shName.StartsWith("SAMC") || shName.StartsWith("SAMD") || shName.StartsWith("SAMR") || shName.StartsWith("SAMB") || shName.StartsWith("SAML")) aDirSam = "\\Sam0"; else aDirSam = "\\Sam"; // EAK if (shName == "SAMD10D13A" || shName == "SAMD10D14A" || shName == "SAMD10D12A"|| shName == "SAMD11D14A") // EAK shName = shName + "S";//Different Device ID (DID) string aFileName = family.BSP.Directories.InputDir + aDirSam +"\\Utils\\Cmsis\\" + family.FamilyFilePrefix + "\\Include\\" + shName; if (family.FamilyFilePrefix.ToUpper().StartsWith("SAMG")) aFileName = family.BSP.Directories.InputDir + "\\Sam\\Utils\\Cmsis\\samg\\" + family.FamilyFilePrefix + "\\Include\\" + shName; if (family.Definition.Name.ToUpper() == "SAM4C" || family.Definition.Name.ToUpper() == "SAM4CM" || family.Definition.Name.ToUpper() == "SAM4CP" || family.Definition.Name.ToUpper() == "SAM4CM32") aFileName = aFileName + "_0.h"; else aFileName = aFileName + ".h"; int RAMStart = -1; int FLASHStart = -1; if (Regex.IsMatch(mcu.Name, "SAML21...B")) aFileName = aFileName.Replace("\\Include\\S", "\\Include_b\\S"); foreach (var ln in File.ReadAllLines(aFileName)) { // var m = Regex.Match(ln, @"(#define [IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+)+.*"); var m = Regex.Match(ln, @"(#define [ID]*[IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+[L]?)+.*"); if (m.Success) { RAMStart = Convert.ToInt32(m.Groups[2].Value, 16); } m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*"); if (!m.Success) m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_CNC_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*"); if (!m.Success) m = Regex.Match(ln, @"(#define BOOTROM_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");//samb11 if (m.Success) { FLASHStart = Convert.ToInt32(m.Groups[2].Value, 16); } if (FLASHStart > -1 && RAMStart > -1) break; } if (RAMStart == -1) throw new Exception("no RAM Start"); // Console.WriteLine("RAMBase mcu {0} NO file :{1} ", mcu.Name, aFileName); if (FLASHStart == -1) throw new Exception("no FLASH Start"); // Console.WriteLine("FLASHBase mcu {0} NO file :{1} ",mcu.Name , aFileName); layout.Memories.Insert(0, new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = (uint)FLASHStart, Size = (uint)mcu.FlashSize }); layout.Memories.Insert(0, new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = (uint)RAMStart, Size = (uint)mcu.RAMSize }); return layout; }
private MemoryLayout ReadMemoryLayout(string ldFile) { var memoryLayout = new MemoryLayout(); memoryLayout.Memories = new List<Memory>(); var rgMemory = new Regex(@"\s*m_([\w]+)\s*\([RWX]+\)\s*:\s*ORIGIN\s*=\s*0x([0-9a-fA-F]+)\s*,\s*LENGTH\s*=\s*0x([0-9a-fA-F]+)"); foreach (var match in rgMemory.Matches(File.ReadAllText(ldFile)).Cast<Match>()) { string name; if (!LdMemoryNameToBSPName.TryGetValue(match.Groups[1].Value, out name)) { continue; } Memory memory = null; if (name == "SRAM") { memory = memoryLayout.Memories.FirstOrDefault(mem => mem.Name == SRAM_MEMORY); if (memory != null) { memory.Size += uint.Parse(match.Groups[3].Value, System.Globalization.NumberStyles.HexNumber); } } if (memory == null) { memory = new Memory { Name = name, Start = uint.Parse(match.Groups[2].Value, System.Globalization.NumberStyles.HexNumber), Size = uint.Parse(match.Groups[3].Value, System.Globalization.NumberStyles.HexNumber), Access = MemoryAccess.Undefined, Type = name == SRAM_MEMORY ? MemoryType.RAM : MemoryType.FLASH }; if (memory.Name == FLASH_MEMORY) { memoryLayout.Memories.Insert(0, memory); } else { memoryLayout.Memories.Add(memory); } } } return memoryLayout; }
public void GetMemoryMcu(MCUFamilyBuilder pfam) { if (pfam.FamilyFilePrefix.StartsWith("STM32W1")) { string kvStr = "STM32W108HB"; MemoryLayout layoutW1 = new MemoryLayout { DeviceName = "STM32W108xx", Memories = new List<Memory>() }; layoutW1.Memories.Add(new Memory { Name = "FLASH", Access = MemoryAccess.Undefined,// Readable | MemoryAccess.Writable | MemoryAccess.Executable Type = MemoryType.FLASH, Start = 0x08000000, Size = 128 * 1024 }); layoutW1.Memories.Add(new Memory { Name = "SRAM", Access = MemoryAccess.Undefined,// MemoryAccess.Writable, Type = MemoryType.RAM, Start = 0x20000000, Size = 8 * 1024 }); _SpecialMemoryLayouts.Add(new KeyValuePair<Regex, MemoryLayout>(new Regex(kvStr.Replace('x', '.') + ".*"), layoutW1)); } else { string aDirIcf = pfam.Definition.StartupFileDir; if (!aDirIcf.EndsWith("gcc")) throw new Exception("No Gcc sturtup Tamplate"); aDirIcf = aDirIcf.Replace("\\gcc", "\\iar\\linker"); if (!Directory.Exists(aDirIcf)) throw new Exception("No dir " + aDirIcf); foreach (var fnIcf in Directory.GetFiles(aDirIcf, "stm32*_flash.icf")) { string kvStr = Path.GetFileName(fnIcf).Replace("_flash.icf", ""); _SpecialMemoryLayouts.Add(new KeyValuePair<Regex, MemoryLayout>(new Regex(kvStr.Replace('x', '.') + ".*", RegexOptions.IgnoreCase), GetLayoutFromICF(fnIcf, kvStr))); } } }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { foreach (var kv in _SpecialMemoryLayouts) if (kv.Key.IsMatch(mcu.Name)) return kv.Value; MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() }; layout.Memories.Add(new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = FLASHBase, Size = (uint)mcu.FlashSize, }); layout.Memories.Add(new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = SRAMBase, Size = (uint)mcu.RAMSize, }); return layout; }
public MemoryLayout GetLayoutFromICF(string pFileNameICF,string pNameDev) { MemoryLayout layout = new MemoryLayout { DeviceName = pNameDev, Memories = new List<Memory>() }; int StartFlash = NO_DATA; int SizeFlash = NO_DATA; /*int StartRAM = NO_DATA; int SizeRAM = NO_DATA; int StartCCM = NO_DATA; int SizeCCM = NO_DATA; */ foreach (var ln in File.ReadAllLines(pFileNameICF)) { var m = Regex.Match(ln, @"define symbol __ICFEDIT_region_([\w\d]+)_start__[ ]*=[ ]*([x0-9A-Faf]+)[ ]*;"); if (m.Success) { StartFlash = (int)ParseHex(m.Groups[2].Value); continue; } m = Regex.Match(ln, @"define symbol __ICFEDIT_region_([\w\d]+)_end__[ ]*=[ ]*([x0-9A-Faf]+)[ ]*;"); if (m.Success) { SizeFlash = (int)ParseHex(m.Groups[2].Value); MemoryType aTypeData = MemoryType.RAM; string aNameData = m.Groups[1].Value; if (m.Groups[1].Value.Contains("ROM")) aTypeData = MemoryType.FLASH; if (m.Groups[1].Value == "ROM") aNameData = "FLASH"; else if (m.Groups[1].Value == "RAM") aNameData = "SRAM"; if (StartFlash != NO_DATA && SizeFlash != NO_DATA) { SizeFlash -= StartFlash; if ((SizeFlash % 1024) != 0) SizeFlash += 1; layout.Memories.Add(new Memory { Name = aNameData, Access = MemoryAccess.Undefined,// Readable | MemoryAccess.Writable | MemoryAccess.Executable Type = aTypeData, Start = (uint)StartFlash, Size = (uint)SizeFlash }); } else throw new Exception("Error ld size flash"); StartFlash = NO_DATA; continue; } } return layout; }
public override void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName) { base.GenerateLinkerScriptsAndUpdateMCU(ldsDirectory, familyFilePrefix, mcu, layout, generalizedName); }
public LdsFileGenerator(LinkerScriptTemplate scriptTemplate, MemoryLayout memoryTemplate) { _ScriptTemplate = scriptTemplate; _MemoryTemplate = memoryTemplate; if (memoryTemplate.Memories == null) { throw new Exception("Memory list cannot be empty"); } foreach (var mem in memoryTemplate.Memories) { if (mem.IsPrimary) { if (mem.Type == MemoryType.FLASH) { _MainFLASH = mem; } else if (mem.Type == MemoryType.RAM) { _MainRAM = mem; } } } foreach (var mem in memoryTemplate.Memories) { _Memories[mem.Name] = mem; if (mem.Type == MemoryType.FLASH) { if (_MainFLASH == null) { _MainFLASH = mem; } if (mem.Access == MemoryAccess.Undefined) { mem.Access = MemoryAccess.Readable | MemoryAccess.Executable; } } if (mem.Type == MemoryType.RAM) { if (_MainRAM == null) { _MainRAM = mem; } if (mem.Access == MemoryAccess.Undefined) { mem.Access = MemoryAccess.Readable | MemoryAccess.Writable | MemoryAccess.Executable; } } // Main flash can be 0! if (mem.Size == 0 && ((_MainFLASH == null) || (mem.MemoryDefinitionString != _MainFLASH.MemoryDefinitionString))) { throw new Exception("Memory size cannot be 0"); } } if (_MainRAM == null) { throw new Exception("Cannot find the primary RAM memory. At least one memory with Type = RAM should be defined."); } if (_MainFLASH == null) { _MainFLASH = _MainRAM; //throw new Exception("Cannot find the primary FLASH memory. At least one memory with Type = FLASH should be defined."); } }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { var layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() }; layout.Memories.Add(new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = FLASHBase, Size = (uint)mcu.FlashSize }); layout.Memories.Add(new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = SRAMBase, Size = (uint)mcu.RAMSize }); return layout; }
public MemoryLayout Clone() { var r = new MemoryLayout { DeviceName = DeviceName, Memories = new List<Memory>() }; foreach (var m in Memories) r.Memories.Add(m.Clone()); return r; }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes. MemoryLayout layout = new MemoryLayout(); layout.Memories = new List<Memory>(); layout.DeviceName = mcu.Name; string aFileName = family.BSP.Directories.InputDir + "\\Device\\SiliconLabs\\" + family.FamilyFilePrefix.Substring(0, family.FamilyFilePrefix.Length - 1) + "\\Include\\" + mcu + ".h"; Match m; Regex rg = new Regex(@"(#define RAM_MEM_BASE[ \t]*.*0x)([0-9][U][L])+.*"); int RAMStart = 0; foreach (var ln in File.ReadAllLines(aFileName)) { m = Regex.Match(ln, @"#define RAM_MEM_BASE[ \t]+.*0x([\d]+)UL.*"); RAMStart = 0; if (m.Success) { RAMStart = Convert.ToInt32(m.Groups[1].Value, 16); break; } } if (RAMStart == 0) throw new Exception("no RAM Start"); layout.Memories.Insert(0, new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = FLASHBase, Size = (uint)mcu.FlashSize }); layout.Memories.Insert(0, new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = (uint)RAMStart, Size = (uint)mcu.RAMSize }); return layout; }
public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family) { MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() }; string aDir = Directories.InputDir + @"\CMSIS\Infineon\" + family.Definition.Name + @"_series\Source\GCC"; Regex aRgFl1 = new Regex(@"((FLASH)[ \(]+RX[\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)"); Regex aRgFl2 = new Regex(@"((FLASH_1_uncached)[ \(]+RX[\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)"); Regex aRgRam1 = new Regex(@"((SRAM)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)"); Regex aRgRam3 = new Regex(@"((PSRAM_1)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)"); Regex aRgRam2 = new Regex(@"((SRAM_combined)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)"); string aStartFlash = ""; string aLenFlash = ""; string aStartRam = ""; string aLenRam = ""; int idX = mcu.Name.IndexOf("x"); string longMCUName = mcu.Name.Replace("_", "-"); string expectedScriptPath = string.Format(@"{0}\{1}x{2:d4}.ld", aDir, family.Definition.Name, mcu.Name.Substring(idX + 1)); if (!File.Exists(expectedScriptPath)) { expectedScriptPath = string.Format(@"{0}\{1}x{2:d4}.ld", aDir, longMCUName.Substring(0, longMCUName.IndexOf('-')), mcu.Name.Substring(idX + 1)); if (!File.Exists(expectedScriptPath)) { throw new Exception("Failed to find linker script for " + mcu.Name); } } Regex[] sramRegexes = new Regex[] { aRgRam1, aRgRam2, aRgRam3 }; Match[] sramMatches = new Match[sramRegexes.Length]; foreach (var line in File.ReadAllLines(expectedScriptPath)) { // Search Flash notes var m = aRgFl1.Match(line); if (!m.Success) m = aRgFl2.Match(line); if (m.Success) { aStartFlash = m.Groups[3].Value; aLenFlash = m.Groups[4].Value; } for (int i = 0; i < sramRegexes.Length; i++) if (sramMatches[i] == null) { m = sramRegexes[i].Match(line); if (m.Success) sramMatches[i] = m; } continue; } foreach(var m in sramMatches) { if (m != null) { aStartRam = m.Groups[3].Value; aLenRam = m.Groups[4].Value; break; } } if (string.IsNullOrEmpty(aStartFlash) || string.IsNullOrEmpty(aLenFlash) || string.IsNullOrEmpty(aStartRam) || string.IsNullOrEmpty(aLenRam)) { throw new Exception("Failed to find FLASH/RAM parameters"); } layout.Memories.Add(new Memory { Name = "FLASH", Access = MemoryAccess.Undefined, Type = MemoryType.FLASH, Start = Convert.ToUInt32(aStartFlash, 16), Size = Convert.ToUInt32(aLenFlash, 16), }); layout.Memories.Add(new Memory { Name = "SRAM", Access = MemoryAccess.Undefined, Type = MemoryType.RAM, Start = Convert.ToUInt32(aStartRam, 16), Size = Convert.ToUInt32(aLenRam, 16), }); return layout; }