-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathupdate.py
More file actions
52 lines (37 loc) · 1.65 KB
/
update.py
File metadata and controls
52 lines (37 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# SPDX-License-Identifier: MIT
import pathlib
import subprocess
import tempfile
from .bluetooth import BluetoothFWCollection
from .core import FWPackage
from .multitouch import MultitouchFWCollection
from .wifi import WiFiFWCollection
def update_firmware(source, dest, manifest):
raw_fw = source.joinpath("all_firmware.tar.gz")
if not raw_fw.exists():
print(f"Could not find {raw_fw}")
pkg = FWPackage(dest)
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = pathlib.Path(tmpdir)
subprocess.run(["tar", "xf", str(raw_fw.resolve())], cwd=tmpdir, check=True)
col = WiFiFWCollection(str(tmpdir.joinpath("firmware", "wifi")))
pkg.add_files(sorted(col.files()))
col = BluetoothFWCollection(str(tmpdir.joinpath("firmware", "bluetooth")))
pkg.add_files(sorted(col.files()))
col = MultitouchFWCollection(str(tmpdir.joinpath("fud_firmware")))
pkg.add_files(sorted(col.files()))
pkg.close()
pkg.save_manifest(manifest)
if __name__ == "__main__":
import argparse
import logging
logging.basicConfig()
parser = argparse.ArgumentParser(description='Update vendor firmware tarball')
parser.add_argument('source', metavar='DIR', type=pathlib.Path,
help='path containing raw firmware')
parser.add_argument('dest', metavar='FILE', type=pathlib.Path,
help='output vendor firmware tarball')
parser.add_argument('manifest', metavar='FILE', type=pathlib.Path,
help='output vendor firmware manifest')
args = parser.parse_args()
update_firmware(args.source, args.dest, args.manifest)