Esempio n. 1
0
        public bool FlashWrite(UInt32 Addr, UInt32 Size, byte[] Data)
        {
            bool   status     = false;
            Int32  Size_Left  = (Int32)Size;
            Int32  len_actual = 0;
            UInt32 offset     = 0;

            if (IsInited & Data.Length >= Size & Size > 0)
            {
                CallbackLog?.Invoke(String.Format("Flash Write at 0x{0:X}, size {1}", Addr, Size));
                status = true;
                TimeSpan time = StopwatchUtil.Time(() =>
                {
                    //JLinkARM.JLINKARM_SetBP(0, AmebaZ_Addresses.FlasherBreakpoint);
                    JLinkARM.JLINKARM_SetBPEx(AmebaZ_Addresses.FlasherBreakpoint, (0x000000F0 | 0xFFFFFF00 | 0x1));
                    //Thread.Sleep(25);
                    //JLinkARM.JLINKARM_GoEx(0x8000_0000, 1);

                    while (status)
                    {
                        len_actual = Size_Left;

                        if (len_actual > AmebaZ_Addresses.FlasherDataLen)
                        {
                            len_actual = (Int32)AmebaZ_Addresses.FlasherDataLen;
                        }

                        int halted = JLinkARM.JLINKARM_WaitForHalt(2000);
                        if (halted == 0)
                        {
                            CallbackError?.Invoke(String.Format("Wait for flasher Timeout!"));
                            status = false;
                            break;
                        }
                        else if (halted < 0)
                        {
                            CallbackError?.Invoke(String.Format("SoC Halt Error!"));
                            status = false;
                            break;
                        }

                        byte[] Data_RAW = new byte[len_actual];
                        Array.Copy(Data, offset, Data_RAW, 0, len_actual);

                        GCHandle Data_RAW_hndl = GCHandle.Alloc(Data_RAW, GCHandleType.Pinned);
                        IntPtr Data_RAW_Ptr    = Data_RAW_hndl.AddrOfPinnedObject();
                        JLinkARM.JLINKARM_WriteMem(AmebaZ_Addresses.FlasherData, (UInt32)len_actual, Data_RAW_Ptr);
                        Data_RAW_hndl.Free();

                        WriteU32(AmebaZ_Addresses.FlasherWriteAddr, Addr + offset);
                        WriteU32(AmebaZ_Addresses.FlasherBlockWriteSize, (UInt32)len_actual); // старт записи

                        Size_Left -= len_actual;
                        offset    += (UInt32)len_actual;

                        if (Size_Left == 0)
                        {
                            break;
                        }

                        //JLinkARM.JLINKARM_Go();
                        JLinkARM.JLINKARM_GoEx(0x8000_0000, 1);
                    }
                });

                WriteU8(AmebaZ_Addresses.FlasherSetComplete, 0x01); // выходим из загрузчика
                //JLinkARM.JLINKARM_Go();
                JLinkARM.JLINKARM_GoEx(0x8000_0000, 1);
                CallbackLog?.Invoke(String.Format("Time {0:0.00} ms, Speed {1:0.00} KB/s", time.TotalMilliseconds, (double)((double)Size / time.TotalMilliseconds)));
            }

            return(status);
        }
Esempio n. 2
0
        protected async override Task <ExitCode> InvokeInternal(ILogger logger)
        {
            var processManager = new ProcessManager();

            // Validate the presence of Xamarin.iOS
            var missingXamariniOS = false;

            if (_arguments.TemplateType == TemplateType.Managed)
            {
                var dotnetLog = new MemoryLog()
                {
                    Timestamp = false
                };
                var process = new Process();
                process.StartInfo.FileName  = "bash";
                process.StartInfo.Arguments = "-c \"" + _arguments.DotnetPath + " --info | grep \\\"Base Path\\\" | cut -d':' -f 2 | tr -d '[:space:]'\"";

                var result = await processManager.RunAsync(process, new MemoryLog(), dotnetLog, new MemoryLog(), TimeSpan.FromSeconds(5));

                if (result.Succeeded)
                {
                    var sdkPath = dotnetLog.ToString().Trim();
                    if (Directory.Exists(sdkPath))
                    {
                        var xamarinIosPath = Path.Combine(sdkPath, "Xamarin", "iOS", "Xamarin.iOS.CSharp.targets");
                        if (!File.Exists(xamarinIosPath))
                        {
                            missingXamariniOS = true;
                            logger.LogWarning("Failed to find the Xamarin iOS package which is needed for the Managed template: " + xamarinIosPath);
                        }
                    }
                }
            }

            // create the factory, which will be used to find the diff assemblies
            var assemblyLocator           = new AssemblyLocator(Directory.GetCurrentDirectory());
            var assemblyDefinitionFactory = new AssemblyDefinitionFactory(_arguments.TestingFramework, assemblyLocator);

            ITemplatedProject template = _arguments.TemplateType switch
            {
                TemplateType.Managed => new XamariniOSTemplate
                {
                    AssemblyDefinitionFactory = assemblyDefinitionFactory,
                    AssemblyLocator           = assemblyDefinitionFactory.AssemblyLocator,
                    OutputDirectoryPath       = _arguments.OutputDirectory,
                    IgnoreFilesRootDirectory  = _arguments.IgnoreFilesRootDirectory,
                    ProjectFilter             = new ProjectFilter(_arguments.IgnoreFilesRootDirectory, _arguments.TraitsRootDirectory),
                },
                _ => throw new Exception("The 'Native' template is not yet supported. Please use the managed one."),
            };

            var logs       = new Logs(_arguments.WorkingDirectory);
            var runLog     = logs.Create("package-log.txt", "Package Log");
            var consoleLog = new CallbackLog(s => logger.LogInformation(s))
            {
                Timestamp = false
            };

            var aggregatedLog = Log.CreateAggregatedLog(runLog, consoleLog);

            aggregatedLog.WriteLine("Generating scaffold app with:");
            aggregatedLog.WriteLine($"\tAppname: '{_arguments.AppPackageName}'");
            aggregatedLog.WriteLine($"\tAssemblies: '{string.Join(" ", _arguments.Assemblies)}'");
            aggregatedLog.WriteLine($"\tExtraArgs: '{_arguments.MtouchExtraArgs}'");

            // first step, generate the required info to be passed to the factory
            var projects = new List <(string Name, string[] Assemblies, string?ExtraArgs, double TimeoutMultiplier)> {
                // TODO: Timeout multiplier handling
                (Name : _arguments.AppPackageName, Assemblies : _arguments.Assemblies.ToArray(), ExtraArgs : _arguments.MtouchExtraArgs, TimeoutMultiplier : 1.0),
            };

            // TODO: we are not taking into account all the plaforms, just iOS
            var allProjects = new GeneratedProjects();

            foreach (var p in _arguments.Platforms)
            {
                // so wish that mono.options allowed use to use async :/
                var testProjects = await template.GenerateTestProjectsAsync(projects, XHarness.iOS.Shared.TestImporter.Platform.iOS);

                allProjects.AddRange(testProjects);
            }

            // We do have all the required projects, time to compile them
            aggregatedLog.WriteLine("Scaffold app generated.");

            // First step, nuget restore whatever is needed
            var projectPath = Path.Combine(_arguments.OutputDirectory, _arguments.AppPackageName + ".csproj");

            aggregatedLog.WriteLine($"Project path is {projectPath}");
            aggregatedLog.WriteLine($"Performing nuget restore.");

            using (var dotnetRestore = new Process())
            {
                dotnetRestore.StartInfo.FileName = _arguments.DotnetPath;
                var args = new List <string>
                {
                    "restore",
                    projectPath,
                    "--verbosity:detailed"
                };

                dotnetRestore.StartInfo.Arguments = StringUtils.FormatArguments(args);

                var result = await processManager.RunAsync(dotnetRestore, aggregatedLog, _nugetRestoreTimeout);

                if (result.TimedOut)
                {
                    aggregatedLog.WriteLine("nuget restore timedout.");
                    return(ExitCode.PACKAGE_BUNDLING_FAILURE_NUGET_RESTORE);
                }

                if (!result.Succeeded)
                {
                    aggregatedLog.WriteLine($"nuget restore exited with {result.ExitCode}");
                    return(ExitCode.PACKAGE_BUNDLING_FAILURE_NUGET_RESTORE);
                }
            }

            var finalResult = ExitCode.SUCCESS;

            // perform the build of the application
            using (var dotnetBuild = new Process())
            {
                dotnetBuild.StartInfo.FileName = _arguments.DotnetPath;

                // TODO: Only taking into account one platform
                // https://github.com/dotnet/xharness/issues/105
                if (_arguments.Platforms.Count > 1)
                {
                    logger.LogWarning($"Multi-platform targetting is not supported yet. Targetting {_arguments.Platforms[0]} only.");
                }

                dotnetBuild.StartInfo.Arguments = GetBuildArguments(projectPath, _arguments.Platforms[0].ToString());

                aggregatedLog.WriteLine($"Building {_arguments.AppPackageName} ({projectPath})");

                var result = await processManager.RunAsync(dotnetBuild, aggregatedLog, _msBuildTimeout);

                if (result.TimedOut)
                {
                    aggregatedLog.WriteLine("Build timed out after {0} seconds.", _msBuildTimeout.TotalSeconds);
                }
                else if (result.Succeeded)
                {
                    aggregatedLog.WriteLine("Build was successful.");
                }
                else if (!result.Succeeded)
                {
                    logger.LogError($"Build failed with return code: {result.ExitCode}");

                    finalResult = ExitCode.PACKAGE_BUNDLING_FAILURE_BUILD;

                    if (missingXamariniOS)
                    {
                        logger.LogWarning("Possible cause of the failure may be missing Xamarin iOS package");
                    }
                }
            }

            return(finalResult);
        }
Esempio n. 3
0
 public bool FlashWrite()
 {
     CallbackLog?.Invoke("Full Flash Write ...");
     return(FlashWrite(0x0000 /*AmebaZ_Addresses.FlashAddr*/, FlashSize, buffer));
     //return FlashWrite(0x0000 /*AmebaZ_Addresses.FlashAddr*/, 1024/*FlashSize*/, buffer);
 }