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