示例#1
0
        public virtual void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName)
        {
            using (var gen = new LdsFileGenerator(GetTemplateForMCU(mcu), layout))
            {
                using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_flash.lds")))
                    gen.GenerateLdsFile(sw);
                gen.RedirectMainFLASHToRAM = true;
                using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_sram.lds")))
                    gen.GenerateLdsFile(sw);

                mcu.LinkerScriptPath = string.Format("$$SYS:BSP_ROOT$$/{0}LinkerScripts/{1}_$${2}$$.lds", familyFilePrefix, generalizedName, MCUFamilyBuilder.PrimaryMemoryOptionName);
            }
        }
示例#2
0
            void DoGenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName, string ldsSuffix)
            {
                foreach (var sd in SoftDevices)
                {
                    if (!sd.IsCompatible(mcu.Name))
                    {
                        continue;
                    }
                    if (sd.LinkerScriptWithMaximumReservedRAM == null)
                    {
                        using (var gen = new LdsFileGenerator(LDSTemplate, layout))
                        {
                            using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_nosoftdev" + ldsSuffix + ".lds")))
                                gen.GenerateLdsFile(sw);
                        }

                        //IoT
                        var softdevTemplate = LDSTemplate.ShallowCopy();
                        softdevTemplate.Sections = new List <Section>(softdevTemplate.Sections);
                        softdevTemplate.Sections.Insert(0, new Section {
                            Name = ".softdevice", TargetMemory = "FLASH_SOFTDEVICE", Inputs = new List <SectionReference> {
                                new SectionReference {
                                    NamePattern = ".softdevice", Flags = SectionReferenceFlags.Keep
                                }
                            }, Fill = new FillInfo {
                                Pattern = uint.MaxValue, TotalSize = (int)sd.FLASHSize
                            }, Flags = SectionFlags.Unaligned
                        });
                        softdevTemplate.Sections.Insert(1, new Section {
                            Name = ".softdevice_sram", TargetMemory = "SRAM_SOFTDEVICE", Inputs = new List <SectionReference>(), Fill = new FillInfo {
                                Pattern = 0, TotalSize = (int)sd.SRAMSize
                            }, Flags = SectionFlags.Unaligned
                        });

                        var layoutCopy = layout.Clone();
                        var flash      = layoutCopy.Memories.First(m => m.Name == "FLASH");
                        var ram        = layoutCopy.Memories.First(m => m.Name == "SRAM");

                        if (flash.Size < sd.FLASHSize || ram.Size < sd.SRAMSize)
                        {
                            throw new Exception("Device too small for " + sd.Name);
                        }

                        layoutCopy.Memories.Insert(layoutCopy.Memories.IndexOf(flash), new Memory {
                            Name = "FLASH_SOFTDEVICE", Access = MemoryAccess.Readable | MemoryAccess.Executable, Start = flash.Start, Size = sd.FLASHSize
                        });
                        layoutCopy.Memories.Insert(layoutCopy.Memories.IndexOf(ram), new Memory {
                            Name = "SRAM_SOFTDEVICE", Access = MemoryAccess.Readable | MemoryAccess.Writable | MemoryAccess.Executable, Start = ram.Start, Size = sd.SRAMSize
                        });

                        flash.Size  -= sd.FLASHSize;
                        flash.Start += sd.FLASHSize;

                        ram.Size  -= sd.SRAMSize;
                        ram.Start += sd.SRAMSize;

                        using (var gen = new LdsFileGenerator(softdevTemplate, layoutCopy))
                        {
                            using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_" + sd.Name.ToLower() + ldsSuffix + ".lds")))
                                gen.GenerateLdsFile(sw, new string[] { "", "GROUP(" + sd.Name + "_softdevice.o)", "" });
                        }
                    }
                    else
                    {
                        BuildLinkerScriptBasedOnOriginalNordicScripts(ldsDirectory, generalizedName, ldsSuffix, sd);
                    }
                }
                mcu.LinkerScriptPath = $"$$SYS:BSP_ROOT$$/{familyFilePrefix}LinkerScripts/{generalizedName}_$${SoftdevicePropertyID}$$.lds";
            }