blob: 3544c2a9feee6b02741853597394c7dbbd30ddce [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __NVM_H__
8#define __NVM_H__
9
10#ifndef __ASSEMBLY__
11#include <stddef.h>
12#include <tftf.h>
13#include "tests_list.h"
14
15#define TEST_BUFFER_SIZE 0x80
16
17typedef struct {
18 /*
19 * @brief Last executed TFTF build message which consists of date and
20 * time when TFTF is built.
21 *
22 * A mismatch with the build message of currently executing binary will
23 * determine whether TFTF data structures stored in NVM needs to be
24 * initialised or not.
25 */
26 char build_message[BUILD_MESSAGE_SIZE];
27
28 /*
29 * The following 2 fields track the progress in the test session. They
30 * indicate which test case we are dealing with and the progress of this
31 * test, i.e. whether it hasn't started yet, or it is being executed
32 * right now, ...
33 */
34 test_ref_t test_to_run;
35 test_progress_t test_progress;
36
37 /*
38 * @brief Scratch buffer for test internal use.
39 *
40 * A buffer that the test can use as a scratch area for whatever it is
41 * doing.
42 */
43 char testcase_buffer[TEST_BUFFER_SIZE];
44
45 /*
46 * @brief Results of tests.
47 *
48 * @note TESTCASE_RESULT_COUNT is defined in tests_list.h
49 * (auto-generated file).
50 */
51 TESTCASE_RESULT testcase_results[TESTCASE_RESULT_COUNT];
52
53 /*
54 * @brief Size of \a result_buffer.
55 */
56 unsigned result_buffer_size;
57
58 /*
59 * Buffer containing the output of all tests.
60 * Each test appends its output to the end of \a result_buffer.
61 * Tests which produce no output write nothing in \a result_buffer.
62 */
63 char *result_buffer;
64} tftf_state_t;
65
66/*
67 * Helper macros to access fields of \a tftf_state_t structure.
68 */
69#define TFTF_STATE_OFFSET(_field) offsetof(tftf_state_t, _field)
70
71/*
72 * Return 1 if we need to start a new test session;
73 * 0 if we need to resume an interrupted session.
74 */
75unsigned int new_test_session(void);
76
77/*
78 * @brief Initialize NVM if necessary.
79 *
80 * When TFTF is launched on the target, its data structures need
81 * to be initialised in NVM. However if some test resets the board
82 * (as part of its normal behaviour or because it crashed) then
83 * TFTF data structure must be left unchanged in order to resume
84 * the test session where it has been left.
85 *
86 * This function detects whether TFTF has just been launched and if so
87 * initialises its data structures. If TFTF has just reset then it does
88 * nothing.
89 *
90 * @return STATUS_SUCCESS on success, another status code on failure.
91 */
92STATUS tftf_init_nvm(void);
93
94/*
95 * @brief Clean NVM.
96 *
97 * Clean TFTF data structures in NVM.
98 * This function must be called when all tests have completed.
99 *
100 * @return STATUS_SUCCESS on success, another status code on failure.
101 */
102STATUS tftf_clean_nvm(void);
103
104/* Writes the buffer to the flash at offset with length equal to
105 * size
106 * Returns: STATUS_FAIL, STATUS_SUCCESS, STATUS_OUT_OF_RESOURCES
107 */
108STATUS tftf_nvm_write(unsigned long long offset, const void *buffer, size_t size);
109
110/* Reads the flash into buffer at offset with length equal to
111 * size
112 * Returns: STATUS_FAIL, STATUS_SUCCESS, STATUS_OUT_OF_RESOURCES
113 */
114STATUS tftf_nvm_read(unsigned long long offset, void *buffer, size_t size);
115#endif /*__ASSEMBLY__*/
116
117#endif