aboutsummaryrefslogtreecommitdiffstats
path: root/meta-ti-bsp/recipes-kernel/linux/ti-kernel-devicetree-prefix.inc
blob: 04c910040b5b2c22cd85afa72c163ce47a380717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def get_dtbs_from_kernel(dts_dir, dts_prefix):
    import os
    import glob
    matches = []

    for prefix in dts_prefix.split():
        filenames = glob.glob(dts_dir + prefix + '*.dts')
        filenames += glob.glob(dts_dir + prefix + '*.dtso')
        for filename in filenames:
            # Before v6.2 kernels DTB Overlays shared the same name as DTB files
            # so we need to search the file to find the type
            with open(filename) as f:
                file_postfix = '.dtbo' if '/plugin/;' in f.read() else '.dtb'
            filename = os.path.split(filename)[1]
            filename = os.path.splitext(filename)[0] + file_postfix
            filename = os.path.join(os.path.split(prefix)[0], filename)
            matches.append(filename)
    return ' '.join(matches)

def get_merge_dtbs_from_kernel(dts_dir, dts_pattern):
    import os
    matches = []
    if dts_dir == "":
        return ' '
    for pattern in dts_pattern.split():
        pattern_dir = os.path.split(pattern)[0]
        pattern_target = os.path.split(pattern)[1].replace(".","-") + "s"
        makefile = dts_dir + "/" + pattern_dir + "/Makefile"
        if os.path.exists(makefile):
            with open(makefile) as f:
                if pattern_target in f.read():
                    matches.append(pattern)
    return ' '.join(matches)

KERNEL_DEVICETREE_DTBMERGE ?= ""

KERNEL_DEVICETREE = " \
    ${@get_dtbs_from_kernel('${S}/arch/${ARCH}/boot/dts/', '${KERNEL_DEVICETREE_PREFIX}')} \
    ${@get_merge_dtbs_from_kernel('${S}/arch/${ARCH}/boot/dts/', '${KERNEL_DEVICETREE_DTBMERGE}')} \
"