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 / gen_nios2_system.h.pl
blobb7bcff588f35791c74c22e2537f95d65ce1eb317
1 # This script generates an appropriate hardware.h file for Nios II Linux based
2 # on information within the target hardware's system.ptf file. This script
3 # outputs everything to stdout.
5 # usage:
7 # [SOPC Builder]$ perl gen_hardware.h.pl <target cpu> <exec location> \
8 # <upload location>
11 use PTF::SystemPTF;
12 use strict;
13 use integer;
15 my $target_cpu;
16 my $exec_location;
17 my $upload_location;
19 if (scalar (@ARGV) != 3) {
20 print STDERR "ERROR: Invalid number of parameters.\n";
21 print ("#error Invalid number of parameters.\n");
22 exit;
23 } else {
24 $target_cpu = $ARGV[0];
25 $exec_location = $ARGV[1];
26 $upload_location = $ARGV[2];
30 # startup the parser.
32 my $system = SystemPTF->new;
33 if (!$system) {
34 print STDERR "ERROR: Specified file is not a SYSTEM ptf file.\n";
35 print ("#error Specified file is not a SYSTEM ptf file.\n");
36 exit;
40 # print header for nios2_system.h
42 print <<ENDOFHEADER;
43 #ifndef __NIOS2_SYSTEM_H__
44 #define __NIOS2_SYSTEM_H__
47 * This file contains hardware information about the target platform.
48 * The nios2_system.h file is being phased out and will be removed in a
49 * later release.
51 * All base addresses for non memory devices have their high bit turned on to
52 * bypass the cache.
54 * This file is automatically generated. Do not modify.
57 ENDOFHEADER
60 # generate contents for nios2_system.h
62 my $result; # dummy variable
63 my $cpu = $system->getCPU ($target_cpu);
64 if (! $cpu) {
65 print STDERR "ERROR: $target_cpu is not a valid CPU in system: " . $system->getName () . ".\n";
66 print "#error $target_cpu is not a valid CPU in system: " . $system->getName () . ".\n";
67 exit 1;
70 my $exec_module = $system->getModule ($exec_location);
71 if (! $exec_module) {
72 print STDERR "ERROR: $exec_location is not a valid module in the system: " . $system->getName() . ".\n";
73 print "#error $exec_location is not a valid module in system: " . $system->getName () . ".\n";
74 exit 1;
77 my $upload_module = $system->getModule ($upload_location);
78 if (! $upload_module) {
79 print STDERR "ERROR: $upload_location is not a valid module in the system: " . $system->getName() . ".\n";
80 print "#error $upload_location is not a valid module in system: " . $system->getName () . ".\n";
81 exit 1;
84 my %found_classes;
85 my @found_classes_order;
87 # the SYSPTF environment variable is set by kernel build process.
88 if ($ENV{SYSPTF} ne "") {
89 print "/* Input System: " . $ENV{SYSPTF} . ":" . $system->getName () . " */\n";
90 } else {
91 print "/* Input System: " . $system->getName () . " */\n";
93 print "/* Target CPU: " . $target_cpu . " */\n";
95 print "\n";
97 print <<ENDOFCONSTANTS;
98 /* Nios II Constants */
99 #define NIOS2_STATUS_PIE_MSK 0x1
100 #define NIOS2_STATUS_PIE_OFST 0
101 #define NIOS2_STATUS_U_MSK 0x2
102 #define NIOS2_STATUS_U_OFST 1
103 ENDOFCONSTANTS
105 print "\n";
107 print "/*\n";
108 print " * Outputting basic values from system.ptf.\n";
109 print " */\n\n";
112 # Start outputing information about each module.
114 my @module_names = $system->getSlaveModules ($target_cpu);
115 foreach my $module_name (@module_names) {
116 my $module = $system->getModule ($module_name);
117 my $module_class = $module->getClass ();
118 my @module_ports = $module->getPorts ();
119 my $mask = 0;
120 my $text_printed = 0;
121 my $output = "";
123 # $output .= "/* $module_name (of type $module_class) */\n";
125 if (! exists $found_classes{$module_class}) {
126 push @found_classes_order, $module_class;
128 push @{$found_classes{$module_class}}, $module_name;
130 if (! $module->isMemoryDevice () && ! $module->isCustomInstruction ()) {
131 # turn on high bit for base address
132 $mask = 0x80000000;
135 if (scalar (@module_ports) == 1) {
136 my $base_address;
137 my $mem_size;
138 my $mem_end;
140 # base address information
141 $base_address = $module->getBaseAddress ();
142 if ($base_address) {
143 $output .= sprintf ("#define na_%-50s %#010x\n",
144 ($module_name, hex ($base_address) | $mask));
145 $text_printed = 1;
147 if ($module->isMemoryDevice()) {
148 # output size and end address
149 $mem_size = $module->getSize();
150 $output .= sprintf ("#define na_%-50s %#010x\n",
151 ($module_name . "_size", hex ($mem_size)));
152 $mem_end = hex ($mem_size) + hex($base_address);
153 $output .= sprintf ("#define na_%-50s %#010x\n",
154 ($module_name . "_end", $mem_end));
156 $text_printed = 1;
159 # irq information
160 $result = $module->getIRQ ();
161 if (defined ($result)) {
162 $output .= sprintf ("#define na_%-30s %30s\n",
163 ($module_name . "_irq", $result));
164 $text_printed = 1;
167 } else {
168 # if device has multiple ports
169 foreach my $port_name (@module_ports) {
170 # base address information
171 $result = $module->getBaseAddress ($port_name);
172 if ($result) {
173 $output .= sprintf ("#define na_%-50s %#010x\n",
174 ($module_name . "_" . $port_name, hex ($result) | $mask));
175 $text_printed = 1;
178 # irq information
179 $result = $module->getIRQ ($port_name);
180 if (defined ($result)) {
181 $output .= sprintf ("#define na_%-30s %30s\n",
182 ($module_name . "_" . $port_name . "_irq", $result));
183 $text_printed = 1;
188 if ($text_printed == 1) {
189 # $output .= "\n";
190 print $output;
194 print "\n";
197 # Handle special cases through customized perl scripts
199 foreach my $class_name (@found_classes_order) {
200 my $code = "";
202 foreach my $dir (@INC) {
203 if (-e "$dir/nios2_system.h/$class_name.pm") {
204 print "/* Executing ...scripts/nios2_system.h/$class_name.pm */\n";
205 $code .= "require \"$dir/nios2_system.h/BasicModule.pm\";";
206 $code .= "require \"$dir/nios2_system.h/$class_name.pm\";";
207 $code .= $class_name . "::run(\$system, \@{\$found_classes{\$class_name}});";
208 eval $code;
209 if ($@) {
210 print "#warning Could not execute ...scripts/nios2_system.h/$class_name.pm\n";
211 print "#warning Error message is stored in nios2_system.h:\n";
212 print "/*\n";
213 print "$@";
214 print "*/\n";
215 print STDERR "Could not execute ...scripts/nios2_system.h/$class_name.pm\n";
216 print STDERR "Error message follows:\n";
217 print STDERR "$@";
219 last;
225 # Write out system information
227 print "/*\n";
228 print " * Basic System Information\n";
229 print " */\n";
231 $result = $cpu->getWSAAssignment ('cache_icache_size');
232 printf ("#define %-53s %10d\n", ("nasys_icache_size", $result));
234 $result = $cpu->getConstant ('nasys_icache_line_size');
235 printf ("#define %-53s %10d\n", ("nasys_icache_line_size", $result));
237 $result = $cpu->getWSAAssignment ('cache_dcache_size');
238 printf ("#define %-53s %10d\n", ("nasys_dcache_size", $result));
240 $result = $cpu->getConstant ('nasys_dcache_line_size');
241 printf ("#define %-53s %10d\n", ("nasys_dcache_line_size", $result));
243 print "\n";
245 printf ("#define %-33s %30s\n",
246 ("nasys_program_mem", "na_${exec_location}"));
247 printf ("#define %-33s %30s\n",
248 ("nasys_program_mem_size", "na_${exec_location}_size"));
249 printf ("#define %-33s %30s\n",
250 ("nasys_program_mem_end", "na_${exec_location}_end"));
252 print "\n";
254 if ($upload_location eq "flash_kernel") {
255 # nothing to do
256 print ("/* Redefinition of CFI flash memory unecessary */\n");
257 } else {
258 my $module = $system->getModule ("flash_kernel");
259 if ($module) {
260 # there is a conflicting module in the system, error.
261 print STDERR "Error, a SOPC module named flash_kernel already exists but is not the upload location.\n";
262 print "#error The module name \"flash_kernel\" already exists but isn't the upload location.\n";
263 print "#error This will break the kernel.\n";
264 print "#error Please rename the module to something else in SOPC Builder.\n\n";
265 exit 1;
266 } else {
267 print ("/*\n");
268 print (" * Redefining upload location ($upload_location) to flash_kernel.\n");
269 print (" */\n\n");
270 # undefine the original module names and re-define them here.
271 print ("#undef na_${upload_location}\n");
272 print ("#undef na_${upload_location}_size\n");
273 print ("#undef na_${upload_location}_end\n");
275 my $base_address = $upload_module->getBaseAddress ();
276 printf ("#define %-33s %30s\n",
277 ("na_flash_kernel", $base_address));
279 my $mem_size = $upload_module->getSize();
280 printf ("#define %-33s %30s\n",
281 ("na_flash_kernel_size", $mem_size));
283 my $mem_end = hex ($base_address) + hex ($mem_size);
284 printf ("#define %-53s %#010x\n",
285 ("na_flash_kernel_end", $mem_end));
289 print "\n";
291 printf ("#define %-33s %30s\n",
292 ("nasys_clock_freq", $system->getClockFreq()));
293 printf ("#define %-33s %30s\n",
294 ("nasys_clock_freq_1000", int ($system->getClockFreq()) / 1000));
297 my ($reset_location, $reset_offset) = $cpu->getResetLocationOffset();
298 my ($reset_module_name, $reset_port_name) = ($reset_location =~ /(.*)\/(.*)/);
299 my $reset_module = $system->getModule ($reset_module_name);
300 my $reset_address = $reset_module->getBaseAddress ($reset_port_name);
302 $reset_address = hex ($reset_address) + hex ($reset_offset);
303 printf ("#define %-53s %#010x\n",
304 ("CPU_RESET_ADDRESS", $reset_address));
307 print "\n";
310 # print footer for nios2_system.h
312 print <<ENDOFFOOTER;
313 #endif /* __NIOS2_SYSTEM_H__ */
314 ENDOFFOOTER