fix mechanism to write images

not 100 % sure that it is tested properly
This commit is contained in:
2026-08-20 17:43:48 +02:00
parent e81d0db1ca
commit 7e0e00ad30
4 changed files with 24 additions and 27 deletions
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
../firmware/bootfiles.bin
BIN
View File
Binary file not shown.
+24 -27
View File
@@ -43,53 +43,46 @@ class HostSystem:
class Linux(HostSystem):
rescue = """
Remark: not all cables might work.
Example on Markus Mac:
- does not work: black USB C to USB C cable
- works: white USB A to USB C cable plugged into docking station.
Please unpower the box with compute module,
start this script again and put power immediately."""
rescue = ""
usbbootdir = os.path.expanduser('~/usbboot')
def get_disks(self):
return [line for line in cmd('lsblk -d').split('\n') if line]
def rpiboot(self):
lines = []
with Popen(['sudo', './rpiboot', '-d', 'mass-storage-gadget64'], stdout=PIPE) as p:
msg = '\nswitch device power on now'
with Popen(['sudo', f'{self.usbbootdir}/rpiboot', '-d', f'{self.usbbootdir}/mass-storage-gadget64'], stdout=PIPE) as p:
tmo = 1
t = 0
while select([p.stdout], [], [], tmo)[0]:
rawline = p.stdout.readline()
if not rawline:
return tmo != 1
line = rawline.decode('latin-1').strip()
print(line)
if lines is None:
pass # print(line)
elif 'Waiting' in line:
if 'Waiting' in line:
tmo = 30
lines.append(line)
t = time.time()
elif tmo == 1:
lines.append(line)
else:
print('\n'.join(lines))
print(line)
lines = None
if msg:
print(msg)
msg = None
else:
p.terminate()
return False
def find_raspi(self):
input('make sure device is not connected [confirm]')
prevset = set(self.get_disks())
input('now connect [confirm]')
disks = self.wait_disks(prevset, 5)
short = {v.split()[0] for v in prevset}
if short != {'mmcblk0boot1', 'mmcblk0boot0', 'mmcblk0', 'NAME'}:
# not the disks we typically have on a dual-eth-rpi
input('make sure device is not powered [confirm]')
prevset = set(self.get_disks())
if self.kind in EMMC: # need rpiboot
disks = None
else:
input('now connect the device [confirm]')
disks = self.wait_disks(prevset, 5)
if not disks:
print('can not yet detect disk, try to run rpiboot')
print('if is blocked at "Waiting for BCM...", turn off and on power of target rpi')
input('\nconnect the device with power off [confirm]')
# cmd('sudo ./rpiboot -d mass-storage-gadget64')
self.rpiboot()
disks = self.wait_disks(prevset, 15)
@@ -111,6 +104,10 @@ class Linux(HostSystem):
return None
def write_image(self):
if not os.path.exists(self.usbbootdir):
print(f'please install the usbboot directory at {self.usbbootdir}')
return
print('troubleshooting: install newest version of usbboot')
proposed = [v.split()[0] for v in self.find_raspi()]
self.list_external()
if len(proposed) == 1:
@@ -135,7 +132,7 @@ class Linux(HostSystem):
print('you may be prompted for your account password for sudo')
os.system(f'sudo umount /dev/{dev}')
print('')
prt('get, uncompress and write... (takes about 15 min)')
prt('get, uncompress and write... (takes about 20-30 min)')
os.system(f'ssh {IMAGES_HOST} "dd if={self.imgdir}/{image} bs=512k" | lz4 -d | sudo dd of=/dev/{dev} bs=512k')
prt('unmount bootfs')
for _ in range(3):