CC27xxDriverLibrary
hapi.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2024 Texas Instruments Incorporated. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1) Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2) Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * 3) Neither the name of the copyright holder nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  ******************************************************************************
30  * \file hapi.h
31  *
32  * \brief ROM Hard API header file for applications
33  ******************************************************************************/
34 #ifndef __HAPI_H__
35 #define __HAPI_H__
36 #include <stdint.h>
37 #include <stdbool.h>
38 #include "sha256sw.h"
39 #include "../inc/hw_flash.h"
40 
45 #define FLASH_API_KEY 0xB7E3A08FU
46 
47 //*****************************************************************************
48 //
49 // Defines for selecting flash bank.
50 //
51 //*****************************************************************************
52 #define FLASH_BANK_0 FLASH_CMDCTL_BANKSEL_BANK0
53 #define FLASH_BANK_1 FLASH_CMDCTL_BANKSEL_BANK1
54 
55 // ------------------------------------------------------------
56 // Macros used in applications to actually call HAPI functions
57 // ------------------------------------------------------------
58 
59 #ifndef DRIVERLIB_NS
60 //*****************************************************************************
61 //
62 // Below functions will only be compiled into the driverlib.a library and not
63 // the driverlib_ns.a library.
64 // Non-secure applications might be able to access some/all of these functions
65 // through veneers declared further below in the #else case.
66 //
67 //*****************************************************************************
68 
69 // Define HAPI table and the functions it points to
70 typedef struct
71 {
72  // 0: Enter standby power state (from privileged thread mode with MSP as call stack)
73  void (*pEnterStandby)(const uint32_t *pCopyList);
74  // 1: [Utility] Calculate CRC32 over nBytes bytes at pData
75  uint32_t (*pCrc32)(const uint8_t *pData, uint32_t nBytes);
76  // 2: Apply copy list
77  void (*pApplyCopyList)(const uint32_t *pList);
78  // 3: Erase (main) flash sector
79  uint32_t (*pFlashSectorErase)(uint32_t key, uint32_t sectorAddress);
80  // 4: Erase (main) selected flash bank
81  uint32_t (*pFlashBankErase)(uint32_t key, uint32_t bankSelect);
82  // 5: Program (main) flash sector
83  uint32_t (*pFlashProgram)(uint32_t key, const uint8_t *pDataBuffer, uint32_t address, uint32_t nBytes);
84  // 6: [Utility] Hamming weight of 32b word (number of bits set)
85  uint32_t (*pCountBits)(uint32_t word);
86  // 7: [Utility] Perform SECDED encoding on array of 64b words
87  void (*pSecdedEncode)(uint8_t *pParity, const uint64_t *pData, uint32_t nWords64);
88  // 8: [Utility] Perform SECDED detection/correction on array of 64b words and parity bytes
89  int32_t (*pSecdedDecode)(uint64_t *pData, const uint8_t *pParity, uint32_t nWords64);
90  // 9: Reserved. Application should not rely on this HAPI entry.
91  void (*pReservedDoNotUse)(void);
92  // 10: SHA256: hash single block of data and produce digest
93  int_fast16_t (*pSha256SwHashData)(SHA256SW_Handle handle,
94  SHA2SW_HashType hashType, // Only SHA2SW_HASH_TYPE_256 supported
95  const void *data,
96  size_t length,
97  uint32_t digest[8]);
98  // 11: SHA256: initialize hash state
99  int_fast16_t (*pSha256SwStart)(SHA256SW_Handle handle,
100  SHA2SW_HashType hashType // Only SHA2SW_HASH_TYPE_256 supported
101  );
102  // 12: SHA256: update hash with data
103  int_fast16_t (*pSha256SwAddData)(SHA256SW_Handle handle, const void *data, size_t length);
104  // 13: SHA256: finalize and produce digest
105  int_fast16_t (*pSha256SwFinalize)(SHA256SW_Handle handle, uint32_t digest[8]);
106  // 14: [Utility] Reset device
107  void (*pResetDevice)(void);
108  // 15: SHA256: Process Block
109  void (*pSHA256SwProcessBlock)(uint32_t digest[8], uint32_t Ws[16]);
110  // 16: SHA256: Round constants
111  const uint32_t (*pSHA256SW_K256)[64];
112  // 17: SHA256: Initial constants
113  const uint32_t (*pSHA256SW_initialDigest256)[8];
114  // 18: Busy loop that waits for nUs microseconds
115  void (*pWaitUs)(uint32_t nUs);
116  // 19: Count leading zeros
117  uint32_t (*pClz)(uint32_t x);
118  // 20: Secure Boot 3v3 Flags: Set Update Image Address
119  int32_t (*pSbSetUpdateImageAddress)(uint32_t address);
120  // 21: Secure Boot 3v3 Flags: Get Update Image Address
121  uint32_t (*pSbGetUpdateImageAddress)(void);
122  // 22: Secure Boot 3v3 Flags: Set ID
123  int32_t (*pSbSetId)(uint32_t id);
124  // 23: Secure Boot 3v3 Flags: Get ID
125  uint32_t (*pSbGetId)(void);
126  // 24: Secure Boot 3v3 Flags: Set Status
127  void (*pSbSetStatus)(uint32_t status);
128  // 25: Secure Boot 3v3 Flags: Get Status
129  uint32_t (*pSbGetStatus)(void);
130  // 26: Set TCM Sync
131  bool (*pSetTcmSync)(bool syncVal);
132 } HARD_API_T;
133 
134  // Define address of HAPI table in ROM and macro for pointer to it
135  #define HAPI_TABLE_BASE_ADDR 0x0F00004C
136  #define P_HAPITAB ((const HARD_API_T *)HAPI_TABLE_BASE_ADDR)
137 
138  // void HapiEnterStandby(const uint32_t *copyList)
139  /*!***************************************************************************
140  * \brief Enter standby power state
141  * Stores the full state of the CPU to MSP call stack so that it can get
142  * restored once we come back out of standby (at which point CPU is reset).
143  * When exiting standby the CPU will appear to return from this function.
144  *
145  * \param[in] copyList
146  * If non-null, the copy list to apply through ApplyCopyList() in the
147  * AsmExitStandby function while waiting for flash to become ready.
148  *
149  * \pre
150  * - Execution state is privileged and call stack being used is MSP
151  * - MSP call stack must reside in retained SRAM (obviously)
152  * - Interrupts have been turned off with CPSID but interrupts enabled in NVIC
153  * - Wakeup event(s) have been configured in AON event fabric
154  * - SCB.SCR.DSLP_EN=0 (if not, in debug standby exit will enter standby again)
155  * \warning
156  * The preconditions must be followed to the letter or bad things will happen
157  * \note
158  * Clobbers r0-r3 (normal per AAPCS)
159  *****************************************************************************/
160  #define HapiEnterStandby(copyList) (P_HAPITAB->pEnterStandby((copyList)))
161 
162  // uint32_t HapiCrc32(const uint8_t *data, uint32_t nBytes)
163  /*!***************************************************************************
164  * \brief Calculate CRC32 over a data image
165  * CRC32 implementation that uses a 256-entry LUT
166  *
167  * \param[in] data
168  * Pointer to the image data
169  * \param[in] nBytes
170  * Size of image in bytes
171  *
172  * \return
173  * CRC-32 checksum of the image
174  *****************************************************************************/
175  #define HapiCrc32(data, nBytes) (P_HAPITAB->pCrc32((data), (nBytes)))
176 
177  // void HapiApplyCopyList(const uint32_t *list)
178  /*!***************************************************************************
179  * \brief Process copy list
180  * Processes a copy list in a flexible CopyList format. Used by trims
181  * in FCFG, for user-defined initialization in CCFG and may be used by
182  * peripheral drivers to do HW reinitialization during wakeup from standby.
183  * The copy list is processed as a sequence of 32b command words, followed by
184  * zero or more literal words (LW):
185  *
186  * Command |31:28|27:20 |19:2 |1:0|LW|Description
187  * -------------|-----|---------|----------------------|---|--|-------------------
188  * EOL |0000 |0000_0000|0000_0000_0000_0000_00|00 |0 |End-of-list
189  * WAIT(N) |0001 |0000_0000|nnnn_nnnn_nnnn_nnnn_nn|00 |0 |Wait N/12 us
190  * NOP = WAIT(0)|0001 |0000_0000|0000_0000_0000_0000_00|00 |0 |No operation
191  * CPY(A*,N) |aaaa |nnnn_nnnn|aaaa_aaaa_aaaa_aaaa_aa|00 |N |Copy N literal words to address A*
192  * CPY(A,1) |aaaa |aaaa_aaaa|aaaa_aaaa_aaaa_aaaa_aa|01 |1 |Copy single literal word to full address A
193  * JMP(A) |aaaa |aaaa_aaaa|aaaa_aaaa_aaaa_aaaa_aa|10 |0 |Jump to new list at full address A
194  * CALL(A) |aaaa |aaaa_aaaa|aaaa_aaaa_aaaa_aaaa_aa|11 |0 |Recurse to list at full address A
195  *
196  * A* is a reduced address space that covers all SRAM and peripheral space.
197  * Bits 27:20 of this address will be assumed to be all zero. Full addresses
198  * must have 32b alignment
199  *
200  * \param[in] list
201  * Pointer to the copy list
202  *****************************************************************************/
203  #define HapiApplyCopyList(list) (P_HAPITAB->pApplyCopyList((list)))
204 
205  // uint32_t HapiFlashSectorErase(uint32_t key, uint32_t addr);
206  /*!***************************************************************************
207  * \brief Erase a flash sector.
208  *
209  * Erase the flash sector that begins at address addr. Function will not return
210  * before erase operation completes or error occurs. Only main sectors and the
211  * CCFG sector is supported and are subject to flash write/erase restrictions.
212  * No default data is written back to CCFG after an erase.
213  *
214  * \warning No accesses to flash may occur during an erase operation. Interrupts
215  * must be disabled prior to calling or care taken that no reads to flash occur.
216  * DMA operations targeting flash must be suspended.
217  *
218  * \param key
219  * Magic number \ref FLASH_API_KEY (0xB7E3A08F) to protect against inadvertent
220  * flash erasures
221  * \param addr
222  * First address of a main sector or the CCFG sector
223  *
224  * \return
225  * Return code
226  * - \ref FAPI_STATUS_SUCCESS (0)
227  * - \ref FAPI_STATUS_ADDRESS_ERROR
228  * - \ref FAPI_STATUS_INVALID_KEY
229  * - \ref FAPI_STATUS_FSM_ERROR
230  *****************************************************************************/
231  #define HapiFlashSectorErase(key, addr) (P_HAPITAB->pFlashSectorErase((key), (addr)))
232 
233  // uint32_t HapiFlashBankErase(uint32_t key, uint32_t bankSelect)
234  /*!***************************************************************************
235  * \brief Erase the specified bank
236  *
237  * This function will erase all main flash sectors in the specified bank
238  *
239  * \warning Please note that code can not execute in flash while any part of
240  * the flash is being programmed or erased. The application must disable
241  * interrupts that have interrupt routines in flash.
242  *
243  * \param key A magic number that must be \ref FLASH_API_KEY. The key protects
244  * against random jumps into the flash API
245  * \param bankSelect The selection between which bank to erase. \ref FLASH_BANK_0
246  * or \ref FLASH_BANK_1.
247  *
248  * \return Returns the status of the sector erase:
249  * - \ref FAPI_STATUS_SUCCESS (0) : Success.
250  * - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Invalid argument.
251  * - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
252  *****************************************************************************/
253  #define HapiFlashBankErase(key, bankSelect) (P_HAPITAB->pFlashBankErase((key), (bankSelect)))
254 
255  // uint32_t HapiFlashProgram(uint32_t key, const uint8_t *data, uint32_t addr, uint32_t nBytes)
256  /*!****************************************************************************
257  * \brief Program to flash (FCFG, CCFG or MAIN)
258  *
259  * This function programs a sequence of bytes into the on-chip flash.
260  * Programming each location consists of the result of an AND operation
261  * of the new data and the existing data; in other words bits that contain
262  * 1 can remain 1 or be changed to 0, but bits that are 0 cannot be changed
263  * to 1. Therefore, a byte can be programmed multiple times as long as these
264  * rules are followed; if a program operation attempts to change a 0 bit to
265  * a 1 bit, that bit will not have its value changed.
266  *
267  * Programming may cross main sector boundaries. This function does not
268  * return until the data has been programmed or a programming error occurs.
269  *
270  * \note It is recommended to disable cache and line buffer before
271  * programming the flash and re-enable/clear cache and line buffer when the
272  * program operation completes.
273  *
274  * \warning Please note that code can not execute in flash while any part of
275  * the flash is being programmed or erased. The application must disable
276  * interrupts that have interrupt routines in flash.
277  *
278  * \warning The \c data pointer can not point to flash.
279  *
280  * \param key A magic number that must be \ref FLASH_API_KEY. The key
281  * protects against random jumps into the flash API
282  * \param data A pointer to the data to be programmed
283  * \param addr The starting address in flash to be programmed
284  * \param nBytes The number of bytes to be programmed
285  *
286  * \return Returns status of the flash programming:
287  * - \ref FAPI_STATUS_SUCCESS (0) : Success.
288  * - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Too many bytes were requested.
289  * - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
290  *****************************************************************************/
291  #define HapiFlashProgram(key, data, addr, nBytes) (P_HAPITAB->pFlashProgram((key), (data), (addr), (nBytes)))
292 
293  // uint32_t HapiCountBits(uint32_t word)
294  /*!***************************************************************************
295  * \brief Return Hamming weight (# bits that are set) of word
296  *
297  * \param[in] word
298  * 32-bit word to count bits for
299  *
300  * \return
301  * Number of bits set in word (0-32)
302  *****************************************************************************/
303  #define HapiCountBits(word) (P_HAPITAB->pCountBits((word)))
304 
305  // void HapiSecdedEncode(uint8_t *parity, const uint64_t *data, uint32_t nWords64)
306  /*!***************************************************************************
307  * \brief Perform SECDED encoding over data array and produce parity array
308  *
309  * Uses the usual (72,64) SECDED generator matrix:
310  * \code
311  * DDDDDDDD DDDDDDDD DDDDDDDD DDDDDDDD DDDDDDDD DDDDDDDD DDDDDDDD DDDDDDDD PPPPPPPP
312  * 66665555 55555544 44444444 33333333 33222222 22221111 11111100 00000000 00000000
313  * 32109876 54321098 76543210 98765432 10987654 32109876 54321098 76543210 76543210
314  * -------------------------------------------------------------------------------------
315  * P7: 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 01111111
316  * P6: 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111110 00000000
317  * P5: 11111111 11111111 11111111 11111111 00000000 00000000 00000000 00000001 00000000
318  * P4: 11111111 11111111 00000000 00000000 11111111 11111111 00000000 00000001 00000000
319  * P3: 11111111 00000000 11111111 00000000 11111111 00000000 11111111 00000001 00000000
320  * P2: 11110000 11110000 11110000 11110000 11110000 11110000 11110000 11110001 00000000
321  * P1: 11001100 11001100 11001100 11001100 11001100 11001100 11001100 11001101 00000000
322  * P0: 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101011 00000000
323  * \endcode
324  *
325  * \param[out] parity
326  * Pointer to where to store parity bytes (one byte per 64b word of data)
327  * \param[in] data
328  * Pointer to the data (4B aligned)
329  * \param[in] nWords64
330  * Number of 64b words of data / bytes of parity
331  *****************************************************************************/
332  #define HapiSecdedEncode(parity, data, nWords64) (P_HAPITAB->pSecdedEncode((parity), (data), (nWords64)))
333 
334  // int32_t HapiSecdedDecode(uint64_t *data, const uint8_t *parity, uint32_t nWords64)
335  /*!***************************************************************************
336  * \brief Perform SECDED correction/detection over data array using parity array
337  * Uses the usual (72,64) SECDED generator matrix.
338  *
339  * \param[inout] data
340  * Pointer to the data (4B aligned)
341  * \param[in] parity
342  * Pointer to the parity bytes (one byte per 64b word of data)
343  * \param[in] nWords64
344  * Number of 64b words of data / bytes of parity
345  *
346  * \return
347  * <0: uncorrectable error detected
348  * >=0: number of bits corrected
349  *****************************************************************************/
350  #define HapiSecdedDecode(data, parity, nWords64) (P_HAPITAB->pSecdedDecode((data), (parity), (nWords64)))
351 
352  // int_fast16_t HapiSha256SwHashData(SHA256SW_Handle handle, const void *data, size_t length, uint32_t digest[8])
353  /*!***************************************************************************
354  * \brief Performs a complete SHA256 hash operation, producing a final
355  * digest for the data.
356  *
357  * This function wraps #HapiSha256SwStart(), #HapiSha256SwAddData(), and
358  * #HapiSha256SwFinalize().
359  *
360  * There is no need to call #HapiSha256SwStart() prior to calling this function.
361  *
362  * The total length of data that can be hashed by this implementation
363  * is 512MiB (0x20000000 bytes.)
364  *
365  * \param[in] handle A #SHA256SW_Handle.
366  *
367  * \param[in] data Data (message) to hash. May point to zero.
368  *
369  * \param[in] length The number of bytes (pointed to by \c data parameter)
370  * to add to the hash.
371  *
372  * \param[out] digest Output location for the final digest. Must be
373  * able to hold 32 bytes of output and be 32-bit aligned.
374  *
375  * \retval #SHA2SW_STATUS_SUCCESS (0) The hash operation succeeded.
376  * \retval #SHA2SW_STATUS_ERROR The hash operation failed.
377  * \retval #SHA2SW_STATUS_UNSUPPORTED Requested Hash Type is unsupported.
378  * \retval #SHA2SW_STATUS_LENGTH_TOO_LARGE The requested length of data to hash
379  * is more than the implementation
380  * supports.
381  * \retval #SHA2SW_STATUS_NULL_INPUT One or more of the pointer inputs is
382  * NULL.
383  *****************************************************************************/
384  #define HapiSha256SwHashData(handle, data, length, digest) \
385  (P_HAPITAB->pSha256SwHashData((handle), SHA2SW_HASH_TYPE_256, (data), (length), (digest)))
386 
387  // int_fast16_t HapiSha256SwStart(SHA256SW_Handle handle)
388  /*!***************************************************************************
389  * \brief Initialize a SHA256SW_Handle, preparing for hashing data.
390  *
391  * \param[in] handle A #SHA256SW_Handle.
392  *
393  * \retval #SHA2SW_STATUS_SUCCESS (0) The hash operation succeeded.
394  * \retval #SHA2SW_STATUS_UNSUPPORTED Requested Hash Type is unsupported.
395  * \retval #SHA2SW_STATUS_NULL_INPUT One or more of the pointer inputs is
396  * NULL.
397  *
398  * \sa #HapiSha256SwAddData()
399  * \sa #HapiSha256SwFinalize()
400  *****************************************************************************/
401  #define HapiSha256SwStart(handle) (P_HAPITAB->pSha256SwStart((handle), SHA2SW_HASH_TYPE_256))
402 
403  // int_fast16_t HapiSha256SwAddData(SHA256SW_Handle handle, const void *data, size_t length)
404  /*!***************************************************************************
405  * \brief Add data to a SHA256 operation.
406  *
407  * Adds data to a hash operation. The \c handle must have been
408  * initialized by a call to HapiSha256SwStart first.
409  *
410  * The total length of data that can be hashed by this implementation
411  * is 512MiB (0x20000000 bytes.)
412  *
413  * After passing in all data to be hashed, call #HapiSha256SwFinalize()
414  * to obtain the final digest.
415  *
416  * \pre handle was previously passed to #HapiSha256SwStart().
417  *
418  * \param[in] handle A #SHA256SW_Handle.
419  *
420  * \param[in] data Data (message) to add to the hash. May point to zero.
421  *
422  * \param[in] length The number of bytes (pointed to by \c data parameter)
423  * to add to the hash.
424  *
425  * \retval #SHA2SW_STATUS_SUCCESS (0) The hash operation succeeded.
426  * \retval #SHA2SW_STATUS_LENGTH_TOO_LARGE The requested length of data to hash
427  * is more than the implementation
428  * supports.
429  * \retval #SHA2SW_STATUS_NULL_INPUT One or more of the pointer inputs is
430  * NULL.
431  *
432  * \sa #HapiSha256SwStart()
433  * \sa #HapiSha256SwFinalize()
434  *****************************************************************************/
435  #define HapiSha256SwAddData(handle, data, length) (P_HAPITAB->pSha256SwAddData((handle), (data), (length)))
436 
437  // int_fast16_t HapiSha256SwFinalize(SHA256SW_Handle handle, uint32_t digest[8])
438  /*!***************************************************************************
439  * \brief Finalize a SHA256 operation, creating the final digest.
440  *
441  * After calling this function, \c handle should not be used again
442  * until it has been reinitialized via a call to #HapiSha256SwStart().
443  *
444  * \pre handle was previously passed to #HapiSha256SwStart() and data to
445  * be hashed was passed to #HapiSha256SwAddData()
446  *
447  * \param[in] handle A #SHA256SW_Handle.
448  *
449  * \param[out] digest Output location for the final digest. Must be
450  * able to hold 32 bytes of output and be 32-bit aligned.
451  *
452  * \retval #SHA2SW_STATUS_SUCCESS (0) The hash operation succeeded.
453  * \retval #SHA2SW_STATUS_NULL_INPUT One or more of the pointer inputs is
454  * NULL.
455  *
456  * \sa #HapiSha256SwStart()
457  * \sa #HapiSha256SwAddData()
458  *****************************************************************************/
459  #define HapiSha256SwFinalize(handle, digest) (P_HAPITAB->pSha256SwFinalize((handle), (digest)))
460 
461  // __noreturn void HapiResetDevice(void)
462  /*!***************************************************************************
463  * \brief Perform system reset of the device
464  *
465  * This function will perform a system reset of the device equal to a pin
466  * reset. Software can determine that this was the cause of reset once
467  * rebooted. The function will never return.
468  *****************************************************************************/
469  #define HapiResetDevice() (P_HAPITAB->pResetDevice())
470 
471  // HAPI entry used for internal purposes
472  #define HapiSha256SWProcessBlock(d, w) (P_HAPITAB->pSHA256SWProcessBlock((d), (w)))
473 
474  // HAPI entry used for internal purposes
475  #define HapiSha256SW_K256 (*P_HAPITAB->pSHA256SW_K256)
476 
477  // HAPI entry used for internal purposes
478  #define HapiSha256SW_initialDigest256 (*P_HAPITAB->pSHA256SW_initialDigest256)
479 
480  // void HapiWaitUs(uint32_t nUs)
481  /*!***************************************************************************
482  * \brief Wait function
483  *
484  * \param[in] nUs
485  * Number of microseconds to wait (min: 1 us, max: 2^26 us)
486  *****************************************************************************/
487  #define HapiWaitUs(nUs) (P_HAPITAB->pWaitUs((nUs)))
488 
489  // uint32_t HapiClz(uint32_t x)
490  /*!***************************************************************************
491  * \brief Count leading zeros
492  *
493  * \param[in] x
494  * Value to count leading zeros for
495  * \return
496  * Number of leading zeroes (0 to 32)
497  *****************************************************************************/
498  #define HapiClz(x) (P_HAPITAB->pClz((x)))
499 
500  // int32_t HapiSbSetUpdateImageAddress(uint32_t addr)
501  /*!***************************************************************************
502  * \brief Set the update image address in the 3v3 flags
503  *
504  * \param[in] addr
505  * Address pointing to the image you wish for ROM to verify and
506  * update to
507  *
508  * \return
509  * The new value of the update image address
510  *****************************************************************************/
511  #define HapiSbSetUpdateImageAddress(addr) (P_HAPITAB->pSbSetUpdateImageAddress((addr)))
512 
513  // uint32_t HapiSbGetUpdateImageAddress(void)
514  /*!***************************************************************************
515  * \brief Get the current update image address from the 3v3 flags
516  *
517  * \return
518  * The current value of update image address
519  *****************************************************************************/
520  #define HapiSbGetUpdateImageAddress() (P_HAPITAB->pSbGetUpdateImageAddress())
521 
522  // int32_t HapiSbSetId(uint32_t id)
523  /*!***************************************************************************
524  * \brief Set the update request ID field in the 3v3 flags
525  *
526  * \param[in] id
527  * The ID of the request you wish for ROM to do
528  *
529  * \return
530  * The new value of the update request ID
531  *****************************************************************************/
532  #define HapiSbSetId(id) (P_HAPITAB->pSbSetId((id)))
533 
534  // uint32_t HapiSbGetId(void)
535  /*!***************************************************************************
536  * \brief Get the current update request ID from the 3v3 flags
537  *
538  * \return
539  * The current value of the update request ID
540  *****************************************************************************/
541  #define HapiSbGetId() (P_HAPITAB->pSbGetId())
542 
543  // int32_t HapiSbSetStatus(uint32_t status)
544  /*!***************************************************************************
545  * \brief Set the update status field in the 3v3 flags
546  *
547  * \param[in] status
548  * The update status you wish to write to the 3v3 flags
549  *
550  * \return
551  * The new value of the update status
552  *****************************************************************************/
553  #define HapiSbSetStatus(status) (P_HAPITAB->pSbSetStatus((status)))
554 
555  // uint32_t HapiSbGetStatus(void)
556  /*!***************************************************************************
557  * \brief Get the current update status from the 3v3 flags
558  *
559  * \return
560  * The current value of the update status
561  *****************************************************************************/
562  #define HapiSbGetStatus() (P_HAPITAB->pSbGetStatus())
563 
564  // bool HapiSetTcmSync(bool syncVal)
565  /*!***************************************************************************
566  * \brief Set TCM sync value to facilitate TCM Gasket configuration
567  *
568  * This function must be called before and after updating the TCM Gasket config
569  * on the device. Calling this function with a `s` of 1 will prepare the TCM
570  * for reconfiguration. Calling this function with a `s` of 0 will complete the
571  * reconfiguration and synchronize the changes.
572  *
573  * \pre The caller must ensure that all bus masters are disabled and that all
574  * interrupts are disabled prior to calling this function
575  *
576  * \param[in] syncVal
577  * The new sync value [0, 1]
578  *
579  * \return
580  * The result of the operation. True if it was successfull and false otherwise
581  *****************************************************************************/
582  #define HapiSetTcmSync(syncVal) (P_HAPITAB->pSetTcmSync((syncVal)))
583 
584 #else
585 //*****************************************************************************
586 //
587 // Secure-only API functions available from non-secure context through
588 // veneers.
589 //
590 // These functions must be linked in from from the secure veneer library.
591 //
592 //*****************************************************************************
593 
594 extern void HapiWaitUs_veneer(uint32_t nUs);
595  #define HapiWaitUs HapiWaitUs_veneer
596 
597 #endif
598 
599 #endif //__HAPI_H__
__tz_c_veneer void HapiWaitUs_veneer(uint32_t nUs)
Definition: hapi_veneers.c:41
SHA256SW Object.
Definition: sha256sw.h:217
Definition: hapi.h:70
SHA2SW_HashType
Enum for the hash types supported by the library.
Definition: sha2sw_common.h:53