public void WriteFlash(Fel fel, byte[] fes, byte[] uboot, UInt32 address, byte[] data, bool verify = true, string what = "NAND") { var size = data.LongLength; size = (size + Fel.sector_size - 1) / Fel.sector_size; size = size * Fel.sector_size; if (data.LongLength != size) { var newData = new byte[size]; Array.Copy(data, newData, data.Length); data = newData; } long maxProgress = (size / 65536) * (verify ? 2 : 1), progress = 0; // upload kernel through fel fel.WriteFlash(address, data, delegate(Fel.CurrentAction action, string command) { switch (action) { case Fel.CurrentAction.WritingMemory: SetStatus?.Invoke("Writing " + what); break; } progress++; SetProgress?.Invoke(Math.Min(progress, maxProgress), maxProgress); } ); if (verify) { var r = fel.ReadFlash((UInt32)Fel.kernel_base_f, (UInt32)data.LongLength, delegate(Fel.CurrentAction action, string command) { switch (action) { case Fel.CurrentAction.ReadingMemory: SetStatus("Reading " + what); break; } progress++; SetProgress?.Invoke(Math.Min(progress, maxProgress), maxProgress); } ); if (!data.SequenceEqual(r)) { throw new Exception("Verify failed for " + what); } } }
public void FlashKernel() { int progress = 0; int maxProgress = 115 + (string.IsNullOrEmpty(Mod) ? 0 : 30) + ((hmodsInstall != null && hmodsInstall.Count() > 0) ? 75 : 0); var hmods = hmodsInstall; hmodsInstall = null; if (WaitForFelFromThread() != DialogResult.OK) { DialogResult = DialogResult.Abort; return; } progress += 5; SetProgress(progress, maxProgress); byte[] kernel; if (!string.IsNullOrEmpty(Mod)) { kernel = CreatePatchedKernel(); progress += 5; SetProgress(progress, maxProgress); } else { kernel = File.ReadAllBytes(KernelDump); } var size = CalcKernelSize(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; } fel.WriteFlash(Fel.kernel_base_f, kernel, delegate(Fel.CurrentAction action, string command) { switch (action) { case Fel.CurrentAction.RunningCommand: SetStatus(Resources.ExecutingCommand + " " + command); break; case Fel.CurrentAction.WritingMemory: SetStatus(Resources.UploadingKernel); break; } progress++; SetProgress(progress, maxProgress); } ); var r = fel.ReadFlash((UInt32)Fel.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); } ); if (!kernel.SequenceEqual(r)) { throw new Exception(Resources.VerifyFailed); } hmodsInstall = hmods; if (hmodsInstall != null && hmodsInstall.Count() > 0) { Memboot(maxProgress, progress); // Lets install some mods } else { var shutdownCommand = string.Format("shutdown", Fel.kernel_base_m); SetStatus(Resources.ExecutingCommand + " " + shutdownCommand); fel.RunUbootCmd(shutdownCommand, true); SetStatus(Resources.Done); SetProgress(maxProgress, maxProgress); } }
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); }
public void FlashKernel() { int progress = 5; int maxProgress = 120 + (string.IsNullOrEmpty(Mod) ? 0 : 5); SetProgress(progress, maxProgress); byte[] kernel; int pos = 0, totalFiles; if (!string.IsNullOrEmpty(Mod)) { kernel = CreatePatchedKernel(ref pos, out totalFiles); progress += 5; SetProgress(progress, maxProgress); } 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; } fel.WriteFlash(Fel.kernel_base_f, kernel, delegate(Fel.CurrentAction action, string command) { switch (action) { case Fel.CurrentAction.RunningCommand: SetStatus(Resources.ExecutingCommand + " " + command); break; case Fel.CurrentAction.WritingMemory: SetStatus(Resources.UploadingKernel); break; } progress++; SetProgress(progress, maxProgress); } ); var r = fel.ReadFlash((UInt32)Fel.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); } ); if (!kernel.SequenceEqual(r)) { throw new Exception(Resources.VerifyFailed); } if (string.IsNullOrEmpty(Mod)) { var shutdownCommand = string.Format("shutdown", Fel.kernel_base_m); SetStatus(Resources.ExecutingCommand + " " + shutdownCommand); fel.RunUbootCmd(shutdownCommand, true); } SetStatus(Resources.Done); SetProgress(maxProgress, maxProgress); }