1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 General Electric Company. All rights reserved.
20 static u8 upgrade_available
= 1;
22 void bootcount_store(ulong a
)
28 if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
,
29 CONFIG_SYS_BOOTCOUNT_FS_DEVPART
, FS_TYPE_ANY
)) {
30 puts("Error selecting device\n");
34 /* Only update bootcount during upgrade process */
35 if (!upgrade_available
)
38 buf
= map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR
, sizeof(bootcount_ext_t
));
39 buf
->magic
= BC_MAGIC
;
40 buf
->version
= BC_VERSION
;
41 buf
->bootcount
= (a
& 0xff);
42 buf
->upgrade_available
= upgrade_available
;
45 ret
= fs_write(CONFIG_SYS_BOOTCOUNT_FS_NAME
,
46 CONFIG_SYS_BOOTCOUNT_ADDR
, 0, sizeof(bootcount_ext_t
),
49 puts("Error storing bootcount\n");
52 ulong
bootcount_load(void)
58 if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
,
59 CONFIG_SYS_BOOTCOUNT_FS_DEVPART
, FS_TYPE_ANY
)) {
60 puts("Error selecting device\n");
64 ret
= fs_read(CONFIG_SYS_BOOTCOUNT_FS_NAME
, CONFIG_SYS_BOOTCOUNT_ADDR
,
65 0, sizeof(bootcount_ext_t
), &len_read
);
66 if (ret
!= 0 || len_read
!= sizeof(bootcount_ext_t
)) {
67 puts("Error loading bootcount\n");
71 buf
= map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR
, sizeof(bootcount_ext_t
));
72 if (buf
->magic
== BC_MAGIC
&& buf
->version
== BC_VERSION
) {
73 upgrade_available
= buf
->upgrade_available
;
74 if (upgrade_available
)
77 puts("Incorrect bootcount file\n");