PotatoNV-crossplatform/usrlock/fastboot.py
Woomymy a1ebe705c9 fastboot: Replace google ADB with fastbootpy
* Google's ADB package is now archived and doesn't build anymore

Change-Id: I592ecc5946db87a0a847fd8f6d5119ed42cae293
Signed-off-by: Woomymy <woomy@woomy.be>
2023-12-29 05:41:47 +05:00

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}")