1#
2# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6
7''' generate a text file with matched compatible strings from the device tree '''
8import argparse
9
10from hardware import config, fdt
11from hardware.utils import rule
12
13
14def run(tree: fdt.FdtParser, hardware: rule.HardwareYaml, config: config.Config,
15        args: argparse.Namespace):
16    if not args.compat_strings_out:
17        raise ValueError('You need to specify a compat-strings-out to use compat strings output')
18    chosen = tree.get_kernel_devices()
19
20    compatibles = set()
21    for dev in chosen:
22        compatibles.add(hardware.get_matched_compatible(dev))
23
24    args.compat_strings_out.write(';'.join(sorted(compatibles)) + ';\n')
25    args.compat_strings_out.close()
26
27
28def add_args(parser):
29    parser.add_argument('--compat-strings-out',
30                        help='output file for compat strings list', type=argparse.FileType('w'))
31