Skip to content

Commit 43042d8

Browse files
committed
asahi_firmware: Clean up FWPackage path handling
Signed-off-by: Hector Martin <[email protected]>
1 parent 9295b19 commit 43042d8

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

asahi_firmware/core.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ def __hash__(self):
2121
return hash(self.sha)
2222

2323
class FWPackage(object):
24-
def __init__(self, tar_path, cpio_path):
24+
def __init__(self, path):
2525
self.closed = False
26-
self.tar_path = tar_path
27-
self.cpio_path = cpio_path
28-
self.tarfile = tarfile.open(tar_path, mode="w")
29-
self.cpiofile = cpio.CPIO(cpio_path)
26+
self.path = path
27+
self.tar_path = os.path.join(path, "firmware.tar")
28+
self.cpio_path = os.path.join(path, "firmware.cpio")
29+
self.tarfile = tarfile.open(self.tar_path, mode="w")
30+
self.cpiofile = cpio.CPIO(self.cpio_path)
3031
self.hashes = {}
3132
self.manifest = []
3233

3334
def close(self):
3435
if self.closed:
3536
return
3637

38+
self.closed = True
39+
3740
ti = tarfile.TarInfo("vendorfw/.vendorfw.manifest")
3841
ti.type = tarfile.REGTYPE
3942
fd = io.BytesIO()
@@ -45,7 +48,10 @@ def close(self):
4548

4649
self.tarfile.close()
4750
self.cpiofile.close()
48-
self.closed = True
51+
52+
with open(os.path.join(self.path, "manifest.txt"), "w") as fd:
53+
for i in self.manifest:
54+
fd.write(i + "\n")
4955

5056
def add_file(self, name, data):
5157
ti = tarfile.TarInfo(name)
@@ -74,10 +80,5 @@ def add_files(self, it):
7480
for name, data in it:
7581
self.add_file(name, data)
7682

77-
def save_manifest(self, filename):
78-
with open(filename, "w") as fd:
79-
for i in self.manifest:
80-
fd.write(i + "\n")
81-
8283
def __del__(self):
8384
self.close()

asahi_firmware/update.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def update_firmware(source, dest):
1212
if not raw_fw.exists():
1313
print(f"Could not find {raw_fw}")
1414

15-
pkg = FWPackage(os.path.join(dest, "firmware.tar"),
16-
os.path.join(dest, "firmware.cpio"))
15+
pkg = FWPackage(dest)
1716

1817
with tempfile.TemporaryDirectory() as tmpdir:
1918
tmpdir = pathlib.Path(tmpdir)
@@ -33,8 +32,6 @@ def update_firmware(source, dest):
3332

3433
pkg.close()
3534

36-
pkg.save_manifest(os.path.join(dest, "manifest.txt"))
37-
3835
def main():
3936
import argparse
4037
import logging

src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ def do_install(self, total_size=None):
431431

432432
pkg = None
433433
if self.osins.needs_firmware:
434-
pkg = asahi_firmware.core.FWPackage("firmware.tar", "firmware.cpio")
434+
os.path.makedirs("vendorfw", exist_ok=True)
435+
pkg = asahi_firmware.core.FWPackage("vendorfw")
435436
self.ins.collect_firmware(pkg)
436437
pkg.close()
437438
self.osins.firmware_package = pkg

src/osinstall.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ def install(self, stub_ins):
126126
p_plain(f" Copying firmware into {info.name} partition...")
127127
base = os.path.join(mountpoint, "vendorfw")
128128
logging.info(f"Firmware -> {base}")
129-
os.makedirs(base, exist_ok=True)
130-
shutil.copy(self.firmware_package.tar_path, os.path.join(base, "firmware.tar"))
131-
shutil.copy(self.firmware_package.cpio_path, os.path.join(base, "firmware.cpio"))
132-
self.firmware_package.save_manifest(os.path.join(base, "manifest.txt"))
129+
shutil.copytree(self.firmware_package.path, base)
133130
if part.get("copy_installer_data", False):
134131
mountpoint = self.dutil.mount(info.name)
135132
data_path = os.path.join(mountpoint, "asahi")

0 commit comments

Comments
 (0)