3 #*****************************************************************************
5 #! FILE NAME : boot_linux
7 #! PARAMETERS : -b <bootimage> the name of the boot image to use
8 #! -d <device> the interface to use, e.g., eth1
10 #! -f save it in flash memory at address 0x10000
11 #! -F save it in flash memory at address 0
13 #! -i <image> name of the image to use (default is fimage)
14 #! -o <offset> the offset in the flash where the flashing
16 #! -O <offset> the offset in the image file where the
17 #! flashing starts from
18 #! -p print the resulting etrax100boot command
19 #! instead of executing it
20 #! -s <size> how much to flash (default is the size of
21 #! the flash minus the offset specified using
23 #! -S <size> the size of the flash
25 #! All sizes and offsets above can be specified as decimal
26 #! numbers, or as hexadecimal numbers by prefixing them with 0x.
27 #! It is also possible to use the suffixes k and M to specify
28 #! kilo (1024) or mega (1048576).
30 #! DESCRIPTION: Extract the start of the image and any registers that should
31 #! be set from the kimage or fimage file, and then boot it.
33 #! FUNCTIONS : convert_size
34 #! extract_hw_settings
36 #! calculate_sdram_init
40 #!----------------------------------------------------------------------------
43 #! $Log: boot_linux,v $
44 #! Revision 1.16 2004/11/01 16:32:27 starvik
45 #! Corrected help text to avoid confusion
47 #! Revision 1.15 2003/01/29 11:48:57 pkj
48 #! Calculate a flash size large enough for the given image if the
49 #! -S option is not specified.
51 #! Revision 1.14 2002/11/18 14:40:09 pkj
52 #! Make use of the --loop option to etrax100boot when initialising
53 #! SDRAM memories. This requires a lot fewer options to be passed
54 #! to the boot loader.
56 #! Revision 1.13 2002/08/15 16:29:02 pkj
57 #! * The -S option now accepts the size in bytes (just like the -s option).
58 #! For backwards compatibility it still assumes sizes of 16 and less to
59 #! be specified in MB.
60 #! * The suffixes k and M can now be used with all sizes and offsets to
61 #! specify them in kilo or mega.
63 #! Revision 1.12 2002/08/15 15:27:34 pkj
64 #! Use $opts{'x'} instead of $opt_x.
66 #! Revision 1.11 2002/07/04 17:06:39 pkj
67 #! * No longer specifies a bootfile by default (not needed any longer).
68 #! * Implemented option -b to specify a bootfile.
69 #! * Removed references to option -l (it was never implemented).
71 #! Revision 1.10 2002/06/04 11:50:23 starvik
72 #! Check if mrs_data is specified in kernelconfig (necessary for MCM)
74 #! Revision 1.9 2002/01/29 10:38:26 pkj
75 #! Change illegal to invalid.
77 #! Revision 1.8 2001/09/13 12:32:10 pkj
78 #! * Added option -S to specify the size of the flash (in MB), as -s
79 #! is used to specify how much to flash nowadays.
80 #! * Made the default size of the flash depend on the size of the image
81 #! file. If it is bigger than 0x200100 then the flash is assumed to
82 #! be 4 MB, otherwise it is assumed to be 2 MB.
83 #! * Added verification of various options.
85 #! Revision 1.7 2001/09/13 10:25:11 pkj
88 #! Revision 1.6 2001/06/29 10:05:16 pkj
89 #! Corrected check for SDRAM.
91 #! Revision 1.5 2001/06/29 09:11:55 pkj
92 #! Synchronised boot_elinux and boot_linux.
94 #!----------------------------------------------------------------------------
95 #! (C) Copyright 2001, Axis Communications AB, LUND, SWEDEN
96 #!****************************************************************************
98 #****************** INCLUDE FILES SECTION ************************************
105 #****************** VARIABLE DECLARATION SECTION *****************************
107 use vars
qw($my_name %opts);
108 use vars qw($text_start $cmd);
109 use vars qw($image_name $image_size);
110 use vars qw($offset $source_offset $flash_size $flashing_size);
111 use vars qw($sdram_timing_address $sdram_config_address);
112 use vars qw($sdram_precharge $sdram_nop $sdram_refresh $sdram_mrs);
114 #****************** CONSTANT SECTION *****************************************
117 $sdram_timing_address = "b0000008";
118 $sdram_config_address = "b000000c";
121 $sdram_precharge = 3;
126 #****************** MAIN PROGRAM SECTION *************************************
128 # The name of this program.
129 $my_name = basename($0);
132 getopts('b:d:fFhi:o:O:ps:S:', \%opts);
134 &print_help if ($opts{'h'});
136 # Name and existance of the image
137 $image_name = ($opts{'i'} ? $opts{'i'} : 'fimage');
138 die "Could not find the image $image_name!\n" unless (-s $image_name);
140 if ($opts{'f'} || $opts{'F'})
142 $image_size = -s $image_name;
144 $offset = ($opts{'f'} ? 0x10000 : 0);
146 $offset = &convert_size($opts{'o'}) if (defined($opts{'o'}));
148 die("$my_name: Invalid destination offset\n") if ($offset !~ /^\d+$/);
150 my $base_name = basename($image_name);
151 if ($base_name eq 'timage' || $base_name eq 'flash1.img')
157 $source_offset = $offset;
160 $source_offset = &convert_size($opts{'O'}) if (defined($opts{'O'}));
162 die("$my_name: Invalid source offset\n") if ($source_offset !~ /^\d+$/);
163 die("$my_name: Source offset > image size\n") if ($source_offset > $image_size);
165 if (defined($opts{'S'}))
167 # Backwards compatibility to allow specifying the flash size in MB
168 # without using an M suffix
169 $opts{'S'} .= 'M' if ($opts{'S'} =~ /^\d+$/ && $opts{'S'} <= 16);
171 $flash_size = &convert_size($opts{'S'});
175 # Calculate a flash size large enough for the image without the checksum
177 $flash_size = ($image_size - $source_offset + $offset) & 0xFFFF0000;
180 die("$my_name: Invalid flash size\n") if ($flash_size !~ /^\d+$/);
181 die("$my_name: Destination offset > flash size\n") if ($offset > $flash_size);
182 if (defined($opts{'s'}))
184 $flashing_size = &convert_size($opts{'s'});
188 $flashing_size = $flash_size - $offset;
191 die("$my_name: Invalid size to flash\n") if ($flashing_size !~ /^\d+$/);
193 if ($flashing_size > $flash_size - $offset)
195 $flashing_size = $flash_size - $offset;
196 printf("Warning: Flashing size limited to 0x%lx due to the offset (0x%lx) and flash size (0x%lx).\n", $flashing_size, $offset, $flash_size);
199 if ($flashing_size > $image_size - $source_offset)
201 $flashing_size = $image_size - $source_offset;
202 printf("Warning: Flashing size limited to 0x%lx due to the offset (0x%lx) and image size (0x%lx).\n", $flashing_size, $source_offset, $image_size);
206 # Create the command line to boot the image
207 if (system('./etrax100boot --help > /dev/null') == 0)
209 $cmd = './etrax100boot';
211 elsif (system('svinto_boot --help > /dev/null') == 0)
213 $cmd = 'svinto_boot';
217 die("Cannot find e100boot program in your PATH!\n");
220 $cmd .= " --device $opts{'d'}" if ($opts{'d'});
222 $cmd .= &extract_hw_settings;
224 $cmd .= " --bootfile $opts{'b'}" if ($opts{'b'});
225 $cmd .= " --file $image_name $text_start";
227 if ($opts{'f'} || $opts{'F'})
229 $cmd .= sprintf(" --flash %lx %lx %lx --jump 0",
230 hex($text_start) + $source_offset, $offset, $flashing_size);
234 $cmd .= " --jump $text_start";
239 print "Command:\n$cmd\n";
248 #****************** FUNCTION DEFINITION SECTION ******************************
250 #*****************************************************************************
252 ## FUNCTION NAME: convert_size
254 ##****************************************************************************
261 if ($arg =~ /^0x([\da-fA-F]+)([kM])?$/)
265 elsif ($arg =~ /^(\d+)([kM])?$/)
284 return $size * 1048576;
288 #*****************************************************************************
290 ## FUNCTION NAME: extract_hw_settings
292 ##****************************************************************************
294 sub extract_hw_settings
299 my $return_value = "";
302 # The hw information table has the following format
306 # serial debg port (dword)
307 # sdram enabled (dword)
308 # register address (dword)
309 # register value (dword)
313 open(FILE, "$image_name") || die("Could not open '$image_name'");
317 if (m/HW_PARAM_MAGIC/g)
319 # Seek to first byte after magic
320 seek(FILE, -length($_) + pos($_), 1);
325 $text_start = &get_dword;
326 $dbg_port = &get_dword;
327 $sdram_enabled = int(&get_dword);
331 my $register = &get_dword;
332 my $value = &get_dword;
334 last if ($register eq "00000000");
338 if ($register eq $sdram_config_address)
340 $sdram_config = $value;
342 elsif ($register eq $sdram_timing_address)
344 $return_value .= &calculate_sdram_init($value, $sdram_config);
349 $return_value .= " --setreg $register $value";
354 return $return_value;
357 #*****************************************************************************
359 ## FUNCTION NAME: get_dword
361 ##****************************************************************************
367 read(FILE, $data, 4);
368 return unpack("H8", pack("V", unpack("N", $data)));
371 #*****************************************************************************
373 ## FUNCTION NAME: calculate_sdram_init
375 ##****************************************************************************
377 sub calculate_sdram_init
379 # Refer to ETRAX 100LX Designers Reference for a description of SDRAM
381 my $sdram_init_val = hex($_[0]);
382 my $sdram_config_val = hex($_[1]);
383 my $bus_width = $sdram_config_val & 0x00800000;
391 $mrs_data = ($sdram_init_val & 0x00ff0000) >> 16;
392 $sdram_init_val &= 0x8000ffff; # Make sure mrs data is 0
393 $sdram_init_val |= 0x80000000; # Make sure sdram is enabled
394 $speed = $sdram_init_val & 0x1000;
395 $cas_latency = $sdram_init_val & 0x3;
396 if ($speed) # 100 MHz
405 # Calculate value of mrs_data
406 # CAS latency = 2 && bus_width = 32 => 0x40
407 # CAS latency = 3 && bus_width = 32 => 0x60
408 # CAS latency = 2 && bus_width = 16 => 0x20
409 # CAS latency = 3 && bus_width = 16 => 0x30
412 if ($bus_width == 0) # 16 bits
414 $mrs_data = $cas_latency == 2 ? 0x20 : 0x30;
418 $mrs_data = $cas_latency == 2 ? 0x40 : 0x60;
422 $temp = $sdram_init_val | 0x0000c000; # Disable refresh
423 $return_value .= &sdram_command($temp);
424 $return_value .= " --pause 20000";
426 $return_value .= &sdram_command($temp, $sdram_precharge);
427 $return_value .= &sdram_command($temp, $sdram_nop);
429 $return_value .= " --setreg +0 7";
430 $return_value .= " --label label1";
431 $return_value .= &sdram_command($temp, $sdram_refresh);
432 $return_value .= &sdram_command($temp, $sdram_nop);
433 $return_value .= " --loop +0 label1";
435 $return_value .= &sdram_command($temp, $sdram_mrs, $mrs_data);
436 $return_value .= &sdram_command($temp, $sdram_nop);
438 $return_value .= &sdram_command($sdram_init_val);
440 return $return_value;
443 #*****************************************************************************
445 ## FUNCTION NAME: sdram_command
447 ##****************************************************************************
451 my($temp, $value, $mrs_data) = @_;
454 if ($value == $sdram_mrs)
456 $value = sprintf("%lx", $temp | ($value << 9) | ($mrs_data << 16));
460 $value = sprintf("%lx", $temp | ($value << 9));
463 return " --setreg $sdram_timing_address $value";
466 #*****************************************************************************
468 ## FUNCTION NAME: print_help
470 ##****************************************************************************
474 print "\nAXIS $my_name, ", '$Revision: 1.16 $ $Date: 2004/11/01 16:32:27 $ ', "\n";
476 Copyright (C) 2001-2002 Axis Communications AB
479 This program is used to boot (and flash) a linux image to a box.
480 It tries to extract the required ETRAX 100 settings from the image file.
486 -b <bootfile> : The boot image to use.
487 -d <device> : The network interface to use, default is eth0.
488 -f : Save the image in the flash memory starting at
490 -F : Save the image in the flash memory starting at
492 -h : Print this help text.
493 -i <image> : The path and name of the image to use, default
495 -o <offset> : The offset in the flash where the flashing starts.
496 -O <offset> : The offset in the image file where the flashing
498 -p : Print the resulting etrax100boot command instead
500 -s <size> : How much to flash (default is the size of the
501 flash minus the offset specified using -o or -f).
502 -S <size> : The size of the flash.
504 All sizes and offsets above can be specified as decimal numbers, or as
505 hexadecimal numbers by prefixing them with 0x. It is also possible to use
506 the suffixes k and M to specify kilo (1024) or mega (1048576).
511 #****************** END OF FILE boot_linux ***********************************
This page took 0.088392 seconds and 5 git commands to generate.