mirror of
https://github.com/mashed-potatoes/PotatoNV.git
synced 2024-11-10 01:02:20 +01:00
Now it can flash bootloader. wow!
This commit is contained in:
parent
f572372ed2
commit
388381334b
2 changed files with 64 additions and 2 deletions
|
@ -1,5 +1,9 @@
|
||||||
using System;
|
using Potato.Fastboot;
|
||||||
|
using Potato.ImageFlasher;
|
||||||
|
using PotatoNV_next.Utils;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -8,9 +12,66 @@ namespace PotatoNV_next
|
||||||
{
|
{
|
||||||
class Core
|
class Core
|
||||||
{
|
{
|
||||||
public static void StartProcess(Controls.NVForm.FormEventArgs formEventArgs)
|
private static void FlashBootloader(Bootloader bootloader, string port)
|
||||||
{
|
{
|
||||||
|
var flasher = new ImageFlasher();
|
||||||
|
|
||||||
|
Log.Info("Verifying images...");
|
||||||
|
|
||||||
|
foreach (var image in bootloader.Images)
|
||||||
|
{
|
||||||
|
Log.Debug($"VrStat of {image.Role}: {image.IsValid}");
|
||||||
|
|
||||||
|
if (!image.IsValid)
|
||||||
|
{
|
||||||
|
throw new Exception($"Image `{image.Role}` is invalid!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Success("Verification passed!");
|
||||||
|
|
||||||
|
Log.Debug($"Opening {port}...");
|
||||||
|
|
||||||
|
flasher.Open(port);
|
||||||
|
|
||||||
|
Log.Info($"Uploading {bootloader.Name} bootloader");
|
||||||
|
|
||||||
|
foreach (var image in bootloader.Images)
|
||||||
|
{
|
||||||
|
Log.Info($" - {image.Role}");
|
||||||
|
flasher.Write(image.Path, (int)image.Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
flasher.Close();
|
||||||
|
|
||||||
|
Log.Success("Bootloader uploaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StartProcess(Controls.NVForm.FormEventArgs args)
|
||||||
|
{
|
||||||
|
var worker = new BackgroundWorker();
|
||||||
|
worker.DoWork += Worker_DoWork;
|
||||||
|
worker.RunWorkerAsync(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Worker_DoWork(object sender, DoWorkEventArgs e)
|
||||||
|
{
|
||||||
|
var args = e.Argument as Controls.NVForm.FormEventArgs;
|
||||||
|
var fb = new Fastboot();
|
||||||
|
|
||||||
|
if (args.TargetMode == UsbController.Device.DMode.DownloadVCOM)
|
||||||
|
{
|
||||||
|
Log.Info("--> Flashing bootloader");
|
||||||
|
FlashBootloader(args.Bootloader, args.Target.Split(':')[0]);
|
||||||
|
|
||||||
|
Log.Info("Waiting for any device...");
|
||||||
|
fb.Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Info("Connecting to fastboot device...");
|
||||||
|
fb.Connect();
|
||||||
|
fb.Command("reboot");
|
||||||
|
fb.Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace PotatoNV_next
|
||||||
{
|
{
|
||||||
Icon = MediaConverter.ImageSourceFromBitmap(Properties.Resources.Fire.ToBitmap());
|
Icon = MediaConverter.ImageSourceFromBitmap(Properties.Resources.Fire.ToBitmap());
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
nvFrom.OnFormSubmit += Core.StartProcess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue