]> git.sur5r.net Git - u-boot/blob - board/xilinx/ml300/sw_services/uboot_v1_00_a/data/uboot_v2_1_0.tcl
* Patch by Peter Ryser, 20 Feb 2004:
[u-boot] / board / xilinx / ml300 / sw_services / uboot_v1_00_a / data / uboot_v2_1_0.tcl
1 #
2 #      Author: Xilinx, Inc.
3 #      
4 #      
5 #      This program is free software; you can redistribute it and/or modify it
6 #      under the terms of the GNU General Public License as published by the
7 #      Free Software Foundation; either version 2 of the License, or (at your
8 #      option) any later version.
9 #      
10 #      
11 #      XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
12 #      COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
13 #      ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
14 #      XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
15 #      FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
16 #      ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
17 #      XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
18 #      THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
19 #      WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
20 #      CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 #      FITNESS FOR A PARTICULAR PURPOSE.
22 #      
23 #      
24 #      Xilinx hardware products are not intended for use in life support
25 #      appliances, devices, or systems. Use in such applications is
26 #      expressly prohibited.
27 #      
28 #      
29 #      (c) Copyright 2002-2004 Xilinx Inc.
30 #      All rights reserved.
31 #      
32 #      
33 #      You should have received a copy of the GNU General Public License along
34 #      with this program; if not, write to the Free Software Foundation, Inc.,
35 #      675 Mass Ave, Cambridge, MA 02139, USA.
36 #
37 # Globals
38 lappend drvlist
39 set ltypes "../../../sw_services/uboot_v1_00_a/data/Ltypes"
40
41 proc uboot_drc {lib_handle} {
42     puts "U-Boot DRC..."
43 }
44
45 proc generate {libname} {
46     
47     global drvlist
48     
49     # Get list of peripherals connected to uboot
50     set conn_periphs [xget_handle $libname "ARRAY" "connected_periphs"]
51     #lappend drvlist
52     if {[string compare -nocase $conn_periphs ""] != 0} {
53         set conn_periphs_elems [xget_handle $conn_periphs "ELEMENTS" "*"]
54         # For each periph
55         foreach periph_elem $conn_periphs_elems {
56             set periph [xget_value $periph_elem "PARAMETER" "periph_name"]
57             # 1. Get driver
58             set drv [xget_swhandle $periph]
59             set posn [lsearch -exact $drvlist $drv]
60             if {$posn == -1} {
61                 lappend drvlist $drv
62             }
63         }
64         
65         set file_handle [xopen_include_file "xparameters.h"]
66         puts $file_handle "\n/******************************************************************/\n"
67         puts $file_handle "/* U-Boot Redefines */"
68         puts $file_handle "\n/******************************************************************/\n"
69         close $file_handle
70         
71         foreach drv $drvlist {
72             set drvname [xget_value $drv "NAME"]
73             
74             #Redefines xparameters.h
75             if {[string compare -nocase $drvname "uartns550"] == 0} {
76                 xredefine_uartns550 $drv "xparameters.h"
77             }  elseif {[string compare -nocase $drvname "emac"] == 0} {
78                 xredefine_emac $drv "xparameters.h"
79             }
80         }
81     }
82     
83     # define core_clock
84     xredefine_params $libname "xparameters.h" "CORE_CLOCK_FREQ_HZ"
85 }
86
87 proc xget_corefreq {} {
88     set processor [xget_processor] 
89     set name [xget_value $processor "NAME"]
90     puts "procname : $name"
91     set processor_driver [xget_swhandle [xget_value $processor "NAME"]]
92     puts "procdrv : $processor_driver"
93     if {[string compare -nocase $processor_driver ""] != 0} {
94         set arg "CORE_CLOCK_FREQ_HZ"
95         #set retval [xget_value $processor_driver "PARAMETER" $arg]
96         set retval [xget_dname [xget_value $processor_driver "NAME"] $arg]
97         return $retval
98     }
99 }
100
101 # procedure that adds # defines to xparameters.h as XPAR_argument
102 proc xredefine_params {handle file_name args} {
103     
104     puts "xredfine ..."
105     # Open include file
106     set file_handle [xopen_include_file $file_name]
107     puts "args : $args"
108
109     foreach arg $args {
110         if {[string compare -nocase $arg "CORE_CLOCK_FREQ_HZ"] == 0} {
111             set value [xget_corefreq]
112             puts "corefreq : $value"
113         } else {
114             set value [xget_value $handle "PARAMETER" $arg]
115             puts "value : $value"
116         }
117         
118         if {$value != ""} {
119             set value [xformat_addr_string $value $arg]
120             set name [string toupper $arg]
121             set name [format "XPAR_%s" $name]
122             puts $file_handle "#define $name $value"
123         }
124     }
125
126     puts $file_handle "\n/******************************************************************/\n"
127     close $file_handle
128 }
129
130 # uart redefines...
131 proc xredefine_uartns550 {drvhandle file_name} {
132     
133     xredefine_include_file $drvhandle $file_name "uartns550" "C_BASEADDR" "C_HIGHADDR" "CLOCK_HZ" "DEVICE_ID"
134     
135 }
136
137 proc xredefine_emac {drvhandle file_name} {
138     
139     xredefine_include_file $drvhandle $file_name "emac" "C_BASEADDR" "C_HIGHADDR" "C_DMA_PRESENT" "C_MII_EXIST" "C_ERR_COUNT_EXIST" "DEVICE_ID"
140     
141 }
142
143 #######################
144
145 proc xredefine_include_file {drv_handle file_name drv_string args} {
146     
147     # Open include file
148     set file_handle [xopen_include_file $file_name]
149     
150     # Get all peripherals connected to this driver
151     set periphs [xget_periphs $drv_handle] 
152     
153     set pname [format "XPAR_%s_" [string toupper $drv_string]]
154     
155     # Print all parameters for all peripherals
156     set device_id 0
157     set sub_periphs 1
158     foreach periph $periphs {
159         puts "$periph : $drv_string : $sub_periphs"
160
161         for {set i 0} {$i < $sub_periphs} {incr i} {
162             foreach arg $args {
163                 set name "${pname}${device_id}_"
164             
165                 if {[string compare -nocase "CLOCK_HZ" $arg] == 0} {
166                     set xdrv_string [format "%s%s" "X" $drv_string]
167                     set value [xget_dname $xdrv_string $arg]
168                     set name "${name}CLOCK_FREQ_HZ"
169                 } else {
170                     if {[string match C_* $arg]} {
171                         set name [format "%s%s" $name [string range $arg 2 end]]
172                     } else {
173                         set name "${name}${arg}"
174                     }
175                     set value [xget_name $periph $arg]
176                 }
177
178                 if {[string compare -nocase "uartns550" $drv_string] == 0} {
179                     if {[string compare -nocase "C_BASEADDR" $arg] == 0} {
180                         set value [format "(%s%s%s)" $value "+" "0x1000"]
181                     }
182                 }
183
184                 puts $file_handle "#define $name $value"
185                 if {[string compare -nocase "DEVICE_ID" $arg] == 0} {
186                     incr device_id
187                 }
188             }
189         }
190     }           
191     puts $file_handle "\n/******************************************************************/\n"
192     close $file_handle
193 }
194
195 ##################################################
196 # procedure post_generate
197 # This generates the drivers directory for uboot
198 # and runs the ltypes script
199 ##################################################
200
201 proc post_generate {lib_handle} {
202     
203     global drvlist
204     
205     # Create U-Boot tree structure
206     set pwd [pwd]
207     set common_dir "uboot/board/xilinx/common"
208     set xilinx_enet_dir "uboot/board/xilinx/xilinx_enet"
209     set ml300_dir  "uboot/board/xilinx/ml300"
210     
211     exec bash -c "mkdir -p $common_dir $xilinx_enet_dir $ml300_dir"
212     
213     # Copy files for xilinx_ocp
214     xcopy_commonfiles
215
216     foreach drv $drvlist {
217         set drvname [xget_value $drv "NAME"]
218         set ver [xget_value $drv "PARAMETER" "DRIVER_VER"]
219         set ver [string map {. _} $ver]
220         set dirname [format "%s_v%s" $drvname $ver]
221         
222         if {[string compare -nocase $drvname "emac"] == 0} {
223             xcopy_emac $drv $dirname
224         }
225     }
226     
227     # Call Ltypes Script here
228     set uboot "uboot"
229     xltype_file $uboot
230
231     # Move xparameters.h around
232     exec bash -c "cp ../../include/xparameters.h $ml300_dir"
233
234     # copy the whole U-Boot BSP to its final destination
235     set value [xget_value $lib_handle "PARAMETER" TARGET_DIR]
236     puts "TARGET_DIR : $value"
237
238     if {$value != ""} {
239         if {[file isdirectory $value] == 0} {
240             exec bash -c "mkdir -p $value"
241         }
242         exec bash -c "cp -Rp uboot/* $value"
243     }
244 }
245
246 proc xcopy_commonfiles {} {
247
248     global drvlist
249
250     set common_dir "uboot/board/xilinx/common"
251     
252     foreach drv $drvlist {
253         set depends [xget_value $drv "OPTION" "DEPENDS"]
254         foreach dep $depends {
255             puts "dep : $dep"
256             if {[file isdirectory "../$dep"] == 1} {
257                 exec bash -c "cp -f ../$dep/src/*.c $common_dir"
258                 exec bash -c "cp -f ../$dep/src/*.h $common_dir"
259             }
260         }
261     }
262     
263 }
264
265 proc xcopy_emac {drv_handle dirname} {
266     set emac "board/xilinx/xilinx_enet"
267     xcopy_dir $dirname $emac
268 }
269
270 proc xcopy_dir {srcdir dstdir} {
271     
272     set dstdirname [format "%s%s" "uboot/" $dstdir]
273     if {[file isdirectory "../$srcdir"] == 1} {
274         # Copy files from src to dst
275         exec bash -c "mkdir -p $dstdirname"
276         exec bash -c "cp -f ../$srcdir/src/*.c $dstdirname"
277         exec bash -c "cp -f ../$srcdir/src/*.h $dstdirname"
278     } else {
279         puts "$srcdir does not exist ..."
280     }
281 }
282
283
284 proc xltype_file {filename} {
285
286     global ltypes
287
288     puts $filename
289
290     if {[file isdirectory $filename]} {
291         foreach entry [glob -nocomplain [file join $filename *]] {
292             xltype_file $entry
293         }
294     } else {
295         exec bash -c "$ltypes $filename"
296     }
297     
298 }