Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) 2018 Theobroma Systems Design und Consulting GmbH |
| 4 | */ |
| 5 | |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <bootcount.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 9 | #include <asm/test.h> |
| 10 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 12 | #include <test/ut.h> |
| 13 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 14 | static int dm_test_bootcount_rtc(struct unit_test_state *uts) |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 15 | { |
| 16 | struct udevice *dev; |
| 17 | u32 val; |
| 18 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 19 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount@0", |
| 20 | &dev)); |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 21 | 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 Simek | 4f18f92 | 2020-05-28 11:48:55 +0200 | [diff] [blame] | 28 | 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 Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 39 | DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 40 | |
| 41 | static 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 | |
| 59 | DM_TEST(dm_test_bootcount_syscon_four_bytes, |
| 60 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 61 | |
| 62 | static 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 Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 79 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 80 | DM_TEST(dm_test_bootcount_syscon_two_bytes, |
| 81 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |