Philipp Tomsich | 6f2d59c | 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 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <bootcount.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 10 | #include <asm/test.h> |
| 11 | #include <dm/test.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <test/test.h> |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 13 | #include <test/ut.h> |
| 14 | |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 15 | static int dm_test_bootcount_rtc(struct unit_test_state *uts) |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 16 | { |
| 17 | struct udevice *dev; |
| 18 | u32 val; |
| 19 | |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 20 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount@0", |
| 21 | &dev)); |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 22 | 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 Simek | f692b47 | 2020-05-28 11:48:55 +0200 | [diff] [blame] | 29 | 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 Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 40 | DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 41 | |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 42 | static 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 | |
| 60 | DM_TEST(dm_test_bootcount_syscon_four_bytes, |
| 61 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 62 | |
| 63 | static 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 | } |
| 80 | |
| 81 | DM_TEST(dm_test_bootcount_syscon_two_bytes, |
| 82 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |