Michal Sojka [Mon, 25 Apr 2022 20:49:03 +0000 (22:49 +0200)]
Fix u-boot prompt handling
Commit 9c9a064 ("Reset u-boot download timeout with every '#'",
2022-04-03) broke behavior on systems with '#' in u-boot prompt. Due
to that commit, the prompt after file transfer is not detected and
novaboot timeouts. We fix that by switching the order of expect
patterns so that the prompt has priority over progress bar '#'
characters.
Michal Sojka [Mon, 25 Apr 2022 20:21:32 +0000 (22:21 +0200)]
server: Refactor delayed power-off logic
From time to time, I'm facing problems with delayed power off not
working. I'm not sure what is the exact reason, but a potential reason
could be that the board was powered on but the systemd service
novaboot-delayed-power-off.service, which is responsible for powering
off, was not started. To prevent that, we change the logic so that
powering on happens as a start job of the same service.
Michal Sojka [Tue, 12 Apr 2022 22:42:51 +0000 (00:42 +0200)]
tests: Fix grub server tests
The behavior was probably changed in the recent network booting
changes. Since those tests were disabled, we didn't catch that a test
needs to be changed too.
Michal Sojka [Sun, 3 Apr 2022 12:25:53 +0000 (14:25 +0200)]
Reset u-boot download timeout with every '#'
Previously, we used two consecutive hash characters, but it turned out
that a Raspberry Pi, on our network experiences few timeouts at the
beginning (see '#T ' sequences below) and there are never two
consecutive hashes before the timeout elapses.
U-Boot> tftpboot ${kernel_addr_r} /rpi/kernel
Using ethernet@7d580000 device
TFTP from server 10.35.95.2; our IP address is 10.35.95.45
Filename '/rpi/kernel'.
Load address: 0x80000
Loading: #T #T T T Kernel load: timeout at /home/wsh/.nix-profile/bin/novaboot line 1298, <> line 7.
Therefore, we reset the timeout after just a single hash. Now the
above example runs as shown below:
U-Boot> tftpboot ${kernel_addr_r} /rpi/kernel
Using ethernet@7d580000 device
TFTP from server 10.35.95.2; our IP address is 10.35.95.45
Filename '/rpi/kernel'.
Load address: 0x80000
Loading: #T #T T ################################################ 45 MiB
2 MiB/s
done
Michal Sojka [Fri, 17 Dec 2021 09:35:03 +0000 (10:35 +0100)]
server: Fix enabling of delayed power off
The documented procedure stopped working after the last commit because
the [Install] section was removed from
novaboot-delayed-power-off.service.
In addition to adding the [Install] section, we also reshuffle
documentation and update systemd unit dependencies to make
power-on/off operations more reliable. The latter should (hopefully)
fix some race conditions that were possible in the past.
Michal Sojka [Thu, 18 Nov 2021 17:58:42 +0000 (18:58 +0100)]
server: Fix delayed power off
Th novaboot-delayed-power-off.service was meant to activate
system-level systemd timer at uses session shutdown. However, this
never worked, because an user service cannot be activated as a part of
session shutdown, because each service depends on app.slice and this
slice is being stopped in the shutdown sequence, which results in
removing the service start request from the shutdown transaction. This
behavior is demonstrated by the systemd debug log below:
Pulling in novaboot-delayed-power-off.service/start from shutdown.target/start
Added job novaboot-delayed-power-off.service/start to transaction.
Pulling in app.slice/start from novaboot-delayed-power-off.service/start
Pulling in novaboot-delayed-power-off.service/stop from app.slice/stop
Added job novaboot-delayed-power-off.service/stop to transaction.
Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
novaboot-delayed-power-off.service: Deleting job novaboot-delayed-power-off.service/start as dependency of job app.slice/start
Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
Found redundant job novaboot-delayed-power-off.service/stop, dropping from transaction.
Therefore, we don't use a service with ExecStart, but use ExecStop to
start the shutdown timer and start the service by novaboot-shell
whenever the board is powered on.
Michal Sojka [Fri, 22 Oct 2021 12:47:54 +0000 (14:47 +0200)]
Make <<>> fail if it cannot open a file
By default, only a warning is printed and the script continues.
Example of this situation:
% novaboot non-existent --gen-only
novaboot: Read /home/wsh/.config/novaboot
novaboot: Effective options: non-existent --gen-only
Can't open non-existent: No such file or directory at /home/wsh/src/novaboot/novaboot line 362.
We do not add a test for this, because we make all warnings fatal when
running tests.
Michal Sojka [Fri, 22 Oct 2021 12:19:30 +0000 (14:19 +0200)]
Replace <> with <<>>
The reason is that <> can be dangerous. From Perl documentation:
Since the null filehandle uses the two argument form of "open" in
perlfunc it interprets special characters, so if you have a script like
this:
while (<>) {
print;
}
and call it with "perl dangerous.pl 'rm -rfv *|'", it actually opens a
pipe, executes the "rm" command and reads "rm"'s output from that pipe.
If you want all items in @ARGV to be interpreted as file names, you can
use the module "ARGV::readonly" from CPAN, or use the double diamond
bracket:
while (<<>>) {
print;
}
Using double angle brackets inside of a while causes the open to use
the three argument form (with the second argument being "<"), so all
arguments in "ARGV" are treated as literal filenames (including "-").
(Note that for convenience, if you use "<<>>" and if @ARGV is empty, it
will still read from the standard input.)
Michal Sojka [Mon, 28 Jun 2021 06:19:34 +0000 (08:19 +0200)]
shell.nix: Add grub2 and dhcp
This is to allow manual testing of --dhcp-tftp --grub2 functionality.
Currently, I don't have time to fully automate the tests, but this is
how I tested it manually:
1. Create testboot script with the following content:
alberand [Wed, 31 Mar 2021 20:51:58 +0000 (22:51 +0200)]
Create tftpd.pid in default location
This way we restrict the user in commands which he can run under sudo.
It's better to use * wildcard in the pkill command as it doesn't write
anything to the filesystem.
alberand [Wed, 24 Feb 2021 17:16:06 +0000 (18:16 +0100)]
tftpd: Run with mapfile
This mapfile is needed as some pxeclient add zero byte \x00 to the end
of the filename. This is a known bug. The mapfile contains rule to
remove that byte.
Michal Sojka [Mon, 12 Apr 2021 06:26:00 +0000 (08:26 +0200)]
Copy files to TFTP server with default permissions
Previously, we used rsync's --perm option to mirror source permissions
at target. This could have caused the files to be inaccessible by the
TFTP server, because source permissions were to tight. To overcome
this problem, we now always set the target permissions to the default
value by using --chmod. From rsync manual:
To give new files the destination-default permissions (while
leaving existing files unchanged), make sure that the --perms
option is off and use --chmod=ugo=rwX.
Note that this change does not require changes on the server
side (novaboot-shell).
Michal Sojka [Tue, 26 Jan 2021 11:08:46 +0000 (12:08 +0100)]
Add README.md
It is shorter than the current README.pod (man page), to which it
links. In addition to the man page, it contains installation
instructions and links to server-side documentation.
Michal Sojka [Mon, 25 Jan 2021 00:12:08 +0000 (01:12 +0100)]
server: Refactor console setup to a separate function
Also drop exec before the command, because it only causes troubles.
Thanks to dropping exec, we had to change the testsuite, because
without exec it starts a new process, which is not killed by "kill
$COPROC_PID" and since it holds a lock (via flock), we could not run
the following tests.
Michal Sojka [Wed, 20 Nov 2019 22:10:07 +0000 (23:10 +0100)]
tests: Get rid of asynchronous process substitution
Under bash, processes substitution is run asynchronously. This means
that the messages printed by the process can be mixed with other
messages, which causes random tests to fail, because the wvtest
protocol lines are corrupted.
Now we run all processes synchronously and the test no longer fail
randomly.
Jan Kaisrlik [Mon, 4 Nov 2019 16:28:01 +0000 (17:28 +0100)]
Disable echo in default stty arguments
From time to time I observe that the novaboot hangs in the uboot menu
with weird characters on the line like this
=> MC: mmc@7000: 0^M^JLoading Environment from MMC... OK^M^JIn: serial@3000^M^JNet: eth0: ethernet@ff3f0000^M^JHit any key to stop autoboot: 2 ^H^H^H 0^M^J=> MC: mmc@7000: 0^M^JLoading Environment from MMC... OK^M^JIn: serial@3000^M^JNet:
Unknown command 'MC:' - try 'help'
When I tried to play with stty options I realized that the echo option
breaks the communication. The reason is that when echo is
enabled (which is by default), all characters sent by the target are
echoed back to the target, which may interpret them.
It turns out that the problem appears only during the first initial
novaboot conversation with the bootloader after. After switching to
interactive mode, echo is automatically disabled by Expect.pm and for
subsequent boots, echo remains disabled.
[Note: Commit message updated by Michal Sojka based on GitHub
discussion https://github.com/wentasah/novaboot/pull/5 and his
investigation of the issue.]
Michal Sojka [Thu, 31 Oct 2019 22:27:44 +0000 (23:27 +0100)]
server: Always use flock with --no-fork
Without this my test suite fails. The reason for not using --no-fork
was that it didn't work well on some systems. Since I'm annoyed by not
working test suite, I'm willing to investigate --no-fork problems if
they still exist on current Linux systems.