blob: b77b472d1f2635ea7b577c9fff8bd169c7a49d07 [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
6#include <common.h>
7#include <dm.h>
8#include <bootcount.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Philipp Tomsich1fc53302018-12-14 21:14:29 +010010#include <asm/test.h>
11#include <dm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060012#include <test/test.h>
Philipp Tomsich1fc53302018-12-14 21:14:29 +010013#include <test/ut.h>
14
Nandor Han88895812021-06-10 15:40:38 +030015static int dm_test_bootcount_rtc(struct unit_test_state *uts)
Philipp Tomsich1fc53302018-12-14 21:14:29 +010016{
17 struct udevice *dev;
18 u32 val;
19
Nandor Han88895812021-06-10 15:40:38 +030020 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount@0",
21 &dev));
Philipp Tomsich1fc53302018-12-14 21:14:29 +010022 ut_assertok(dm_bootcount_set(dev, 0));
23 ut_assertok(dm_bootcount_get(dev, &val));
24 ut_assert(val == 0);
25 ut_assertok(dm_bootcount_set(dev, 0xab));
26 ut_assertok(dm_bootcount_get(dev, &val));
27 ut_assert(val == 0xab);
28
Michal Simek4f18f922020-05-28 11:48:55 +020029 ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 1, &dev));
30 ut_assertok(dm_bootcount_set(dev, 0));
31 ut_assertok(dm_bootcount_get(dev, &val));
32 ut_assert(val == 0);
33 ut_assertok(dm_bootcount_set(dev, 0xab));
34 ut_assertok(dm_bootcount_get(dev, &val));
35 ut_assert(val == 0xab);
36
Philipp Tomsich1fc53302018-12-14 21:14:29 +010037 return 0;
38}
39
Nandor Han88895812021-06-10 15:40:38 +030040DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
41
42static int dm_test_bootcount_syscon_four_bytes(struct unit_test_state *uts)
43{
44 struct udevice *dev;
45 u32 val;
46
47 sandbox_set_enable_memio(true);
48 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_4@0",
49 &dev));
50 ut_assertok(dm_bootcount_set(dev, 0xab));
51 ut_assertok(dm_bootcount_get(dev, &val));
52 ut_assert(val == 0xab);
53 ut_assertok(dm_bootcount_set(dev, 0));
54 ut_assertok(dm_bootcount_get(dev, &val));
55 ut_assert(val == 0);
56
57 return 0;
58}
59
60DM_TEST(dm_test_bootcount_syscon_four_bytes,
61 UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
62
63static int dm_test_bootcount_syscon_two_bytes(struct unit_test_state *uts)
64{
65 struct udevice *dev;
66 u32 val;
67
68 sandbox_set_enable_memio(true);
69 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_2@0",
70 &dev));
71 ut_assertok(dm_bootcount_set(dev, 0xab));
72 ut_assertok(dm_bootcount_get(dev, &val));
73 ut_assert(val == 0xab);
74 ut_assertok(dm_bootcount_set(dev, 0));
75 ut_assertok(dm_bootcount_get(dev, &val));
76 ut_assert(val == 0);
77
78 return 0;
79}
Philipp Tomsich1fc53302018-12-14 21:14:29 +010080
Nandor Han88895812021-06-10 15:40:38 +030081DM_TEST(dm_test_bootcount_syscon_two_bytes,
82 UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);