1 # This script generates arch/nios2nommu/hardware.mk based on user input
5 # [SOPC Builder]$ perl hwselect.pl <ptf file path> <target file path>
18 # Subroutine: Prompt user for an answer
28 if (! ($answer >= $min && $answer <= $max)) {
29 print "Invalid response, please try again.\n";
31 } until $answer >= $min && $answer <= $max;
37 # Check for correct number of args
40 if (scalar (@ARGV) != 2) {
41 print STDERR
"ERROR: Invalid number of parameters.\n";
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";
60 $system = SystemPTF
->new (filename
=> $ptf_filename);
62 print STDERR
"ERROR: Specified file is not a SYSTEM ptf file.\n";
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');
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";
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);
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";
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";
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";
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";
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";
166 print "\n--- Settings written to $target_filename\n\n";