source: rtems/c/src/lib/libbsp/arm/beagle/startup/bspstarthooks.c @ 7a66986

4.115
Last change on this file since 7a66986 was 7a66986, checked in by Claas Ziemke <ziemke@…>, on 08/22/12 at 12:39:02

Added BeagleBoard? BSP

Coding done in course of GSoC2012.

Commit edited to be brought up-to-date with mainline by
Ben Gras <beng@…>.

  • Property mode set to 100644
File size: 9.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup beagle
5 *
6 * @brief Startup code.
7 */
8
9/*
10 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
11 *
12 *  Claas Ziemke
13 *  Kernerstrasse 11
14 *  70182 Stuttgart
15 *  Germany
16 *  <claas.ziemke@gmx.net>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#include <bsp.h>
24#include <bsp/start.h>
25#include <bsp/beagle.h>
26#include <bsp/linker-symbols.h>
27#include <bsp/uart-output-char.h>
28#include <libcpu/arm-cp15.h>
29
30#ifdef BEAGLE_DISABLE_READ_WRITE_DATA_CACHE
31  #define BEAGLE_MMU_READ_WRITE_DATA BEAGLE_MMU_READ_WRITE
32#else
33  #define BEAGLE_MMU_READ_WRITE_DATA BEAGLE_MMU_READ_WRITE_CACHED
34#endif
35
36#ifdef BEAGLE_DISABLE_READ_ONLY_PROTECTION
37  #define BEAGLE_MMU_READ_ONLY_DATA BEAGLE_MMU_READ_WRITE_CACHED
38  #define BEAGLE_MMU_CODE BEAGLE_MMU_READ_WRITE_CACHED
39#else
40  #define BEAGLE_MMU_READ_ONLY_DATA BEAGLE_MMU_READ_ONLY_CACHED
41  #define BEAGLE_MMU_CODE BEAGLE_MMU_READ_ONLY_CACHED
42#endif
43
44//LINKER_SYMBOL(beagle_translation_table_base);
45
46static BSP_START_TEXT_SECTION void clear_bss(void)
47{
48  const int *end = (const int *) bsp_section_bss_end;
49  int *out = (int *) bsp_section_bss_begin;
50
51  /* Clear BSS */
52  while (out != end) {
53    *out = 0;
54    ++out;
55  }
56}
57
58/*#ifndef BEAGLE_DISABLE_MMU
59  typedef struct {
60    uint32_t begin;
61    uint32_t end;
62    uint32_t flags;
63  } beagle_mmu_config;
64
65  static const BSP_START_DATA_SECTION beagle_mmu_config
66    beagle_mmu_config_table [] = {
67    {
68      .begin = (uint32_t) bsp_section_fast_text_begin,
69      .end = (uint32_t) bsp_section_fast_text_end,
70      .flags = BEAGLE_MMU_CODE
71    }, {
72      .begin = (uint32_t) bsp_section_fast_data_begin,
73      .end = (uint32_t) bsp_section_fast_data_end,
74      .flags = BEAGLE_MMU_READ_WRITE_DATA
75#ifdef BEAGLE_SCRATCH_AREA_SIZE
76    }, {
77      .begin = (uint32_t) &beagle_scratch_area [0],
78      .end = (uint32_t) &beagle_scratch_area [BEAGLE_SCRATCH_AREA_SIZE],
79      .flags = BEAGLE_MMU_READ_ONLY_DATA
80#endif
81    }, {
82      .begin = (uint32_t) bsp_section_start_begin,
83      .end = (uint32_t) bsp_section_start_end,
84      .flags = BEAGLE_MMU_CODE
85    }, {
86      .begin = (uint32_t) bsp_section_vector_begin,
87      .end = (uint32_t) bsp_section_vector_end,
88      .flags = BEAGLE_MMU_READ_WRITE_CACHED
89    }, {
90      .begin = (uint32_t) bsp_section_text_begin,
91      .end = (uint32_t) bsp_section_text_end,
92      .flags = BEAGLE_MMU_CODE
93    }, {
94      .begin = (uint32_t) bsp_section_rodata_begin,
95      .end = (uint32_t) bsp_section_rodata_end,
96      .flags = BEAGLE_MMU_READ_ONLY_DATA
97    }, {
98      .begin = (uint32_t) bsp_section_data_begin,
99      .end = (uint32_t) bsp_section_data_end,
100      .flags = BEAGLE_MMU_READ_WRITE_DATA
101    }, {
102      .begin = (uint32_t) bsp_section_bss_begin,
103      .end = (uint32_t) bsp_section_bss_end,
104      .flags = BEAGLE_MMU_READ_WRITE_DATA
105    }, {
106      .begin = (uint32_t) bsp_section_work_begin,
107      .end = (uint32_t) bsp_section_work_end,
108      .flags = BEAGLE_MMU_READ_WRITE_DATA
109    }, {
110      .begin = (uint32_t) bsp_section_stack_begin,
111      .end = (uint32_t) bsp_section_stack_end,
112      .flags = BEAGLE_MMU_READ_WRITE_DATA
113    }, {
114      .begin = 0x0U,
115      .end = 0x100000U,
116      .flags = BEAGLE_MMU_READ_ONLY_CACHED
117    }, {
118      .begin = 0x20000000U,
119      .end = 0x200c0000U,
120      .flags = BEAGLE_MMU_READ_WRITE
121    }, {
122      .begin = 0x30000000U,
123      .end = 0x32000000U,
124      .flags = BEAGLE_MMU_READ_WRITE
125    }, {
126      .begin = 0x40000000U,
127      .end = 0x40100000U,
128      .flags = BEAGLE_MMU_READ_WRITE
129    }, {
130      .begin = (uint32_t) beagle_magic_zero_begin,
131      .end = (uint32_t) beagle_magic_zero_end,
132      .flags = BEAGLE_MMU_READ_WRITE_DATA
133    }
134  };
135
136  static BSP_START_TEXT_SECTION void set_translation_table_entries(
137    uint32_t *ttb,
138    const beagle_mmu_config *config
139  )
140  {
141    uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin);
142    uint32_t iend =
143      ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
144
145    if (config->begin != config->end) {
146      while (i < iend) {
147        ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags;
148        ++i;
149      }
150    }
151  }
152
153  static BSP_START_TEXT_SECTION void
154    setup_translation_table_and_enable_mmu(uint32_t ctrl)
155  {
156    uint32_t const dac =
157      ARM_CP15_DAC_DOMAIN(BEAGLE_MMU_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT);
158    uint32_t *const ttb = (uint32_t *) beagle_translation_table_base;
159    size_t const config_entry_count =
160      sizeof(beagle_mmu_config_table) / sizeof(beagle_mmu_config_table [0]);
161    size_t i = 0;
162
163    arm_cp15_set_domain_access_control(dac);
164    arm_cp15_set_translation_table_base(ttb);
165
166    // Initialize translation table with invalid entries
167    for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
168      ttb [i] = 0;
169    }
170
171    for (i = 0; i < config_entry_count; ++i) {
172      set_translation_table_entries(ttb, &beagle_mmu_config_table [i]);
173    }
174
175    // Enable MMU and cache
176    ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
177    arm_cp15_set_control(ctrl);
178  }
179#endif*/
180
181/*static BSP_START_TEXT_SECTION void setup_mmu_and_cache(void)
182{
183  uint32_t ctrl = 0;
184
185  // Disable MMU and cache, basic settings
186  ctrl = arm_cp15_get_control();
187  ctrl &= ~(ARM_CP15_CTRL_I | ARM_CP15_CTRL_R | ARM_CP15_CTRL_C
188    | ARM_CP15_CTRL_V | ARM_CP15_CTRL_M);
189  ctrl |= ARM_CP15_CTRL_S | ARM_CP15_CTRL_A;
190  arm_cp15_set_control(ctrl);
191
192  arm_cp15_cache_invalidate();
193  arm_cp15_tlb_invalidate();
194
195  #ifndef BEAGLE_DISABLE_MMU
196    //setup_translation_table_and_enable_mmu(ctrl);
197  #endif
198}*/
199
200/*BSP_START_TEXT_SECTION bool beagle_start_pll_setup(
201  uint32_t hclkpll_ctrl,
202  uint32_t hclkdiv_ctrl,
203  bool force
204)
205{
206  uint32_t pwr_ctrl = BEAGLE_PWR_CTRL;
207  bool settings_ok =
208    ((BEAGLE_HCLKPLL_CTRL ^ hclkpll_ctrl) & BSP_MSK32(1, 16)) == 0
209      && ((BEAGLE_HCLKDIV_CTRL ^ hclkdiv_ctrl) & BSP_MSK32(0, 8)) == 0;
210
211  if ((pwr_ctrl & PWR_NORMAL_RUN_MODE) == 0 || (!settings_ok && force)) {
212    // Disable HCLK PLL output
213    BEAGLE_PWR_CTRL = pwr_ctrl & ~PWR_NORMAL_RUN_MODE;
214
215    // Configure HCLK PLL
216    BEAGLE_HCLKPLL_CTRL = hclkpll_ctrl;
217    while ((BEAGLE_HCLKPLL_CTRL & HCLK_PLL_LOCK) == 0) {
218      // Wait
219    }
220
221    // Setup HCLK divider
222    BEAGLE_HCLKDIV_CTRL = hclkdiv_ctrl;
223
224    // Enable HCLK PLL output
225    BEAGLE_PWR_CTRL = pwr_ctrl | PWR_NORMAL_RUN_MODE;
226  }
227
228  return settings_ok;
229}*/
230
231#if BEAGLE_OSCILLATOR_MAIN != 13000000U
232  #error "unexpected main oscillator frequency"
233#endif
234
235/*static BSP_START_TEXT_SECTION void setup_pll(void)
236{
237  uint32_t hclkpll_ctrl = BEAGLE_HCLKPLL_CTRL_INIT_VALUE;
238  uint32_t hclkdiv_ctrl = BEAGLE_HCLKDIV_CTRL_INIT_VALUE;
239
240  beagle_start_pll_setup(hclkpll_ctrl, hclkdiv_ctrl, false);
241}*/
242
243BSP_START_TEXT_SECTION void bsp_start_hook_0(void)
244{
245  //setup_pll();
246  //setup_mmu_and_cache();
247}
248
249/*static BSP_START_TEXT_SECTION void stop_dma_activities(void)
250{
251  #ifdef BEAGLE_STOP_GPDMA
252    BEAGLE_DO_STOP_GPDMA;
253  #endif
254
255  #ifdef BEAGLE_STOP_ETHERNET
256    BEAGLE_DO_STOP_ETHERNET;
257  #endif
258
259  #ifdef BEAGLE_STOP_USB
260    BEAGLE_DO_STOP_USB;
261  #endif
262}*/
263
264static BSP_START_TEXT_SECTION void setup_uarts(void)
265{
266  uint32_t uartclk_ctrl = 0;
267
268  #ifdef BEAGLE_CONFIG_U3CLK
269    uartclk_ctrl |= 1U << 0;
270    BEAGLE_U3CLK = BEAGLE_CONFIG_U3CLK;
271  #endif
272  #ifdef BEAGLE_CONFIG_U4CLK
273    uartclk_ctrl |= 1U << 1;
274    BEAGLE_U4CLK = BEAGLE_CONFIG_U4CLK;
275  #endif
276  #ifdef BEAGLE_CONFIG_U5CLK
277    uartclk_ctrl |= 1U << 2;
278    BEAGLE_U5CLK = BEAGLE_CONFIG_U5CLK;
279  #endif
280  #ifdef BEAGLE_CONFIG_U6CLK
281    uartclk_ctrl |= 1U << 3;
282    BEAGLE_U6CLK = BEAGLE_CONFIG_U6CLK;
283  #endif
284
285  #ifdef BEAGLE_CONFIG_UART_CLKMODE
286    BEAGLE_UART_CLKMODE = BEAGLE_CONFIG_UART_CLKMODE;
287  #endif
288
289  BEAGLE_UARTCLK_CTRL = uartclk_ctrl;
290  BEAGLE_UART_CTRL = 0x0;
291  BEAGLE_UART_LOOP = 0x0;
292
293  #ifdef BEAGLE_CONFIG_U5CLK
294    // Clock is already set in BEAGLE_U5CLK
295    BSP_CONSOLE_UART_INIT(0x01);
296  #endif
297}
298
299/*static BSP_START_TEXT_SECTION void setup_timer(void)
300{
301  volatile beagle_timer *timer = BEAGLE_STANDARD_TIMER;
302
303  BEAGLE_TIMCLK_CTRL1 = (1U << 2) | (1U << 3);
304
305  timer->tcr = BEAGLE_TIMER_TCR_RST;
306  timer->ctcr = 0x0;
307  timer->pr = 0x0;
308  timer->ir = 0xff;
309  timer->mcr = 0x0;
310  timer->ccr = 0x0;
311  timer->tcr = BEAGLE_TIMER_TCR_EN;
312}*/
313
314BSP_START_TEXT_SECTION void bsp_start_hook_1(void)
315{
316  //stop_dma_activities();
317  setup_uarts();
318  //setup_timer();
319
320  // Copy .text section
321  arm_cp15_instruction_cache_invalidate();
322  bsp_start_memcpy(
323    (int *) bsp_section_text_begin,
324    (const int *) bsp_section_text_load_begin,
325    (size_t) bsp_section_text_size
326  );
327
328  // Copy .rodata section
329  arm_cp15_instruction_cache_invalidate();
330  bsp_start_memcpy(
331    (int *) bsp_section_rodata_begin,
332    (const int *) bsp_section_rodata_load_begin,
333    (size_t) bsp_section_rodata_size
334  );
335
336  // Copy .data section
337  arm_cp15_instruction_cache_invalidate();
338  bsp_start_memcpy(
339    (int *) bsp_section_data_begin,
340    (const int *) bsp_section_data_load_begin,
341    (size_t) bsp_section_data_size
342  );
343
344  // Copy .fast_text section
345  arm_cp15_instruction_cache_invalidate();
346  bsp_start_memcpy(
347    (int *) bsp_section_fast_text_begin,
348    (const int *) bsp_section_fast_text_load_begin,
349    (size_t) bsp_section_fast_text_size
350  );
351
352  // Copy .fast_data section
353  arm_cp15_instruction_cache_invalidate();
354  bsp_start_memcpy(
355    (int *) bsp_section_fast_data_begin,
356    (const int *) bsp_section_fast_data_load_begin,
357    (size_t) bsp_section_fast_data_size
358  );
359
360  // Clear .bss section
361  clear_bss();
362
363
364
365  // At this point we can use objects outside the .start section
366}
Note: See TracBrowser for help on using the repository browser.