source: rtems-docs/bsp-howto/initilization_code.rst @ 4d2428a

5
Last change on this file since 4d2428a was 4d2428a, checked in by Sebastian Huber <sebastian.huber@…>, on 02/05/20 at 06:18:46

bsp-howto: Minor edit

Update #2852.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 2020 embedded brains GmbH
4.. Copyright (C) 2020 Sebastian Huber
5.. Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR)
6
7System Initialization
8*********************
9
10Introduction
11============
12
13The system initialization consists of a low-level initialization performed by
14the start code in the start file (:file:`start.o`) and a high-level
15initialization carried out by :c:func:`boot_card()`.  The final step of a
16successful high-level initialization is to switch to the initialization task
17and change into the normal system mode with multi-threading enabled.  Errors
18during system initialization are fatal and end up in a call to
19:c:func:`_Terminate()`.
20
21Low-Level Initialization via Start Code in the Start File (start.o)
22===================================================================
23
24The start code in the start file (:file:`start.o`) must be provided by the BSP.
25It is the first file presented to the linker and starts the process to link an
26executable (application image).  It should contain the entry symbol of the
27executable.  It is the responsibility of the linker script in conjunction with
28the compiler specifications file or compiler options to put the start code in
29the correct location in the executable.  The start code is typically written in
30assembly language since it will tinker with the stack pointer.  The general
31rule of thumb is that the start code in assembly language should do the minimum
32necessary to allow C code to execute to complete the initialization sequence.
33
34The low-level system initialization may depend on a platform initialization
35carried out by a boot loader.  The low-level system initialization may perform
36the following steps:
37
38* Initialize the initialization stack.  The initialization stack should use the
39  ISR stack area.  The symbols :c:macro:`_ISR_Stack_area_begin`,
40  :c:macro:`_ISR_Stack_area_end`, and :c:macro:`_ISR_Stack_size` should be used
41  to do this.
42
43* Initialize processor registers and modes.
44
45* Initialize pins.
46
47* Initialize clocks (PLLs).
48
49* Initialize memory controllers.
50
51* Initialize instruction, data, and unified caches.
52
53* Initialize memory management or protection units (MMU).
54
55* Initialize processor exceptions.
56
57* Copy the data sections from a read-only section to the runtime location.
58
59* Set the BSS (``.bss``) section to zero.
60
61* Initialize the C runtime environment.
62
63* Call :c:func:`boot_card()` to hand over to the high-level initialization.
64
65For examples of start file codes see:
66
67* `bsps/arm/shared/start/start.S <https://git.rtems.org/rtems/tree/bsps/arm/shared/start/start.S>`_
68
69* `bsps/riscv/shared/start/start.S <https://git.rtems.org/rtems/tree/bsps/riscv/shared/start/start.S>`_
70
71High-Level Initialization via boot_card()
72=========================================
73
74The high-level initialization is carried out by :c:func:`boot_card()`.  For the
75high-level initialization steps see the `Initialization Manager` chapter in the
76RTEMS Classic API Guide.  There are several system initialization steps which
77must be implemented by the BSP.
78
79Early BSP Initialization
80------------------------
81
82The BSP may provide a system initialization handler (order
83:c:macro:`RTEMS_SYSINIT_BSP_EARLY`) to perform an early BSP initialization.
84This handler is invoked before the memory information and high-level dynamic
85memory services (workspace and C program heap) are initialized.
86
87Memory Information
88------------------
89
90The BSP must provide the memory information to the system with an
91implementation of the :c:func:`_Memory_Get()` function.  The BSP should use the
92default implementation in
93`bsps/shared/shared/start/bspgetworkarea-default.c <https://git.rtems.org/rtems/tree/bsps/shared/start/bspgetworkarea-default.c>`_.
94The memory information is used by low-level memory consumers such as the
95per-CPU data, the workspace, and the C program heap.  The BSP may use a system
96initialization handler (order :c:macro:`RTEMS_SYSINIT_MEMORY`) to set up the
97infrastructure used by :c:func:`_Memory_Get()`.
98
99BSP Initialization
100------------------
101
102The BSP must provide an implementation of the :c:func:`bsp_start()` function.
103This function is registered as a system initialization handler (order
104:c:macro:`RTEMS_SYSINIT_BSP_START`) in the module implementing
105:c:func:`boot_card()`.  The :c:func:`bsp_start()` function should perform a
106general platform initialization.  The interrupt controllers are usually
107initialized here.  The C program heap may be used in this handler.  It is not
108allowed to create any operating system objects, e.g. RTEMS semaphores or tasks.
109The BSP may register additional system initialization handlers in the module
110implementing :c:func:`bsp_start()`.
111
112Error Handling
113==============
114
115Errors during system initialization are fatal and end up in a call to
116:c:func:`_Terminate()`.  See also the `Fatal Error Manager` chapter in the
117RTEMS Classic API Guide.
118
119The BSP may use BSP-specific fatal error codes, see
120`<bsp/fatal.h> <https://git.rtems.org/rtems/tree/bsps/include/bsp/fatal.h>`_.
121
122The BSP should provide an initial extension which implements a fatal error
123handler.  It should use the default implementation provided by
124`<bsp/default-initial-extension.h> <https://git.rtems.org/rtems/tree/bsps/include/bsp/default-initial-extension.h>`_ and
125`bspfatal-default.c <https://git.rtems.org/rtems/tree/bsps/shared/start/bspfatal-default.c>`_.
126If the default implementation is used, the BSP must implement a
127:c:func:`bsp_reset()` function which should reset the platform.
Note: See TracBrowser for help on using the repository browser.