From 256fd87dd515be8bf722443e0f174cafef2768e6 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 8 Sep 2015 12:56:46 +0200 Subject: [PATCH] Allow redirecting U-Boot command output to a file --- README.pod | 7 +++++-- novaboot | 27 +++++++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.pod b/README.pod index d0c6e6f..463c45f 100644 --- a/README.pod +++ b/README.pod @@ -734,8 +734,8 @@ script is the same as giving B<--uboot-init> option to novaboot. The following syntax variants are supported: - uboot[:] - uboot[:] < + uboot[:] [> ] + uboot[:] < [> ] C is the literal U-Boot command. @@ -749,6 +749,9 @@ executed and its standard output is sent to U-Boot. Example: uboot < printf "mmc write \$loadaddr 1 %x" $(($(/usr/bin/stat -c%s rootfs.ext4) / 512)) +When C file> part is present, the output of the U-Boot command +is written into the given file. + =back Example (Linux): diff --git a/novaboot b/novaboot index 1e66129..88380f3 100755 --- a/novaboot +++ b/novaboot @@ -370,9 +370,16 @@ while (!$skip_reading && ($_ = <>)) { if (/^uboot(?::([0-9]+)s)? +(< *)?(.*)/) { # uboot line # TODO: If U-Boot supports some interactive menu, it might # make sense to store uboot lines per novaboot script. - push @uboot_init, { command => $2 ? "" : $3, - system => $2 ? $3 : "", - timeout => $1 // 10 }; + my ($timeout, $redir, $string, $dest) = ($1, $2, $3); + if ($string =~ /(.*) *> *(.*)/) { + $string = $1; + $dest = $2; + } + push @uboot_init, { command => $redir ? "" : $string, + system => $redir ? $string : "", + timeout => $timeout, + dest => $dest, + }; next; } @@ -1111,7 +1118,12 @@ if (defined $uboot) { $before_match, $after_match) = $exp->expect($timeout, $uboot_prompt); die "No U-Boot prompt: $error" if $error; - #print "\n>>>>$before_match<<<<\n"; + + if ($cmdspec->{dest}) { + open(my $fh, ">", $cmdspec->{dest}) or die "Cannot open '$cmdspec->{dest}': $!"; + print $fh $before_match; + close($fh); + } } # Load files if there are some load lines in the script @@ -1939,8 +1951,8 @@ script is the same as giving B<--uboot-init> option to novaboot. The following syntax variants are supported: - uboot[:] - uboot[:] < + uboot[:] [> ] + uboot[:] < [> ] C is the literal U-Boot command. @@ -1954,6 +1966,9 @@ executed and its standard output is sent to U-Boot. Example: uboot < printf "mmc write \$loadaddr 1 %x" $(($(/usr/bin/stat -c%s rootfs.ext4) / 512)) +When C file> part is present, the output of the U-Boot command +is written into the given file. + =back Example (Linux): -- 2.39.2