scripts: check_init_priorities: fix device function name display

Device init pointers have been moved off struct init_entry and into
struct device in 766bfe7b2e, but check_init_priorities.py have not been
modified to check the new pointer so it's been showing NULL for all
devices since.

Fix it by searching down the right pointer for device init entries.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2025-07-23 18:14:47 +01:00 committed by Chris Friedt
parent 6e3a1fda49
commit b1fccaad6e
2 changed files with 18 additions and 4 deletions

View File

@ -49,6 +49,9 @@ _IGNORE_COMPATIBLES = frozenset([
"zephyr,cdc-acm-uart",
])
# The offset of the init pointer in "struct device", in number of pointers.
DEVICE_INIT_OFFSET = 5
class Priority:
"""Parses and holds a device initialization priority.
@ -108,6 +111,7 @@ class ZephyrInitLevels:
def _load_objects(self):
"""Initialize the object table."""
self._objects = {}
self._object_addr = {}
for section in self._elf.iter_sections():
if not isinstance(section, SymbolTableSection):
@ -119,6 +123,7 @@ class ZephyrInitLevels:
sym.entry.st_info.type in ["STT_OBJECT", "STT_FUNC"]):
self._objects[sym.entry.st_value] = (
sym.name, sym.entry.st_size, sym.entry.st_shndx)
self._object_addr[sym.name] = sym.entry.st_value
def _load_level_addr(self):
"""Find the address associated with known init levels."""
@ -205,13 +210,18 @@ class ZephyrInitLevels:
arg0_name = self._object_name(self._initlevel_pointer(addr, 0, shidx))
arg1_name = self._object_name(self._initlevel_pointer(addr, 1, shidx))
self.initlevels[level].append(f"{obj}: {arg0_name}({arg1_name})")
ordinal = self._device_ord_from_name(arg1_name)
if ordinal:
dev_addr = self._object_addr[arg1_name]
_, _, shidx = self._objects[dev_addr]
arg0_name = self._object_name(self._initlevel_pointer(
dev_addr, DEVICE_INIT_OFFSET, shidx))
prio = Priority(level, priority)
self.devices[ordinal] = (prio, arg0_name)
self.initlevels[level].append(f"{obj}: {arg0_name}({arg1_name})")
addr += size
priority += 1

View File

@ -210,15 +210,19 @@ class testZephyrInitLevels(unittest.TestCase):
0x04: ("b", 4, 0),
0x08: ("c", 4, 0),
}
obj._object_addr = {
"__device_dts_ord_11": 0x00,
"__device_dts_ord_22": 0x04,
}
mock_ip.side_effect = lambda *args: args
def mock_obj_name(*args):
if args[0] == (0, 0, 0):
if args[0] == (0, 5, 0):
return "i0"
elif args[0] == (0, 1, 0):
return "__device_dts_ord_11"
elif args[0] == (4, 0, 0):
elif args[0] == (4, 5, 0):
return "i1"
elif args[0] == (4, 1, 0):
return "__device_dts_ord_22"