From 0b8b0733e865d9df22e0abc72cca68c0e4fa9b65 Mon Sep 17 00:00:00 2001 From: Arian Date: Thu, 14 Jul 2022 18:26:54 +0200 Subject: [PATCH] android: merge_dtbs: Respect miboard-id while merging Change-Id: Ic5b38a122173d8e9ecc1f0f399411cb37acf3150 --- build/tasks/kernel.mk | 2 +- build/tools/merge_dtbs.py | 50 ++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/build/tasks/kernel.mk b/build/tasks/kernel.mk index 4e008efdb..3340ba5b8 100644 --- a/build/tasks/kernel.mk +++ b/build/tasks/kernel.mk @@ -610,7 +610,7 @@ ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) $(hide) find $(DTBS_BASE) -type f -name "*.dtb*" | xargs rm -f $(hide) find $(DTBS_OUT) -type f -name "*.dtb*" | xargs rm -f mv $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/*/*.dtb $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/*/*.dtbo $(DTBS_BASE)/ - PATH=$(abspath $(HOST_OUT_EXECUTABLES)):$${PATH} python3 $(BUILD_TOP)/vendor/lineage/build/tools/merge_dtbs.py $(DTBS_BASE) $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/qcom $(DTBS_OUT) + PATH=$(abspath $(HOST_OUT_EXECUTABLES)):$${PATH} python3 $(BUILD_TOP)/vendor/stag/build/tools/merge_dtbs.py $(DTBS_BASE) $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/qcom $(DTBS_OUT) cat $(shell find $(DTB_OUT)/out -type f -name "${TARGET_MERGE_DTBS_WILDCARD}.dtb" | sort) > $@ else cat $(shell find $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts -type f -name "*.dtb" | sort) > $@ diff --git a/build/tools/merge_dtbs.py b/build/tools/merge_dtbs.py index 898be4ccc..a54093174 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 @@ def __str__(self): 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 @@ def __sub__(self, other): msm-id = , board-id = , pmic-id = <0, 1> + miboard-id = , Other has plat, board, pmic are: msm-id = , board-id = pmic-id = <0> + miboard-id = , (self - other) will split self into a set of devicetrees with different identifers and meets the following requirements: @@ -86,11 +91,13 @@ def __sub__(self, other): 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 @@ def __sub__(self, other): 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 @@ def __sub__(self, other): 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 @@ def _do_equivalent(self, other, property): 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 @@ def __gt__(self, other): 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 @@ def __contains__(self, other): 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 @@ def __init__(self, filename): # 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 @@ def save(self, name=None, out_dir='.'): 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 @@ def __str__(self): 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])