source: rtems/bsps/arm/raspberrypi/start/bspstarthooks.c @ 19efa9a0

5
Last change on this file since 19efa9a0 was 19efa9a0, checked in by G S Niteesh Babu <niteesh.gs@…>, on 03/28/20 at 18:24:07

bsp/raspberrypi: Fix build warnings.

1) _Memory_Initialize makes pointer from integer

without a cast.

2) printf format error, expects %u but %lu provided.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_start
5 *
6 * @brief Rasberry Pi startup code.
7 */
8
9/*
10 * Copyright (c) 2013. Hesham AL-Matary
11 * Copyright (c) 2013 by Alan Cudmore
12 * based on work by:
13 * Copyright (c) 2009
14 * embedded brains GmbH
15 * Obere Lagerstr. 30
16 * D-82178 Puchheim
17 * Germany
18 * <rtems@embedded-brains.de>
19 *
20 * The license and distribution terms for this file may be
21 * found in the file LICENSE in this distribution or at
22 * http://www.rtems.org/license/LICENSE
23 */
24
25#include <bspopts.h>
26#include <bsp/start.h>
27#include <bsp/raspberrypi.h>
28#include <libcpu/arm-cp15.h>
29#include <bsp.h>
30#include <bsp/bootcard.h>
31#include <bsp/linker-symbols.h>
32#include <bsp/arm-cp15-start.h>
33
34#include <rtems/sysinit.h>
35
36#ifdef RTEMS_SMP
37#include <rtems/score/smp.h>
38#endif
39
40#if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
41  #define USE_UBOOT
42#endif
43
44#ifdef USE_UBOOT
45  #include <bsp/u-boot.h>
46#else
47  #include <bsp/vc.h>
48#endif
49
50BSP_START_DATA_SECTION static arm_cp15_start_section_config
51raspberrypi_mmu_config_table[] = {
52  ARMV7_CP15_START_DEFAULT_SECTIONS,
53  {
54    .begin = RPI_PERIPHERAL_BASE,
55    .end =   RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE,
56    .flags = ARMV7_MMU_DEVICE
57  }
58#if (BSP_IS_RPI2 == 1)
59  /* Core local peripherals area - timer, mailboxes */
60  , {
61    .begin = BCM2836_CORE_LOCAL_PERIPH_BASE,
62    .end =   BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE,
63    .flags = ARMV7_MMU_DEVICE
64  }
65#endif
66};
67
68void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
69{
70  uint32_t sctlr_val;
71#ifdef RTEMS_SMP
72  uint32_t cpu_index_self = _SMP_Get_current_processor();
73#endif /* RTEMS_SMP */
74
75  sctlr_val = arm_cp15_get_control();
76
77  /*
78   * Current U-boot loader seems to start kernel image
79   * with I and D caches on and MMU enabled.
80   * If RTEMS application image finds that cache is on
81   * during startup then disable caches.
82   */
83  if (sctlr_val & (ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M)) {
84    if (sctlr_val & (ARM_CP15_CTRL_C | ARM_CP15_CTRL_M)) {
85      /*
86       * If the data cache is on then ensure that it is clean
87       * before switching off to be extra carefull.
88       */
89#ifdef RTEMS_SMP
90      if (cpu_index_self != 0) {
91        arm_cp15_data_cache_clean_level(0);
92        arm_cp15_cache_invalidate_level(0, 0);
93      } else
94#endif /* RTEMS_SMP */
95      {
96        rtems_cache_flush_entire_data();
97        rtems_cache_invalidate_entire_data();
98      }
99    }
100    arm_cp15_flush_prefetch_buffer();
101    sctlr_val &= ~(ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M | ARM_CP15_CTRL_A);
102    arm_cp15_set_control(sctlr_val);
103  }
104#ifdef RTEMS_SMP
105  if (cpu_index_self != 0) {
106    arm_cp15_cache_invalidate_level(0, 0);
107  } else
108#endif /* RTEMS_SMP */
109  {
110    rtems_cache_invalidate_entire_data();
111  }
112  rtems_cache_invalidate_entire_instruction();
113  arm_cp15_branch_predictor_invalidate_all();
114  arm_cp15_tlb_invalidate();
115  arm_cp15_flush_prefetch_buffer();
116
117  /* Clear Translation Table Base Control Register */
118  arm_cp15_set_translation_table_base_control_register(0);
119
120  /* Clear Secure or Non-secure Vector Base Address Register */
121  arm_cp15_set_vector_base_address(bsp_vector_table_begin);
122
123#ifdef RTEMS_SMP
124  if (cpu_index_self == 0) {
125    rpi_ipi_initialize();
126  } else {
127    rpi_start_rtems_on_secondary_processor();
128  }
129#endif
130}
131
132BSP_START_TEXT_SECTION static uintptr_t raspberrypi_get_ram_end(void)
133{
134  uintptr_t ram_end;
135
136#ifdef USE_UBOOT
137  ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
138                        bsp_uboot_board_info.bi_memsize;
139#else
140  bcm2835_get_arm_memory_entries spec;
141
142  if (bcm2835_mailbox_get_arm_memory( &spec ) >= 0) {
143    ram_end = spec.base + spec.size;
144  } else {
145    /* Use the workspace end from the linker command file for fallback. */
146    ram_end = (uintptr_t) bsp_section_work_end;
147  }
148#endif
149
150  return ram_end;
151}
152
153BSP_START_TEXT_SECTION static void bsp_memory_management_initialize(void)
154{
155  uintptr_t ram_end = raspberrypi_get_ram_end();
156  uint32_t ctrl = arm_cp15_get_control();
157
158  ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
159
160  raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
161    ram_end;
162
163  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
164    ctrl,
165    (uint32_t *) bsp_translation_table_base,
166    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
167    &raspberrypi_mmu_config_table[0],
168    RTEMS_ARRAY_SIZE(raspberrypi_mmu_config_table)
169  );
170}
171
172void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
173{
174  bsp_start_copy_sections();
175  bsp_memory_management_initialize();
176  bsp_start_clear_bss();
177
178  rpi_video_init();
179}
180
181static Memory_Area _Memory_Areas[1];
182
183static void bsp_memory_initialize(void)
184{
185  _Memory_Initialize(
186    &_Memory_Areas[0],
187    (void *)
188    raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
189    (void *)
190    raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
191  );
192}
193
194RTEMS_SYSINIT_ITEM(
195  bsp_memory_initialize,
196  RTEMS_SYSINIT_MEMORY,
197  RTEMS_SYSINIT_ORDER_MIDDLE
198);
199
200static const Memory_Information _Memory_Information =
201  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
202
203const Memory_Information *_Memory_Get(void)
204{
205  return &_Memory_Information;
206}
Note: See TracBrowser for help on using the repository browser.