]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/sciclient/examples/sciclient_firmware_boot_TestApp/sciclient_firmware_boot_main.c
Migrating to SYSFW version v2020.05 and AM64 presilicon
[processor-sdk/pdk.git] / packages / ti / drv / sciclient / examples / sciclient_firmware_boot_TestApp / sciclient_firmware_boot_main.c
1 /*
2  *  Copyright (C) 2017-2018 Texas Instruments Incorporated
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
34 /**
35  *  \file sciclient_firmware_boot_main.c
36  *
37  *  \brief Implementation of System firmware boot test
38  *
39  */
41 /* ========================================================================== */
42 /*                             Include Files                                  */
43 /* ========================================================================== */
45 #include <stdint.h>
46 #include <string.h>
47 #include <ti/csl/tistdtypes.h>
48 #include <ti/csl/soc.h>
49 #include <ti/csl/arch/csl_arch.h>
50 #include <ti/csl/hw_types.h>
51 #include <ti/osal/CacheP.h>
52 #include <ti/drv/sciclient/examples/common/sciclient_appCommon.h>
53 #include <ti/osal/TimerP.h>
55 #if defined(BUILD_MCU1_0) && defined(SOC_AM65XX)
56 #include <ti/drv/mmcsd/MMCSD.h>
57 #include <ti/drv/mmcsd/soc/MMCSD_soc.h>
58 #include <ti/drv/mmcsd/src/MMCSD_osal.h>
60 /* FATFS header file */
61 #include <ti/fs/fatfs/ff.h>
62 #include <ti/fs/fatfs/FATFS.h>
63 #include <ti/board/board.h>
64 #endif
66 /* ========================================================================== */
67 /*                           Macros & Typedefs                                */
68 /* ========================================================================== */
70 #if defined (SOC_AM64X)
71 #define PRINT_UART
72 #endif
74 /* ========================================================================== */
75 /*                            Global Variables                                */
76 /* ========================================================================== */
77 static volatile int32_t gTestStatus;
78 volatile static uint64_t time_usecs[5] = { 0 };
80 volatile uint32_t loop = 1U;
82 #pragma DATA_SECTION(gSciclient_firmware, ".firmware")
84 #if defined (BUILD_MCU1_0) && defined(SOC_AM65XX)
85 uint32_t gSciclient_firmware[SCICLIENT_FIRMWARE_SIZE_IN_BYTES/4];
87 /* MMCSD function table for MMCSD implementation */
88 FATFS_DrvFxnTable FATFS_drvFxnTable = {
89     &MMCSD_close,
90     &MMCSD_control,
91     &MMCSD_init,
92     &MMCSD_open,
93     &MMCSD_write,
94     &MMCSD_read
95 };
97 /* FATFS configuration structure */
98 FATFS_HwAttrs FATFS_initCfg[_VOLUMES] =
99 {
100     { 1U },
101     { 0U },
102     { 0U },
103     { 0U }
104 };
106 /* FATFS objects */
107 FATFS_Object FATFS_objects[_VOLUMES];
109 /* FATFS Handle */
110 FATFS_Handle sciclientTest_fatfsHandle = NULL;
112 /* FATFS configuration structure */
113 const FATFS_Config FATFS_config[_VOLUMES + 1] = {
114     {
115         &FATFS_drvFxnTable,
116         &FATFS_objects[0],
117         &FATFS_initCfg[0]
118     },
120     {
121          &FATFS_drvFxnTable,
122          &FATFS_objects[1],
123          &FATFS_initCfg[1]
124     },
126     {
127          &FATFS_drvFxnTable,
128          &FATFS_objects[2],
129          &FATFS_initCfg[2]
130     },
132     {NULL, NULL, NULL},
134     {NULL, NULL, NULL}
135 };
136 #else
137 uint32_t gSciclient_firmware[SCICLIENT_FIRMWARE_SIZE_IN_BYTES/4] = SCICLIENT_FIRMWARE;
138 #endif
139 /* ========================================================================== */
140 /*                         Structure Declarations                             */
141 /* ========================================================================== */
143 /* None */
145 /* ========================================================================== */
146 /*                          Function Declarations                             */
147 /* ========================================================================== */
148 static int32_t App_loadFirmwareTest(void);
149 #if defined(SOC_AM65XX)
150 int32_t sciclientTest_ReadSysfwImage(void *sysfw_ptr, uint32_t num_bytes);
151 #endif
152 void App_printPerfStats(void);
153 static int32_t App_boardCfgTest(void);
154 static int32_t App_getRevisionTestPol(void);
155 void _resetvectors (void);
158 /* ========================================================================== */
159 /*                          Function Definitions                              */
160 /* ========================================================================== */
161 /**
162  *  main
163  *  Application main function.
164  */
165 int32_t main(void)
167 #if defined (SOC_J721E)
168     /* Relocate CSL Vectors to ATCM*/
169     memcpy((void *)CSL_MCU_ARMSS_ATCM_BASE, (void *)_resetvectors, 0x100);
170 #elif defined (SOC_AM65XX)
171     /* Relocate CSL Vectors to ATCM*/
172     memcpy((void *)CSL_MCU_ATCM_BASE, (void *)_resetvectors, 0x100);
173     App_sciclientConsoleInit();
174 #else
175     /* Relocate CSL Vectors to ATCM*/
176     memcpy((void *)CSL_R5FSS0_ATCM_BASE, (void *)_resetvectors, 0x100);
177 #ifdef PRINT_UART
178     App_sciclientConsoleInit();
179 #endif
180 #endif
181     App_loadFirmwareTest();
182     App_getRevisionTestPol();
183     App_boardCfgTest();
184     #if defined(SOC_AM65XX)
185     App_printPerfStats();
186     #endif
187     
188     while (loop) {;}
189     
190     return 0;
193 /* ========================================================================== */
194 /*                 Internal Function Definitions                              */
195 /* ========================================================================== */
197 int32_t App_loadFirmwareTest(void)
199     uint64_t start_ticks=0, stop_ticks=0;
201     int32_t status = CSL_EFAIL;
202     void *sysfw_ptr = gSciclient_firmware;
204 #if defined(SOC_AM65XX)
205 #ifdef PRINT_UART
206     App_sciclientPrintf(
207                       "Make sure sysfw.bin is present in SD Card... \n");
208     App_sciclientPrintf(
209                       " Reading from SD Card... \n");
210 #endif
211     status = sciclientTest_ReadSysfwImage(sysfw_ptr, SCICLIENT_FIRMWARE_SIZE_IN_BYTES);
212     /*Do a cache writeback*/
213     CacheP_wbInv(sysfw_ptr, SCICLIENT_FIRMWARE_SIZE_IN_BYTES);
215     if (status != CSL_PASS)
216     {
217 #ifdef PRINT_UART
218         App_sciclientPrintf(
219                       " DMSC read from SD Card Failed... \n");
220 #endif
221     }
222     else
223     {
224 #ifdef PRINT_UART
225         App_sciclientPrintf(
226                        " DMSC Loading the Firmware... \n");
227 #endif
228     }
229     #else
230     sysfw_ptr = (void *)&gSciclient_firmware;
232     /*Do a cache writeback*/
233     CacheP_wbInv(sysfw_ptr, SCICLIENT_FIRMWARE_SIZE_IN_BYTES);
234     #endif
236     start_ticks = TimerP_getTimeInUsecs();
237     status = Sciclient_loadFirmware(sysfw_ptr);
238     stop_ticks = TimerP_getTimeInUsecs();
240     time_usecs[0U] = (stop_ticks-start_ticks);
242     start_ticks=0U;
243     stop_ticks=0U;
245     if (status == CSL_PASS)
246     {
247 #ifdef PRINT_UART
248         App_sciclientPrintf(
249                           " DMSC Loading the Firmware...SUCCESS \n");
250 #endif
251     }
252     else
253     {
254 #ifdef PRINT_UART
255         App_sciclientPrintf(
256                           " DMSC Loading the Firmware...FAILED \n");
257 #endif
258         while (loop) {;}
259     }
261     return status;
264 #if defined(SOC_AM65XX)
265 int32_t sciclientTest_ReadSysfwImage(void *sysfw_ptr, uint32_t num_bytes)
267     int32_t retVal = CSL_PASS;
268     const TCHAR *fileName = "0:/sysfw.bin";
269     FIL     fp;
270     FRESULT  fresult;
271     uint32_t bytes_read = 0;
272     MMCSD_v2_HwAttrs hwAttrsConfig;
274      if(MMCSD_socGetInitCfg(FATFS_initCfg[0].drvInst,&hwAttrsConfig)!=0) {
275        App_sciclientPrintf("\nUnable to get config.Exiting. TEST FAILED.\r\n");
276        retVal = CSL_EFAIL;
277      }
279     hwAttrsConfig.enableInterrupt = ((uint32_t)(0U));
280     hwAttrsConfig.configSocIntrPath=NULL;
282     if(MMCSD_socSetInitCfg(FATFS_initCfg[0].drvInst,&hwAttrsConfig)!=0) {
283        App_sciclientPrintf("\nUnable to set config.Exiting. TEST FAILED.\r\n");
284        retVal = CSL_EFAIL;
285      }
287     if (sciclientTest_fatfsHandle)
288     {
289     }
290     else
291     {
292         /* Initialization of the driver. */
293         FATFS_init();
295         /* MMCSD FATFS initialization */
296         FATFS_open(0U, NULL, &sciclientTest_fatfsHandle);
297     }
299     fresult = f_open(&fp, fileName, ((BYTE)FA_READ));
300     if (fresult != FR_OK)
301     {
302         App_sciclientPrintf("\n SD Boot - sysfw File open fails \n");
303        retVal = CSL_EFAIL;
304     }
305     fresult  = f_read(&fp, sysfw_ptr, num_bytes, &bytes_read);
306     if (fresult != FR_OK)
307     {
308         App_sciclientPrintf("\n SD Boot - sysfw read fails \n");
309        retVal = CSL_EFAIL;
310     }
312     f_close(&fp);
314     return retVal;
316 #endif
318 int32_t App_getRevisionTestPol(void)
320     uint64_t start_ticks=0, stop_ticks=0;
322     int32_t status = CSL_EFAIL;
323     Sciclient_ConfigPrms_t        config =
324     {
325         SCICLIENT_SERVICE_OPERATION_MODE_POLLED,
326         NULL
327     };
329     struct tisci_msg_version_req request;
330     const Sciclient_ReqPrm_t      reqPrm =
331     {
332         TISCI_MSG_VERSION,
333         TISCI_MSG_FLAG_AOP,
334         (uint8_t *) &request,
335         sizeof(request),
336         SCICLIENT_SERVICE_WAIT_FOREVER
337     };
339     struct tisci_msg_version_resp response;
340     Sciclient_RespPrm_t           respPrm =
341     {
342         0,
343         (uint8_t *) &response,
344         sizeof (response)
345     };
346  
348     start_ticks = TimerP_getTimeInUsecs();
349     status = Sciclient_init(&config);
350     stop_ticks = TimerP_getTimeInUsecs();
352     time_usecs[1] = (stop_ticks-start_ticks);
354     start_ticks=0U;
355     stop_ticks=0U;
357     if (status == CSL_PASS)
358     {
359         start_ticks = TimerP_getTimeInUsecs();
360         status = Sciclient_service(&reqPrm, &respPrm);
361         stop_ticks = TimerP_getTimeInUsecs();
363         time_usecs[2] = (stop_ticks-start_ticks);
365         start_ticks=0U;
366         stop_ticks=0U;
368         if (CSL_PASS == status)
369         {
370             if (respPrm.flags == TISCI_MSG_FLAG_ACK)
371             {
372                 status = CSL_PASS;
373 #ifdef PRINT_UART
374                 App_sciclientPrintf(
375                                   " DMSC Firmware Version %s\n",
376                                   (char *) response.str);
377                 App_sciclientPrintf(
378                                   " Firmware revision 0x%x\n", response.version);
379                 App_sciclientPrintf(
380                                   " ABI revision %d.%d\n", response.abi_major,
381                                   response.abi_minor);
382 #endif
383             }
384             else
385             {
386                 while (loop) {;}
387 #ifdef PRINT_UART
388                 App_sciclientPrintf(
389                                   " DMSC Firmware Get Version failed \n");
390 #endif
391             }
392         }
393         else
394         {
395             while (loop) {;}
396 #ifdef PRINT_UART
397             App_sciclientPrintf(
398                               " DMSC Firmware Get Version failed \n");
399 #endif
400         }
401     }
402     if (status == CSL_PASS)
403     {
404         start_ticks = TimerP_getTimeInUsecs();
405         status = Sciclient_deinit();
406         stop_ticks = TimerP_getTimeInUsecs();
408         time_usecs[3] = (stop_ticks-start_ticks);
410         start_ticks=0U;
411         stop_ticks=0U;
412     }
413     return status;
416 int32_t App_boardCfgTest(void)
418     int32_t status = CSL_PASS;
419     int32_t temp_status = CSL_EFAIL;
421     uint64_t start_ticks=0U, stop_ticks=0U;
423     Sciclient_ConfigPrms_t        config =
424     {
425         SCICLIENT_SERVICE_OPERATION_MODE_POLLED,
426         NULL
427     };
429     if (Sciclient_init(&config) == CSL_PASS)
430     {
431 #ifdef PRINT_UART
432         App_sciclientPrintf(
433                           "Sciclient init...PASSED \n");
434 #endif
436         start_ticks = TimerP_getTimeInUsecs();
437         temp_status = Sciclient_boardCfg(NULL);
438         stop_ticks = TimerP_getTimeInUsecs();
439         time_usecs[4] = (stop_ticks-start_ticks);
441         start_ticks=0U;
442         stop_ticks=0U;
444         if (temp_status == CSL_PASS)
445         {
446 #ifdef PRINT_UART
447             App_sciclientPrintf(
448                               " Board configuration test...PASSED \n");
449 #endif
450         }
451         else
452         {
453             while (loop) {;}
454 #ifdef PRINT_UART
455             App_sciclientPrintf(
456                               " Board configuration test...FAILED \n");
457 #endif
458             status = CSL_EFAIL;
459         }
460         if (Sciclient_boardCfgPm(NULL) == CSL_PASS)
461         {
462 #ifdef PRINT_UART
463             App_sciclientPrintf(
464                               " Board configuration for PM test...PASSED \n");
465 #endif
466         }
467         else
468         {
469             while (loop) {;}
470 #ifdef PRINT_UART
471             App_sciclientPrintf(
472                               " Board configuration for PM test...FAILED \n");
473 #endif
474             status = CSL_EFAIL;
475         }
477         if (Sciclient_boardCfgRm(NULL) == CSL_PASS)
478         {
479 #ifdef PRINT_UART
480             App_sciclientPrintf(
481                               " Board configuration for RM test...PASSED \n");
482 #endif
483         }
484         else
485         {
486             while (loop) {;}
487 #ifdef PRINT_UART
488             App_sciclientPrintf(
489                               " Board configuration for RM test...FAILED \n");
490 #endif
491             status = CSL_EFAIL;
492         }
493         if (Sciclient_boardCfgSec(NULL) == CSL_PASS)
494         {
495 #ifdef PRINT_UART
496             App_sciclientPrintf(
497                               " Board configuration for SECURITY test......PASSED \n");
498 #endif
499         }
500         else
501         {
502             while (loop) {;}
503 #ifdef PRINT_UART
504             App_sciclientPrintf(
505                               " Board configuration for SECURITY test...FAILED \n");
506 #endif
507             status = CSL_EFAIL;
508         }
509     }
510     else
511     {
512         while (loop) {;}
513 #ifdef PRINT_UART
514         App_sciclientPrintf(
515                           "Sciclient init...FAILED \n");
516 #endif
517         status = CSL_EFAIL;
518     }
519     Sciclient_deinit();
520     return status;
523 void App_printPerfStats()
525 #ifdef PRINT_UART
526     App_sciclientPrintf("\n======================================\n");
527     App_sciclientPrintf("           PERFORMANCE OF APIS          \n");
528     App_sciclientPrintf("======================================\n");
530     App_sciclientPrintf("Sciclient_loadFirmware |   %llu us    \n", time_usecs[0]);
531     App_sciclientPrintf("Sciclient_init         |   %llu us    \n", time_usecs[1]);
532     App_sciclientPrintf("Sciclient_service      |   %llu us    \n", time_usecs[2]);
533     App_sciclientPrintf("Sciclient_deinit       |   %llu us    \n", time_usecs[3]);
534     App_sciclientPrintf("Sciclient_boardCfg     |   %llu us    \n", time_usecs[4]);
535     App_sciclientPrintf("======================================\n\n Note: Here Sciclient_service is done for getRevision(Polling).\n");
536 #endif