summaryrefslogtreecommitdiff
path: root/common/tools/genNVRAM/nvram_range.pl
blob: de447ca6318b7f6a255aef47e821b9e9be4929c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case bundling);
use Pod::Usage;
use Config;

my $OUI = "00:13:d7";

my $temp_conf = "tmp.conf";
my @dpw_table = ( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' );

# Argument parsing
my $help;
my $start;
my $end;
my $conf;
GetOptions (
	'help|h' => \$help,
	'start|s=i' => \$start,
	'end|e=i' => \$end,
	'conf|c=s' => \$conf,
	) or pod2usage (2);
pod2usage (1) if $help;

# check args
defined $start && defined $end && defined $conf or pod2usage(2);

# check parameters
if ($start <= 0) {
	$start = 0;
}

if($end < $start) {
	$end = $start;
}

srand;

sub dpw_generate {
	my ($i, $dpw);
	$dpw = "";
	for $i (0 .. 18) {
		if($i % 5 == 4) {
			$dpw = join '', $dpw, "-";
		}
		else {
			$dpw = join '', $dpw, $dpw_table[int(rand 32)];
		}
	}
	return $dpw;
}

my $index;
for $index ($start .. $end) {
# open config file
	open CONF, $conf or die "Cannot open $conf for read :$!";
# open temp config file
	open TEMP_CONF, ">$temp_conf" or die "Cannot open $temp_conf for read :$!";

# fill it with std input conf file
	while(<CONF>) {
		print TEMP_CONF "$_";
	}
	close CONF;

# add ethernet and plc address
	print TEMP_CONF "plc=$OUI:", sprintf("%02x", ($index & 0xff0000) >> 16), ":", sprintf("%02x", (($index & 0x00ff00) >> 8) & 0xfe), ":", sprintf("%02x", $index & 0x0000ff), "\n";
	print TEMP_CONF "ethernet=$OUI:", sprintf("%02x", ($index & 0xff0000) >> 16), ":", sprintf("%02x", (($index & 0x00ff00) >> 8) | 0x01), ":", sprintf("%02x", $index & 0x0000ff), "\n";
# add DPW
	print TEMP_CONF "dpw=", &dpw_generate, "\n";
	close TEMP_CONF;

	system ("./genNVRAM --type spc300 --infile $temp_conf --outfile nvram_".sprintf("%06x", $index).".bin");
}

system ("rm $temp_conf");

__END__

=head1 NAME

nvram_range.pl - generate a range of SPC300 NVRAM binary files.

=head1 SYNOPSIS

nvram_range.pl Arguments [Options]

Arguments:
	-h, --help		brief help message
	-s, --start 	start mac offset
	-e, --end 	    end mac offset
	-c, --conf      configuration file

=cut