blob: 4b0a4b37931f89849c793a79eaade84522cbc21f [file] [log] [blame]
Philipp Tomsich6f2d59c2018-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 Tomsich6f2d59c2018-12-14 21:14:29 +01006#include <dm.h>
7#include <bootcount.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Philipp Tomsich6f2d59c2018-12-14 21:14:29 +01009#include <asm/test.h>
10#include <dm/test.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060011#include <test/test.h>
Philipp Tomsich6f2d59c2018-12-14 21:14:29 +010012#include <test/ut.h>
13
Nandor Hanc50b21b2021-06-10 15:40:38 +030014static int dm_test_bootcount_rtc(struct unit_test_state *uts)
Philipp Tomsich6f2d59c2018-12-14 21:14:29 +010015{
16 struct udevice *dev;
17 u32 val;
18
Nandor Hanc50b21b2021-06-10 15:40:38 +030019 ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount@0",
20 &dev));
Philipp Tomsich6f2d59c2018-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 Simekf692b472020-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 Tomsich6f2d59c2018-12-14 21:14:29 +010036 return 0;
37}
38
Simon Glass725c4382024-08-22 07:57:48 -060039DM_TEST(dm_test_bootcount_rtc, UTF_SCAN_PDATA | UTF_SCAN_FDT);
Philipp Tomsich6f2d59c2018-12-14 21:14:29 +010040
Nandor Hanc50b21b2021-06-10 15:40:38 +030041static 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,
Simon Glass725c4382024-08-22 07:57:48 -060060 UTF_SCAN_PDATA | UTF_SCAN_FDT);
Nandor Hanc50b21b2021-06-10 15:40:38 +030061
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}
79
80DM_TEST(dm_test_bootcount_syscon_two_bytes,
Simon Glass725c4382024-08-22 07:57:48 -060081 UTF_SCAN_PDATA | UTF_SCAN_FDT);