MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / scripts / hwselect.pl
blob8181bee7d291afd721975ea79af2ea597906e04a
1 # This script generates arch/nios2nommu/hardware.mk based on user input
3 # usage:
5 # [SOPC Builder]$ perl hwselect.pl <ptf file path> <target file path>
8 use PTF::SystemPTF;
9 use strict;
10 use integer;
12 my $ptf_filename;
13 my $target_filename;
14 my $index;
15 my $system;
18 # Subroutine: Prompt user for an answer
21 sub request_answer {
22 my ($min, $max) = @_;
23 my $answer;
25 do {
26 print "Selection: ";
27 $answer = <STDIN>;
28 if (! ($answer >= $min && $answer <= $max)) {
29 print "Invalid response, please try again.\n";
31 } until $answer >= $min && $answer <= $max;
33 return $answer;
37 # Check for correct number of args
40 if (scalar (@ARGV) != 2) {
41 print STDERR "ERROR: Invalid number of parameters.\n";
42 exit;
43 } else {
44 $ptf_filename = $ARGV[0];
45 $target_filename = $ARGV[1];
49 # Check to see if the specified file exists
52 if (! -e $ptf_filename) {
53 print STDERR "ERROR: Could not open SYSTEM ptf file.\n";
54 exit;
58 # startup the parser.
60 $system = SystemPTF->new (filename => $ptf_filename);
61 if (!$system) {
62 print STDERR "ERROR: Specified file is not a SYSTEM ptf file.\n";
63 exit;
67 # Grab listing of Nios II processors and force user to select one:
70 print "\n--- Please select which CPU you wish to build the kernel against:\n\n";
72 my @cpulist = $system->getCPUList ('altera_nios2');
73 my %cpuinfo;
75 $index = 1;
76 foreach my $cpu (@cpulist) {
77 my $cpu_module = $system->getCPU ($cpu);
78 if ($cpu_module->isEnabled ()) {
79 my $class = $cpu_module->getClass();
80 my $type = $cpu_module->getWSAAssignment('cpu_selection');
81 my $version = $cpu_module->getVersion();
83 print "($index) $cpu - Class: $class Type: $type Version: $version\n";
85 $index += 1;
88 print "\n";
90 my $cpu_selection = $cpulist[request_answer (1, $index - 1) - 1];
93 # Grab list of memory devices that $cpu_selection is hooked up to:
95 my @modulelist = $system->getSlaveModules ($cpu_selection);
96 my %cfiinfo;
97 my %meminfo;
98 foreach my $module_name (@modulelist) {
99 my $module = $system->getModule ($module_name);
100 my $class = $module->getClass ();
102 if ($module->isEnabled ()) {
103 if ($class eq 'altera_avalon_cfi_flash') {
104 $cfiinfo{$module_name}{class} = $class;
105 $cfiinfo{$module_name}{size} = $module->getSize();
108 if ($module->isMemoryDevice()) {
109 $meminfo{$module_name}{class} = $class;
110 $meminfo{$module_name}{size} = $module->getSize();
116 # Select an upload device:
118 print "\n--- Please select a device to upload the kernel to:\n\n";
120 $index = 1;
121 foreach my $name (keys (%cfiinfo)) {
122 my $size = hex ($cfiinfo{$name}{size});
123 print "($index) $name\n\tClass: $cfiinfo{$name}{class}\n\tSize: $size bytes\n\n";
124 $index += 1;
127 my @cfilist = keys (%cfiinfo);
128 my $cfi_selected = $cfilist[request_answer (1, $index - 1) - 1];
130 delete $meminfo{$cfi_selected};
133 # Select program memory to execute kernel from:
135 print "\n--- Please select a device to execute kernel from:\n\n";
137 $index = 1;
138 foreach my $name (keys (%meminfo)) {
139 my $size = hex ($meminfo{$name}{size});
140 print "($index) $name\n\tClass: $meminfo{$name}{class}\n\tSize: $size bytes\n\n";
141 $index += 1;
144 my @memlist = keys (%meminfo);
145 my $mem_selected = $memlist[request_answer (1, $index - 1) - 1];
147 print "\n--- Summary using\n\n";
148 print "PTF: $ptf_filename\n";
149 print "CPU: $cpu_selection\n";
150 print "Device to upload to: $cfi_selected\n";
151 print "Program memory to execute from: $mem_selected\n";
154 # Write settings out to Makefile fragment
156 open (HWMK, ">$target_filename") ||
157 die "Could not write to $target_filename";
159 print HWMK "SYSPTF = $ptf_filename\n";
160 print HWMK "CPU = $cpu_selection\n";
161 print HWMK "UPLMEM = $cfi_selected\n";
162 print HWMK "EXEMEM = $mem_selected\n";
164 close (HWMK);
166 print "\n--- Settings written to $target_filename\n\n";