1 # SPDX-FileCopyrightText: 2023 Steve Jeong for Hardkernel
3 # SPDX-License-Identifier: MIT
6 Device Tree Alias Functions
9 from typing import Optional
14 def get_dts_alias(device: str) -> Optional[str]:
15 """Get the Device Tree Alias"""
16 uevent_path = "/sys/bus/platform/devices/" + device + "/uevent"
17 if os.path.exists(uevent_path):
18 with open(uevent_path, "r", encoding="utf-8") as fd:
19 pattern = r"^OF_ALIAS_0=(.*)$"
20 uevent = fd.read().split("\n")
22 match = re.search(pattern, line)
24 return match.group(1).upper()