blob: dfa151b6e16d2928a63aab3e4b2fe21a67156816 [file] [log] [blame]
Ward Vandewege5bd560c2013-06-08 10:00:55 +02001#!/usr/bin/perl
2#
3# Update the onboard NIC mac address in a coreboot rom image for mcp55-based boards
4#
5# This program is free software (GPLv2 or higher).
6#
7# 2008-01-30 Ward Vandewege (ward@gnu.org)
8
9my $mac = $ARGV[0];
10my $file = $ARGV[1];
11
12if (($mac eq '') or ($file eq '')) {
13 print "\nSyntax: $0 <mac address> <rom image>\n";
14 exit 1;
15}
16
17if (! -f $file) {
18 print "\nSyntax: $0 <mac address> <rom image>\n";
19 print "\nERROR: Could not find file '$file'.\n\n";
20 exit 1;
21}
22
23if (!($mac =~ /^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$/)) {
24 print "\nSyntax: $0 <mac address> <rom image>\n";
25 print "\nERROR: The mac address you specified ($mac) is not a valid mac address.\n\n";
26 exit 1;
27}
28
29my @mac = split(/:/,$mac);
30
31my $newmac = '';
32
33for (my $c = 5; $c >= 0; $c--) {
34 $newmac .= chr(hex($mac[$c]));
35}
36
37open(ROMIMAGE,"+<",$file) or die "Can't open file $file for writing\n";
38seek(ROMIMAGE,-48,2);
39
40print ROMIMAGE $newmac;
41close(ROMIMAGE);
42
43print "Mac address succesfully updated to $mac in $file\n";
44exit 0;