]> rtime.felk.cvut.cz Git - novaboot.git/blobdiff - novaboot
Add support for $NB_MYIP in --uboot-init
[novaboot.git] / novaboot
index 357ff032c1d011348adb48ade4acf705583133ae..76b48bcbf060cccc3f7c12459d1d83759ac2bad4 100755 (executable)
--- a/novaboot
+++ b/novaboot
@@ -252,7 +252,7 @@ my @scripts;
 my $file;
 my $EOF;
 my $last_fn = '';
-my ($modules, $variables, $generated, $continuation);
+my ($modules, $variables, $generated, $continuation) = ([], {}, []);
 my $skip_reading = defined($on_opt) || defined($off_opt);
 while (!$skip_reading && ($_ = <>)) {
     if ($ARGV ne $last_fn) { # New script
@@ -740,6 +740,8 @@ $builddir ||= dirname(File::Spec->rel2abs( ${$scripts[0]}{filename})) if scalar
 if (defined $builddir) {
     chdir($builddir) or die "Can't change directory to $builddir: $!";
     print "novaboot: Entering directory `$builddir'\n";
+} else {
+    $builddir = $invocation_dir;
 }
 
 ## File generation phase
@@ -985,8 +987,13 @@ if (defined $uboot) {
     $exp->expect(20,
                 [qr/Hit any key to stop autoboot:/, sub { $exp->send("\n"); exp_continue; }],
                 $uboot_prompt) || die "No uBoot prompt deteceted";
-    while (@uboot_init) {
-       my $cmd = shift @uboot_init;
+    foreach my $cmd (@uboot_init) {
+       if ($cmd =~ /\$NB_MYIP/) {
+           my $ip = (grep /inet /, `ip addr show eth0`)[0] || die "Problem determining our IP address";
+           $ip =~ s/\s*inet ([0-9.]*).*/$1/;
+           $cmd =~ s/\$NB_MYIP/$ip/g;
+       }
+       chomp($cmd);
        $exp->send("$cmd\n");
        $exp->expect(10, $uboot_prompt) || die "uBoot prompt timeout";
     }
@@ -1004,8 +1011,8 @@ if (defined $uboot) {
 
        $exp->send("tftp $kern_addr $kbin\n");
        $exp->expect(10,
-                    [qr/#/, sub { exp_continue; }],
-                    $uboot_prompt) || die "Kernel load failed";
+                    [qr/##/, sub { exp_continue; }],
+                    $uboot_prompt) || die "No U-Boot prompt deteceted";
        if (defined $dtb) {
            $dtb_addr = '7f0000';
            $exp->send("tftp $dtb_addr $dtb\n");
@@ -1543,6 +1550,9 @@ Command(s) to send the U-Boot bootloader before loading the images and
 booting them. This option can be given multiple times. After sending
 commands from each option novaboot waits for U-Boot I<prompt>.
 
+If the command contains string I<$NB_MYIP> then this string is
+replaced by IPv4 address of eth0 interface.
+
 =back
 
 =head2 Target interaction phase