log/serial: handle spurious EOF

While booting up, some devices send garbage over the serial connection.
This can result in an unexpected EOF event within expect(1). A filter
program may be specified with '--log-serial-filter' to circumvent this
problem. Then, the output of the serial program is piped through
the filter, which may sanitize the character stream.

Fixes #1395.
This commit is contained in:
Josef Söntgen 2015-02-12 12:35:37 +01:00 committed by Christian Helmuth
parent 6329395026
commit 0f47ac958b
1 changed files with 33 additions and 5 deletions

View File

@ -1,7 +1,8 @@
##
# Get the output of the target machine via serial connection
#
# \param --log-serial-cmd Cmd that is executed to capture the output
# \param --log-serial-cmd Cmd that is executed to capture the output
# \param --log-serial-filter Sanitize output by piping it through a filter
#
source [genode_dir]/tool/run/log.inc
@ -16,6 +17,11 @@ proc log_serial_cmd { } {
}
proc log_serial_filter { } {
return [get_cmd_arg --log-serial-filter ""]
}
##
# Log output of the test machine via serial device
#
@ -24,14 +30,36 @@ proc run_log { wait_for_re timeout_value } {
set kernel_msg [run_boot_string]
eval spawn [log_serial_cmd]
#
# Certain devices send garbage through the serial connection that may
# result in an unexpected EOF in expect. This is caused by TCL using the
# terminal encoding for the channel to the spawned program and interpreting
# the input for conversion to UTF-8. In the case of the serial connection,
# this may not be valid with garbage bytes in the character stream. If any
# garbage coming from the serial connection is interpreted as the beginning
# of a UTF-8 multi-byte sequence but does not resemble the complete
# sequence (i.e., is truncated), parsing may result in EOF. To prevent this
# from happening one may use a filter that sanitizes the serial output,
# i.e., lets only ASCII characters through.
#
set serial_cmd_chain [log_serial_cmd]
if {[get_cmd_switch --log-serial-filter]} {
set serial_cmd_chain "$serial_cmd_chain | [log_serial_filter]"
}
#
# XXX the initial timeout was estimated by testing and is merely enough
# to load large scenarios via TFTP.
#
set timeout 210
spawn /bin/sh -c "$serial_cmd_chain"
set output_spawn_id $spawn_id
set timeout 210
expect {
$kernel_msg { }
-i $output_spawn_id $kernel_msg { }
eof {
puts stderr "Serial command process died unexpectedly"
puts stderr "Aborting, received EOF"
return false
}
timeout {