source: rtems/bsps/arm/imx/start/bspstarthooks.c @ eea21eac

5
Last change on this file since eea21eac was eea21eac, checked in by Sebastian Huber <sebastian.huber@…>, on 12/13/19 at 05:18:36

bsps: Rework work area initialization

The work area initialization was done by the BSP through
bsp_work_area_initialize(). This approach predated the system
initialization through the system initialization linker set. The
workspace and C program heap were unconditionally initialized. The aim
is to support RTEMS application configurations which do not need the
workspace and C program heap. In these configurations, the workspace
and C prgram heap should not get initialized.

Change all bsp_work_area_initialize() to implement _Memory_Get()
instead. Move the dirty memory, sbrk(), per-CPU data, workspace, and
malloc() heap initialization into separate system initialization steps.
This makes it also easier to test the individual initialization steps.

This change adds a dependency to _Heap_Extend() to all BSPs. This
dependency will be removed in a follow up change.

Update #3838.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2013, 2018 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#define ARM_CP15_TEXT_SECTION BSP_START_TEXT_SECTION
16
17#include <bsp.h>
18#include <bsp/bootcard.h>
19#include <bsp/fdt.h>
20#include <bsp/linker-symbols.h>
21#include <bsp/start.h>
22#include <bsp/arm-cp15-start.h>
23#include <bsp/arm-a9mpcore-start.h>
24
25#include <rtems/sysinit.h>
26
27#include <libfdt.h>
28
29BSP_START_DATA_SECTION static arm_cp15_start_section_config
30imx_mmu_config_table[] = {
31  ARMV7_CP15_START_DEFAULT_SECTIONS,
32  {
33    .begin = 0x07000000U,
34    .end = 0x70000000U,
35    .flags = ARMV7_MMU_DEVICE
36  }
37};
38
39BSP_START_DATA_SECTION static char memory_path[] = "/memory";
40
41BSP_START_TEXT_SECTION static void setup_mmu_and_cache(void)
42{
43  const void *fdt;
44  int node;
45  uint32_t ctrl;
46
47  fdt = bsp_fdt_get();
48  node = fdt_path_offset_namelen(
49    fdt,
50    memory_path,
51    (int) sizeof(memory_path) - 1
52  );
53
54  if (node >= 0) {
55    int len;
56    const void *val;
57
58    val = fdt_getprop(fdt, node, "reg", &len);
59    if (len == 8) {
60      uint32_t begin;
61      uint32_t size;
62
63      begin = fdt32_to_cpu(((fdt32_t *) val)[0]);
64      size = fdt32_to_cpu(((fdt32_t *) val)[1]);
65
66      /* The heap code does not like an end address of zero */
67      if (begin + size == 0) {
68        size -= 4;
69      }
70
71      imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
72        begin + size;
73    }
74  }
75
76  ctrl = arm_cp15_start_setup_mmu_and_cache(
77    ARM_CP15_CTRL_A,
78    ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z
79  );
80
81  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
82    ctrl,
83    (uint32_t *) bsp_translation_table_base,
84    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
85    &imx_mmu_config_table[0],
86    RTEMS_ARRAY_SIZE(imx_mmu_config_table)
87  );
88}
89
90BSP_START_TEXT_SECTION void bsp_start_hook_0(void)
91{
92#ifdef RTEMS_SMP
93  uint32_t cpu_id = arm_cortex_a9_get_multiprocessor_cpu_id();
94
95  arm_a9mpcore_start_enable_smp_in_auxiliary_control();
96
97  if (cpu_id != 0) {
98    arm_a9mpcore_start_on_secondary_processor();
99  }
100#endif
101}
102
103BSP_START_TEXT_SECTION void bsp_start_hook_1(void)
104{
105  arm_a9mpcore_start_set_vector_base();
106  bsp_start_copy_sections();
107  setup_mmu_and_cache();
108  bsp_start_clear_bss();
109}
110
111static Memory_Area _Memory_Areas[1];
112
113static void bsp_memory_initialize(void)
114{
115  _Memory_Initialize(
116    &_Memory_Areas[0],
117    imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
118    imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
119  );
120}
121
122RTEMS_SYSINIT_ITEM(
123  bsp_memory_initialize,
124  RTEMS_SYSINIT_MEMORY,
125  RTEMS_SYSINIT_ORDER_MIDDLE
126);
127
128static const Memory_Information _Memory_Information =
129  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
130
131const Memory_Information *_Memory_Get(void)
132{
133  return &_Memory_Information;
134}
Note: See TracBrowser for help on using the repository browser.