1
0

dump-target-info.pl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Cwd;
  5. my (%targets, %architectures, %kernels, %devices);
  6. $ENV{'TOPDIR'} = Cwd::getcwd();
  7. sub parse_targetinfo {
  8. my ($target_dir, $subtarget) = @_;
  9. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 SUBTARGET='$subtarget' |") {
  10. my ($target_name, $target_arch, $target_kernel, $target_testing_kernel, @target_features);
  11. while (defined(my $line = readline M)) {
  12. chomp $line;
  13. if ($line =~ /^Target: (.+)$/) {
  14. $target_name = $1;
  15. }
  16. elsif ($line =~ /^Target-Arch-Packages: (.+)$/) {
  17. $target_arch = $1;
  18. }
  19. elsif ($line =~ /^Linux-Version: (\d\.\d+)\.\d+$/) {
  20. $target_kernel = $1;
  21. }
  22. elsif ($line =~ /^Linux-Testing-Version: (\d\.\d+)\.\d+$/) {
  23. $target_testing_kernel = $1;
  24. }
  25. elsif ($line =~ /^Target-Features: (.+)$/) {
  26. @target_features = split /\s+/, $1;
  27. }
  28. elsif ($line =~ /^@\@$/) {
  29. if ($target_name && $target_arch && $target_kernel &&
  30. !grep { $_ eq 'broken' or $_ eq 'source-only' } @target_features) {
  31. $targets{$target_name} = $target_arch;
  32. $architectures{$target_arch} ||= [];
  33. push @{$architectures{$target_arch}}, $target_name;
  34. $kernels{$target_name} ||= [];
  35. push @{$kernels{$target_name}}, $target_kernel;
  36. if ($target_testing_kernel) {
  37. push @{$kernels{$target_name}}, $target_testing_kernel;
  38. }
  39. }
  40. undef $target_name;
  41. undef $target_arch;
  42. undef $target_kernel;
  43. undef $target_testing_kernel;
  44. @target_features = ();
  45. }
  46. }
  47. close M;
  48. }
  49. }
  50. sub parse_devices {
  51. my ($target_dir, $subtarget) = @_;
  52. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 SUBTARGET='$subtarget' V=s |") {
  53. my ($device_profile, $device_name, @device_alt_names, $device_is_alt);
  54. while (defined(my $line = readline M)) {
  55. chomp $line;
  56. if ($line =~ /^Target-Profile-Name: (.+)$/) {
  57. $device_name = $1;
  58. }
  59. elsif ($line =~ /^Target-Profile: DEVICE_(.+)$/) {
  60. $device_profile = $1;
  61. }
  62. # Logic behind this.
  63. # DUMP duplicate info for each alternative device name and
  64. # the alternative device name are printed first before the
  65. # primary device name
  66. # Alternative device titles always have the full list of
  67. # all the alternative device name.
  68. # The device name pattern for an alternative device name is
  69. # Target-Profile-Name: ALT_NAME (PRIMARY_NAME)
  70. # We compare the detected device name and check if it does
  71. # match the alternative device name pattern with one of
  72. # the alternative device name in Alternative device titles:
  73. # If an alternative device name is detected,
  74. # alternative device is skipped.
  75. elsif ($line =~ /^Alternative device titles:$/) {
  76. while (defined($line = readline M)) {
  77. if ($line =~ /^- (.+)$/) {
  78. if ($device_name =~ /^\Q$1\E \((.+)\)$/) {
  79. $device_is_alt = 1;
  80. last;
  81. }
  82. push @device_alt_names, $1;
  83. }
  84. else {
  85. last;
  86. }
  87. }
  88. }
  89. if ($line =~ /^@\@$/) {
  90. if ($device_name && $device_profile && ! $device_is_alt) {
  91. push @{$devices{$device_profile}}, $device_name;
  92. if (scalar @device_alt_names) {
  93. foreach my $device_alt_name (sort values @device_alt_names) {
  94. push @{$devices{$device_profile}}, $device_alt_name;
  95. }
  96. }
  97. }
  98. undef $device_name;
  99. undef $device_profile;
  100. undef $device_is_alt;
  101. @device_alt_names = ();
  102. }
  103. }
  104. close M;
  105. }
  106. }
  107. sub get_targetinfo {
  108. foreach my $target_makefile (glob "target/linux/*/Makefile") {
  109. my ($target_dir) = $target_makefile =~ m!^(.+)/Makefile$!;
  110. my @subtargets;
  111. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.FEATURES V=s 2>/dev/null |") {
  112. if (defined(my $line = readline M)) {
  113. chomp $line;
  114. if (grep { $_ eq 'broken' or $_ eq 'source-only' } split /\s+/, $line) {
  115. next;
  116. }
  117. }
  118. }
  119. if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.SUBTARGETS V=s 2>/dev/null |") {
  120. if (defined(my $line = readline M)) {
  121. chomp $line;
  122. @subtargets = split /\s+/, $line;
  123. }
  124. close M;
  125. }
  126. push @subtargets, 'generic' if @subtargets == 0;
  127. foreach my $subtarget (@subtargets) {
  128. parse_targetinfo($target_dir, $subtarget);
  129. }
  130. }
  131. }
  132. sub get_devices {
  133. my ($target_subtarget) = @_;
  134. my ($target, $subtarget) = split /\//, $target_subtarget;
  135. my ($target_dir) = "target/linux/" . $target;
  136. parse_devices($target_dir, $subtarget)
  137. }
  138. if (@ARGV == 1 && $ARGV[0] eq 'targets') {
  139. get_targetinfo();
  140. foreach my $target_name (sort keys %targets) {
  141. printf "%s %s\n", $target_name, $targets{$target_name};
  142. }
  143. }
  144. elsif (@ARGV == 1 && $ARGV[0] eq 'architectures') {
  145. get_targetinfo();
  146. foreach my $target_arch (sort keys %architectures) {
  147. printf "%s %s\n", $target_arch, join ' ', @{$architectures{$target_arch}};
  148. }
  149. }
  150. elsif (@ARGV == 1 && $ARGV[0] eq 'kernels') {
  151. get_targetinfo();
  152. foreach my $target_name (sort keys %targets) {
  153. printf "%s %s\n", $target_name, join ' ', @{$kernels{$target_name}};
  154. }
  155. }
  156. elsif (@ARGV == 2 && $ARGV[0] eq 'devices') {
  157. get_devices($ARGV[1]);
  158. foreach my $device (sort keys %devices) {
  159. printf "%s \"%s\"\n", $device, join '" "', @{$devices{$device}};
  160. }
  161. }
  162. else {
  163. print "Usage: $0 targets\n";
  164. print "Usage: $0 architectures\n";
  165. print "Usage: $0 kernels\n";
  166. print "Usage: $0 devices <target/subtarget>\n";
  167. }