Apply formatting
This commit is contained in:
parent
8b943a903a
commit
98040d8a31
10 changed files with 375 additions and 232 deletions
42
flash.py
42
flash.py
|
@ -3,7 +3,7 @@ from boot import dump_bootimg
|
|||
import os
|
||||
import subprocess
|
||||
import click
|
||||
from logger import *
|
||||
from logger import logging, setup_logging, verbose_option
|
||||
|
||||
ROOTFS = 'rootfs'
|
||||
BOOTIMG = 'bootimg'
|
||||
|
@ -29,8 +29,7 @@ def cmd_flash(verbose, what, location):
|
|||
logging.info(f'You need to specify a location to flash {what} to')
|
||||
exit(1)
|
||||
if location not in locations:
|
||||
logging.info(
|
||||
f'Invalid location {location}. Choose one of {", ".join(locations)} for location')
|
||||
logging.info(f'Invalid location {location}. Choose one of {", ".join(locations)} for location')
|
||||
exit(1)
|
||||
|
||||
dir = '/dev/disk/by-id'
|
||||
|
@ -38,41 +37,50 @@ def cmd_flash(verbose, what, location):
|
|||
sanitized_file = file.replace('-', '').replace('_', '').lower()
|
||||
if f'jumpdrive{location.split("-")[0]}' in sanitized_file:
|
||||
path = os.path.realpath(os.path.join(dir, file))
|
||||
result = subprocess.run(['lsblk',
|
||||
path,
|
||||
'-o', 'SIZE'],
|
||||
capture_output=True)
|
||||
result = subprocess.run(['lsblk', path, '-o', 'SIZE'], capture_output=True)
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to lsblk {path}')
|
||||
exit(1)
|
||||
if result.stdout == b'SIZE\n 0B\n':
|
||||
logging.info(
|
||||
f'Disk {path} has a size of 0B. That probably means it is not available (e.g. no microSD inserted or no microSD card slot installed in the device) or corrupt or defect')
|
||||
f'Disk {path} has a size of 0B. That probably means it is not available (e.g. no microSD inserted or no microSD card slot installed in the device) or corrupt or defect'
|
||||
)
|
||||
exit(1)
|
||||
|
||||
if location.endswith('-file'):
|
||||
logging.fatal('Not implemented yet')
|
||||
exit()
|
||||
else:
|
||||
result = subprocess.run(['dd',
|
||||
f'if={image_name}',
|
||||
f'of={path}',
|
||||
'bs=20M',
|
||||
'iflag=direct',
|
||||
'oflag=direct',
|
||||
'status=progress'])
|
||||
result = subprocess.run([
|
||||
'dd',
|
||||
f'if={image_name}',
|
||||
f'of={path}',
|
||||
'bs=20M',
|
||||
'iflag=direct',
|
||||
'oflag=direct',
|
||||
'status=progress',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to flash {image_name} to {path}')
|
||||
exit(1)
|
||||
|
||||
elif what == BOOTIMG:
|
||||
result = subprocess.run(['fastboot', 'erase', 'dtbo'])
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'erase',
|
||||
'dtbo',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to erase dtbo')
|
||||
exit(1)
|
||||
|
||||
path = dump_bootimg(image_name)
|
||||
result = subprocess.run(['fastboot', 'flash', 'boot', path])
|
||||
result = subprocess.run([
|
||||
'fastboot',
|
||||
'flash',
|
||||
'boot',
|
||||
path,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.info(f'Failed to flash boot.img')
|
||||
exit(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue