blob: f66927a5d37e925f1666c0501df10d742dd636f7 [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}
Simon Glass725c4382024-08-22 07:57:48 -060038DM_TEST(dm_test_bootcount_rtc, UTF_SCAN_PDATA | UTF_SCAN_FDT);
Philipp Tomsich6f2d59c2018-12-14 21:14:29 +010039
Nandor Hanc50b21b2021-06-10 15:40:38 +030040static 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 Hanc50b21b2021-06-10 15:40:38 +030057DM_TEST(dm_test_bootcount_syscon_four_bytes,
Simon Glass725c4382024-08-22 07:57:48 -060058 UTF_SCAN_PDATA | UTF_SCAN_FDT);
Nandor Hanc50b21b2021-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 Glassb073d482024-08-22 07:57:49 -060077DM_TEST(dm_test_bootcount_syscon_two_bytes, UTF_SCAN_PDATA | UTF_SCAN_FDT);