byte[] WaitRead(UInt32 address, UInt32 size) { SetStatus(Resources.WaitingForDevice); int errorCount = 0; while (true) { try { if ((errorCount > 0) && (errorCount % 5) == 0) { fel.Close(); Thread.Sleep(1000); fel.Open(vid, pid); } fel.ClearInputBuffer(); fel.VerifyDevice(); var data = fel.ReadMemory(address, size); return(data); } catch (Exception ex) { errorCount++; if (errorCount >= 15) { throw ex; } Thread.Sleep(1000); } } }
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; } } }
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; } } }
void WaitForDeviceFromThread() { if (InvokeRequired) { Invoke(new Action(WaitForDeviceFromThread)); return; } if (fel != null) { fel.Close(); } DeviceWaitResult = WaitingForm.WaitForDevice(vid, pid) ? DialogResult.OK : DialogResult.Abort; }
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); }
public void StartThread() { fel = new Fel(); try { fel.Open(vid, pid); 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; } } catch (ThreadAbortException) { } catch (Exception ex) { ShowError(ex.Message); } finally { thread = null; if (fel != null) { fel.Close(); fel = null; } } }
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; } } }
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); }