[keystone-rtos/mcsdk-tools.git] / boot_loader / examples / srio / srioboot_ddrinit / src / srioboot_ddrinit.c
1 /******************************************************************************
2 * Copyright (c) 2011 Texas Instruments Incorporated - http://www.ti.com
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 emac 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 PURPOSE: SRIO Boot DDR Init Example
36 **************************************************************************************
37 * FILE NAME: srioboot_ddrinit.c
38 *
39 * DESCRIPTION: A simple example to initialize the DDR before booting an image via SRIO.
40 *
41 ***************************************************************************************/
42 #include <stdlib.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include "platform.h"
47 #define DEVICE_REG32_W(x,y) *(volatile uint32_t *)(x)=(y)
48 #define DEVICE_REG32_R(x) (*(volatile uint32_t *)(x))
50 #ifdef _EVMC6657L_
51 #define MAGIC_ADDR 0x8ffffc
52 #endif
54 #ifdef _EVMC6678L_
55 #define MAGIC_ADDR 0x87fffc
56 #endif
58 #ifdef _EVMC6670L_
59 #define MAGIC_ADDR 0x8ffffc
60 #endif
62 #define BOOT_MAGIC_ADDR(x) (MAGIC_ADDR + (1<<28) + (x<<24))
64 /* OSAL functions for Platform Library */
65 uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment)
66 {
67 return malloc(num_bytes);
68 }
70 void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes)
71 {
72 /* Free up the memory */
73 if (dataPtr)
74 {
75 free(dataPtr);
76 }
77 }
79 void Osal_platformSpiCsEnter(void)
80 {
81 return;
82 }
84 void Osal_platformSpiCsExit (void)
85 {
86 return;
87 }
89 void
90 start_boot
91 (
92 void
93 )
94 {
95 void (*exit)();
96 uint32_t entry_addr;
98 while(1)
99 {
100 entry_addr = DEVICE_REG32_R(BOOT_MAGIC_ADDR(0));
101 if (entry_addr != 0)
102 {
103 /* jump to the exit point, which will be the entry point for the full IBL */
104 exit = (void (*)())entry_addr;
105 (*exit)();
106 }
107 platform_delay(1);
108 }
109 }
111 /******************************************************************************
112 * Function: main
113 ******************************************************************************/
114 void main ()
115 {
116 platform_init_flags init_flags;
117 platform_init_config init_config;
119 /* Initialize main Platform lib */
120 memset(&init_config, 0, sizeof(platform_init_config));
121 memset(&init_flags, 1, sizeof(platform_init_flags));
122 init_flags.phy = 0;
123 if (platform_init(&init_flags, &init_config) != Platform_EOK)
124 {
125 printf ("Platform init failed!\n");
126 return;
127 }
129 /* Clear the boot entry address of the boot image and start to boot */
130 DEVICE_REG32_W(BOOT_MAGIC_ADDR(0), 0);
131 start_boot();
132 }