Rev 1892 | Rev 2187 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1892 | Rev 2156 | ||
|---|---|---|---|
| 1 | #!/usr/bin/perl -w |
1 | #!/usr/bin/perl -w |
| 2 | ################################################ |
2 | ################################################ |
| 3 | # |
3 | # |
| 4 | # author: arune @ efnet |
4 | # author: arune @ efnet |
| 5 | # |
5 | # |
| 6 | ################################################ |
6 | ################################################ |
| 7 | 7 | ||
| 8 | use integer; |
8 | use integer; |
| 9 | use threads; |
9 | use threads; |
| 10 | use Cwd qw(abs_path); |
10 | use Cwd qw(abs_path); |
| 11 | use File::Basename; |
11 | use File::Basename; |
| 12 | use Getopt::Long; |
12 | use Getopt::Long; |
| - | 13 | use Time::HiRes qw(usleep nanosleep); |
|
| 13 | 14 | ||
| 14 | $host = "localhost"; |
15 | $host = "localhost"; |
| 15 | $port = 1201; |
16 | $port = 1201; |
| 16 | 17 | ||
| 17 | # Get hostname and port from command line arguments |
18 | # Get hostname and port from command line arguments |
| 18 | if ( @ARGV > 0 ) { |
19 | if ( @ARGV > 0 ) { |
| 19 | GetOptions( "host=s" => \$host, # |
20 | GetOptions( "host=s" => \$host, # |
| 20 | "port=i" => \$port, # |
21 | "port=i" => \$port, # |
| 21 | ); |
22 | ); |
| 22 | } |
23 | } |
| 23 | 24 | ||
| 24 | my $path = dirname(abs_path($0)); |
25 | my $path = dirname(abs_path($0)); |
| 25 | 26 | ||
| 26 | # Read atom functions from separate file |
27 | # Read atom functions from separate file |
| 27 | if (-e $path."/AtomLib.pl") { |
28 | if (-e $path."/AtomLib.pl") { |
| 28 | require $path."/AtomLib.pl"; |
29 | require $path."/AtomLib.pl"; |
| 29 | } else { |
30 | } else { |
| 30 | print "Error: No AtomLib.pl was found in ".$path.". \n\n"; |
31 | print "Error: No AtomLib.pl was found in ".$path.". \n\n"; |
| 31 | exit 1; |
32 | exit 1; |
| 32 | } |
33 | } |
| 33 | 34 | ||
| 34 | # Read devices from separate file |
35 | # Read devices from separate file |
| 35 | if (-e $path."/devices.pl") { |
36 | if (-e $path."/devices.pl") { |
| 36 | require $path."/devices.pl"; |
37 | require $path."/devices.pl"; |
| 37 | } else { |
38 | } else { |
| 38 | print "Error: No devices.pl was found in ".$path.". \n\n"; |
39 | print "Error: No devices.pl was found in ".$path.". \n\n"; |
| 39 | exit 1; |
40 | exit 1; |
| 40 | } |
41 | } |
| 41 | 42 | ||
| 42 | $biosfile = "bios.inc"; |
43 | $biosfile = "bios.inc"; |
| 43 | open (FP, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n"; |
44 | open (FP, "+<".$biosfile) or die "Error: Cannot open file $biosfile\n"; |
| 44 | @file = <FP>; |
45 | @file = <FP>; |
| 45 | close FP; |
46 | close FP; |
| 46 | 47 | ||
| 47 | 48 | ||
| 48 | # Check bios.inc for the settings that should be updated |
49 | # Check bios.inc for the settings that should be updated |
| 49 | my $foundidrow = 0; |
50 | my $foundidrow = 0; |
| 50 | my $foundmcurow = 0; |
51 | my $foundmcurow = 0; |
| 51 | my $foundhfrow = 0; |
52 | my $foundhfrow = 0; |
| 52 | my $foundlfrow = 0; |
53 | my $foundlfrow = 0; |
| 53 | my $foundefrow = 0; |
54 | my $foundefrow = 0; |
| 54 | my $foundbootrow = 0; |
55 | my $foundbootrow = 0; |
| 55 | foreach $file (@file) { |
56 | foreach $file (@file) { |
| 56 | if ($file =~ m/^NODE_HW_ID=/) { |
57 | if ($file =~ m/^NODE_HW_ID=/) { |
| 57 | print "\nCurrent id-setting: ".$file."\n"; |
58 | print "\nCurrent id-setting: ".$file."\n"; |
| 58 | $foundidrow = 1; |
59 | $foundidrow = 1; |
| 59 | } |
60 | } |
| 60 | if ($file =~ m/^MCU=/) { |
61 | if ($file =~ m/^MCU=/) { |
| 61 | $foundmcurow = 1; |
62 | $foundmcurow = 1; |
| 62 | } |
63 | } |
| 63 | if ($file =~ m/^HIGHFUSE=/) { |
64 | if ($file =~ m/^HIGHFUSE=/) { |
| 64 | $foundhfrow = 1; |
65 | $foundhfrow = 1; |
| 65 | } |
66 | } |
| 66 | if ($file =~ m/^LOWFUSE=/) { |
67 | if ($file =~ m/^LOWFUSE=/) { |
| 67 | $foundlfrow = 1; |
68 | $foundlfrow = 1; |
| 68 | } |
69 | } |
| 69 | if ($file =~ m/^EXTFUSE=/) { |
70 | if ($file =~ m/^EXTFUSE=/) { |
| 70 | $foundefrow = 1; |
71 | $foundefrow = 1; |
| 71 | } |
72 | } |
| 72 | if ($file =~ m/^BOOT_START=/) { |
73 | if ($file =~ m/^BOOT_START=/) { |
| 73 | $foundbootrow = 1; |
74 | $foundbootrow = 1; |
| 74 | } |
75 | } |
| 75 | } |
76 | } |
| 76 | if ($foundidrow == 0) { |
77 | if ($foundidrow == 0) { |
| 77 | print "Error: Did not find NODE_HW_ID= in file $biosfile\n"; |
78 | print "Error: Did not find NODE_HW_ID= in file $biosfile\n"; |
| 78 | exit 1; |
79 | exit 1; |
| 79 | } |
80 | } |
| 80 | if ($foundmcurow == 0) { |
81 | if ($foundmcurow == 0) { |
| 81 | print "Error: Did not find MCU= in file $biosfile\n"; |
82 | print "Error: Did not find MCU= in file $biosfile\n"; |
| 82 | exit 1; |
83 | exit 1; |
| 83 | } |
84 | } |
| 84 | if ($foundhfrow == 0) { |
85 | if ($foundhfrow == 0) { |
| 85 | print "Error: Did not find HIGHFUSE= in file $biosfile\n"; |
86 | print "Error: Did not find HIGHFUSE= in file $biosfile\n"; |
| 86 | exit 1; |
87 | exit 1; |
| 87 | } |
88 | } |
| 88 | if ($foundlfrow == 0) { |
89 | if ($foundlfrow == 0) { |
| 89 | print "Error: Did not find LOWFUSE= in file $biosfile\n"; |
90 | print "Error: Did not find LOWFUSE= in file $biosfile\n"; |
| 90 | exit 1; |
91 | exit 1; |
| 91 | } |
92 | } |
| 92 | if ($foundefrow == 0) { |
93 | if ($foundefrow == 0) { |
| 93 | print "Error: Did not find EXTFUSE= in file $biosfile\n"; |
94 | print "Error: Did not find EXTFUSE= in file $biosfile\n"; |
| 94 | exit 1; |
95 | exit 1; |
| 95 | } |
96 | } |
| 96 | if ($foundbootrow == 0) { |
97 | if ($foundbootrow == 0) { |
| 97 | print "Error: Did not find BOOT_START= in file $biosfile\n"; |
98 | print "Error: Did not find BOOT_START= in file $biosfile\n"; |
| 98 | exit 1; |
99 | exit 1; |
| 99 | } |
100 | } |
| 100 | 101 | ||
| 101 | my $hwid = ""; |
102 | my $hwid = ""; |
| 102 | my @device = (); |
103 | my @device = (); |
| 103 | 104 | ||
| 104 | #print "/usr/bin/atomic -s $host -p $port -c \"Node_WaitForInformation\"\n"; |
105 | #print "/usr/bin/atomic -s $host -p $port -c \"Node_WaitForInformation\"\n"; |
| 105 | #my @lines = qx{/usr/bin/atomic -s $host -p $port -c \"Node_GetInformation 0xB23F54EA\"}; |
106 | #my @lines = qx{/usr/bin/atomic -s $host -p $port -c \"Node_GetInformation 0xB23F54EA\"}; |
| 106 | #my @lines = qx{/usr/bin/atomic -s $host -p $port -c \"Node_WaitForInformation\"}; |
107 | #my @lines = qx{/usr/bin/atomic -s $host -p $port -c \"Node_WaitForInformation\"}; |
| 107 | 108 | ||
| 108 | $socket = atomd_initialize($host, $port); |
109 | $socket = atomd_initialize($host, $port); |
| - | 110 | usleep(100000); |
|
| - | 111 | atomd_kill_promt($socket); |
|
| 109 | atomd_send_command($socket, "Node_WaitForInformation"); |
112 | atomd_send_command($socket, "Node_WaitForInformation"); |
| 110 | #atomd_send_command($socket, "Node_GetInformation 0x7DD44E0A"); |
113 | #atomd_send_command($socket, "Node_GetInformation 0x7DD44E0A"); |
| 111 | $return = atomd_read_command_response($socket); |
114 | $return = atomd_read_command_response($socket); |
| 112 | 115 | ||
| 113 | my @lines = split(/\n/, $return); |
116 | my @lines = split(/\n/, $return); |
| 114 | 117 | ||
| 115 | my $foundDeviceType = 0; |
118 | my $foundDeviceType = 0; |
| 116 | foreach (@lines) |
119 | foreach (@lines) |
| 117 | { |
120 | { |
| 118 | my $line = $_; |
121 | my $line = $_; |
| 119 | print($line."\n"); |
122 | print($line."\n"); |
| 120 | chomp($line); |
123 | chomp($line); |
| 121 | 124 | ||
| 122 | if (index($line, "Id") != -1) |
125 | if (index($line, "Id") != -1) |
| 123 | { |
126 | { |
| 124 | my $temp = substr($line, index($line, ":") + 1); |
127 | my $temp = substr($line, index($line, ":") + 1); |
| 125 | 128 | ||
| 126 | $temp =~ s/^\s+//; |
129 | $temp =~ s/^\s+//; |
| 127 | $temp =~ s/\s+$//; |
130 | $temp =~ s/\s+$//; |
| 128 | 131 | ||
| 129 | my @hwidChars = split(//, $temp); |
132 | my @hwidChars = split(//, $temp); |
| 130 | $hwid = $hwidChars[0]. $hwidChars[1]. $hwidChars[8]. $hwidChars[9]. $hwidChars[6]. $hwidChars[7]. $hwidChars[4]. $hwidChars[5]. $hwidChars[2]. $hwidChars[3]; |
133 | $hwid = $hwidChars[0]. $hwidChars[1]. $hwidChars[8]. $hwidChars[9]. $hwidChars[6]. $hwidChars[7]. $hwidChars[4]. $hwidChars[5]. $hwidChars[2]. $hwidChars[3]; |
| 131 | 134 | ||
| 132 | print "Setting HWID in bios.inc to ".$hwid."\n"; |
135 | print "Setting HWID in bios.inc to ".$hwid."\n"; |
| 133 | } |
136 | } |
| 134 | elsif (index($line, "Device Type") != -1) |
137 | elsif (index($line, "Device Type") != -1) |
| 135 | { |
138 | { |
| 136 | $devicename = substr($line, index($line, ":") + 1); |
139 | $devicename = substr($line, index($line, ":") + 1); |
| 137 | 140 | ||
| 138 | $devicename =~ s/^\s+//; |
141 | $devicename =~ s/^\s+//; |
| 139 | $devicename =~ s/\s+$//; |
142 | $devicename =~ s/\s+$//; |
| 140 | 143 | ||
| 141 | @device = $devices[0]; |
144 | @device = $devices[0]; |
| 142 | foreach (@devices) |
145 | foreach (@devices) |
| 143 | { |
146 | { |
| 144 | if (@{$_}[0] eq $devicename) |
147 | if (@{$_}[0] eq $devicename) |
| 145 | { |
148 | { |
| 146 | @device = @{$_}; |
149 | @device = @{$_}; |
| 147 | $foundDeviceType = 1; |
150 | $foundDeviceType = 1; |
| 148 | } |
151 | } |
| 149 | } |
152 | } |
| 150 | 153 | ||
| 151 | if ($foundDeviceType == 0) |
154 | if ($foundDeviceType == 0) |
| 152 | { |
155 | { |
| 153 | print "\nWarning: Unknown device type, will not set MCU settings\n\n"; |
156 | print "\nWarning: Unknown device type, will not set MCU settings\n\n"; |
| 154 | } |
157 | } |
| 155 | else |
158 | else |
| 156 | { |
159 | { |
| 157 | print "Setting device type to ".$device[0]."\n"; |
160 | print "Setting device type to ".$device[0]."\n"; |
| 158 | } |
161 | } |
| 159 | } |
162 | } |
| 160 | } |
163 | } |
| 161 | 164 | ||
| 162 | if ($hwid eq "" || $foundDeviceType == 0) |
165 | if ($hwid eq "" || $foundDeviceType == 0) |
| 163 | { |
166 | { |
| 164 | exit(1); |
167 | exit(1); |
| 165 | } |
168 | } |
| 166 | 169 | ||
| 167 | # Open bios.inc and replace all settings |
170 | # Open bios.inc and replace all settings |
| 168 | open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n"; |
171 | open (FP, "<".$biosfile) or die "Cannot open file $biosfile\n"; |
| 169 | @file = <FP>; |
172 | @file = <FP>; |
| 170 | close FP; |
173 | close FP; |
| 171 | open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n"; |
174 | open (FP, ">".$biosfile) or die "Cannot open file $biosfile\n"; |
| 172 | foreach $file (@file) { |
175 | foreach $file (@file) { |
| 173 | $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=$hwid/g; |
176 | $file =~ s/^NODE_HW_ID=.*/NODE_HW_ID=$hwid/g; |
| 174 | if ($device[0] ne "unknown") |
177 | if ($device[0] ne "unknown") |
| 175 | { |
178 | { |
| 176 | $file =~ s/^MCU=.*/MCU=$device[0]/g; |
179 | $file =~ s/^MCU=.*/MCU=$device[0]/g; |
| 177 | $file =~ s/^HIGHFUSE=.*/HIGHFUSE=$device[1]/g; |
180 | $file =~ s/^HIGHFUSE=.*/HIGHFUSE=$device[1]/g; |
| 178 | $file =~ s/^LOWFUSE=.*/LOWFUSE=$device[2]/g; |
181 | $file =~ s/^LOWFUSE=.*/LOWFUSE=$device[2]/g; |
| 179 | $file =~ s/^EXTFUSE=.*/EXTFUSE=$device[3]/g; |
182 | $file =~ s/^EXTFUSE=.*/EXTFUSE=$device[3]/g; |
| 180 | $file =~ s/^BOOT_START=.*/BOOT_START=$device[4]/g; |
183 | $file =~ s/^BOOT_START=.*/BOOT_START=$device[4]/g; |
| 181 | } |
184 | } |
| 182 | print FP $file; |
185 | print FP $file; |
| 183 | } |
186 | } |
| 184 | close FP; |
187 | close FP; |
| 185 | 188 | ||
| 186 | exit(0); |
189 | exit(0); |
| 187 | 190 | ||
| 188 | 191 | ||