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]);
38 /* Make sure the data is written to RAM */
39 flush_dcache_range((ulong)&save_addr[0],
40 (((ulong)&save_addr[REPEAT_PATTERN + OFFS_PATTERN] &
41 ~(ARCH_DMA_MINALIGN - 1)) + ARCH_DMA_MINALIGN));
44 ulong bootcount_load(void)
51 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
52 size += gd->bd->bi_dram[i].size;
53 save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
55 counter = readl(&save_addr[0]);
57 /* Is the counter reliable, check in the big pattern for bit errors */
58 for (i = 0; (i < REPEAT_PATTERN) && (counter != 0); i++) {
59 tmp = readl(&save_addr[i + OFFS_PATTERN]);
60 if (tmp != patterns[i % NBR_OF_PATTERNS])