Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | Boot Count Limit |
| 4 | ================ |
| 5 | |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 6 | This is enabled by CONFIG_BOOTCOUNT_LIMIT. |
| 7 | |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 8 | This allows to detect multiple failed attempts to boot Linux. |
| 9 | |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 10 | After a power-on reset, the "bootcount" variable will be initialized to 1, and |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 11 | each reboot will increment the value by 1. |
| 12 | |
| 13 | If, after a reboot, the new value of "bootcount" exceeds the value of |
| 14 | "bootlimit", then instead of the standard boot action (executing the contents of |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 15 | "bootcmd"), an alternate boot action will be performed, and the contents of |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 16 | "altbootcmd" will be executed. |
| 17 | |
| 18 | If the variable "bootlimit" is not defined in the environment, the Boot Count |
| 19 | Limit feature is disabled. If it is enabled, but "altbootcmd" is not defined, |
| 20 | then U-Boot will drop into interactive mode and remain there. |
| 21 | |
| 22 | It is the responsibility of some application code (typically a Linux |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 23 | application) to reset the variable "bootcount" to 0 when the system booted |
| 24 | successfully, thus allowing for more boot cycles. |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 25 | |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 26 | CONFIG_BOOTCOUNT_EXT |
| 27 | -------------------- |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 28 | |
| 29 | This adds support for maintaining boot count in a file on an EXT filesystem. |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 30 | The file to use is defined by: |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 31 | |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 32 | CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE |
| 33 | CONFIG_SYS_BOOTCOUNT_EXT_DEVPART |
| 34 | CONFIG_SYS_BOOTCOUNT_EXT_NAME |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 35 | |
| 36 | The format of the file is: |
| 37 | |
| 38 | ==== ================= |
| 39 | type entry |
| 40 | ==== ================= |
| 41 | u8 magic |
| 42 | u8 version |
| 43 | u8 bootcount |
| 44 | u8 upgrade_available |
| 45 | ==== ================= |
| 46 | |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 47 | To prevent unattended usage of "altbootcmd", the "upgrade_available" variable is |
Frédéric Danis | cf01a7e | 2020-03-17 17:59:09 +0100 | [diff] [blame] | 48 | used. |
Michael Opdenacker | 0ed5c7a | 2022-03-02 16:56:02 +0100 | [diff] [blame] | 49 | If "upgrade_available" is 0, "bootcount" is not saved. |
| 50 | If "upgrade_available" is 1, "bootcount" is saved. |
| 51 | So a userspace application should take care of setting the "upgrade_available" |
| 52 | and "bootcount" variables to 0, if the system boots successfully. |
| 53 | This also avoids writing the "bootcount" information on all reboots. |