Пример #1
0
        static int Main(string[] args)
        {
            try
            {
                var result = CommandLine.Parser.Default.ParseArguments <MembootOptions, FlashBootOptions, FlashUbootOptions, ReadNandOptions, FlashNandOptions, RunUbootCommandOptions, UpdateEnterFelCommandOptions>(args).MapResult(
                    (MembootOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists && opts.BootImage.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.Memboot(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.BootImage.OpenRead());
                        return(0);
                    }
                    return(1);
                },
                    (FlashBootOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists && opts.BootImage.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.FlashBoot(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.BootImage.OpenRead());
                        return(0);
                    }
                    return(1);
                },
                    (FlashUbootOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.FlashUboot(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.FlashAll);
                        return(0);
                    }
                    return(1);
                },
                    (ReadNandOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        var data           = helpers.ReadFlash(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.Address, opts.Length, true);
                        using (var file = opts.Output.Open(FileMode.Create))
                        {
                            file.Write(data, 0, data.Length);
                            file.Close();
                        }
                        return(0);
                    }
                    return(1);
                },
                    (FlashNandOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.WriteFlash(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.Address, opts.Input.OpenRead(), true, opts.Verify);
                        return(0);
                    }
                    return(1);
                },
                    (RunUbootCommandOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.RunCommand(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.Command, opts.noreturn, true);
                        return(0);
                    }
                    return(1);
                },
                    (UpdateEnterFelCommandOptions opts) =>
                {
                    FelDevice().Wait();
                    try
                    {
                        using (FelLib.Fel fel = new FelLib.Fel())
                        {
                            fel.WriteLine += Console.WriteLine;
                            if (!fel.Open(isFel: false))
                            {
                                throw new Exception("USB Device Not Found");
                            }

                            if (!fel.UsbUpdateProbe())
                            {
                                throw new Exception("Failed to handshake with burn mode");
                            }
                            if (!fel.UsbUpdateEnterFel())
                            {
                                throw new Exception("Failed to enter FEL");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }

                    return(0);
                },
                    errs => 1
                    );

                Console.ReadLine();
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException);
                Console.ReadLine();
                return(1);
            }
        }
Пример #2
0
        static int Main(string[] args)
        {
            try
            {
                var result = CommandLine.Parser.Default.ParseArguments <MembootOptions, FlashBootOptions, FlashUbootOptions, ReadNandOptions, FlashNandOptions, RunUbootCommandOptions>(args).MapResult(
                    (MembootOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists && opts.BootImage.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.Memboot(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.BootImage.OpenRead());
                        return(0);
                    }
                    return(1);
                },
                    (FlashBootOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists && opts.BootImage.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.FlashBoot(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.BootImage.OpenRead());
                        return(0);
                    }
                    return(1);
                },
                    (FlashUbootOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.FlashUboot(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.FlashAll);
                        return(0);
                    }
                    return(1);
                },
                    (ReadNandOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        var data           = helpers.ReadFlash(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.Address, opts.Length, true);
                        using (var file = opts.Output.Open(FileMode.Create))
                        {
                            file.Write(data, 0, data.Length);
                            file.Close();
                        }
                        return(0);
                    }
                    return(1);
                },
                    (FlashNandOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.WriteFlash(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.Address, opts.Input.OpenRead(), true, opts.Verify);
                        return(0);
                    }
                    return(1);
                },
                    (RunUbootCommandOptions opts) =>
                {
                    if (opts.Fes.Exists && opts.Uboot.Exists)
                    {
                        FelDevice().Wait();
                        var helpers        = new FelHelpers.Helpers();
                        helpers.SetStatus += Console.WriteLine;
                        helpers.WriteLine += Console.WriteLine;
                        helpers.RunCommand(opts.Fes.OpenRead(), opts.Uboot.OpenRead(), opts.Command, opts.noreturn, true);
                        return(0);
                    }
                    return(1);
                },
                    errs => 1
                    );

                Console.ReadLine();
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException);
                Console.ReadLine();
                return(1);
            }
        }