]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
Allow redirecting U-Boot command output to a file
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 8 Sep 2015 10:56:46 +0000 (12:56 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 8 Sep 2015 10:56:46 +0000 (12:56 +0200)
README.pod
novaboot

index d0c6e6f7004268650999f637898e482885e067ef..463c45f9ae54f8ed2ae49042680c90d5791e39b3 100644 (file)
@@ -734,8 +734,8 @@ script is the same as giving B<--uboot-init> option to novaboot. The
 following syntax variants are supported:
 
 
-  uboot[:<timeout>] <string>
-  uboot[:<timeout>] < <shell>
+  uboot[:<timeout>] <string> [> <file>]
+  uboot[:<timeout>] < <shell> [> <file>]
 
 C<string> 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<E<gt> file> part is present, the output of the U-Boot command
+is written into the given file.
+
 =back
 
 Example (Linux):
index 1e6612996e1709cf4858c689e5de02ed6e2de906..88380f3da8722cdcfcc87bc85dddac254788de11 100755 (executable)
--- 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[:<timeout>] <string>
-  uboot[:<timeout>] < <shell>
+  uboot[:<timeout>] <string> [> <file>]
+  uboot[:<timeout>] < <shell> [> <file>]
 
 C<string> 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<E<gt> file> part is present, the output of the U-Boot command
+is written into the given file.
+
 =back
 
 Example (Linux):