Skip to content

Commit

Permalink
android: merge_dtbs: Respect miboard-id while merging
Browse files Browse the repository at this point in the history
Change-Id: Ic5b38a122173d8e9ecc1f0f399411cb37acf3150
  • Loading branch information
ArianK16a authored and vjspranav committed Jun 25, 2024
1 parent 38d04d9 commit 0b8b073
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build/tasks/kernel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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) > $@
Expand Down
50 changes: 34 additions & 16 deletions build/tools/merge_dtbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -57,25 +58,29 @@ 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):
"""
This devicetree has plat, board, and pmic id described like this:
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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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))
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit 0b8b073

Please sign in to comment.