Skip to content

Commit 766ecc0

Browse files
WhatAmISupposedToPutHerejannau
authored andcommitted
Extract and store ALS calibration
Signed-off-by: Sasha Finkelstein <[email protected]>
1 parent 3865eba commit 766ecc0

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

asahi_firmware/als.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

src/stub.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from asahi_firmware.multitouch import MultitouchFWCollection
77
from asahi_firmware.kernel import KernelFWCollection
88
from asahi_firmware.isp import ISPFWCollection
9+
from asahi_firmware.als import AlsFWCollection
910
from util import *
1011

1112
class StubInstaller(PackageInstaller):
@@ -460,6 +461,9 @@ def collect_firmware(self, pkg):
460461
logging.info("Collecting Kernel firmware")
461462
col = KernelFWCollection(kernel_path)
462463
pkg.add_files(sorted(col.files()))
464+
logging.info("Collecting ALS firmware")
465+
col = AlsFWCollection()
466+
pkg.add_files(sorted(col.files()))
463467
logging.info("Making fallback firmware archive")
464468
subprocess.run(["tar", "czf", "all_firmware.tar.gz",
465469
"fud_firmware",

0 commit comments

Comments
 (0)