|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +import pathlib, tempfile, subprocess |
| 3 | + |
| 4 | +from .core import FWPackage |
| 5 | +from .wifi import WiFiFWCollection |
| 6 | +from .bluetooth import BluetoothFWCollection |
| 7 | + |
| 8 | +def update_firmware(source, dest, manifest): |
| 9 | + raw_fw = source.joinpath("all_firmware.tar.gz") |
| 10 | + if not raw_fw.exists(): |
| 11 | + print(f"Could not find {raw_fw}") |
| 12 | + |
| 13 | + pkg = FWPackage(dest) |
| 14 | + |
| 15 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 16 | + tmpdir = pathlib.Path(tmpdir) |
| 17 | + subprocess.run(["tar", "xf", str(raw_fw.resolve())], cwd=tmpdir, check=True) |
| 18 | + col = WiFiFWCollection(str(tmpdir.joinpath("firmware", "wifi"))) |
| 19 | + pkg.add_files(sorted(col.files())) |
| 20 | + col = BluetoothFWCollection(str(tmpdir.joinpath("firmware", "bluetooth"))) |
| 21 | + pkg.add_files(sorted(col.files())) |
| 22 | + |
| 23 | + pkg.close() |
| 24 | + |
| 25 | + pkg.save_manifest(manifest) |
| 26 | + |
| 27 | +if __name__ == "__main__": |
| 28 | + import argparse |
| 29 | + |
| 30 | + parser = argparse.ArgumentParser(description='Update vendor firmware tarball') |
| 31 | + parser.add_argument('source', metavar='DIR', type=pathlib.Path, |
| 32 | + help='path containing raw firmware') |
| 33 | + parser.add_argument('dest', metavar='FILE', type=pathlib.Path, |
| 34 | + help='output vendor firmware tarball') |
| 35 | + parser.add_argument('manifest', metavar='FILE', type=pathlib.Path, |
| 36 | + help='output vendor firmware manifest') |
| 37 | + |
| 38 | + args = parser.parse_args() |
| 39 | + |
| 40 | + update_firmware(args.source, args.dest, args.manifest) |
0 commit comments