Exemple #1
0
        public Conclusion WaitForFelOrMembootableShell(Tasker tasker, Object syncObject = null)
        {
            if (tasker.HostForm.InvokeRequired)
            {
                return((Conclusion)tasker.HostForm.Invoke(new Func <Tasker, Object, Conclusion>(WaitForFelOrMembootableShell), new object[] { tasker, syncObject }));
            }

            tasker.SetStatus(Resources.WaitingForDevice);
            if (hakchi.Shell.IsOnline && hakchi.Shell.Execute("[ -f /proc/atags ]") == 0)
            {
                return(Conclusion.Success);
            }

            if (!WaitingFelForm.WaitForDevice(Shared.ClassicUSB.vid, Shared.ClassicUSB.pid, tasker.HostForm))
            {
                return(Conclusion.Abort);
            }

            fel.Fes1Bin = Resources.fes1;
            if (ConfigIni.Instance.MembootUboot == Fel.UbootType.SD)
            {
                fel.UBootBin = Resources.ubootSD;
            }
            else
            {
                fel.UBootBin = Resources.uboot;
            }
            if (!fel.Open(Shared.ClassicUSB.vid, Shared.ClassicUSB.pid))
            {
                throw new FelException("Can't open device");
            }
            tasker.SetStatus(Resources.UploadingFes1);
            fel.InitDram(true);
            return(Conclusion.Success);
        }
Exemple #2
0
        public void StartThread()
        {
            fel = new Fel();
            SetProgress(0, 1);
            try
            {
                if (Task != Tasks.DownloadAllCovers)
                {
                    if (!File.Exists(fes1Path))
                    {
                        throw new FileNotFoundException(fes1Path + " not found");
                    }
                    if (!File.Exists(ubootPath))
                    {
                        throw new FileNotFoundException(ubootPath + " not found");
                    }
                    fel.Fes1Bin  = File.ReadAllBytes(fes1Path);
                    fel.UBootBin = File.ReadAllBytes(ubootPath);
                    fel.Open(vid, pid);
                    SetStatus(Resources.UploadingFes1);
                    fel.InitDram(true);
                }
                switch (Task)
                {
                case Tasks.DumpKernel:
                    DoKernelDump();
                    break;

                case Tasks.FlashKernel:
                    FlashKernel();
                    break;

                case Tasks.Memboot:
                    Memboot();
                    break;

                case Tasks.DownloadAllCovers:
                    DownloadAllCovers();
                    break;
                }
                Thread.Sleep(1000);
                DialogResult = DialogResult.OK;
            }
            catch (ThreadAbortException) { }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                thread = null;
                if (fel != null)
                {
                    fel.Close();
                    fel = null;
                }
            }
        }
Exemple #3
0
        public void StartThread()
        {
            fel          = new Fel();
            fel.Fes1Bin  = Resources.fes1;
            fel.UBootBin = Resources.uboot;
            SetProgress(0, 100);
            try
            {
                fel.Open(vid, pid);
                SetStatus(Resources.UploadingFes1);
                fel.InitDram(true);
                switch (Task)
                {
                case Tasks.DumpKernel:
                    SetText(Resources.DumpingKernel);
                    DoKernelDump();
                    break;

                case Tasks.FlashKernel:
                    if (!string.IsNullOrEmpty(Mod))
                    {
                        SetText(Resources.FlasingCustom);
                    }
                    else
                    {
                        SetText(Resources.FlasingOriginal);
                    }
                    FlashKernel();
                    break;

                case Tasks.Memboot:
                    SetText(Resources.UploadingGames);
                    Memboot();
                    break;
                }
                Thread.Sleep(1000);
                DialogResult = DialogResult.OK;
            }
            catch (ThreadAbortException) { }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                thread = null;
                if (fel != null)
                {
                    fel.Close();
                    fel = null;
                }
            }
        }
Exemple #4
0
        private Conclusion WaitForFelOrMembootableShell(Tasker tasker, Object syncObject = null, bool sdRequired = false)
        {
            var hostForm = tasker.GetSpecificViews <Form>().FirstOrDefault();

            if (hostForm == default(Form))
            {
                hostForm = tasker.HostForm;
            }
            if (hostForm.InvokeRequired)
            {
                return((Conclusion)hostForm.Invoke(new Func <Tasker, Object, bool, Conclusion>(WaitForFelOrMembootableShell), new object[] { tasker, syncObject, sdRequired }));
            }

            tasker.SetStatus(Resources.WaitingForDevice);
            if (hakchi.Shell.IsOnline && hakchi.Shell.Execute("[ -f /proc/atags ]") == 0)
            {
                if (sdRequired)
                {
                    if (hakchi.Shell.Execute("hakchi mmcUsed") == 0)
                    {
                        return(Conclusion.Success);
                    }
                }
                else
                {
                    return(Conclusion.Success);
                }
            }

            if (!WaitingFelForm.WaitForDevice(hostForm))
            {
                return(Conclusion.Abort);
            }

            fel.Fes1Bin  = Resources.fes1;
            fel.UBootBin = hakchi.Hmod.GetUboot(UbootType.SD).ToArray();
            if (!fel.Open())
            {
                throw new FelException("Can't open device");
            }
            tasker.SetStatus(Resources.UploadingFes1);
            fel.InitDram(true);
            return(Conclusion.Success);
        }
Exemple #5
0
        public void StartThread()
        {
            fel          = new Fel();
            fel.Fes1Bin  = Resources.fes1;
            fel.UBootBin = Resources.uboot;
            SetProgress(0, 100);
            try
            {
                fel.Open(vid, pid);
                SetStatus(Resources.UploadingFes1);
                fel.InitDram(true);
                switch (Task)
                {
                case Tasks.DumpKernel:
                    DoKernelDump();
                    break;

                case Tasks.FlashKernel:
                    FlashKernel();
                    break;

                case Tasks.Memboot:
                    Memboot();
                    break;
                }
                Thread.Sleep(1000);
                DialogResult = DialogResult.OK;
            }
            catch (ThreadAbortException) { }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                thread = null;
                if (fel != null)
                {
                    fel.Close();
                    fel = null;
                }
            }
        }
Exemple #6
0
        public Conclusion WaitForFelOrMembootableShell(Tasker tasker, Object syncObject = null)
        {
            var hostForm = tasker.GetSpecificViews <Form>().FirstOrDefault();

            if (hostForm == default(Form))
            {
                hostForm = tasker.HostForm;
            }
            if (hostForm.InvokeRequired)
            {
                return((Conclusion)hostForm.Invoke(new Func <Tasker, Object, Conclusion>(WaitForFelOrMembootableShell), new object[] { tasker, syncObject }));
            }

            tasker.SetStatus(Resources.WaitingForDevice);
            if (hakchi.Shell.IsOnline && hakchi.Shell.Execute("[ -f /proc/atags ]") == 0)
            {
                return(Conclusion.Success);
            }

            if (!WaitingFelForm.WaitForDevice(hostForm))
            {
                return(Conclusion.Abort);
            }

            fel.Fes1Bin = Resources.fes1;
            if (ConfigIni.Instance.MembootUboot == ConfigIni.UbootType.SD)
            {
                fel.UBootBin = Resources.ubootSD;
            }
            else
            {
                fel.UBootBin = Resources.uboot;
            }
            if (!fel.Open())
            {
                throw new FelException("Can't open device");
            }
            tasker.SetStatus(Resources.UploadingFes1);
            fel.InitDram(true);
            return(Conclusion.Success);
        }
Exemple #7
0
        DialogResult WaitForFelFromThread()
        {
            if (InvokeRequired)
            {
                return((DialogResult)Invoke(new Func <DialogResult>(WaitForFelFromThread)));
            }
            SetStatus(Resources.WaitingForDevice);
            if (fel != null)
            {
                fel.Close();
            }
            TaskbarProgress.SetState(this, TaskbarProgress.TaskbarStates.Paused);
            var result = WaitingFelForm.WaitForDevice(vid, pid, this);

            if (result)
            {
                fel = new Fel();
                if (!File.Exists(fes1Path))
                {
                    throw new FileNotFoundException(fes1Path + " not found");
                }
                if (!File.Exists(ubootPath))
                {
                    throw new FileNotFoundException(ubootPath + " not found");
                }
                fel.Fes1Bin  = File.ReadAllBytes(fes1Path);
                fel.UBootBin = File.ReadAllBytes(ubootPath);
                fel.Open(vid, pid);
                SetStatus(Resources.UploadingFes1);
                fel.InitDram(true);
                TaskbarProgress.SetState(this, TaskbarProgress.TaskbarStates.Normal);
                return(DialogResult.OK);
            }
            TaskbarProgress.SetState(this, TaskbarProgress.TaskbarStates.Normal);
            return(DialogResult.Abort);
        }
Exemple #8
0
        public void FlashKernel()
        {
            int progress    = 5;
            int maxProgress = 120 + (string.IsNullOrEmpty(Mod) ? 0 : 5);

            SetProgress(progress, maxProgress);

            byte[] kernel;
            if (!string.IsNullOrEmpty(Mod))
            {
                kernel    = CreatePatchedKernel(Mod);
                progress += 5;
                SetProgress(progress, maxProgress);
            }
            else
            {
                kernel = File.ReadAllBytes(KernelDump);
            }
            var size = CalKernelSize(kernel);

            if (size > kernel.Length || size > kernel_max_size)
            {
                throw new Exception(Resources.InvalidKernelSize + " " + size);
            }

            size = (size + sector_size - 1) / sector_size;
            size = size * sector_size;
            if (kernel.Length != size)
            {
                var newK = new byte[size];
                Array.Copy(kernel, newK, kernel.Length);
                kernel = newK;
            }

            bool flashCommandExecuted = false;

            try
            {
                fel.WriteFlash(kernel_base_f, kernel,
                               delegate(Fel.CurrentAction action, string command)
                {
                    switch (action)
                    {
                    case Fel.CurrentAction.RunningCommand:
                        SetStatus(Resources.ExecutingCommand + " " + command);
                        flashCommandExecuted = true;
                        break;

                    case Fel.CurrentAction.WritingMemory:
                        SetStatus(Resources.UploadingKernel);
                        break;
                    }
                    progress++;
                    SetProgress(progress, maxProgress);
                }
                               );
            }
            catch (USBException ex)
            {
                fel.Close();
                if (flashCommandExecuted)
                {
                    SetStatus(Resources.WaitingForDevice);
                    waitDeviceResult = null;
                    WaitForDeviceInvoke(vid, pid);
                    while (waitDeviceResult == null)
                    {
                        Thread.Sleep(100);
                    }
                    if (!(waitDeviceResult ?? false))
                    {
                        DialogResult = DialogResult.Abort;
                        return;
                    }
                    Thread.Sleep(500);
                    fel          = new Fel();
                    fel.Fes1Bin  = Resources.fes1;
                    fel.UBootBin = Resources.uboot;
                    fel.Open(vid, pid);
                    SetStatus(Resources.UploadingFes1);
                    fel.InitDram(true);
                }
                else
                {
                    throw ex;
                }
            }
            var r = fel.ReadFlash((UInt32)kernel_base_f, (UInt32)kernel.Length,
                                  delegate(Fel.CurrentAction action, string command)
            {
                switch (action)
                {
                case Fel.CurrentAction.RunningCommand:
                    SetStatus(Resources.ExecutingCommand + " " + command);
                    break;

                case Fel.CurrentAction.ReadingMemory:
                    SetStatus(Resources.Verifying);
                    break;
                }
                progress++;
                SetProgress(progress, maxProgress);
            }
                                  );

            for (int i = 0; i < kernel.Length; i++)
            {
                if (kernel[i] != r[i])
                {
                    throw new Exception(Resources.VerifyFailed);
                }
            }
            var bootCommand = string.Format("boota {0:x}", kernel_base_m);

            SetStatus(Resources.ExecutingCommand + " " + bootCommand);
            fel.RunUbootCmd(bootCommand, true);
            SetStatus(Resources.Done);
            SetProgress(maxProgress, maxProgress);
        }
Exemple #9
0
        public void Memboot()
        {
            int pos = 0, totalFiles = 0;
            int progress = 5;

            SetProgress(progress, 300);
            int maxProgress = -1;

            do
            {
                if (pos > 0)
                {
                    ShowMessage(Resources.ParticallyBody, Resources.ParticallyTitle);
                    DeviceWaitResult = DialogResult.None;
                    WaitForDeviceFromThread();
                    while (DeviceWaitResult == DialogResult.None)
                    {
                        Thread.Sleep(500);
                    }
                    if (DeviceWaitResult != DialogResult.OK)
                    {
                        DialogResult = DialogResult.Abort;
                        return;
                    }
                    fel          = new Fel();
                    fel.Fes1Bin  = File.ReadAllBytes(fes1Path);
                    fel.UBootBin = File.ReadAllBytes(ubootPath);
                    fel.Open(vid, pid);
                    SetStatus(Resources.UploadingFes1);
                    fel.InitDram(true);
                }

                byte[] kernel;
                if (!string.IsNullOrEmpty(Mod))
                {
                    kernel = CreatePatchedKernel(ref pos, out totalFiles);
                }
                else
                {
                    kernel = File.ReadAllBytes(KernelDump);
                }
                var size = CalKernelSize(kernel);
                if (size > kernel.Length || size > Fel.kernel_max_size)
                {
                    throw new Exception(Resources.InvalidKernelSize + " " + size);
                }
                size = (size + Fel.sector_size - 1) / Fel.sector_size;
                size = size * Fel.sector_size;
                if (kernel.Length != size)
                {
                    var newK = new byte[size];
                    Array.Copy(kernel, newK, kernel.Length);
                    kernel = newK;
                }

                progress += 5;
                if (maxProgress < 0)
                {
                    if (pos > 0)
                    {
                        maxProgress = (kernel.Length / 67000 + 15) * totalFiles / pos + 75 * ((int)Math.Ceiling((float)totalFiles / (float)pos) - 1);
                    }
                    else
                    {
                        maxProgress = (kernel.Length / 67000 + 15);
                    }
                }
                SetProgress(progress, maxProgress);

                SetStatus(Resources.UploadingKernel);
                fel.WriteMemory(Fel.flash_mem_base, kernel,
                                delegate(Fel.CurrentAction action, string command)
                {
                    switch (action)
                    {
                    case Fel.CurrentAction.WritingMemory:
                        SetStatus(Resources.UploadingKernel);
                        break;
                    }
                    progress++;
                    SetProgress(progress, maxProgress);
                }
                                );

                var bootCommand = string.Format("boota {0:x}", Fel.kernel_base_m);
                SetStatus(Resources.ExecutingCommand + " " + bootCommand);
                fel.RunUbootCmd(bootCommand, true);
            } while (pos < totalFiles);
            SetStatus(Resources.Done);
            SetProgress(maxProgress, maxProgress);
        }