[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / boot / sbl / src / qspi / sbl_qspi.c
1 /**
2 * \file sbl_qspi.c
3 *
4 * \brief This file contains functions for QSPI read/write operations for SBL
5 *
6 */
8 /*
9 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the
21 * distribution.
22 *
23 * Neither the name of Texas Instruments Incorporated nor the names of
24 * its contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 */
41 /* ========================================================================== */
42 /* Include Files */
43 /* ========================================================================== */
44 #include <stdint.h>
46 /* TI-RTOS Header files */
47 #include <ti/drv/spi/SPI.h>
48 #include <ti/drv/spi/soc/QSPI_v1.h>
49 #include <ti/drv/spi/src/SPI_osal.h>
51 /* SBL Header files. */
52 #include "sbl_image_copy.h"
53 #include "sbl_rprc_parse.h"
54 #include "sbl_soc.h"
56 /* Macro representing the offset where the App Image has to be written/Read from
57 the QSPI Flash.
58 */
59 #define QSPI_OFFSET_SI (0x80000)
61 /* QSPI Flash Read Sector API. */
62 int32_t SBL_QSPI_ReadSectors(void *dstAddr,
63 void *srcOffsetAddr,
64 uint32_t length);
66 /* Initialize the QSPI driver and the controller. */
67 void SBL_QSPI_Initialize();
69 /* Sets the src address to the given offset address. */
70 void SBL_QSPI_seek(void *srcAddr, uint32_t location);
72 int32_t SBL_QSPI_ReadSectors(void *dstAddr,
73 void *srcOffsetAddr,
74 uint32_t length);
76 void *boardHandle;
78 int32_t SBL_QSPIBootImage(sblEntryPoint_t *pEntry)
79 {
80 int32_t retVal;
81 uint32_t offset = QSPI_OFFSET_SI;
83 /* Initialization of the driver. */
84 SBL_QSPI_Initialize();
86 retVal = SBL_MulticoreImageParse((void *) &offset, QSPI_OFFSET_SI, pEntry);
88 /* Close the QSPI driver */
89 SBL_qspiClose(&boardHandle);
91 return retVal;
92 }
94 void SBL_QSPI_Initialize()
95 {
96 SBL_qspiInit(&boardHandle);
98 /* Initialize the function pointers to parse through the RPRC format. */
99 fp_readData = &SBL_QSPI_ReadSectors;
100 fp_seek = &SBL_QSPI_seek;
101 }
103 int32_t SBL_QSPI_ReadSectors(void *dstAddr,
104 void *srcOffsetAddr,
105 uint32_t length)
106 {
107 int32_t ret;
108 ret = SBL_qspiFlashRead(&boardHandle, (uint8_t *) dstAddr, length,
109 *((uint32_t *) srcOffsetAddr));
110 *((uint32_t *) srcOffsetAddr) += length;
111 return ret;
112 }
114 void SBL_QSPI_seek(void *srcAddr, uint32_t location)
115 {
116 *((uint32_t *) srcAddr) = location;
117 }