Software APIs
bootstrap_unittest_util.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOTSTRAP_UNITTEST_UTIL_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOTSTRAP_UNITTEST_UTIL_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/lib/base/mock_abs_mmio.h"
11 #include "sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.h"
12 #include "sw/device/silicon_creator/lib/drivers/mock_otp.h"
13 #include "sw/device/silicon_creator/lib/drivers/mock_rstmgr.h"
14 #include "sw/device/silicon_creator/lib/drivers/mock_spi_device.h"
15 #include "sw/device/silicon_creator/lib/error.h"
16 #include "sw/device/silicon_creator/testing/rom_test.h"
17 
18 namespace bootstrap_unittest_util {
19 
21  protected:
22  /**
23  * Sets an expectation for a bootstrap request check.
24  *
25  * @param requested Whether bootstrap is requested.
26  */
27  void ExpectBootstrapRequestCheck(bool requested);
28 
29  /**
30  * Sets an expectation for a spi flash command.
31  *
32  * @param cmd Command struct to output.
33  */
35 
36  /**
37  * Sets an expectation for getting the SPI flash status register.
38  *
39  * @param wel Value of the WEL bit.
40  */
41  void ExpectSpiFlashStatusGet(bool wel);
42 
43  /**
44  * Sets an expectation for enabling write for the data partition.
45  */
47 
48  /**
49  * Sets an expectation for enabling erase for the data partition.
50  */
52 
53  /**
54  * Sets an expectation for disabling all permissions for the data partition.
55  */
57 
58  /**
59  * Sets expectations for a chip erase.
60  *
61  * @param err0 Result of erase for the first bank.
62  * @param err1 Result of erase for the second bank.
63  */
64  void ExpectFlashCtrlChipErase(rom_error_t err0, rom_error_t err1);
65 
66  /**
67  * Sets expectations for a sector erase.
68  *
69  * @param err0 Result of erase for the first page.
70  * @param err1 Result of erase for the second page.
71  * @param addr Erase start address.
72  */
73  void ExpectFlashCtrlSectorErase(rom_error_t err0, rom_error_t err1,
74  uint32_t addr);
75 
76  /**
77  * Sets expectations for a chip erase verification.
78  *
79  * @param err0 Result of erase verification for the first bank.
80  * @param err1 Result of erase verification for the second bank.
81  */
82  void ExpectFlashCtrlEraseVerify(rom_error_t err0, rom_error_t err1);
83 
84  ::rom_test::MockAbsMmio mmio_;
85  ::rom_test::MockFlashCtrl flash_ctrl_;
86  ::rom_test::MockOtp otp_;
87  ::rom_test::MockRstmgr rstmgr_;
88  ::rom_test::MockSpiDevice spi_device_;
89 };
90 
91 /**
92  * Returns a struct that represents a CHIP_ERASE command.
93  *
94  * @return A `spi_device_cmd_t` that represents a CHIP_ERASE command.
95  */
96 spi_device_cmd_t ChipEraseCmd();
97 
98 /**
99  * Returns a struct that represents a SECTOR_ERASE command.
100  *
101  * @param address Address field of the command.
102  * @return A `spi_device_cmd_t` that represents a SECTOR_ERASE command.
103  */
104 spi_device_cmd_t SectorEraseCmd(uint32_t address);
105 
106 /**
107  * Returns a struct that represents a PAGE_PROGRAM command.
108  *
109  * @param address Address field of the command.
110  * @param payload_byte_count Payload size in bytes.
111  * @return A `spi_device_cmd_t` that represents a PAGE_PROGRAM command.
112  */
113 spi_device_cmd_t PageProgramCmd(uint32_t address, size_t payload_byte_count);
114 
115 spi_device_cmd_t ResetCmd();
116 
117 } // namespace bootstrap_unittest_util
118 
119 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOTSTRAP_UNITTEST_UTIL_H_