107 Commits

Author SHA1 Message Date
Miguel Pires
d097436c1c many: fix formatting w/ gofmt 1.19
Go 1.19 includes some changes to gofmt which intend to make lists and
heading clearer when rendered (https://go.dev/doc/go1.19). This commit
is the result of running the new gofmt and manually fixing some of it.
This was necessary because the new gofmt assumed lines beginning w/ tabs
to start lists or examples. While this is often true in our codebase,
we occasionally also use tabs to indent the lines after a TODO or FIXME
prefix or in yaml (e.g., excerpts of a snap.yaml). This meant that a lot of the
reformatted comments were broken and had to be fixed manually.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-16 14:23:11 +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
a51858b1e7 bootloader: rename RebootArgumentsBootloader interface to RebootBootloader 2022-02-02 18:12:39 +01:00
Alfonso Sánchez-Beato
f0d19f3379 bootloader: add interface for bootloaders needing reboot args
These reboot arguments are passed from systemd to the reboot syscall.
2022-01-28 16:48:30 +01:00
Alfonso Sánchez-Beato
8e4e1f1901 boot,bootloader: add interface to update env from initramfs
This new interface is needed by piboot for the moment, and makes sure
that we do not reconfigure the bootloader while changing the
environment file from the initramfs.
2022-01-18 12:47:14 +01:00
Alfonso Sánchez-Beato
5403502c9f bootloader: add support for piboot
Add support for the official RPi bootloader, so we can use it instead
of RPi's U-Boot port. The U-Boot port is a community effort, so it has
a series of problems, like:

  1. It takes some time until it gets ported when a new RPi model
     appears in the market
  2. It lacks support for USB drivers so USB is not possible

This commit makes it possible to use RPi bootloader, however there are
some limitations that cannot be directly solved as this firmware is
closed source:

  1. We can cold-boot only from the first partition in the disk. This
     implies that we need to write boot assets to the ubuntu-seed
     partition instead of to ubuntu-boot.
  2. The OS updates mechanism depends on a volatile flag that gets
     removed in cold boots. That makes it not possible to distinguish
     sometimes between failed updates and having power-cycled a device
     before really trying a pending update.
  3. There is no scripting language for the RPi bootloader. The only
     way to influence its behavior is by changes to the
     {config,tryboot}.txt files.

The implementation leverages the os_prefix [1] setting in the
bootloader configuration files to select the
kernel/initramfs/dtb/dtbos/cmdline to use in the next
boot. Environment is stored in key=value pairs in text files that are
translated to bootloader configuration when needed (a new kernel is
installed, the run mode changes, etc.). To be able to try new kernels,
fail-safe OS updates are used [2].

[1] https://www.raspberrypi.com/documentation/computers/config_txt.html#os_prefix
[2] https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#fail-safe-os-updates-tryboot
2021-11-16 16:43:55 +01:00
Maciej Borzecki
d4f888598f boot, bootloader: extend unit tests, bump year
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-04-15 19:21:46 +02:00
Maciej Borzecki
98da32f4ef bootloader: introduce full set of command line arguments, refactor trusted bootloader interface
Introduce a structure for passing components of kernel command line. Extend the
structure with a field to carry the full set of arguments. Introduce support in
grub.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-04-15 19:20:21 +02:00
Ian Johnson
8275345afc bootloader: add check for prepare-image time and more tests validating options
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-12-03 12:03:07 -06:00
Ian Johnson
421c677428 bootloader: remove installableBootloader interface and methods
This is not used anywhere anymore, so let's just drop it. If we need it again,
we can bring it back.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-11-30 17:49:09 -06:00
Ian Johnson
e3d7c4f378 Merge pull request #9673 from anonymouse64/feature/uc20-lk-bootloader-4-take-2
bootloader/many: rm ConfigFile, add Present for indicating presence of bloader

Now we have a specific method on the Bootloader interface which tells Find()
whether the specific bootloader is actually present on the current system. This
will simplify future bootloader implementations to be able to return errors when
identifying if a bootloader is present on the system is more complicated a
question than just if the config file for that bootloader exists.

This is required for the UC20 lk bootloader work, where the Present() implementation will be more complicated than just whether a file exists.
2020-11-23 18:24:52 -06:00
Ian Johnson
5a717a278a bootloader: refactor static set of bootloaders to list instead of a map
This is simpler and avoids from having to maintain the list of names of
bootloaders in three locations, one in the bootloader implementation itself, one
in the gadget.yaml bootloader setting, and one in Find(). Now we just have the
bootloader implementation and the gadget.yaml validator.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-11-20 09:03:22 -06:00
Ian Johnson
e3df360d41 Revert "bootloader/bootloader.go: refactor ForGadget slightly"
This reverts commit 072b8847eb.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-11-20 08:56:03 -06:00
Maciej Borzecki
900faa90f6 bootloader: indicate when boot config was updated
Indicate when the bootloader boot config was updated. This allows the callers to
take a better decision as to whether an update or some other action is required.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-11-20 13:31:44 +01:00
Ian Johnson
072b8847eb bootloader/bootloader.go: refactor ForGadget slightly
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-11-19 15:39:56 -06:00
Ian Johnson
e4ab1c5ca9 bootloader/many: rm ConfigFile, add Present for indicating presence of bloader
Now we have a specific method on the Bootloader interface which tells Find()
whether the specific bootloader is actually present on the current system. This
will simplify future bootloader implementations to be able to return errors when
identifying if a bootloader is present on the system is more complicated a
question than just if the config file for that bootloader exists.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-11-19 15:39:56 -06:00
Maciej Borzecki
a13a6f7e8f image, bootloader: comment tweaks
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-11-16 09:05:02 +01:00
Maciej Borzecki
00b07447f1 bootloader: use ForGadget when installing boot config
Address TODO added during UC20 development and use a ForGadget helper when
installing boot configs of a bootloader.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-11-13 14:30:38 +01:00
Maciej Borzecki
479a54bfef bootloader: document some methods do not need rootdir
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-10-09 13:51:58 +02:00
Maciej Borzecki
579fc64e73 bootloader, boot: drop IsCurrentlyManaged check
The check is no longer needed.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-09-29 09:42:35 +02:00
Maciej Borzecki
330bebb454 bootloader: comment tweaks, drop unnecessary mock
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-09-25 14:32:55 +02:00
Maciej Borzecki
98486c0010 Revert "bootloader: drop GetRecoverySystemEnv, drop from grub, update mocks"
This reverts commit 2618d31eba.
2020-09-25 14:18:36 +02:00
Maciej Borzecki
6ff7100e3e bootloader: comment tweaks
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-09-24 14:08:30 +02:00
Maciej Borzecki
2618d31eba bootloader: drop GetRecoverySystemEnv, drop from grub, update mocks
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-09-24 14:06:36 +02:00