Ejemplo n.º 1
0
        void FirmwareFromCS()
        {
            var csFiles        = Directory.EnumerateFiles(SourceFolder);
            var csFilesContent = csFiles
                                 .Select(path => new FSTextFile()
            {
                Name = path, Content = File.ReadAllText(path)
            })
                                 .ToList();

            if (csFilesContent.Any())
            {
                foreach (var cs in csFilesContent)
                {
                    Console.WriteLine($"Found CS source: {cs.Name}");
                }

                // translate source files
                var tx     = new CSharp2CPPTranslator();
                var source = new FSSnapshot();
                source.Files.AddRange(csFilesContent);
                tx.Run(source);
                var firmwareSource = tx.Result;

                // create soc resource records
                var socGenerator      = new SOCGenerator();
                var socRecordsBuilder = new SOCRecordsBuilder();
                var socRecords        = socRecordsBuilder.ToSOCRecords(0x800, tx.SOCResources);
                firmwareSource.Add(socGenerator.SOCImport(socRecords));

                FileTools.CreateDirectoryRecursive(FirmwareFolder);
                var m = new FSManager(FirmwareFolder);
                m.SaveSnapshot(firmwareSource);
            }

            ModifyMakefile();

            if (File.Exists(MakefileFile))
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    var context = RISCVIntegration
                                  .DefaultContext(FirmwareFolder)
                                  .WithMakeTarget("bin");

                    RISCVIntegrationClient.Make(context).Wait();
                }
                else
                {
                    using (new CurrentDirectory(FirmwareFolder))
                    {
                        Toolchain.Make("bin");
                    }
                }
            }
            else
            {
                Console.WriteLine($"Makefile was not found: {MakefileFile}");
            }
        }
Ejemplo n.º 2
0
        public async Task MakeTest()
        {
            // translate source files
            var tx     = new CSharp2CPPTranslator();
            var source = new FSSnapshot();

            source.Files.Add(LoadSource("SOCBlinker.cs"));
            tx.Run(source);
            var firmwareSource = tx.Result;

            // create soc resource records
            var socGenerator      = new SOCGenerator();
            var socRecordsBuilder = new SOCRecordsBuilder();
            var socRecords        = socRecordsBuilder.ToSOCRecords(0x800, tx.SOCResources);

            firmwareSource.Add(socGenerator.SOCImport(socRecords));
            IntermediateData.SaveToMake(firmwareSource);

            // run makefile
            var context = RISCVIntegration
                          .DefaultContext(TestPath.MakeFolder)
                          .WithMakeTarget("bin");

            await RISCVIntegrationClient.Make(context);
        }
Ejemplo n.º 3
0
        public async Task MakeTest_FirmwareFolder()
        {
            var context = RISCVIntegration
                          .DefaultContext(TestPath.FirmwareSourceFolder)
                          .WithMakeTarget("firmware.bin");

            await RISCVIntegrationClient.Make(context);
        }
Ejemplo n.º 4
0
        public async Task MakeTest_MakeFolder()
        {
            var context = RISCVIntegration
                          .DefaultContext(TestPath.MakeFolder)
                          .WithMakeTarget("bin");

            await RISCVIntegrationClient.Make(context);
        }
        void Build(string testName)
        {
            // prepare source code for test
            File.Copy(Path.Combine(SourcesLocation, $"{testName}.S"), Path.Combine(TestLocation, $"{testName}.S"));

            var Makefile  = Path.Combine(TestLocation, "Makefile");
            var makeLines = File.ReadAllLines(Makefile);

            makeLines[0] = $"files = {testName}.S";
            File.WriteAllLines(Makefile, makeLines);

            // make test instructions
            var context = RISCVIntegration
                          .DefaultContext(TestLocation)
                          .WithMakeTarget("bin");

            RISCVIntegrationClient.Make(context).Wait();
        }
        public bool FirmwareFromAppFolder()
        {
            if (!SourceExists)
            {
                return(false);
            }

            // delete old firmware before making new one
            if (File.Exists(FirmwareFile))
            {
                File.Delete(FirmwareFile);
            }

            var appName        = Path.GetFileName(appPath);
            var sourceFolder   = Path.Combine(appPath, "source");
            var firmwareFolder = Path.Combine(appPath, "firmware");

            var csFiles        = Directory.EnumerateFiles(sourceFolder);
            var csFilesContent = csFiles
                                 .Select(path => new FSTextFile()
            {
                Name = path, Content = File.ReadAllText(path)
            })
                                 .ToList();

            if (csFilesContent.Any())
            {
                foreach (var cs in csFilesContent)
                {
                    Console.WriteLine($"Found CS source: {cs.Name}");
                }

                // translate source files
                var tx     = new CSharp2CPPTranslator();
                var source = new FSSnapshot();
                source.Files.AddRange(csFilesContent);
                tx.Run(source);
                var firmwareSource = tx.Result;

                // create soc resource records
                var socGenerator      = new SOCGenerator();
                var socRecordsBuilder = new SOCRecordsBuilder();
                var socRecords        = socRecordsBuilder.ToSOCRecords(0x800, tx.SOCResources);
                firmwareSource.Add(socGenerator.SOCImport(socRecords));

                FileTools.CreateDirectoryRecursive(firmwareFolder);
                var m = new FSManager(firmwareFolder);
                m.SaveSnapshot(firmwareSource);
            }

            ModifyMakefile();

            if (File.Exists(MakefileFile))
            {
                var context = RISCVIntegration
                              .DefaultContext(firmwareFolder)
                              .WithMakeTarget("bin");

                RISCVIntegrationClient.Make(context).Wait();
            }

            if (File.Exists(FirmwareFile))
            {
                var disassembler = new Disassembler();
                File.WriteAllText(FirmwareAsmFile, disassembler.Disassemble(Instructions()));
            }

            return(File.Exists(FirmwareFile));
        }