示例#1
0
文件: fup.cs 项目: glocklueng/NXP_DFU
        public static bool phaseTwo(String filename, NXPDFUMachine nxpdfu)
        {
            bool       done         = false;
            int        transferSize = (dfu.wTransferSize < dfu.iobuf.Length) ? dfu.wTransferSize : dfu.iobuf.Length;
            int        totalbytes   = 0;
            FileStream bin          = File.Open(filename, FileMode.Open);
            int        actual;

            nxpdfu.set_debug(0, 0);
            verboseOut("Erase...");
            nxpdfu.erase_all();
            verboseOut("Program...");
            nxpdfu.program_region(bin, 0);
            verboseOut("Verify Read back...");
            if (nxpdfu.verify_read(bin, 0))
            {
                verboseOut("Firmware update verified!");
            }
            else
            {
                Console.WriteLine("ERROR IN VERIFY! PLEASE TRY AGAIN!!");
                return(false);
            }

            verboseOut("Reboot.");
            nxpdfu.reset();

            return(true);
        }
示例#2
0
文件: fup.cs 项目: glocklueng/NXP_DFU
        public static void Main(string[] args)
        {
            bool   show_help = false;
            String secloader = "";
            String binfile   = "";
            int    exitCode  = 1;

            var p = new OptionSet()
            {
                { "v|verbose", "tell me what's happening during program.", v => chatty = (v != null) },
                { "d|debug", "more debugging output.", v => debug = (v != null) },
                { "s|secondary_loader=", "filename of secondary loader", v => secloader = v },
                { "b|binfile=", "filename of bin flash image", v => binfile = v },
                { "h|help", "show this message and exit", v => show_help = (v != null) },
            };

            List <string> extra;

            try {
                extra = p.Parse(args);
            }
            catch (OptionException e) {
                Console.Write("fup: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `fup --help' for more information.");
                return;
            }

            if (secloader.Length == 0 || binfile.Length == 0)
            {
                show_help = true;
            }


            if (show_help)
            {
                ShowHelp(p);
                return;
            }

            if (debug)
            {
                chatty = true;
            }

            ourDevice = findOurDevice();
            dfu       = new DFUMachine(ourDevice);

            if (dfu.findInterface())
            {
                verboseOut("Found DFU interface");
                dfu.claimIface();
                DEBUG("wTransferSize = " + dfu.wTransferSize.ToString());
            }
            //Hack
            if (dfu.wTransferSize == 0)
            {
                dfu.wTransferSize = 2048;
            }
            phaseOne(secloader, dfu);

            verboseOut("Wait 5 sec for next phase ...");
            Thread.Sleep(5000);
            if (ourDevice.IsOpen)
            {
                ourDevice.Close();
            }
            ourDevice = findOurDevice();
            nxpdfu    = new NXPDFUMachine(ourDevice);
            if (nxpdfu.findInterface())
            {
                verboseOut("Found DFU interface");
                nxpdfu.claimIface();
                DEBUG("wTransferSize = " + nxpdfu.wTransferSize.ToString());
            }
            //Hack
            if (nxpdfu.wTransferSize == 0)
            {
                nxpdfu.wTransferSize = 2048;
            }
            if (phaseTwo(binfile, nxpdfu))
            {
                exitCode = 0;
            }

            if (ourDevice.IsOpen)
            {
                ourDevice.Close();
            }
            UsbDevice.Exit();
            Environment.Exit(exitCode);
        } //Main