405 Commits

Author SHA1 Message Date
alfonsosanchezbeato
f0ecb9f1d0 b/piboot.go: check EEPROM version for RPi4
* b/piboot.go: check EEPROM version for RPi4

Check EEPROM version for RPi4 to make sure that tryboot is
supported. If the EEPROM need updating, return an error when
installing the kernel.

* bootloader: add unit tests for detection of RPi4 EEPROM

* bootloader/piboot: use osutil instead of using directly os.Stat

* bootloader: address review comments
2022-04-07 19:22:19 +02:00
Alfonso Sánchez-Beato
0a200c018b boot,bootloader: add missing grub.cfg assets mocks in some tests
This is the same fix as commit 17fbdc7c, but in other tests.

The current code will mock the `amd64` architecture when running some
tests but it does not mock the `grub.cfg:static-cmdline` or the
`grub-recovery.cfg:static-cmdline`. This is needed because the
`bootloader/asserts` package registers the cmdline via `init()` so
this happens before the architecture is mocked in the testing
code. Hence the tests will fail when inspecting the command line on
non amd64/i386 machines.

This commit makes the mocking explicit. An alternative approach would
be to move the snippet registration out of `init()` and run it on
first boot but that has it's own problems so this other approach was
followed.
2022-04-07 14:37:24 +02:00
alfonsosanchezbeato
13db8109ff b/a: do not set console in kernel command line for arm64
* b/assets: use different kernel command line for arm64

Do not set console in the kernel command line for arm64. The defaults
are better than setting ttyS0 as in x86, also this is our choice in
server images. The kernel will choose the preferred console depending
on whether dtb or ACPI is available:

1. When having a device tree, it will take the content of the
   /chosen/stdout-path node [1]. This node is properly filled in most
   of the cases.

2. If using ACPI tables, it will look for the console in the ACPI SPCR
   table [2,3]. This is different to what is done in x86 [4], as in that
   case the SPCR table is used only if earlycon is set.

[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/chosen.txt
[2] https://docs.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
[3] https://elixir.bootlin.com/linux/v5.17/source/arch/arm64/kernel/acpi.c#L229
[4] https://elixir.bootlin.com/linux/v5.17/source/arch/x86/kernel/acpi/boot.c#L1615

* b/assets: register different grub snippets per arch

This is needed now as the kernel command line parameters will differ
across architectures.

* b/a/grub.go: fix tests for ubuntu-18.04-32

Co-authored-by: Michael Vogt <mvo@ubuntu.com>
2022-04-05 11:27:36 +02:00
Alfonso Sánchez-Beato
00bf976c26 bootloader/piboot: add support for armhf
Add support for armhf. The difference is that in this case the
pi-kernel snap stores the device trees in a different directory.
2022-04-01 10:23:30 +02:00
Michael Vogt
2af863e2aa Merge pull request #11068 from alfonsosanchezbeato/piboot
bootloader: add support for piboot
2022-03-18 10:03:03 +01:00
Alfonso Sánchez-Beato
59cf517516 bootloader/bootloader_test: remove now unneeded test case 2022-03-16 17:22:29 +01:00
Alfonso Sánchez-Beato
5a399f258d bootloader/piboot: create empty env file always
It does not really make sense to ship a non-empty environment in the
gadget, so remove that case.
2022-03-16 17:22:26 +01:00
Alfonso Sánchez-Beato
419092ecc1 bootloader/piboot.md: add better description of config files and fix typo 2022-03-16 17:20:40 +01:00
Alfonso Sánchez-Beato
fdf5ae865d bootloader: add some additional unit tests for piboot 2022-03-15 11:16:47 +01:00
Alfonso Sánchez-Beato
ef4036c5a2 b/piboot.go: do not use snapd_*_cmdline_args and rename some methods
snapd_*_cmdline_args only apply to TrustedAssetsBootloader interface,
that is not implemented by piboot. Also, rename a couple of methods
with better names.
2022-03-15 11:16:47 +01:00
Michael Vogt
439f267378 many: replace use of "sanity" for interface implementation checks
This commit replaces the use of "sanity" with more inclusive
naming. When `// sanity` is used to check if an interface is
implemented the comment `expected interface is implemented`
is used.
2022-03-14 17:35:33 +01:00
Samuele Pedroni
550fad4640 bootloader: allow different names for the grub binary in different archs
Merge pull request #11282 from alfonsosanchezbeato/grub-multiarch

Currently, the grub binary name is always grubx64.efi. However, for
arm64 the usual name is Ubuntu us grubaa64.efi. Make it dependent on
architecture, so one or the other is expected in each case. This will
allow using grub on arm64 systems.
2022-03-01 11:57:19 +01:00
Alfonso Sánchez-Beato
cccf9997f5 bootloader/piboot: minor GetBootVars() refactor 2022-02-28 14:51:53 +01:00
Alfonso Sánchez-Beato
6161322b65 bootloader/piboot.md: fix some errors in documentation 2022-02-28 14:49:54 +01:00
Alfonso Sánchez-Beato
5519698c94 bootloader/piboot: simplify mocking of seed dir
Just using a variable is enough, intstead of simulating by a function.
2022-02-23 16:25:58 +01:00
Alfonso Sánchez-Beato
b3a12846f5 bootloader/piboot: implement RebootBootloader interface
Implement RebootBootloader interface so now piboot does not write the
reboot arguments when kernel is set to "try" state - instead piboot
will return those areguments when required, right before calling
shutdown.
2022-02-23 16:25:51 +01:00
Alfonso Sánchez-Beato
8c240a75aa bootloader: make sure to revert seed partition directory
Otherwise we could point to data from  previous test if not calling
again MockPibootFiles().
2022-02-23 16:23:53 +01:00
Alfonso Sánchez-Beato
8a519f46b1 boot,bootloader: add error parameter to GetRebootArguments() 2022-02-23 16:23:53 +01:00
Alfonso Sánchez-Beato
2543d2c2e3 Merge branch 'master' into piboot 2022-02-22 15:38:12 +01:00
Alfonso Sánchez-Beato
ead29039b9 bootloader/grub_test.go: remove now unused variable 2022-02-16 12:22:11 +01:00
Alfonso Sánchez-Beato
5903d72f39 bootloader: use AddCleanup instead of TearDownTest in tests
Use AddCleanup from the test suite instead of relying on TearDownTest
to clean-up state after a test finishes.
2022-02-16 12:01:06 +01:00
Alfonso Sánchez-Beato
077fbe2a03 bootloader/grub_test: add multi-arch support 2022-02-15 19:12:34 +01:00
Alfonso Sánchez-Beato
347b73cbee bootloader/grub: check for prepare image time when retrieving boot assets 2022-02-15 19:11:34 +01:00
Alfonso Sánchez-Beato
f2fdf40bf0 bootloader: include grub prefix in some names uin grub.go 2022-02-14 19:06:08 +01:00
Alfonso Sánchez-Beato
721bf78f27 bootloader: use different boot assets in grub depending on arch
Make the choosing of boot assets dependent dynamically on arch instead
of having static names. This will facilitate overriding by environment
variables if needed in the future.
2022-02-14 10:49:04 +01:00