Files
lineage_patches/vendor/lineage/0001-android-merge_dtbs-Respect-miboard-id-while-merging.patch
2024-04-11 00:49:37 +08:00

205 lines
8.1 KiB
Diff

From 6a0a02f56cc761f27565c072fe7f3d33514ff9ed Mon Sep 17 00:00:00 2001
From: Arian <arian.kulmer@web.de>
Date: Thu, 14 Jul 2022 18:26:54 +0200
Subject: [PATCH] android: merge_dtbs: Respect miboard-id while merging
Change-Id: Ic5b38a122173d8e9ecc1f0f399411cb37acf3150
---
build/tools/merge_dtbs.py | 50 ++++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 16 deletions(-)
diff --git a/build/tools/merge_dtbs.py b/build/tools/merge_dtbs.py
index 898be4cc..a5409317 100755
--- a/build/tools/merge_dtbs.py
+++ b/build/tools/merge_dtbs.py
@@ -44,10 +44,11 @@ def split_array(array, cells):
return frozenset(tuple(array[i*cells:(i*cells)+cells]) for i in range(len(array) // cells))
class DeviceTreeInfo(object):
- def __init__(self, plat, board, pmic):
+ def __init__(self, plat, board, pmic, miboard):
self.plat_id = plat
self.board_id = board
self.pmic_id = pmic
+ self.miboard_id = miboard
def __str__(self):
s = ""
@@ -57,13 +58,15 @@ class DeviceTreeInfo(object):
s += " board-id = <{}>;".format(" ".join(map(str, self.board_id)))
if self.pmic_id is not None:
s += " pmic-id = <{}>;".format(" ".join(map(str, self.pmic_id)))
+ if self.miboard_id is not None:
+ s += " miboard-id = <{}>;".format(" ".join(map(str, self.miboard_id)))
return s.strip()
def __repr__(self):
return "<{} {}>".format(self.__class__.__name__, str(self))
def has_any_properties(self):
- return self.plat_id is not None or self.board_id is not None or self.pmic_id is not None
+ return self.plat_id is not None or self.board_id is not None or self.pmic_id is not None or self.miboard_id is not None
def __sub__(self, other):
"""
@@ -71,11 +74,13 @@ class DeviceTreeInfo(object):
msm-id = <A>, <B>
board-id = <c>, <d>
pmic-id = <0, 1>
+ miboard-id = <e>, <f>
Other has plat, board, pmic are:
msm-id = <A>, <B>
board-id = <c>
pmic-id = <0>
+ miboard-id = <e>, <f>
(self - other) will split self into a set of devicetrees with different identifers
and meets the following requirements:
@@ -86,11 +91,13 @@ class DeviceTreeInfo(object):
assert self.plat_id is None or isinstance(self.plat_id, (set, frozenset))
assert self.board_id is None or isinstance(self.board_id, (set, frozenset))
assert self.pmic_id is None or isinstance(self.pmic_id, (set, frozenset))
+ assert self.miboard_id is None or isinstance(self.miboard_id, (set, frozenset))
assert other in self
new_plat = other.plat_id is not None and self.plat_id != other.plat_id
new_board = other.board_id is not None and self.board_id != other.board_id
new_pmic = other.pmic_id is not None and self.pmic_id != other.pmic_id
+ new_miboard = other.miboard_id is not None and self.miboard_id != other.miboard_id
res = set()
# Create the devicetree that matches other exactly
@@ -101,13 +108,15 @@ class DeviceTreeInfo(object):
s.board_id = other.board_id
if new_pmic:
s.pmic_id = other.pmic_id
+ if new_miboard:
+ s.miboard_id = other.miboard_id
res.add(s)
# now create the other possibilities by removing any combination of
# other's plat, board, and/or pmic. Set logic (unique elemnts) handles
# duplicate devicetrees IDs spit out by this loop
- for combo in combinations_with_replacement([True, False], 3):
- if not any((c and n) for (c, n) in zip(combo, (new_plat, new_board, new_pmic))):
+ for combo in combinations_with_replacement([True, False], 4):
+ if not any((c and n) for (c, n) in zip(combo, (new_plat, new_board, new_pmic, new_miboard))):
continue
s = copy.deepcopy(self)
if combo[0] and new_plat:
@@ -116,16 +125,18 @@ class DeviceTreeInfo(object):
s.board_id -= other.board_id
if combo[2] and new_pmic:
s.pmic_id -= other.pmic_id
+ if combo[3] and new_miboard:
+ s.miboard_id -= other.miboard_id
res.add(s)
return res
def __hash__(self):
- # Hash should only consider msm-id/board-id/pmic-id
- return hash((self.plat_id, self.board_id, self.pmic_id))
+ # Hash should only consider msm-id/board-id/pmic-id/miboard-id
+ return hash((self.plat_id, self.board_id, self.pmic_id, self.miboard_id))
def __and__(self, other):
s = copy.deepcopy(self)
- for prop in ['plat_id', 'board_id', 'pmic_id']:
+ for prop in ['plat_id', 'board_id', 'pmic_id', 'miboard_id']:
if getattr(self, prop) is None or getattr(other, prop) is None:
setattr(s, prop, None)
else:
@@ -141,14 +152,14 @@ class DeviceTreeInfo(object):
def __eq__(self, other):
"""
- Checks whether other plat_id, board_id, pmic_id matches either identically
+ Checks whether other plat_id, board_id, pmic_id, miboard_id matches either identically
or because the property is none
"""
if not isinstance(other, DeviceTreeInfo):
return False
if not other.has_any_properties():
return False
- return all(map(lambda p: self._do_equivalent(other, p), ['plat_id', 'board_id', 'pmic_id']))
+ return all(map(lambda p: self._do_equivalent(other, p), ['plat_id', 'board_id', 'pmic_id', 'miboard_id']))
def _do_gt(self, other, property):
@@ -180,7 +191,7 @@ class DeviceTreeInfo(object):
return False
if not other.has_any_properties():
return False
- return all(map(lambda p: self._do_gt(other, p), ['plat_id', 'board_id', 'pmic_id']))
+ return all(map(lambda p: self._do_gt(other, p), ['plat_id', 'board_id', 'pmic_id', 'miboard_id']))
def _do_contains(self, other, property):
@@ -214,7 +225,7 @@ class DeviceTreeInfo(object):
return False
if not other.has_any_properties():
return False
- return all(map(lambda p: self._do_contains(other, p), ['plat_id', 'board_id', 'pmic_id']))
+ return all(map(lambda p: self._do_contains(other, p), ['plat_id', 'board_id', 'pmic_id', 'miboard_id']))
class DeviceTree(DeviceTreeInfo):
def __init__(self, filename):
@@ -224,7 +235,8 @@ class DeviceTree(DeviceTreeInfo):
# default pmic-id-size is 4
pmic_id_size = self.get_prop('/', 'qcom,pmic-id-size', check_output=False) or 4
pmic_id = split_array(self.get_prop('/', 'qcom,pmic-id', check_output=False), pmic_id_size)
- super().__init__(msm_id, board_id, pmic_id)
+ miboard_id = split_array(self.get_prop('/', 'xiaomi,miboard-id', check_output=False), 2)
+ super().__init__(msm_id, board_id, pmic_id, miboard_id)
if not self.has_any_properties():
print('WARNING! {} has no properties and may match with any other devicetree'.format(self.filename))
@@ -260,10 +272,10 @@ class InnerMergedDeviceTree(DeviceTreeInfo):
It has a platform, board, and pmic ID, the "base" devicetree, and some set of add-on
devicetrees
"""
- def __init__(self, filename, plat_id, board_id, pmic_id, techpacks=None):
+ def __init__(self, filename, plat_id, board_id, pmic_id, miboard_id, techpacks=None):
self.base = filename
self.techpacks = techpacks or []
- super().__init__(plat_id, board_id, pmic_id)
+ super().__init__(plat_id, board_id, pmic_id, miboard_id)
def try_add(self, techpack):
if not isinstance(techpack, DeviceTree):
@@ -317,6 +329,12 @@ class InnerMergedDeviceTree(DeviceTreeInfo):
print(' {}'.format(' '.join(cmd)))
subprocess.run(cmd, check=True)
+ if self.miboard_id:
+ board_iter = self.miboard_id if isinstance(self.miboard_id, tuple) else chain.from_iterable(self.miboard_id)
+ cmd = ['fdtput', '-t', 'i', out_file, '/', 'xiaomi,miboard-id'] + list(map(str, board_iter))
+ print(' {}'.format(' '.join(cmd)))
+ subprocess.run(cmd, check=True)
+
return DeviceTree(out_file)
def get_name(self):
@@ -336,7 +354,7 @@ class InnerMergedDeviceTree(DeviceTreeInfo):
class MergedDeviceTree(object):
def __init__(self, other):
- self.merged_devicetrees = {InnerMergedDeviceTree(other.filename, other.plat_id, other.board_id, other.pmic_id)}
+ self.merged_devicetrees = {InnerMergedDeviceTree(other.filename, other.plat_id, other.board_id, other.pmic_id, other.miboard_id)}
def try_add(self, techpack):
did_add = False
@@ -395,7 +413,7 @@ def main():
.format(sys.argv[0]))
sys.exit(1)
- # 1. Parse the devicetrees -- extract the device info (msm-id, board-id, pmic-id)
+ # 1. Parse the devicetrees -- extract the device info (msm-id, board-id, pmic-id, miboard-id)
bases = parse_dt_files(sys.argv[1])
techpacks = parse_dt_files(sys.argv[2])
--
2.25.1