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 | |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <bootcount.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 9 | #include <asm/test.h> |
| 10 | #include <dm/test.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 12 | #include <test/ut.h> |
| 13 | |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 14 | static int dm_test_bootcount_rtc(struct unit_test_state *uts) |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 15 | { |
| 16 | struct udevice *dev; |
| 17 | u32 val; |
| 18 | |
Nandor Han | c50b21b | 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 | 6f2d59c | 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 | f692b47 | 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 | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 36 | return 0; |
| 37 | } |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 38 | DM_TEST(dm_test_bootcount_rtc, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Philipp Tomsich | 6f2d59c | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 39 | |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 40 | static 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 Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 57 | DM_TEST(dm_test_bootcount_syscon_four_bytes, |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 58 | UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Nandor Han | c50b21b | 2021-06-10 15:40:38 +0300 | [diff] [blame] | 59 | |
| 60 | static 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 Glass | b073d48 | 2024-08-22 07:57:49 -0600 | [diff] [blame] | 77 | DM_TEST(dm_test_bootcount_syscon_two_bytes, UTF_SCAN_PDATA | UTF_SCAN_FDT); |