1 | .. SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. Copyright (C) 2018 Chris Johns <chrisj@rtems.org> |
---|
4 | |
---|
5 | BSP Initialization |
---|
6 | ================== |
---|
7 | .. index:: BSP Initialization |
---|
8 | |
---|
9 | The bootloader jumps or calls the RTEMS executable's entry point, normally a |
---|
10 | fixed address. The BSP entry point or start up code performs: |
---|
11 | |
---|
12 | #. Low level processor specific initialization that such as setting control |
---|
13 | registers so the processor is operating in a mode RTEMS is built for |
---|
14 | |
---|
15 | #. Cache flushing, clearing and invalidation |
---|
16 | |
---|
17 | #. Memory management unit (MMU) set up if required |
---|
18 | |
---|
19 | #. Clear the uninitialized data section |
---|
20 | |
---|
21 | #. Process a command line if supported by the bootloader |
---|
22 | |
---|
23 | #. Call ``bootcard`` which disabled interrupts, saves away a command line if |
---|
24 | the BSP supports it then call the RTEMS kernel early initialize entry point |
---|
25 | ``rtems_initialize_executive``. This call never returns. |
---|
26 | |
---|
27 | Further BSP initialization happens as part of RTEMS kernel's System |
---|
28 | Initialization process. The following handlers are declared and if provided are |
---|
29 | placed at the beginning of the initialization handler list. The BSP can |
---|
30 | provides: |
---|
31 | |
---|
32 | ``bsp_work_area_initialize`` |
---|
33 | This function determines the amount of memory that can be given to RTEMS for |
---|
34 | the workspace and the C library heap which ``malloc`` uses. The call |
---|
35 | typically uses the ``bsp_work_area_initialize_default`` to perform actually |
---|
36 | perform the initialization. |
---|
37 | |
---|
38 | ``bsp_start`` |
---|
39 | This function is specialized for each architecture and even for some BSPs. It |
---|
40 | performs the low level initialization RTEMS needs so it can run on the |
---|
41 | architecture and BSP. |
---|
42 | |
---|
43 | ``bsp_predriver_hook`` |
---|
44 | This function can be used to initialize hardware drivers depend on such as |
---|
45 | configuring an interrupt controller. The default version is empty and does |
---|
46 | nothing. |
---|
47 | |
---|
48 | BSPs all perform similar operations with common functionality and the RTEMS |
---|
49 | kernel provides common code that can be shared between BSPs. The use of the |
---|
50 | common code is encouraged for all new BSPs. |
---|
51 | |
---|
52 | RTEMS Initialization |
---|
53 | ==================== |
---|
54 | .. index:: RTEMS Initialization |
---|
55 | |
---|
56 | The RTEMS kernel initialization is: |
---|
57 | |
---|
58 | #. Invoke the registered system initialization handlers |
---|
59 | |
---|
60 | #. Set the system state to **up** |
---|
61 | |
---|
62 | #. If the kernel supports SMP request multitasking start. All online cores are |
---|
63 | transferred to the **ready to start multitasking** state. |
---|
64 | |
---|
65 | #. Start threaded multitasking. RTEMS starts multitasking by getting the first |
---|
66 | thread to run and dispatching it. |
---|
67 | |
---|
68 | C++ static object constructors are called in the context of the first running |
---|
69 | thread before the thread body is entered. |
---|
70 | |
---|
71 | System Initialization Handlers |
---|
72 | ------------------------------ |
---|
73 | |
---|
74 | RTEMS supports the automatic registration of services used in |
---|
75 | applications. This method of initialization automatically configures RTEMS with |
---|
76 | only the services used in an application. There is no manual configuration of |
---|
77 | services used and no updating of initialization function tables. |
---|
78 | |
---|
79 | RTEMS uses specialized sections in the ELF executable to perform this task. The |
---|
80 | system is based on the `FreeBSD SYSINT Framework |
---|
81 | <https://www.freebsd.org/doc/en/books/arch-handbook/sysinit.html>`_. Ordered |
---|
82 | initialization is performed before multitasking is started. |
---|
83 | |
---|
84 | The RTEMS Tool ``rtems-exeinfo`` can provide some detail about the registered |
---|
85 | handlers. The following shows the initialization handlers for the *hello world* |
---|
86 | sample application in the RTEMS kernel's testsuite:: |
---|
87 | |
---|
88 | $ rtems-exeinfo --init arm-rtems5/c/xilinx_zynq_zedboard/testsuites/samples/hello.exe |
---|
89 | RTEMS Executable Info 5.5416cfa39dd6 |
---|
90 | rtems-exeinfo --init arm-rtems5/c/xilinx_zynq_zedboard/testsuites/samples/hello.exe |
---|
91 | exe: arm-rtems5/c/xilinx_zynq_zedboard/testsuites/samples/hello.exe |
---|
92 | |
---|
93 | Compilation: |
---|
94 | Producers: 2 |
---|
95 | | GNU AS 2.31.1: 14 objects |
---|
96 | | GNU C11 7.3.0 20180125 (RTEMS 5, RSB e55769c64cf1a201588565a5662deafe3f1ccdcc, Newlib 103b055035fea328f8bc7826801760fb1c055683): 284 objects |
---|
97 | Common flags: 4 |
---|
98 | | -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard |
---|
99 | |
---|
100 | Init sections: 2 |
---|
101 | .init_array |
---|
102 | 0x001047c1 frame_dummy |
---|
103 | .rtemsroset |
---|
104 | 0x00104c05 bsp_work_area_initialize |
---|
105 | 0x00104c41 bsp_start |
---|
106 | 0x0010eb45 zynq_debug_console_init |
---|
107 | 0x0010ec19 rtems_counter_sysinit |
---|
108 | 0x0010b779 _User_extensions_Handler_initialization |
---|
109 | 0x0010c66d rtems_initialize_data_structures |
---|
110 | 0x00107751 _RTEMS_tasks_Manager_initialization |
---|
111 | 0x0010d4f5 _POSIX_Keys_Manager_initialization |
---|
112 | 0x0010dd09 _Thread_Create_idle |
---|
113 | 0x0010cf01 rtems_libio_init |
---|
114 | 0x001053a5 rtems_filesystem_initialize |
---|
115 | 0x0010546d _Console_simple_Initialize |
---|
116 | 0x0010c715 _IO_Initialize_all_drivers |
---|
117 | 0x001076d5 _RTEMS_tasks_Initialize_user_tasks_body |
---|
118 | 0x0010cfa9 rtems_libio_post_driver |
---|
119 | |
---|
120 | The section ``.rtemsroset`` lists the handlers called in order. The handlers |
---|
121 | can be split into the BSP initialization handlers that start the BSP: |
---|
122 | |
---|
123 | - ``bsp_work_area_initialize`` |
---|
124 | - ``bsp_start`` |
---|
125 | - ``zynq_debug_console_init`` |
---|
126 | - ``rtems_counter_sysinit`` |
---|
127 | |
---|
128 | And the remainder are handlers for services used by the application. The list |
---|
129 | varies based on the services the application uses. |
---|