2 # SPDX-License-Identifier: GPL-2.0-only
4 # Copyright 2016 by Frank Rowand
5 # Copyright 2016 by Gaurav Minocha
16 $script_name =~ s|^.*/||;
19 # ----- constants for print_flags()
21 # Position in string $pr_flags. Range of 0..($num_pr_flags - 1).
22 $pr_flag_pos_mcompatible = 0;
23 $pr_flag_pos_driver = 1;
24 $pr_flag_pos_mdriver = 2;
25 $pr_flag_pos_config = 3;
26 $pr_flag_pos_mconfig = 4;
27 $pr_flag_pos_node_not_enabled = 5;
28 $pr_flag_pos_white_list = 6;
29 $pr_flag_pos_hard_coded = 7;
30 $pr_flag_pos_config_hard_coded = 8;
31 $pr_flag_pos_config_none = 9;
32 $pr_flag_pos_config_m = 10;
33 $pr_flag_pos_config_y = 11;
34 $pr_flag_pos_config_test_fail = 12;
36 $num_pr_flags = $pr_flag_pos_config_test_fail + 1;
38 # flags in @pr_flag_value must be unique values to allow simple regular
39 # expessions to work for --include_flags and --exclude_flags.
40 # Convention: use upper case letters for potential issues or problems.
42 @pr_flag_value = ('M', 'd', 'D', 'c', 'C', 'E', 'W', 'H', 'x', 'n', 'm', 'y', 'F');
45 "multiple compatibles found for this node",
46 "driver found for this compatible",
47 "multiple drivers found for this compatible",
48 "kernel config found for this driver",
49 "multiple config options found for this driver",
50 "node is not enabled",
51 "compatible is white listed",
52 "matching driver and/or kernel config is hard coded",
53 "kernel config hard coded in Makefile",
54 "one or more kernel config file options is not set",
55 "one or more kernel config file options is set to 'm'",
56 "one or more kernel config file options is set to 'y'",
57 "one of more kernel config file options fails to have correct value"
63 %driver_config = (); # driver config array, indexed by driver source file
64 %driver_count = (); # driver_cnt, indexed by compatible
65 %compat_driver = (); # compatible driver array, indexed by compatible
66 %existing_config = (); # existing config symbols present in given config file
67 # expected values are: "y", "m", a decimal number, a
68 # hex number, or a string
70 # ----- magic compatibles, do not have a driver
72 # Will not search for drivers for these compatibles.
74 %compat_white_list = (
80 # Will not search for drivers for these compatibles.
82 # These compatibles have a very large number of false positives.
84 # 'hardcoded_no_driver' is a magic value. Other code knows this
85 # magic value. Do not use 'no_driver' here!
87 # Revisit each 'hardcoded_no_driver' to see how the compatible
88 # is used. Are there drivers that can be provided?
90 %driver_hard_code_list = (
91 'cache' => ['hardcoded_no_driver'],
92 'eeprom' => ['hardcoded_no_driver'],
93 'gpio' => ['hardcoded_no_driver'],
94 'gpio-keys' => ['drivers/input/keyboard/gpio_keys.c'],
95 'i2c-gpio' => ['drivers/i2c/busses/i2c-gpio.c'],
96 'isa' => ['arch/mips/mti-malta/malta-dt.c',
97 'arch/x86/kernel/devicetree.c'],
98 'led' => ['hardcoded_no_driver'],
99 'm25p32' => ['hardcoded_no_driver'],
100 'm25p64' => ['hardcoded_no_driver'],
101 'm25p80' => ['hardcoded_no_driver'],
102 'mtd-ram' => ['drivers/mtd/maps/physmap_of.c'],
103 'pwm-backlight' => ['drivers/video/backlight/pwm_bl.c'],
104 'spidev' => ['hardcoded_no_driver'],
105 'syscon' => ['drivers/mfd/syscon.c'],
106 'tlv320aic23' => ['hardcoded_no_driver'],
107 'wm8731' => ['hardcoded_no_driver'],
110 # Use these config options instead of searching makefiles
112 %driver_config_hard_code_list = (
114 # this one needed even if %driver_hard_code_list is empty
115 'no_driver' => ['no_config'],
116 'hardcoded_no_driver' => ['no_config'],
118 # drivers/usb/host/ehci-ppc-of.c
119 # drivers/usb/host/ehci-xilinx-of.c
121 # drivers/usb/host/ehci-hcd.c
122 # thus the search of Makefile for the included .c files is incorrect
123 # ehci-hcd.c wraps the includes with ifdef CONFIG_USB_EHCI_HCD_..._OF
125 # similar model for ohci-hcd.c (but no ohci-xilinx-of.c)
127 # similarly, uhci-hcd.c includes uhci-platform.c
129 'drivers/usb/host/ehci-ppc-of.c' => ['CONFIG_USB_EHCI_HCD',
130 'CONFIG_USB_EHCI_HCD_PPC_OF'],
131 'drivers/usb/host/ohci-ppc-of.c' => ['CONFIG_USB_OHCI_HCD',
132 'CONFIG_USB_OHCI_HCD_PPC_OF'],
134 'drivers/usb/host/ehci-xilinx-of.c' => ['CONFIG_USB_EHCI_HCD',
135 'CONFIG_USB_EHCI_HCD_XILINX'],
137 'drivers/usb/host/uhci-platform.c' => ['CONFIG_USB_UHCI_HCD',
138 'CONFIG_USB_UHCI_PLATFORM'],
140 # scan_makefile will find only one of these config options:
141 # ifneq ($(CONFIG_SOC_IMX6)$(CONFIG_SOC_LS1021A),)
142 'arch/arm/mach-imx/platsmp.c' => ['CONFIG_SOC_IMX6 && CONFIG_SMP',
143 'CONFIG_SOC_LS1021A && CONFIG_SMP'],
147 # 'virt/kvm/arm/.*' are controlled by makefiles in other directories,
148 # using relative paths, such as 'KVM := ../../../virt/kvm'. Do not
149 # add complexity to find_kconfig() to deal with this. There is a long
150 # term intent to change the kvm related makefiles to the normal kernel
151 # style. After that is done, this entry can be removed from the
154 @black_list_driver = (
155 # kvm no longer a problem after commit 503a62862e8f in 4.7-rc1
164 Usage: $script_name [options] device-tree...
166 device_tree is: dts_file | dtb_file | proc_device-tree
170 -c FILE Read kernel config options from FILE
171 --config FILE synonym for 'c'
172 --config-format config file friendly output format
173 --exclude-flag FLAG exclude entries with a matching flag
174 -h Display this message and exit
175 --help synonym for 'h'
176 --black-list-driver use driver black list
177 --white-list-config use config white list
178 --white-list-driver use driver white list
179 --include-flag FLAG include only entries with a matching flag
180 --include-suspect include only entries with an uppercase flag
181 --short-name do not show the path portion of the node name
182 --show-lists report of white and black lists
183 --version Display program version and exit
186 Report driver source files that match the compatibles in the device
187 tree file and the kernel config options that enable the driver source
190 This program must be run in the root directory of a Linux kernel
193 The default format is a report that is intended to be easily human
196 An alternate format can be selected by --config-format. This will
197 create output that can easily be edited to create a fragment that can
198 be appended to the existing kernel config file. Each entry consists of
199 multiple lines. The first line reports flags, the node path, compatible
200 value, driver file matching the compatible, configuration options, and
201 current values of the configuration options. For each configuration
202 option, the following lines report the current value and the value that
203 is required for the driver file to be included in the kernel.
205 If a large number of drivers or config options is listed for a node,
206 and the '$pr_flag_value[$pr_flag_pos_hard_coded]' flag is set consider using --white-list-config and/or
207 --white-list-driver. If the white list option suppresses the correct
208 entry please report that as a bug.
211 This program uses heuristics to guess which driver(s) support each
212 compatible string and which config option(s) enables the driver(s).
213 Do not believe that the reported information is fully correct.
214 This program is intended to aid the process of determining the
215 proper kernel configuration for a device tree, but this is not
216 a fully automated process -- human involvement may still be
219 The driver match heuristic used is to search for source files
220 containing the compatible string enclosed in quotes.
222 This program might not be able to find all drivers matching a
225 Some makefiles are overly clever. This program was not made
226 complex enough to handle them. If no config option is listed
227 for a driver, look at the makefile for the driver source file.
228 Even if a config option is listed for a driver, some other
229 available config options may not be listed.
234 for ($k = 0; $k < $num_pr_flags; $k++) {
235 printf " %s %s\n", $pr_flag_value[$k], $pr_flag_help[$k];
240 Upper case letters indicate potential issues or problems.
246 $k = $pr_flag_pos_hard_coded;
247 printf " %s %s\n", $pr_flag_value[$k], $pr_flag_help[$k];
251 will be set if the config or driver is in the white lists, even if
252 --white-list-config and --white-list-driver are not specified.
253 This is a hint that 1) many of these reported lines are likely to
254 be incorrect, and 2) using those options will reduce the number of
255 drivers and/or config options reported.
257 --white-list-config and --white-list-driver may not be accurate if this
258 program is not well maintained. Use them with appropriate skepticism.
259 Use the --show-lists option to report the values in the list.
263 1 error processing command line
264 2 unable to open or read kernel config file
265 3 unable to open or process input device tree file(s)
269 dt_to_config arch/arm/boot/dts/my_dts_file.dts
274 --config \${KBUILD_OUTPUT}/.config \\
275 arch/\${ARCH}/boot/dts/my_dts_file.dts
277 Full report, with config file issues noted.
279 dt_to_config --include-suspect \\
280 --config \${KBUILD_OUTPUT}/.config \\
281 arch/\${ARCH}/boot/dts/my_dts_file.dts
283 Report of node / compatible string / driver tuples that should
284 be further investigated. A node may have multiple compatible
285 strings. A compatible string may be matched by multiple drivers.
286 A driver may have config file issues noted. The compatible string
287 and/or driver may be in the white lists.
289 dt_to_config --include-suspect --config-format \\
290 --config ${KBUILD_OUTPUT}/.config \\
291 arch/\${ARCH}/boot/dts/my_dts_file.dts
293 Report of node / compatible string / driver tuples that should
294 be further investigated. The report can be edited to uncomment
295 the config options to select the desired tuple for a given node.
296 A node may have multiple compatible strings. A compatible string
297 may be matched by multiple drivers. A driver may have config file
298 issues noted. The compatible string and/or driver may be in the
306 # pr_flags_ref is a reference to $pr_flags
308 my $pr_flags_ref = shift;
311 substr $$pr_flags_ref, $pos, 1, $pr_flag_value[$pos];
318 # return 1 if anything printed, else 0
320 # some fields of pn_arg_ref might not be used in this function, but
321 # extract all of them anyway.
322 my $pn_arg_ref = shift;
324 my $compat = $pn_arg_ref->{compat};
325 my $compatible_cnt = $pn_arg_ref->{compatible_cnt};
326 my $config = $pn_arg_ref->{config};
327 my $config_cnt = $pn_arg_ref->{config_cnt};
328 my $driver = $pn_arg_ref->{driver};
329 my $driver_cnt = $pn_arg_ref->{driver_cnt};
330 my $full_node = $pn_arg_ref->{full_node};
331 my $node = $pn_arg_ref->{node};
332 my $node_enabled = $pn_arg_ref->{node_enabled};
333 my $white_list = $pn_arg_ref->{white_list};
335 my $pr_flags = '-' x $num_pr_flags;
338 # ----- set flags in $pr_flags
340 if ($compatible_cnt > 1) {
341 &set_flag(\$pr_flags, $pr_flag_pos_mcompatible);
344 if ($config_cnt > 1) {
345 &set_flag(\$pr_flags, $pr_flag_pos_mconfig);
348 if ($driver_cnt >= 1) {
349 &set_flag(\$pr_flags, $pr_flag_pos_driver);
352 if ($driver_cnt > 1) {
353 &set_flag(\$pr_flags, $pr_flag_pos_mdriver);
356 # These strings are the same way the linux kernel tests.
357 # The ePapr lists of values is slightly different.
359 ($node_enabled eq "") ||
360 ($node_enabled eq "ok") ||
361 ($node_enabled eq "okay")
363 &set_flag(\$pr_flags, $pr_flag_pos_node_not_enabled);
367 &set_flag(\$pr_flags, $pr_flag_pos_white_list);
370 if (exists($driver_hard_code_list{$compat}) ||
371 (exists($driver_config_hard_code_list{$driver}) &&
372 ($driver ne "no_driver"))) {
373 &set_flag(\$pr_flags, $pr_flag_pos_hard_coded);
376 my @configs = split(' && ', $config);
377 for $configs (@configs) {
378 $not = $configs =~ /^!/;
381 if (($configs ne "no_config") && ($configs ne "no_makefile")) {
382 &set_flag(\$pr_flags, $pr_flag_pos_config);
385 if (($config_cnt >= 1) &&
386 ($configs !~ /CONFIG_/) &&
387 (($configs ne "no_config") && ($configs ne "no_makefile"))) {
388 &set_flag(\$pr_flags, $pr_flag_pos_config_hard_coded);
391 my $existing_config = $existing_config{$configs};
392 if ($existing_config eq "m") {
393 &set_flag(\$pr_flags, $pr_flag_pos_config_m);
394 # Possible fail, depends on whether built in or
396 &set_flag(\$pr_flags, $pr_flag_pos_config_test_fail);
397 } elsif ($existing_config eq "y") {
398 &set_flag(\$pr_flags, $pr_flag_pos_config_y);
400 &set_flag(\$pr_flags, $pr_flag_pos_config_test_fail);
402 } elsif (($config_file) && ($configs =~ /CONFIG_/)) {
403 &set_flag(\$pr_flags, $pr_flag_pos_config_none);
405 &set_flag(\$pr_flags, $pr_flag_pos_config_test_fail);
410 # ----- include / exclude filters
412 if ($include_flag_pattern && ($pr_flags !~ m/$include_flag_pattern/)) {
416 if ($exclude_flag_pattern && ($pr_flags =~ m/$exclude_flag_pattern/)) {
420 if ($config_format) {
423 print "$pr_flags : ";
431 # return number of lines printed
433 # some fields of pn_arg_ref might not be used in this function, but
434 # extract all of them anyway.
435 my $pn_arg_ref = shift;
437 my $compat = $pn_arg_ref->{compat};
438 my $compatible_cnt = $pn_arg_ref->{compatible_cnt};
439 my $config = $pn_arg_ref->{config};
440 my $config_cnt = $pn_arg_ref->{config_cnt};
441 my $driver = $pn_arg_ref->{driver};
442 my $driver_cnt = $pn_arg_ref->{driver_cnt};
443 my $full_node = $pn_arg_ref->{full_node};
444 my $node = $pn_arg_ref->{node};
445 my $node_enabled = $pn_arg_ref->{node_enabled};
446 my $white_list = $pn_arg_ref->{white_list};
450 if (! &print_flags($pn_arg_ref)) {
460 print " : $compat : $driver : $config : ";
462 my @configs = split(' && ', $config);
465 for $configs (@configs) {
467 my $existing_config = $existing_config{$configs};
468 if (!$existing_config) {
469 # check for /-m/, /-y/, or /-objs/
470 if ($configs !~ /CONFIG_/) {
471 $existing_config = "x";
474 if ($existing_config) {
475 print "$separator", "$existing_config";
478 print "$separator", "n";
488 if ($config_format) {
489 for $configs (@configs) {
490 $not = $configs =~ /^!/;
492 my $existing_config = $existing_config{$configs};
495 if ($configs !~ /CONFIG_/) {
496 print "# $configs\n";
497 } elsif ($existing_config eq "m") {
498 print "# $configs is m\n";
499 print "# $configs=n\n";
500 } elsif ($existing_config eq "y") {
501 print "# $configs is set\n";
502 print "# $configs=n\n";
504 print "# $configs is not set\n";
505 print "# $configs=n\n";
509 if ($configs !~ /CONFIG_/) {
510 print "# $configs\n";
511 } elsif ($existing_config eq "m") {
512 print "# $configs is m\n";
513 print "# $configs=y\n";
514 } elsif ($existing_config eq "y") {
515 print "# $configs is set\n";
516 print "# $configs=y\n";
518 print "# $configs is not set\n";
519 print "# $configs=y\n";
531 my $pn_arg_ref = shift;
534 # ----- Find Kconfig symbols that enable driver
536 my ($dir, $base) = $driver =~ m{(.*)/(.*).c};
538 my $makefile = $dir . "/Makefile";
539 if (! -r $makefile) {
540 $makefile = $dir . "/Kbuild";
542 if (! -r $makefile) {
545 $config = 'no_makefile';
546 push @{ $driver_config{$driver} }, $config;
550 if (!open(MAKEFILE_FILE, "<", "$makefile")) {
560 while ($next_line = <MAKEFILE_FILE>) {
573 $line = $line . $next_line;
574 if ($next_line =~ /\\$/) {
578 if ($line =~ /^\s*#/) {
583 # ----- condition ... else ... endif
585 if ($line =~ /^([ ]\s*|)else\b/) {
586 $if_config = "!" . pop @if_config;
587 $if_config =~ s/^!!//;
588 push @if_config, $if_config;
589 $line =~ s/^([ ]\s*|)else\b//;
592 ($null, $ifeq_config, $ifeq_config_val ) = $line =~ /^([ ]\s*|)ifeq\b.*\b(CONFIG_[A-Za-z0-9_]*)(.*)/;
593 ($null, $ifneq_config, $ifneq_config_val) = $line =~ /^([ ]\s*|)ifneq\b.*\b(CONFIG_[A-Za-z0-9_]*)(.*)/;
594 ($null, $ifdef_config) = $line =~ /^([ ]\s*|)ifdef\b.*\b(CONFIG_[A-Za-z0-9_]*)/;
595 ($null, $ifndef_config) = $line =~ /^([ ]\s*|)ifndef\b.*\b(CONFIG_[A-Za-z0-9_]*)/;
597 ($null, $ifeq) = $line =~ /^([ ]\s*|)ifeq\b\s*(.*)/;
598 ($null, $ifneq) = $line =~ /^([ ]\s*|)ifneq\b\s*(.*)/;
599 ($null, $ifdef) = $line =~ /^([ ]\s*|)ifdef\b\s*(.*)/;
600 ($null, $ifndef) = $line =~ /^([ ]\s*|)ifndef\b\s*(.*)/;
602 # Order of tests is important. Prefer "CONFIG_*" regex match over
603 # less specific regex match.
605 $if_config = $ifdef_config;
606 } elsif ($ifeq_config) {
607 if ($ifeq_config_val =~ /y/) {
608 $if_config = $ifeq_config;
610 $if_config = "!" . $ifeq_config;
612 } elsif ($ifndef_config) {
613 $if_config = "!" . $ifndef_config;
614 } elsif ($ifneq_config) {
615 if ($ifneq_config_val =~ /y/) {
616 $if_config = "!" . $ifneq_config;
618 $if_config = $ifneq_config;
625 $if_config = "!" . $ifndef;
627 $if_config = "!" . $ifneq;
631 $if_config =~ s/^!!//;
634 push @if_config, $if_config;
639 if ($line =~ /^([ ]\s*|)endif\b/) {
645 # ----- simple CONFIG_* = *.[co] or xxx [+:?]*= *.[co]
646 # Most makefiles select on *.o, but
647 # arch/powerpc/boot/Makefile selects on *.c
649 ($config) = $line =~ /(CONFIG_[A-Za-z0-9_]+).*\b$base.[co]\b/;
651 # ----- match a make variable instead of *.[co]
652 # Recursively expanded variables are not handled.
656 ($make_var) = $line =~ /\s*(\S+?)\s*[+:\?]*=.*\b$base.[co]\b/;
658 if ($make_var =~ /[a-zA-Z0-9]+-[ym]/) {
660 } elsif ($make_var =~ /[a-zA-Z0-9]+-objs/) {
663 push @make_var, $make_var;
669 for $make_var (@make_var) {
670 ($config) = $line =~ /(CONFIG_[A-Za-z0-9_]+).*\b$make_var\b/;
676 for $make_var (@make_var) {
677 ($config) = $line =~ /\s*(\S+?)\s*[+:\?]*=.*\b$make_var\b/;
682 # ----- next if no config found
689 for $if_config (@if_config) {
690 $config = $if_config . " && " . $config;
693 push @{ $driver_config{$driver} }, $config;
698 close(MAKEFILE_FILE);
705 my $pn_arg_ref = shift;
708 my $lines_printed = 0;
711 if (!@{ $driver_config{$driver} }) {
712 &scan_makefile($pn_arg_ref, $driver);
713 if (!@{ $driver_config{$driver} }) {
714 push @{ $driver_config{$driver} }, "no_config";
718 @configs = @{ $driver_config{$driver} };
720 $$pn_arg_ref{config_cnt} = $#configs + 1;
721 for my $config (@configs) {
722 $$pn_arg_ref{config} = $config;
723 $lines_printed += &print_node($pn_arg_ref);
726 return $lines_printed;
730 sub handle_compatible()
732 my $full_node = shift;
734 my $compatible = shift;
735 my $node_enabled = shift;
738 my $lines_printed = 0;
741 return if (!$node or !$compatible);
743 # Do not process compatible property of root node,
744 # it is used to match board, not to bind a driver.
745 return if ($node eq "/");
747 $pn_arg{full_node} = $full_node;
748 $pn_arg{node} = $node;
749 $pn_arg{node_enabled} = $node_enabled;
751 my @compatibles = split('", "', $compatible);
753 $compatibles[0] =~ s/^"//;
754 $compatibles[$#compatibles] =~ s/"$//;
756 $pn_arg{compatible_cnt} = $#compatibles + 1;
759 for $compat (@compatibles) {
761 $pn_arg{compat} = $compat;
762 $pn_arg{driver_cnt} = 0;
763 $pn_arg{white_list} = 0;
765 if (exists($compat_white_list{$compat})) {
766 $pn_arg{white_list} = 1;
767 $pn_arg{driver} = "no_driver";
768 $pn_arg{config_cnt} = 1;
769 $pn_arg{config} = "no_config";
770 $lines_printed += &print_node(\%pn_arg);
774 # ----- if compat previously seen, use cached info
776 if (exists($compat_driver{$compat})) {
777 for my $driver (@{ $compat_driver{$compat} }) {
778 $pn_arg{driver} = $driver;
779 $pn_arg{driver_cnt} = $driver_count{$compat};
780 $pn_arg{config_cnt} = $#{ $driver_config{$driver}} + 1;
782 for my $config (@{ $driver_config{$driver} }) {
783 $pn_arg{config} = $config;
784 $lines_printed += &print_node(\%pn_arg);
787 if (!@{ $driver_config{$driver} }) {
788 # no config cached yet
789 # $driver in %driver_hard_code_list
790 # but not %driver_config_hard_code_list
791 $lines_printed += &find_kconfig(\%pn_arg, $driver);
798 # ----- Find drivers (source files that contain compatible)
800 # this will miss arch/sparc/include/asm/parport.h
801 # It is better to move the compatible out of the .h
802 # than to add *.h. to the files list, because *.h generates
803 # a lot of false negatives.
805 my $drivers = `git grep -l '"$compat"' -- $files`;
807 if ($drivers eq "") {
808 $pn_arg{driver} = "no_driver";
809 $pn_arg{config_cnt} = 1;
810 $pn_arg{config} = "no_config";
811 push @{ $compat_driver{$compat} }, "no_driver";
812 $lines_printed += &print_node(\%pn_arg);
816 my @drivers = split("\n", $drivers);
817 $driver_count{$compat} = $#drivers + 1;
818 $pn_arg{driver_cnt} = $#drivers + 1;
821 for my $driver (@drivers) {
822 push @{ $compat_driver{$compat} }, $driver;
823 $pn_arg{driver} = $driver;
825 # ----- if driver previously seen, use cached info
827 $pn_arg{config_cnt} = $#{ $driver_config{$driver} } + 1;
828 for my $config (@{ $driver_config{$driver} }) {
829 $pn_arg{config} = $config;
830 $lines_printed += &print_node(\%pn_arg);
832 if (@{ $driver_config{$driver} }) {
836 if ($black_list_driver) {
837 for $black (@black_list_driver) {
838 next DRIVER if ($driver =~ /^$black$/);
843 # ----- Find Kconfig symbols that enable driver
845 $lines_printed += &find_kconfig(\%pn_arg, $driver);
850 # White space (line) between nodes for readability.
851 # Each node may report several compatibles.
852 # For each compatible, multiple drivers may be reported.
853 # For each driver, multiple CONFIG_ options may be reported.
854 if ($lines_printed) {
866 my $node_enabled = "";
869 print STDERR "file '$file' is not readable or does not exist\n";
873 if (!open(DT_FILE, "-|", "$dtx_diff $file")) {
875 print STDERR "shell command failed:\n";
876 print STDERR " $dtx_diff $file\n";
882 while ($line = <DT_FILE>) {
887 &handle_compatible($full_node, $node, $compatible,
890 while ($end_node_count-- > 0) {
894 $full_node = @full_node[-1];
897 $node =~ s/^\s*(.*)\s+\{.*/$1/;
901 } elsif ($full_node ne '/') {
902 $full_node = $full_node . '/' . $node;
904 $full_node = '/' . $node;
906 push @full_node, $full_node;
917 if ($line =~ /(\s+|^)status =/) {
918 $node_enabled = $line;
919 $node_enabled =~ s/^\t*//;
920 $node_enabled =~ s/^status = "//;
921 $node_enabled =~ s/";$//;
925 if ($line =~ /(\s+|^)compatible =/) {
926 # Extract all compatible entries for this device
927 # White space matching here and in handle_compatible() is
928 # precise, because input format is the output of dtc,
929 # which is invoked by dtx_diff.
931 $compatible =~ s/^\t*//;
932 $compatible =~ s/^compatible = //;
933 $compatible =~ s/;$//;
937 &handle_compatible($full_node, $node, $compatible, $node_enabled);
943 sub read_config_file()
945 if (! -r $config_file) {
946 print STDERR "file '$config_file' is not readable or does not exist\n";
950 if (!open(CONFIG_FILE, "<", "$config_file")) {
951 print STDERR "open $config_file failed\n";
958 while ($line = <CONFIG_FILE>) {
960 next LINE if ($line =~ /^\s*#/);
961 next LINE if ($line =~ /^\s*$/);
962 @line = split /=/, $line;
963 $existing_config{@line[0]} = @line[1];
975 print STDERR " ERROR processing command line options\n";
976 print STDERR " $msg\n" if ($msg ne "");
978 print STDERR " For help, type '$script_name --help'\n";
983 # -----------------------------------------------------------------------------
984 # program entry point
986 Getopt::Long::Configure("no_ignore_case", "bundling");
989 "c=s" => \$config_file,
990 "config=s" => \$config_file,
991 "config-format" => \$config_format,
992 "exclude-flag=s" => \@exclude_flag,
995 "black-list-driver" => \$black_list_driver,
996 "white-list-config" => \$white_list_config,
997 "white-list-driver" => \$white_list_driver,
998 "include-flag=s" => \@include_flag,
999 "include-suspect" => \$include_suspect,
1000 "short-name" => \$short_name,
1001 "show-lists" => \$show_lists,
1002 "version" => \$version,
1011 my $exit_after_messages = 0;
1014 print STDERR "\n$script_name $VUFX\n\n";
1015 $exit_after_messages = 1;
1021 $exit_after_messages = 1;
1028 print "These compatibles are hard coded to have no driver.\n";
1030 for my $compat (sort keys %compat_white_list) {
1036 print "The driver for these compatibles is hard coded (white list).\n";
1038 my $max_compat_len = 0;
1039 for my $compat (sort keys %driver_hard_code_list) {
1040 if (length $compat > $max_compat_len) {
1041 $max_compat_len = length $compat;
1044 for my $compat (sort keys %driver_hard_code_list) {
1045 if (($driver ne "hardcoded_no_driver") && ($driver ne "no_driver")) {
1047 for my $driver (@{ $driver_hard_code_list{$compat} }) {
1050 print " " x ($max_compat_len - length $compat);
1053 print " ", " " x $max_compat_len;
1062 print "The configuration option for these drivers is hard coded (white list).\n";
1064 my $max_driver_len = 0;
1065 for my $driver (sort keys %driver_config_hard_code_list) {
1066 if (length $driver > $max_driver_len) {
1067 $max_driver_len = length $driver;
1070 for my $driver (sort keys %driver_config_hard_code_list) {
1071 if (($driver ne "hardcoded_no_driver") && ($driver ne "no_driver")) {
1073 for my $config (@{ $driver_config_hard_code_list{$driver} }) {
1076 print " " x ($max_driver_len - length $driver);
1079 print " ", " " x $max_driver_len;
1088 print "These drivers are black listed.\n";
1090 for my $driver (@black_list_driver) {
1096 $exit_after_messages = 1;
1100 if ($exit_after_messages) {
1105 $exclude_flag_pattern = "[";
1106 for my $exclude_flag (@exclude_flag) {
1107 $exclude_flag_pattern = $exclude_flag_pattern . $exclude_flag;
1109 $exclude_flag_pattern = $exclude_flag_pattern . "]";
1111 $exclude_flag_pattern =~ s/^\[\]$//;
1114 $include_flag_pattern = "[";
1115 for my $include_flag (@include_flag) {
1116 $include_flag_pattern = $include_flag_pattern . $include_flag;
1118 $include_flag_pattern = $include_flag_pattern . "]";
1120 $include_flag_pattern =~ s/^\[\]$//;
1123 if ($exclude_flag_pattern) {
1125 for $pr_flag_value (@pr_flag_value) {
1126 if ($exclude_flag_pattern =~ m/$pr_flag_value/) {
1131 &cmd_line_err("invalid value for FLAG in --exclude-flag\n");
1136 if ($include_flag_pattern) {
1138 for $pr_flag_value (@pr_flag_value) {
1139 if ($include_flag_pattern =~ m/$pr_flag_value/) {
1144 &cmd_line_err("invalid value for FLAG in --include-flag\n");
1149 if ($include_suspect) {
1150 $include_flag_pattern =~ s/\[//;
1151 $include_flag_pattern =~ s/\]//;
1152 $include_flag_pattern = "[" . $include_flag_pattern . "A-Z]";
1155 if ($exclude_flag_pattern =~ m/$include_flag_pattern/) {
1156 &cmd_line_err("the same flag appears in both --exclude-flag and --include-flag or --include-suspect\n");
1161 # ($#ARGV < 0) is valid for --help, --version
1163 &cmd_line_err("device-tree... is required");
1169 &read_config_file();
1173 # avoid pushing duplicates for this value
1174 $driver = "hardcoded_no_driver";
1175 for $config ( @{ $driver_config_hard_code_list{$driver} } ) {
1176 push @{ $driver_config{$driver} }, $config;
1179 if ($white_list_driver) {
1180 for my $compat (keys %driver_hard_code_list) {
1181 for my $driver (@{ $driver_hard_code_list{$compat} }) {
1182 push @{ $compat_driver{$compat} }, $driver;
1183 if ($driver ne "hardcoded_no_driver") {
1184 $driver_count{$compat} = scalar @{ $compat_driver{$compat} };
1190 if ($white_list_config) {
1191 for my $driver (keys %driver_config_hard_code_list) {
1192 if ($driver ne "hardcoded_no_driver") {
1193 for $config ( @{ $driver_config_hard_code_list{$driver} } ) {
1194 push @{ $driver_config{$driver} }, $config;
1200 if (-x "scripts/dtc/dtx_diff") {
1201 $dtx_diff = "scripts/dtc/dtx_diff";
1205 print STDERR "$script_name must be run from the root directory of a Linux kernel tree\n";