Commit eda0ba38a8dfd2572089bd229a027d497c340158
Committed by
Tom Rini
1 parent
85b8c5c4bf
Exists in
master
and in
50 other branches
bootcount: store bootcount var in environment
If no softreset save registers are found on the hardware "bootcount" is stored in the environment. To prevent a saveenv on all reboots, the environment variable "upgrade_available" is introduced. If "upgrade_available" is 0, "bootcount" is always 0 therefore no need to save the environment on u-boot boot, if "upgrade_available" is 1 "bootcount" is incremented in the environment and environment gets written on u-boot start. So the Userspace Applikation must set the "upgrade_available" and "bootcount" variable to 0 (for example with fw_setenv), if a boot was successfully. Signed-off-by: Heiko Schocher <hs@denx.de>
Showing 3 changed files with 46 additions and 0 deletions Side-by-side Diff
README
... | ... | @@ -784,6 +784,22 @@ |
784 | 784 | as a convenience, when switching between booting from |
785 | 785 | RAM and NFS. |
786 | 786 | |
787 | +- Bootcount: | |
788 | + CONFIG_BOOTCOUNT_LIMIT | |
789 | + Implements a mechanism for detecting a repeating reboot | |
790 | + cycle, see: | |
791 | + http://www.denx.de/wiki/view/DULG/UBootBootCountLimit | |
792 | + | |
793 | + CONFIG_BOOTCOUNT_ENV | |
794 | + If no softreset save registers are found on the hardware | |
795 | + "bootcount" is stored in the environment. To prevent a | |
796 | + saveenv on all reboots, the environment variable | |
797 | + "upgrade_available" is used. If "upgrade_available" is | |
798 | + 0, "bootcount" is always 0, if "upgrade_available" is | |
799 | + 1 "bootcount" is incremented in the environment. | |
800 | + So the Userspace Applikation must set the "upgrade_available" | |
801 | + and "bootcount" variable to 0, if a boot was successfully. | |
802 | + | |
787 | 803 | - Pre-Boot Commands: |
788 | 804 | CONFIG_PREBOOT |
789 | 805 |
drivers/bootcount/Makefile
drivers/bootcount/bootcount_env.c
1 | +/* | |
2 | + * (C) Copyright 2013 | |
3 | + * Heiko Schocher, DENX Software Engineering, hs@denx.de. | |
4 | + * | |
5 | + * SPDX-License-Identifier: GPL-2.0+ | |
6 | + */ | |
7 | + | |
8 | +#include <common.h> | |
9 | + | |
10 | +void bootcount_store(ulong a) | |
11 | +{ | |
12 | + int upgrade_available = getenv_ulong("upgrade_available", 10, 0); | |
13 | + | |
14 | + if (upgrade_available) { | |
15 | + setenv_ulong("bootcount", a); | |
16 | + saveenv(); | |
17 | + } | |
18 | +} | |
19 | + | |
20 | +ulong bootcount_load(void) | |
21 | +{ | |
22 | + int upgrade_available = getenv_ulong("upgrade_available", 10, 0); | |
23 | + ulong val = 0; | |
24 | + | |
25 | + if (upgrade_available) | |
26 | + val = getenv_ulong("bootcount", 10, 0); | |
27 | + | |
28 | + return val; | |
29 | +} |