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 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <bootcount.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 10 | #include <asm/test.h> |
| 11 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <test/test.h> |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 13 | #include <test/ut.h> |
| 14 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 15 | static int dm_test_bootcount_rtc(struct unit_test_state *uts) |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 16 | { |
| 17 | struct udevice *dev; |
| 18 | u32 val; |
| 19 | |
Nandor Han | 8889581 | 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 | 1fc5330 | 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 | 4f18f92 | 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 | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 40 | DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 41 | |
| 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 | } |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 80 | |
Nandor Han | 8889581 | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 81 | DM_TEST(dm_test_bootcount_syscon_two_bytes, |
| 82 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |