Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 |
| 4 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 8 | #include <environment.h> |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 9 | |
| 10 | void bootcount_store(ulong a) |
| 11 | { |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 12 | int upgrade_available = env_get_ulong("upgrade_available", 10, 0); |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 13 | |
| 14 | if (upgrade_available) { |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 15 | env_set_ulong("bootcount", a); |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 16 | env_save(); |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 17 | } |
| 18 | } |
| 19 | |
| 20 | ulong bootcount_load(void) |
| 21 | { |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 22 | int upgrade_available = env_get_ulong("upgrade_available", 10, 0); |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 23 | ulong val = 0; |
| 24 | |
| 25 | if (upgrade_available) |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 26 | val = env_get_ulong("bootcount", 10, 0); |
Heiko Schocher | 040c5c3 | 2013-11-04 14:04:59 +0100 | [diff] [blame] | 27 | |
| 28 | return val; |
| 29 | } |