예제 #1
0
            public LDFileMemoryInfo(string fn)
            {
                FullPath = fn;
                foreach (var line in File.ReadAllLines(fn))
                {
                    if (line.Contains("__stop_sdh_ble_observers"))
                    {
                        _HasBLEObservers = true;
                    }
                    if (line.Contains("__start_pwr_mgmt_data"))
                    {
                        _HasBLEObservers = true;
                    }

                    var m = Regex.Match(line, $".*(FLASH|RAM).*ORIGIN[ =]+0x([a-fA-F0-9]+).*LENGTH[ =]+0x([a-fA-F0-9]+)");
                    if (m.Success)
                    {
                        var info = new SingleMemoryInfo
                        {
                            Origin = ulong.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber),
                            Length = ulong.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber)
                        };

                        switch (m.Groups[1].Value)
                        {
                        case "FLASH":
                            FLASH = info;
                            break;

                        case "RAM":
                            RAM = info;
                            break;

                        default:
                            throw new Exception("Unexpected memory: " + m.Groups[1].Value);
                        }
                    }
                }

                if (FLASH.Length == 0 || FLASH.Origin == 0)
                {
                    throw new Exception("Missing FLASH in " + fn);
                }
                if (RAM.Length == 0 || RAM.Origin == 0)
                {
                    throw new Exception("Missing RAM in " + fn);
                }
            }
예제 #2
0
파일: Program.cs 프로젝트: whinis/BSPTools
            public LDFileMemoryInfo(string fn)
            {
                FullPath = fn;
                foreach (var line in File.ReadAllLines(fn))
                {
                    if (line.Contains("__stop_sdh_ble_observers"))
                    {
                        _HasBLEObservers = true;
                    }
                    if (line.Contains("__start_pwr_mgmt_data"))
                    {
                        _HasBLEObservers = true;
                    }

                    var m = Regex.Match(line, $".*(FLASH|RAM).*ORIGIN[ =]+0x([a-fA-F0-9]+).*LENGTH[ =]+0x([a-fA-F0-9]+)");
                    if (m.Success)
                    {
                        var info = new SingleMemoryInfo
                        {
                            Origin = ulong.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber),
                            Length = ulong.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber)
                        };

                        switch (m.Groups[1].Value)
                        {
                        case "FLASH":
                            FLASH = info;
                            break;

                        case "RAM":
                            RAM = info;
                            break;

                        default:
                            throw new Exception("Unexpected memory: " + m.Groups[1].Value);
                        }
                    }
                }

                if (FLASH.Length == 0 || FLASH.Origin == 0)
                {
                    throw new Exception("Missing FLASH in " + fn);
                }
                if (RAM.Length == 0 || RAM.Origin == 0)
                {
                    throw new Exception("Missing RAM in " + fn);
                }

                var   makefile       = Path.Combine(Path.GetDirectoryName(fn), "Makefile");
                Regex rgTargets      = new Regex("TARGETS[ \t]*:=[ \t]*(.*)");
                Regex rgSingleTarget = new Regex("^(nrf[0-9]+)_[a-z0-9_]+$");

                if (File.Exists(makefile))
                {
                    foreach (var line in File.ReadAllLines(makefile))
                    {
                        var m = rgTargets.Match(line);
                        if (m.Success)
                        {
                            var targets = m.Groups[1].Value.Trim();
                            m = rgSingleTarget.Match(targets);
                            if (!m.Success)
                            {
                                throw new Exception("Multiple targets found in " + makefile);
                            }

                            TargetDevice = m.Groups[1].Value;
                        }
                    }

                    if (TargetDevice == null)
                    {
                        throw new Exception("No targets defined in " + makefile);
                    }
                }
            }