|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +import os, plistlib, subprocess, logging |
| 3 | +from .core import FWFile |
| 4 | + |
| 5 | +log = logging.getLogger("asahi_firmware.als") |
| 6 | +FACTORY_DIR = "/System/Volumes/Hardware/FactoryData/System/Library/Caches/com.apple.factorydata/" |
| 7 | + |
| 8 | +class AlsFWCollection(object): |
| 9 | + def __init__(self): |
| 10 | + self.fwfiles = [] |
| 11 | + self.load() |
| 12 | + def files(self): |
| 13 | + return self.fwfiles |
| 14 | + def load(self): |
| 15 | + ioreg = subprocess.run(["ioreg", "-r", "-a", "-n", "als", "-l"], capture_output=True) |
| 16 | + if ioreg.returncode != 0: |
| 17 | + log.warning("Unable to run ioreg, ambient light sensor calibration will not be saved") |
| 18 | + return |
| 19 | + tree = plistlib.loads(ioreg.stdout) |
| 20 | + try: |
| 21 | + cal_data = tree[0]["IORegistryEntryChildren"][0]["IORegistryEntryChildren"][0]["IORegistryEntryChildren"][0]["CalibrationData"] |
| 22 | + except: |
| 23 | + log.warning("Unable to find ambient light sensor calibration data") |
| 24 | + return |
| 25 | + filename = "apple/aop-als-cal.bin" |
| 26 | + fw = FWFile(filename, cal_data) |
| 27 | + self.fwfiles.append((filename, fw)) |
| 28 | + log.info(f" Collected {filename}") |
| 29 | + try: |
| 30 | + for f in os.listdir(FACTORY_DIR): |
| 31 | + if not f.startswith('HmCA'): |
| 32 | + continue |
| 33 | + data = open(f'{FACTORY_DIR}/{f}', 'rb').read() |
| 34 | + name = f'apple/{f}' |
| 35 | + fw = FWFile(name, data) |
| 36 | + self.fwfiles.append((name, fw)) |
| 37 | + except: |
| 38 | + log.warning("Unable to find raw ambient light sensor calibration data") |
| 39 | + return |
0 commit comments