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 | |
---|
7 | System Initialization |
---|
8 | ********************* |
---|
9 | |
---|
10 | Introduction |
---|
11 | ============ |
---|
12 | |
---|
13 | The system initialization consists of a low-level initialization performed by |
---|
14 | the start code in the start file (:file:`start.o`) and a high-level |
---|
15 | initialization carried out by :c:func:`boot_card()`. The final step of a |
---|
16 | successful high-level initialization is to switch to the initialization task |
---|
17 | and change into the normal system mode with multi-threading enabled. Errors |
---|
18 | during system initialization are fatal and end up in a call to |
---|
19 | :c:func:`_Terminate()`. |
---|
20 | |
---|
21 | Low-Level Initialization via Start Code in the Start File (start.o) |
---|
22 | =================================================================== |
---|
23 | |
---|
24 | The start code in the start file (:file:`start.o`) must be provided by the BSP. |
---|
25 | It is the first file presented to the linker and starts the process to link an |
---|
26 | executable (application image). It should contain the entry symbol of the |
---|
27 | executable. It is the responsibility of the linker script in conjunction with |
---|
28 | the compiler specifications file or compiler options to put the start code in |
---|
29 | the correct location in the executable. The start code is typically written in |
---|
30 | assembly language since it will tinker with the stack pointer. The general |
---|
31 | rule of thumb is that the start code in assembly language should do the minimum |
---|
32 | necessary to allow C code to execute to complete the initialization sequence. |
---|
33 | |
---|
34 | The low-level system initialization may depend on a platform initialization |
---|
35 | carried out by a boot loader. The low-level system initialization may perform |
---|
36 | the 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 | |
---|
65 | For 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 | |
---|
71 | High-Level Initialization via boot_card() |
---|
72 | ========================================= |
---|
73 | |
---|
74 | The high-level initialization is carried out by :c:func:`boot_card()`. For the |
---|
75 | high-level initialization steps see the `Initialization Manager` chapter in the |
---|
76 | RTEMS Classic API Guide. There are several system initialization steps which |
---|
77 | must be implemented by the BSP. |
---|
78 | |
---|
79 | Early BSP Initialization |
---|
80 | ------------------------ |
---|
81 | |
---|
82 | The BSP may provide a system initialization handler (order |
---|
83 | :c:macro:`RTEMS_SYSINIT_BSP_EARLY`) to perform an early BSP initialization. |
---|
84 | This handler is invoked before the memory information and high-level dynamic |
---|
85 | memory services (workspace and C program heap) are initialized. |
---|
86 | |
---|
87 | Memory Information |
---|
88 | ------------------ |
---|
89 | |
---|
90 | The BSP must provide the memory information to the system with an |
---|
91 | implementation of the :c:func:`_Memory_Get()` function. The BSP should use the |
---|
92 | default implementation in |
---|
93 | `bsps/shared/shared/start/bspgetworkarea-default.c <https://git.rtems.org/rtems/tree/bsps/shared/start/bspgetworkarea-default.c>`_. |
---|
94 | The memory information is used by low-level memory consumers such as the |
---|
95 | per-CPU data, the workspace, and the C program heap. The BSP may use a system |
---|
96 | initialization handler (order :c:macro:`RTEMS_SYSINIT_MEMORY`) to set up the |
---|
97 | infrastructure used by :c:func:`_Memory_Get()`. |
---|
98 | |
---|
99 | BSP Initialization |
---|
100 | ------------------ |
---|
101 | |
---|
102 | The BSP must provide an implementation of the :c:func:`bsp_start()` function. |
---|
103 | This 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 |
---|
106 | general platform initialization. The interrupt controllers are usually |
---|
107 | initialized here. The C program heap may be used in this handler. It is not |
---|
108 | allowed to create any operating system objects, e.g. RTEMS semaphores or tasks. |
---|
109 | The BSP may register additional system initialization handlers in the module |
---|
110 | implementing :c:func:`bsp_start()`. |
---|
111 | |
---|
112 | Error Handling |
---|
113 | ============== |
---|
114 | |
---|
115 | Errors 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 |
---|
117 | RTEMS Classic API Guide. |
---|
118 | |
---|
119 | The 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 | |
---|
122 | The BSP should provide an initial extension which implements a fatal error |
---|
123 | handler. 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>`_. |
---|
126 | If the default implementation is used, the BSP must implement a |
---|
127 | :c:func:`bsp_reset()` function which should reset the platform. |
---|