3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 DECLARE_GLOBAL_DATA_PTR;
13 const ulong patterns[] = { 0x00000000,
18 const ulong NBR_OF_PATTERNS = sizeof(patterns) / sizeof(*patterns);
19 const ulong OFFS_PATTERN = 3;
20 const ulong REPEAT_PATTERN = 1000;
22 void bootcount_store(ulong a)
28 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
29 size += gd->bd->bi_dram[i].size;
30 save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
32 writel(BOOTCOUNT_MAGIC, &save_addr[1]);
34 for (i = 0; i < REPEAT_PATTERN; i++)
35 writel(patterns[i % NBR_OF_PATTERNS],
36 &save_addr[i + OFFS_PATTERN]);
40 ulong bootcount_load(void)
47 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
48 size += gd->bd->bi_dram[i].size;
49 save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
51 counter = readl(&save_addr[0]);
53 /* Is the counter reliable, check in the big pattern for bit errors */
54 for (i = 0; (i < REPEAT_PATTERN) && (counter != 0); i++) {
55 tmp = readl(&save_addr[i + OFFS_PATTERN]);
56 if (tmp != patterns[i % NBR_OF_PATTERNS])