blob: f66927a5d37e925f1666c0501df10d742dd636f7 [file] [log] [blame]
Philipp Tomsich1fc53302018-12-14 21:14:29 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) 2018 Theobroma Systems Design und Consulting GmbH
4 */
5
Philipp Tomsich1fc53302018-12-14 21:14:29 +01006#include <dm.h>
7#include <bootcount.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Philipp Tomsich1fc53302018-12-14 21:14:29 +01009#include <asm/test.h>
10#include <dm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060011#include <test/test.h>
Philipp Tomsich1fc53302018-12-14 21:14:29 +010012#include <test/ut.h>
13
Nandor Han88895812021-06-10 15:40:38 +030014static int dm_test_bootcount_rtc(struct unit_test_state *uts)
Philipp Tomsich1fc53302018-12-14 21:14:29 +010015{
16 struct udevice *dev;
17 u32 val;
18
Nandor Han88895812021-06-10 15:40:38 +030019 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount@0",
20 &dev));
Philipp Tomsich1fc53302018-12-14 21:14:29 +010021 ut_assertok(dm_bootcount_set(dev, 0));
22 ut_assertok(dm_bootcount_get(dev, &val));
23 ut_assert(val == 0);
24 ut_assertok(dm_bootcount_set(dev, 0xab));
25 ut_assertok(dm_bootcount_get(dev, &val));
26 ut_assert(val == 0xab);
27
Michal Simek4f18f922020-05-28 11:48:55 +020028 ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 1, &dev));
29 ut_assertok(dm_bootcount_set(dev, 0));
30 ut_assertok(dm_bootcount_get(dev, &val));
31 ut_assert(val == 0);
32 ut_assertok(dm_bootcount_set(dev, 0xab));
33 ut_assertok(dm_bootcount_get(dev, &val));
34 ut_assert(val == 0xab);
35
Philipp Tomsich1fc53302018-12-14 21:14:29 +010036 return 0;
37}
Simon Glass1a92f832024-08-22 07:57:48 -060038DM_TEST(dm_test_bootcount_rtc, UTF_SCAN_PDATA | UTF_SCAN_FDT);
Nandor Han88895812021-06-10 15:40:38 +030039
40static int dm_test_bootcount_syscon_four_bytes(struct unit_test_state *uts)
41{
42 struct udevice *dev;
43 u32 val;
44
45 sandbox_set_enable_memio(true);
46 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_4@0",
47 &dev));
48 ut_assertok(dm_bootcount_set(dev, 0xab));
49 ut_assertok(dm_bootcount_get(dev, &val));
50 ut_assert(val == 0xab);
51 ut_assertok(dm_bootcount_set(dev, 0));
52 ut_assertok(dm_bootcount_get(dev, &val));
53 ut_assert(val == 0);
54
55 return 0;
56}
Nandor Han88895812021-06-10 15:40:38 +030057DM_TEST(dm_test_bootcount_syscon_four_bytes,
Simon Glass1a92f832024-08-22 07:57:48 -060058 UTF_SCAN_PDATA | UTF_SCAN_FDT);
Nandor Han88895812021-06-10 15:40:38 +030059
60static int dm_test_bootcount_syscon_two_bytes(struct unit_test_state *uts)
61{
62 struct udevice *dev;
63 u32 val;
64
65 sandbox_set_enable_memio(true);
66 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_2@0",
67 &dev));
68 ut_assertok(dm_bootcount_set(dev, 0xab));
69 ut_assertok(dm_bootcount_get(dev, &val));
70 ut_assert(val == 0xab);
71 ut_assertok(dm_bootcount_set(dev, 0));
72 ut_assertok(dm_bootcount_get(dev, &val));
73 ut_assert(val == 0);
74
75 return 0;
76}
Simon Glassd6c52f42024-08-22 07:57:49 -060077DM_TEST(dm_test_bootcount_syscon_two_bytes, UTF_SCAN_PDATA | UTF_SCAN_FDT);