Repository navigation
Expand file tree
/
Copy pathprepare-kernel.py
More file actions
56 lines (51 loc) · 2.83 KB
/
Copy pathprepare-kernel.py
File metadata and controls
56 lines (51 loc) · 2.83 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
53
54
55
56
#!/usr/bin/env python3
"""Apply shared fixes to a clean, pinned E5 kernel without T551M board patches."""
import argparse
from pathlib import Path
import runpy
import subprocess
SHARED = Path(__file__).resolve().parents[1] / 'linux_device_common/kernel'
COMMIT = '020b970e351e'
def apply(kernel):
kernel = Path(kernel)
head = subprocess.check_output(['git', '-C', str(kernel), 'rev-parse', 'HEAD'], text=True).strip()
if not head.startswith(COMMIT):
raise ValueError('Expected E5 kernel ' + COMMIT)
runpy.run_path(str(SHARED / 'display.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'power.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'charger-capabilities.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'emmc.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'sd-power.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'eic.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'thermal.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'sipa.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'fuel-gauge.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'wifi-sae.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'wifi-stations.py'))['apply'](kernel)
# A separate checkout is essential: the donor replaces the charger and
# disables E5's touch firmware and amplifier. Never build E5 from that tree.
for path in ('drivers/power/supply/bq2560x-charger.c',
'drivers/unisoc_platform/sprd_disp/t551m-backlight.h',
'drivers/power/supply/board-charge-profile.h'):
if (kernel / path).exists():
raise ValueError('T551M board adaptation found; use a clean E5 checkout: ' + path)
replace_function = runpy.run_path(str(SHARED / 'charger.py'))['replace_function']
runpy.run_path(str(SHARED / 'usb_charger.py'))['apply'](
kernel, replace_function, restore_board_current=False)
runpy.run_path(str(SHARED / 'otg.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'cpufreq.py'))['apply'](kernel)
runpy.run_path(str(SHARED / 'wifi.py'))['apply'](kernel)
runpy.run_path(str(Path(__file__).with_name('charger.py')))['apply'](kernel, replace_function)
path = kernel / 'drivers/unisoc_platform/sprdwcn/platform/sysfs.c'
text = path.read_text()
marker = 'Default firmware debug log off'
if marker not in text:
anchor = '\t\tsysfs_info.armlog_status = 1;\n#endif'
if text.count(anchor) != 1:
raise ValueError('Unexpected WCN firmware log default')
text = text.replace(anchor, anchor + '\n\t/* ' + marker + '; explicitly enable through sysfs. */\n\tsysfs_info.armlog_status = 0;')
path.write_text(text)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('kernel', type=Path)
apply(parser.parse_args().kernel)