blob: 9cfc7d48aac0e77c828364b255daab14bf0b67d4 [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}
38
Nandor Han88895812021-06-10 15:40:38 +030039DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
40
41static int dm_test_bootcount_syscon_four_bytes(struct unit_test_state *uts)
42{
43 struct udevice *dev;
44 u32 val;
45
46 sandbox_set_enable_memio(true);
47 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_4@0",
48 &dev));
49 ut_assertok(dm_bootcount_set(dev, 0xab));
50 ut_assertok(dm_bootcount_get(dev, &val));
51 ut_assert(val == 0xab);
52 ut_assertok(dm_bootcount_set(dev, 0));
53 ut_assertok(dm_bootcount_get(dev, &val));
54 ut_assert(val == 0);
55
56 return 0;
57}
58
59DM_TEST(dm_test_bootcount_syscon_four_bytes,
60 UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
61
62static int dm_test_bootcount_syscon_two_bytes(struct unit_test_state *uts)
63{
64 struct udevice *dev;
65 u32 val;
66
67 sandbox_set_enable_memio(true);
68 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_2@0",
69 &dev));
70 ut_assertok(dm_bootcount_set(dev, 0xab));
71 ut_assertok(dm_bootcount_get(dev, &val));
72 ut_assert(val == 0xab);
73 ut_assertok(dm_bootcount_set(dev, 0));
74 ut_assertok(dm_bootcount_get(dev, &val));
75 ut_assert(val == 0);
76
77 return 0;
78}
Philipp Tomsich1fc53302018-12-14 21:14:29 +010079
Nandor Han88895812021-06-10 15:40:38 +030080DM_TEST(dm_test_bootcount_syscon_two_bytes,
81 UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);