The wiki is being retired!
Documentation is now handled by the same processes we use for code: Add something to the Documentation/ directory in the coreboot repo, and it will be rendered to https://doc.coreboot.org/. Contributions welcome!
This mechanism permits to test and recover from certain non-booting coreboot images.
This works by having two coreboot images in the same flash chip:
- One fallback/ image: The working image.
- One normal/ image: The image to be tested.
This feature is not widely tested on all boards. It also requires it to have a reboot_bits exported in the CMOS layout.
This also doesn't protect against human errors when using such feature, or bugs in the code responsible for switching between the two images.
- Test new images way faster: if the image doesn't boot it will fallback on the old known-working image and save a long reflashing procedure. Handy for bisecting faster.
- Test new images more safely: Despite of the recommendations of having a way to externally reflash, many new user don't. Still, this method is not totally foolproof.
- More compact testing setup: Since reflashing tools are not mandatory anymore, the tests can be done with less hardware, very useful when traveling.
How it works
Coreboot increments a reboot count at each boot but never clears it. What runs after coreboot is responsible for that.
That way, the count can be cleared by the OS once it's fully booted.
If a certain threshold is attained at boot, coreboot will boot the fallback image.
This scrpit takes an existing coreboot image path as argument.
The most simple way to do it is to run some nvramtool commands, they are described in the scripts below. set-normal-0.sh has to be run:
- After the boot is completed and is declared a success.
- After the resuming is completed.
#!/bin/sh nvramtool -w boot_option=Fallback nvramtool -w last_boot=Fallback nvramtool -w reboot_bits=1
#!/bin/sh nvramtool -w boot_option=Normal nvramtool -w last_boot=Normal nvramtool -w reboot_bits=0
#!/bin/sh nvramtool -a | grep -e boot_option -e last_boot -e reboot_bits
- nvramtool has to be in the path.
- This setup doesn't needs to run that systemd unit when resuming from suspend to ram, but it's not described yet here.
The unit file below has to be activated with:
systemctl enable coreboot-booted-ok systemctl start coreboot-booted-ok
# This file is not part of systemd. # # this file is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Tell coreboot that the computer booted fine. DefaultDependencies=no Wants=display-manager.service After=display-manager.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/local/sbin/nvramtool -w boot_option=Normal ExecStart=/usr/local/sbin/nvramtool -w last_boot=Normal ExecStart=/usr/local/sbin/nvramtool -w reboot_bits=0 [Install] WantedBy=multi-user.target
- The user may wrongly identify which image booted, and because of that, end up reflashing a non-working image.
- Some issues can arrise when the nvram layout is not the same between normal/ and fallback/
- The number of failed boot is fixed at compilation time.
- In order to fully boot, some boards do reset conditionally during the boot process resulting in a non-predictable increment of the boot count.
- Example script exist only for systemd. Still, they are trivial to adapt to other init systems.
- Payloads sometime have fixed default locations when loading things from cbfs:
- When using grub as a payload, grub.cfg is at etc/grub.cfg by default, so if you want to test grub as a payload, remember to change grub.cfg's path not to interfer with the fallback's grub configuration.
- Changing the path of what SeaBIOS loads from cbfs is probably configurable with SeaBIOS cbfs symlinks but not yet tested/documented with the use of the fallback mecanism
- Defined by CONFIG_MAX_REBOOT_CNT, typically 3