1 // SPDX-License-Identifier: GPL-2.0+
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
10 DECLARE_GLOBAL_DATA_PTR;
12 const ulong patterns[] = { 0x00000000,
17 const ulong NBR_OF_PATTERNS = sizeof(patterns) / sizeof(*patterns);
18 const ulong OFFS_PATTERN = 3;
19 const ulong REPEAT_PATTERN = 1000;
21 void bootcount_store(ulong a)
27 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
28 size += gd->bd->bi_dram[i].size;
29 save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
31 writel(CONFIG_SYS_BOOTCOUNT_MAGIC, &save_addr[1]);
33 for (i = 0; i < REPEAT_PATTERN; i++)
34 writel(patterns[i % NBR_OF_PATTERNS],
35 &save_addr[i + OFFS_PATTERN]);
37 /* Make sure the data is written to RAM */
38 flush_dcache_range((ulong)&save_addr[0],
39 (((ulong)&save_addr[REPEAT_PATTERN + OFFS_PATTERN] &
40 ~(ARCH_DMA_MINALIGN - 1)) + ARCH_DMA_MINALIGN));
43 ulong bootcount_load(void)
50 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
51 size += gd->bd->bi_dram[i].size;
52 save_addr = (ulong *)(size - BOOTCOUNT_ADDR);
54 counter = readl(&save_addr[0]);
56 /* Is the counter reliable, check in the big pattern for bit errors */
57 for (i = 0; (i < REPEAT_PATTERN) && (counter != 0); i++) {
58 tmp = readl(&save_addr[i + OFFS_PATTERN]);
59 if (tmp != patterns[i % NBR_OF_PATTERNS])