Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #!/usr/bin/perl -w
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) # Copyright 2015 - Steven Rostedt, Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) # Copyright 2017 - Steven Rostedt, VMware, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) # usage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #  config-bisect.pl [options] good-config bad-config [good|bad]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) # Compares a good config to a bad config, then takes half of the diffs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) # and produces a config that is somewhere between the good config and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) # the bad config. That is, the resulting config will start with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) # good config and will try to make half of the differences of between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) # the good and bad configs match the bad config. It tries because of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) # dependencies between the two configs it may not be able to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) # exactly half of the configs that are different between the two config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) # files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) # Here's a normal way to use it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #  $ cd /path/to/linux/kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #  $ config-bisect.pl /path/to/good/config /path/to/bad/config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) # This will now pull in good config (blowing away .config in that directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) # so do not make that be one of the good or bad configs), and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) # build the config with "make oldconfig" to make sure it matches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) # current kernel. It will then store the configs in that result for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) # the good config. It does the same for the bad config as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) # The algorithm will run, merging half of the differences between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) # the two configs and building them with "make oldconfig" to make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) # the result changes (dependencies may reset changes the tool had made).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) # It then copies the result of its good config to /path/to/good/config.tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) # and the bad config to /path/to/bad/config.tmp (just appends ".tmp" to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) # files passed in). And the ".config" that you should test will be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) # directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) # After the first run, determine if the result is good or bad then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) # run the same command appending the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) # For good results:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #  $ config-bisect.pl /path/to/good/config /path/to/bad/config good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) # For bad results:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #  $ config-bisect.pl /path/to/good/config /path/to/bad/config bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) # Do not change the good-config or bad-config, config-bisect.pl will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) # copy the good-config to a temp file with the same name as good-config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) # but with a ".tmp" after it. It will do the same with the bad-config.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) # If "good" or "bad" is not stated at the end, it will copy the good and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) # bad configs to the .tmp versions. If a .tmp version already exists, it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) # warn before writing over them (-r will not warn, and just write over them).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) # If the last config is labeled "good", then it will copy it to the good .tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) # version. If the last config is labeled "bad", it will copy it to the bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) # .tmp version. It will continue this until it can not merge the two any more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) # without the result being equal to either the good or bad .tmp configs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) my $start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) my $val = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) my $pwd = `pwd`;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) chomp $pwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) my $tree = $pwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) my $build;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) my $output_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) my $reset_bisect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) sub usage {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)     print << "EOF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) usage: config-bisect.pl [-l linux-tree][-b build-dir] good-config bad-config [good|bad]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)   -l [optional] define location of linux-tree (default is current directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)   -b [optional] define location to build (O=build-dir) (default is linux-tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)   good-config the config that is considered good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)   bad-config the config that does not work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)   "good" add this if the last run produced a good config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)   "bad" add this if the last run produced a bad config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)   If "good" or "bad" is not specified, then it is the start of a new bisect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)   Note, each run will create copy of good and bad configs with ".tmp" appended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)     exit(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) sub doprint {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)     print @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) sub dodie {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)     doprint "CRITICAL FAILURE... ", @_, "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)     die @_, "\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sub expand_path {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)     my ($file) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)     if ($file =~ m,^/,) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return $file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)     return "$pwd/$file";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) sub read_prompt {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)     my ($cancel, $prompt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)     my $ans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)     for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if ($cancel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	    print "$prompt [y/n/C] ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	    print "$prompt [y/N] ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	$ans = <STDIN>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	chomp $ans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if ($ans =~ /^\s*$/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	    if ($cancel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		$ans = "c";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	    } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		$ans = "n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if ($cancel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	    last if ($ans =~ /^c$/i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	    print "Please answer either 'y', 'n' or 'c'.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	    print "Please answer either 'y' or 'n'.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)     if ($ans =~ /^c/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)     if ($ans !~ /^y$/i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)     return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) sub read_yn {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)     my ($prompt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)     return read_prompt 0, $prompt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) sub read_ync {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)     my ($prompt) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)     return read_prompt 1, $prompt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) sub run_command {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)     my ($command, $redirect) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)     my $start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)     my $end_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)     my $dord = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)     my $pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)     $start_time = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)     doprint("$command ... ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)     $pid = open(CMD, "$command 2>&1 |") or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	dodie "unable to exec $command";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)     if (defined($redirect)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	open (RD, ">$redirect") or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	    dodie "failed to write to redirect $redirect";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	$dord = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)     while (<CMD>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	print RD  if ($dord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)     waitpid($pid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)     my $failed = $?;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)     close(CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)     close(RD)  if ($dord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)     $end_time = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)     my $delta = $end_time - $start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)     if ($delta == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	doprint "[1 second] ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	doprint "[$delta seconds] ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)     if ($failed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	doprint "FAILED!\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	doprint "SUCCESS\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)     return !$failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ###### CONFIG BISECT ######
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) # config_ignore holds the configs that were set (or unset) for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) # a good config and we will ignore these configs for the rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) # of a config bisect. These configs stay as they were.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) my %config_ignore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) # config_set holds what all configs were set as.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) my %config_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) # config_off holds the set of configs that the bad config had disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) # We need to record them and set them in the .config when running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) # olddefconfig, because olddefconfig keeps the defaults.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) my %config_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) # config_off_tmp holds a set of configs to turn off for now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) my @config_off_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) # config_list is the set of configs that are being tested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) my %config_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) my %null_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) my %dependency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) my $make;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) sub make_oldconfig {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)     if (!run_command "$make olddefconfig") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	# Perhaps olddefconfig doesn't exist in this version of the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	# try oldnoconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	doprint "olddefconfig failed, trying make oldnoconfig\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (!run_command "$make oldnoconfig") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	    doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	    # try a yes '' | oldconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	    run_command "yes '' | $make oldconfig" or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		dodie "failed make config oldconfig";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) sub assign_configs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)     my ($hash, $config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)     doprint "Reading configs from $config\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)     open (IN, $config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	or dodie "Failed to read $config";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)     while (<IN>) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	chomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (/^((CONFIG\S*)=.*)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	    ${$hash}{$2} = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	} elsif (/^(# (CONFIG\S*) is not set)/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	    ${$hash}{$2} = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)     close(IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) sub process_config_ignore {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)     my ($config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)     assign_configs \%config_ignore, $config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) sub get_dependencies {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)     my ($config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)     my $arr = $dependency{$config};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)     if (!defined($arr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)     my @deps = @{$arr};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)     foreach my $dep (@{$arr}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	print "ADD DEP $dep\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	@deps = (@deps, get_dependencies $dep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)     return @deps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) sub save_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)     my ($pc, $file) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)     my %configs = %{$pc};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)     doprint "Saving configs into $file\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)     open(OUT, ">$file") or dodie "Can not write to $file";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)     foreach my $config (keys %configs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	print OUT "$configs{$config}\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)     close(OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) sub create_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)     my ($name, $pc) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)     doprint "Creating old config from $name configs\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)     save_config $pc, $output_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)     make_oldconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) # compare two config hashes, and return configs with different vals.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) # It returns B's config values, but you can use A to see what A was.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) sub diff_config_vals {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)     my ($pa, $pb) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)     # crappy Perl way to pass in hashes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)     my %a = %{$pa};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)     my %b = %{$pb};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)     my %ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)     foreach my $item (keys %a) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (defined($b{$item}) && $b{$item} ne $a{$item}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	    $ret{$item} = $b{$item};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)     return %ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) # compare two config hashes and return the configs in B but not A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) sub diff_configs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)     my ($pa, $pb) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)     my %ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)     # crappy Perl way to pass in hashes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)     my %a = %{$pa};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)     my %b = %{$pb};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)     foreach my $item (keys %b) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (!defined($a{$item})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	    $ret{$item} = $b{$item};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)     return %ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) # return if two configs are equal or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) # 0 is equal +1 b has something a does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) # +1 if a and b have a different item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) # -1 if a has something b does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) sub compare_configs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)     my ($pa, $pb) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)     my %ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)     # crappy Perl way to pass in hashes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)     my %a = %{$pa};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)     my %b = %{$pb};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)     foreach my $item (keys %b) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!defined($a{$item})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	    return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if ($a{$item} ne $b{$item}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	    return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)     foreach my $item (keys %a) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (!defined($b{$item})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	    return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) sub process_failed {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)     my ($config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)     doprint "\n\n***************************************\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)     doprint "Found bad config: $config\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)     doprint "***************************************\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) sub process_new_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)     my ($tc, $nc, $gc, $bc) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)     my %tmp_config = %{$tc};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)     my %good_configs = %{$gc};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)     my %bad_configs = %{$bc};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)     my %new_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)     my $runtest = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)     my $ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)     create_config "tmp_configs", \%tmp_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)     assign_configs \%new_configs, $output_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)     $ret = compare_configs \%new_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)     if (!$ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	doprint "New config equals bad config, try next test\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	$runtest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)     if ($runtest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	$ret = compare_configs \%new_configs, \%good_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (!$ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	    doprint "New config equals good config, try next test\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	    $runtest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)     %{$nc} = %new_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)     return $runtest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) sub convert_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)     my ($config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)     if ($config =~ /^# (.*) is not set/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	$config = "$1=n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)     $config =~ s/^CONFIG_//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)     return $config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) sub print_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)     my ($sym, $config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)     $config = convert_config $config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)     doprint "$sym$config\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) sub print_config_compare {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)     my ($good_config, $bad_config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)     $good_config = convert_config $good_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)     $bad_config = convert_config $bad_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)     my $good_value = $good_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)     my $bad_value = $bad_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)     $good_value =~ s/(.*)=//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)     my $config = $1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)     $bad_value =~ s/.*=//;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)     doprint " $config $good_value -> $bad_value\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) # Pass in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) # $phalf: half of the configs names you want to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) # $oconfigs: The orginial configs to start with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) # $sconfigs: The source to update $oconfigs with (from $phalf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) # $which: The name of which half that is updating (top / bottom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) # $type: The name of the source type (good / bad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) sub make_half {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)     my ($phalf, $oconfigs, $sconfigs, $which, $type) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)     my @half = @{$phalf};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)     my %orig_configs = %{$oconfigs};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)     my %source_configs = %{$sconfigs};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)     my %tmp_config = %orig_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)     doprint "Settings bisect with $which half of $type configs:\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)     foreach my $item (@half) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	doprint "Updating $item to $source_configs{$item}\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	$tmp_config{$item} = $source_configs{$item};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)     return %tmp_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) sub run_config_bisect {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)     my ($pgood, $pbad) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)     my %good_configs = %{$pgood};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)     my %bad_configs = %{$pbad};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)     my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)     my %b_configs = diff_configs \%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)     my %g_configs = diff_configs \%bad_configs, \%good_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)     # diff_arr is what is in both good and bad but are different (y->n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)     my @diff_arr = keys %diff_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)     my $len_diff = $#diff_arr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)     # b_arr is what is in bad but not in good (has depends)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)     my @b_arr = keys %b_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)     my $len_b = $#b_arr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)     # g_arr is what is in good but not in bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)     my @g_arr = keys %g_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)     my $len_g = $#g_arr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)     my $runtest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)     my %new_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)     my $ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)     # Look at the configs that are different between good and bad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)     # This does not include those that depend on other configs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)     #  (configs depending on other configs that are not set would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)     #   not show up even as a "# CONFIG_FOO is not set"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)     doprint "# of configs to check:             $len_diff\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)     doprint "# of configs showing only in good: $len_g\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)     doprint "# of configs showing only in bad:  $len_b\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)     if ($len_diff > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	# Now test for different values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	doprint "Configs left to check:\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	doprint "  Good Config\t\t\tBad Config\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	doprint "  -----------\t\t\t----------\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	foreach my $item (@diff_arr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	    doprint "  $good_configs{$item}\t$bad_configs{$item}\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	my $half = int($#diff_arr / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	my @tophalf = @diff_arr[0 .. $half];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	doprint "Set tmp config to be good config with some bad config values\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	my %tmp_config = make_half \@tophalf, \%good_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	    \%bad_configs, "top", "bad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	$runtest = process_new_config \%tmp_config, \%new_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			    \%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (!$runtest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	    doprint "Set tmp config to be bad config with some good config values\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	    my %tmp_config = make_half \@tophalf, \%bad_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		\%good_configs, "top", "good";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	    $runtest = process_new_config \%tmp_config, \%new_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		\%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)     if (!$runtest && $len_diff > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	# do the same thing, but this time with bottom half
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	my $half = int($#diff_arr / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	doprint "Set tmp config to be good config with some bad config values\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	my %tmp_config = make_half \@bottomhalf, \%good_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	    \%bad_configs, "bottom", "bad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	$runtest = process_new_config \%tmp_config, \%new_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			    \%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	if (!$runtest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	    doprint "Set tmp config to be bad config with some good config values\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	    my %tmp_config = make_half \@bottomhalf, \%bad_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		\%good_configs, "bottom", "good";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	    $runtest = process_new_config \%tmp_config, \%new_configs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		\%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)     if ($runtest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	make_oldconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	doprint "READY TO TEST .config IN $build\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)     doprint "\n%%%%%%%% FAILED TO FIND SINGLE BAD CONFIG %%%%%%%%\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)     doprint "Hmm, can't make any more changes without making good == bad?\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)     doprint "Difference between good (+) and bad (-)\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)     foreach my $item (keys %bad_configs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	if (!defined($good_configs{$item})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	    print_config "-", $bad_configs{$item};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)     foreach my $item (keys %good_configs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	next if (!defined($bad_configs{$item}));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	if ($good_configs{$item} ne $bad_configs{$item}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	    print_config_compare $good_configs{$item}, $bad_configs{$item};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)     foreach my $item (keys %good_configs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (!defined($bad_configs{$item})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	    print_config "+", $good_configs{$item};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)     return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) sub config_bisect {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)     my ($good_config, $bad_config) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)     my $ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)     my %good_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)     my %bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)     my %tmp_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)     doprint "Run good configs through make oldconfig\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)     assign_configs \%tmp_configs, $good_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)     create_config "$good_config", \%tmp_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)     assign_configs \%good_configs, $output_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)     doprint "Run bad configs through make oldconfig\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)     assign_configs \%tmp_configs, $bad_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)     create_config "$bad_config", \%tmp_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)     assign_configs \%bad_configs, $output_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)     save_config \%good_configs, $good_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)     save_config \%bad_configs, $bad_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)     return run_config_bisect \%good_configs, \%bad_configs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) while ($#ARGV >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)     if ($ARGV[0] !~ m/^-/) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)     my $opt = shift @ARGV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)     if ($opt eq "-b") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	$val = shift @ARGV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	if (!defined($val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	    die "-b requires value\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	$build = $val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)     elsif ($opt eq "-l") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	$val = shift @ARGV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	if (!defined($val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	    die "-l requires value\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	$tree = $val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)     elsif ($opt eq "-r") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	$reset_bisect = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)     elsif ($opt eq "-h") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	die "Unknown option $opt\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) $build = $tree if (!defined($build));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) $tree = expand_path $tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) $build = expand_path $build;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if ( ! -d $tree ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)     die "$tree not a directory\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if ( ! -d $build ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)     die "$build not a directory\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) usage if $#ARGV < 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if ($#ARGV == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)     $start = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) } elsif ($#ARGV == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)     $val = $ARGV[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)     if ($val ne "good" && $val ne "bad") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	die "Unknown command '$val', bust be either \"good\" or \"bad\"\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)     usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) my $good_start = expand_path $ARGV[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) my $bad_start = expand_path $ARGV[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) my $good = "$good_start.tmp";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) my $bad = "$bad_start.tmp";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) $make = "make";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if ($build ne $tree) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)     $make = "make O=$build"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) $output_config = "$build/.config";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if ($start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)     if ( ! -f $good_start ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	die "$good_start not found\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)     if ( ! -f $bad_start ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	die "$bad_start not found\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)     if ( -f $good || -f $bad ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	my $p = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	if ( -f $good ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	    $p = "$good exists\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	if ( -f $bad ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	    $p = "$p$bad exists\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	if (!defined($reset_bisect)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	    if (!read_yn "${p}Overwrite and start new bisect anyway?") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		exit (-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)     run_command "cp $good_start $good" or die "failed to copy to $good\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)     run_command "cp $bad_start $bad" or die "failed to copy to $bad\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)     if ( ! -f $good ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	die "Can not find file $good\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)     if ( ! -f $bad ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	die "Can not find file $bad\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)     if ($val eq "good") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	run_command "cp $output_config $good" or die "failed to copy $config to $good\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)     } elsif ($val eq "bad") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	run_command "cp $output_config $bad" or die "failed to copy $config to $bad\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) chdir $tree || die "can't change directory to $tree";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) my $ret = config_bisect $good, $bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (!$ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)     exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if ($ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)     doprint "Cleaning temp files\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)     run_command "rm $good";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)     run_command "rm $bad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)     exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)     doprint "See good and bad configs for details:\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)     doprint "good: $good\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)     doprint "bad:  $bad\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)     doprint "%%%%%%%% FAILED TO FIND SINGLE BAD CONFIG %%%%%%%%\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) exit(2);