OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [boards/] [or32-linux-sim.exp] - Blame information for rev 473

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 453 jeremybenn
#!/bin/bash
2
 
3
# Copyright (C) 2010 Embecosm Limited
4
 
5
# Contributor Jeremy Bennett 
6
# Contributor Joern Rennecke 
7
 
8
# This file is a board description for testing OpenRISC with uClibc and
9
# Or1ksim running Linux.
10
 
11
# This program is free software; you can redistribute it and/or modify it
12
# under the terms of the GNU General Public License as published by the Free
13
# Software Foundation; either version 3 of the License, or (at your option)
14
# any later version.
15
 
16
# This program is distributed in the hope that it will be useful, but WITHOUT
17
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
# more details.
20
 
21
# You should have received a copy of the GNU General Public License along
22
# with this program.  If not, see .
23
 
24 473 jeremybenn
# -----------------------------------------------------------------------------
25
# For telnet targets we need to define some functions.
26 453 jeremybenn
 
27 473 jeremybenn
# -----------------------------------------------------------------------------
28
# Custom proc to close a telnet session
29 453 jeremybenn
 
30 473 jeremybenn
# @param[in] boardname  The board being closed.
31
# -----------------------------------------------------------------------------
32
proc telnet_close {boardname} {
33 453 jeremybenn
 
34 473 jeremybenn
    # Make the telnet process associated with this board the current process
35 453 jeremybenn
    set spawn_id [board_info $boardname fileid]
36
    verbose "Closing $boardname:$spawn_id"
37
 
38 473 jeremybenn
    # If we have a process, close it.
39 453 jeremybenn
    if { $spawn_id >= 0 } {
40 473 jeremybenn
        catch close
41 453 jeremybenn
        catch wait
42
        set spawn_id -1
43
 
44 473 jeremybenn
        set_board_info $boardname,fileid $spawn_id
45 453 jeremybenn
    }
46
}
47
 
48
 
49 473 jeremybenn
# -----------------------------------------------------------------------------
50 453 jeremybenn
# Custom proc to exec programs using telnet
51 473 jeremybenn
 
52
# We seem to only pass in the first of the arguments supplied to the command.
53
 
54
# We seem to set the timeout to 30, no matter what. Not sure that is right
55
# here.
56
 
57
# @param[in] boardname  The board we are telnetting to
58
# @param[in] cmd        The command to run
59
# @param[in] args       Arguments to the command
60
 
61
# @return  A list of the return code (-1 on failure) and any error message.
62
# -----------------------------------------------------------------------------
63 453 jeremybenn
proc telnet_exec {boardname cmd args} {
64
    global timeout
65
    global verbose
66
    set output "(no output)"
67
 
68
    verbose "Executing $boardname:$cmd $args"
69
 
70 473 jeremybenn
    # Get the first argument, if any.
71 453 jeremybenn
    if { [llength $args] > 0 } {
72
        set pargs [lindex $args 0];
73
    } else {
74
        set pargs ""
75
    }
76
 
77 473 jeremybenn
    # Set the shell prompt
78 453 jeremybenn
    if [board_info $boardname exists shell_prompt] {
79
        set shell_prompt [board_info $boardname shell_prompt]
80
    }
81
    if ![info exists shell_prompt] { # if no prompt, then set it to
82
        something generic
83
        set shell_prompt ".*> "
84
    }
85
 
86 473 jeremybenn
    # Start a new telnet session if one doesn't already exist. If sucessful
87
    # the fileid field associated with $boardname will be set to the spawn_id
88
    # of the new telnet process.
89 453 jeremybenn
    if ![board_info $boardname exists fileid] {
90
        if {[telnet_open $boardname] == -1} {
91
            return [list -1
92
                    "telnet to $boardname failed for $cmd, couldn't begin
93
telnet session"]
94
        }
95
    }
96
 
97 473 jeremybenn
    # Make the telnet session the current process.
98 453 jeremybenn
    set spawn_id [board_info $boardname fileid]
99 473 jeremybenn
    set old_timeout $timeout
100 453 jeremybenn
    set timeout 30
101
 
102
    #Hit enter to make sure you get a shell prompt
103
    send -- "\r"
104
 
105
    expect {
106 473 jeremybenn
        # A prompt indicates the current session is alive
107 453 jeremybenn
        -re "$shell_prompt.*$" {
108
            verbose "Got a prompt"
109
        }
110
        default {
111 473 jeremybenn
            # No response try closing the connection and reopening.
112 453 jeremybenn
            telnet_close $boardname
113
            if {[telnet_open $boardname] != -1} {
114
                verbose "started new telnet session, spawn_id is [board_info
115
$boardname fileid]"
116
                send -- "\r"
117
                exp_continue
118
            } else {
119 473 jeremybenn
                set timeout $old_timeout
120 453 jeremybenn
                return [list -1 "telnet to $boardname failed for $cmd, couldn't get
121
a shell prompt"]
122
            }
123 473 jeremybenn
            # I don't think we can get here. Comment out the old code and
124
            # trigger an error
125
            # send -- "\r"
126
            # exp_continue
127
            set timeout $old_timeout
128
            error "Problem reconnecting to telnet."
129 453 jeremybenn
        }
130
    }
131 473 jeremybenn
 
132
    # Shorter timeout for commands. Not sure why we only use the first of the
133
    # arguments.
134 453 jeremybenn
    set timeout 10
135
    send "$cmd $pargs\r"
136
 
137
    expect {
138
        -re "$shell_prompt.*$" {
139
        }
140
        timeout {
141
            if [info exists expect_out(buffer)] {
142
                set execute_output_string $expect_out(buffer)
143
            }
144
            telnet_close $boardname
145 473 jeremybenn
            set timeout $old_timeout
146
            return [list -1 "telnet to $boardname for $cmd $pargs failed (timeout)"
147 453 jeremybenn
        }
148
    }
149 473 jeremybenn
 
150
    #Remove unnecessary strings from the output string
151
 
152 453 jeremybenn
    #If the file path contains any "+" signs, it will mess things up when $cmd
153
    #is used as a regsub pattern (2 lines down), so we replace all "+"s with "."
154
    regsub -all "\\+" $cmd "." cmd
155
    regsub -all $cmd "$expect_out(buffer)" {} output
156
    regsub $shell_prompt $output {} output
157
    regsub -all "\[\r\n\]" $output {} output
158
 
159
    #Check the return status
160
    set timeout 30
161
    send -- "echo \$?\r"
162
    expect -re "$shell_prompt.*$"
163
 
164
    #Regsub the output to get the status number
165
    regsub -all {echo \$\?} $expect_out(buffer) {} status
166
    regsub $shell_prompt $status {} status
167
    regsub -all "\[\r\n \]" $status {} status
168
 
169
    #This probably isn't neccessary..
170
    if {[regexp {[0123456789]+} $status] != 1} {
171
        warning "status not a number, it is <$status>, setting it to 1"
172
        set status 1
173
    }
174
 
175 473 jeremybenn
    set timeout $old_timeout
176 453 jeremybenn
    if {$status == 0} {
177
        return [list "0" "$output"]
178
    } else {
179
        return [list "1" "$output"]
180
    }
181
}
182
 
183 473 jeremybenn
# This is a list of toolchains that are supported on this board.
184
set_board_info target_install {or32-linux}
185
 
186
# No multilib options needed by default.
187
process_multilib_options ""
188
 
189
# Load the generic configuration for this board. This will define a basic set
190
# of routines needed by the tool to communicate with the board.
191
load_generic_config "unix"
192
 
193
# Set up remote target info
194
set_board_info hostname "192.168.0.3"
195
set_board_info username root
196
 
197
# Use the installed compilers to ensure we get search paths that will find
198
# uClibc.
199
send_user "set_board_info compiler /opt/or32-new/bin/or32-linux-gcc\n"
200
global GCC_UNDER_TEST
201
set GCC_UNDER_TEST "/opt/or32-new/bin/or32-linux-gcc"
202
global GXX_UNDER_TEST
203
set GXX_UNDER_TEST "/opt/or32-new/bin/or32-linux-g++"
204
set_board_info compiler /opt/or32-new/bin/or32-linux-gcc
205
set_board_info c++compiler /opt/or32-new/bin/or32-linux-g++
206
set target_alias "or32-linux"
207
 
208
set_board_info connect telnet
209
set_board_info shell_prompt    "~ # "
210
set_board_info telnet_username "root"
211
set_board_info telnet_password ""
212
 
213
set_board_info file_transfer ftp
214
set_board_info ftp_username  root
215
set_board_info ftp_password  ""
216
 
217 453 jeremybenn
# Options for the simulator
218
# set cfg_file [lookfor_file ${srcdir} libgloss/or32/sim.cfg]
219
# set_board_info sim,options "-a \"-f ${cfg_file}\""
220
 
221
# We only support uClibc on this target.  We assume that all multilib options
222
# have been specified before we get here.
223
# set_board_info compiler  "[find_gcc]"
224
 
225 473 jeremybenn
# We need to define the right flags if pthreads is to work.
226
set_board_info cflags    "-D_XOPEN_SOURCE=600"
227
set_board_info cxxflags  "-D_XOPEN_SOURCE=600"
228
 
229 453 jeremybenn
# No linker script needed.
230
set_board_info ldscript ""
231
 
232
# This simulator isn't slow.
233
set_board_info slow_simulator 0
234
 
235
# Can't pass arguments to programs on this target..
236
set_board_info noargs  1
237
 
238
# Used by a few gcc.c-torture testcases to delimit how large the stack can
239
# be.
240
set_board_info gcc,stack_size 65536
241
 
242
# GDB options
243
 
244
# We can't do input in GDB (yet! HA!). It *will* do output, hurrah.
245
set_board_info gdb,noinferiorio 1
246
# Or pass arguments.
247
set_board_info gdb,noargs  1
248
set_board_info noargs 1
249
# And there's no support for signals.
250
set_board_info gdb,nosignals  1

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.