The bootcount feature is a mechanism integrated in U-Boot to keep track of the number of times a device tries to boot. This mechanism is particularly useful for embedded systems and devices where it is essential to take corrective actions when the system is unable to boot normally after a number of attempts.
The bootcount feature works as follows:
-
U-Boot stores a boot count value in a non-volatile memory location of the device.
-
Each time the device starts up, U-Boot increments this boot count value.
-
If the system is able to fully boot, the boot count value is automatically reset from user space.
-
If the system is not able to fully boot after a number of attempts, U-Boot tries an alternate boot command.
The implementation details of this feature may vary depending on the specific U-Boot version and hardware platform in use.
Boot count storage
In ConnectCore 6 devices, U-Boot stores the boot count value as an environment variable.
To avoid continuous write events in the internal eMMC each time the device starts up, the bootcount mechanism only works when the upgrade_available environment variable is set to 1 .
This variable is set to 1 after a firmware update.
If the system is able to fully boot after the update, the upgrade_available variable is removed from the environment and the boot count value stops incrementing.
|
Set boot count limit
By default, the boot count limit is set to zero (or undefined), and the boot count mechanism is disabled.
To activate the bootcount mechanism, set the bootlimit
environment variable to the number of boot attempts you desire for your device.
-
Set the
bootlimit
:=> setenv bootlimit <value>
Where <value> is the number of times your device will attempt to boot.
You can either leave the value empty or set it to 0
to disable the bootcount feature. -
Save the environment by issuing this command:
=> saveenv
-
Reset the device so that the new boot count limit takes effect.
If you use one of the firmware install scripts and choose to install a dual boot system, the script automatically sets a bootlimit of three.
|
Actions after failed boot attempts
If the system is not able to fully boot after the boot attempts established in bootlimit
, U-Boot executes the altbootcmd
command instead of the standard bootcmd
.
The default altbootcmd
command takes different actions depending on the boot strategy:
-
Dual boot systems:
-
Swaps the active partition bank
-
Resets the boot count
-
Reboots the device to let it boot the alternate bank
-
-
Single boot systems:
-
Resets the boot count
-
Reboots the device
-
You can customize altbootcmd to perform a desired set of actions when U-Boot executes the command.
|
Manage boot count
Reset boot count
When the system boot finishes, the boot count value is reset to 0 and saved so that the next boot starts with a count of 1.
This is automatically done by the bootcount-init
systemd service during the startup process.
You can easily customize it by modifying the script located at <dey_sources_folder>/meta-digi/meta-digi-dey/recipes-digi/bootcount/bootcount/bootcount-init
.
In addition to this, you can manually reset and save the boot count value from U-Boot or from the running system. See U-Boot command and Linux command to learn more.
Disable boot count
You can disable the bootcount feature from U-Boot by setting the bootlimit
environment variable to 0
:
=> setenv bootlimit 0
=> saveenv
U-Boot command
You can use U-Boot command bootcount
to manage the boot count value from the bootloader.
This command can be useful for tracking the number of system boots for maintenance or debugging purposes.
=> bootcount print
1
=> bootcount reset
U-Boot uses the bootcount
environment variable to manage the boot count value.
You can use this variable to track the number of system boots for maintenance or debugging purposes.
=> printenv bootcount
=> setenv bootcount 0
Linux command
Digi Embedded Yocto provides a bootcount
command to manage the boot count value from Linux.
This command can be useful for maintenance or debugging purposes.
# bootcount -p
0
# bootcount -r
# bootcount -s 3
Note that once the system boots successfully, the boot count value is always reset to 0.
Expect this value when executing bootcount -p command from Linux.
|