mirror of
https://github.com/mashed-potatoes/PotatoNV-crossplatform.git
synced 2024-11-13 02:14:22 +01:00
a1ebe705c9
* Google's ADB package is now archived and doesn't build anymore Change-Id: I592ecc5946db87a0a847fd8f6d5119ed42cae293 Signed-off-by: Woomymy <woomy@woomy.be>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from time import sleep
|
|
import traceback
|
|
from . import ui
|
|
from fastbootpy import FastbootDevice, FastbootManager
|
|
|
|
def handle_exception(e: Exception, message: str):
|
|
ui.error(message)
|
|
traceback.print_exc()
|
|
exit(1)
|
|
|
|
|
|
class Fastboot:
|
|
def connect(self):
|
|
ui.info("Waiting for fastboot device")
|
|
while True:
|
|
devices = FastbootManager.devices()
|
|
if len(devices) == 1:
|
|
self.fb_dev = FastbootDevice.connect(devices[0])
|
|
ui.info(f"Connected to device {devices[0]}")
|
|
break
|
|
elif len(devices) > 1:
|
|
ui.error("More than one fastboot device is connected!")
|
|
|
|
def write_nvme(self, prop: str, data: bytes):
|
|
cmd = f"getvar:nve:{prop}@".encode('UTF-8')
|
|
print(cmd.decode("utf-8"))
|
|
cmd += data
|
|
ui.info(f"Command: {cmd}")
|
|
result = self.fb_dev.send(cmd)
|
|
ui.info(f"Getvar result: {result}")
|
|
|
|
def reboot(self):
|
|
result = self.fb_dev.reboot()
|
|
ui.info(f"Reboot result: {result}")
|
|
|
|
def reboot_bootloader(self):
|
|
result = self.fb_dev.reboot_bootloader()
|
|
ui.info(f"Reboot bootloader result: {result}")
|
|
|