• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# LiteOS Cortex-A
2
3## Overview
4
5### Porting Scenario
6
7LiteOS Cortex-A supports the ARMv7-a instruction set architecture. If you are porting the kernel to a chipset that uses ARMv7-a, you can directly perform basic adaptation. Otherwise, you need to add support for the architecture used by the chipset. This process is complex and not covered in this document.
8
9### Directory Specifications
10
11For details about the LiteOS Cortex-A directory specifications, see  [LiteOS Cortex-A Overview](https://gitee.com/openharmony/kernel_liteos_a).
12
13## Adaptation Process
14
15LiteOS Cortex-A provides the system initialization process and custom configuration options required for system running. During porting, pay attention to the functions related to hardware configuration in the initialization process.
16
17The LiteOS Cortex-A initialization process consists of seven steps:
18
191.  Add the  **target\_config.h** file and compile the macros **DDR\_MEM\_ADDR** and **DDR\_MEM\_SIZE**, which indicate the start address and length of the board memory, respectively. The prelinker script **board.ld.S** creates the linker script **board.ld** based on the two macros.
202.  Define **g\_archMmuInitMapping**, the global array of MMU mappings, to specify the memory segment attributes and the virtual-to-physical address mappings. The memory mapping will be established based on this array during kernel startup.
213.  If there are multiple cores, define **struct SmpOps**, the handle to the secondary core operation function. The **SmpOps-\>SmpCpuOn** function needs to implement the feature of waking up a secondary core. Then, define the **SmpRegFunc** function and call the **LOS\_SmpOpsSet** interface to register the handle. The registration process is completed by starting the framework using **LOS\_MODULE\_INIT\(SmpRegFunc, LOS\_INIT\_LEVEL\_EARLIEST\)**.
224.  Create a kernel image based on the linker script **board.ld**.
235.  Perform operations such as initialization of the interrupt vector table and MMU page table are performed in the assembly files: **reset\_vector\_up.S** and **reset\_vector\_mp.S**, from which a single-core CPU and a multi-core CPU start, respectively.
246.  Enable the assembly code in **reset\_vector.S** to jump to the **main** function of the C programming language to initialize the hardware clock, software timer, memory, and tasks. This process depends on the feature macro configuration in **target\_config.h**. Then, create the **SystemInit** task to be implemented in the board code, with **OsSchedStart\(\)** enabled for task scheduling.
257.  Call the **DeviceManagerStart** function to initialize the HDF driver. This process is implemented by calling the driver configuration file **hdf.hcs** and drivers source code in the board code.
26
27The figure below shows the overall initialization process.
28
29**Figure 1** Overall initialization process
30![](figures/overall-initialization-process.png "overall-initialization-process")
31
32As can be seen from preceding figure, kernel basic adaptation involves the following parts:
33
34- Adding the **target\_config.h** file, which contains board hardware parameters and feature parameters described in the following table:
35
36  **Table 1** Parameters in the target\_config.h file
37
38  | Parameter               | Description                                                 |
39  | ----------------------- | ----------------------------------------------------------- |
40  | OS_SYS_CLOCK            | System cycle frequency                                      |
41  | DDR_MEM_ADDR            | Start address of the system memory                          |
42  | DDR_MEM_SIZE            | Size of the system memory                                   |
43  | PERIPH_PMM_BASE         | Base address of the peripheral register                     |
44  | PERIPH_PMM_SIZE         | Size of the peripheral register                             |
45  | OS_HWI_MIN              | Minimum number of system interrupts                         |
46  | OS_HWI_MAX              | Maximum number of system interrupts                         |
47  | NUM_HAL_INTERRUPT_UART0 | UART0 interrupt ID                                          |
48  | UART0_REG_BASE          | UART0 register base address                                 |
49  | GIC_BASE_ADDR           | Base address of the GIC interrupt register                  |
50  | GICD_OFFSET             | Offset address of the GICD relative to the GIC base address |
51  | GICC_OFFSET             | Offset address of the GICC relative to the GIC base address |
52
53
54
55- Implementing the **SystemInit** function to initialize services in the user space. Figure 2 shows a typical initialization scenario.
56
57  **Figure  2**  Service startup process
58
59  ![](figures/service-startup-process.png "service-startup-process")
60
61-   Implementing the **main** function for basic kernel initialization and initialization of services in the board kernel space.  Figure 3 shows the initialization process, where the kernel startup framework takes the lead in the initialization process. The light blue part in the figure indicates the phase in which external modules can be registered and started in the startup framework.
62
63    >![](../public_sys-resources/icon-caution.gif) **CAUTION**
64    >
65    >Modules at the same layer cannot depend on each other.
66
67  **Figure 3**  Kernel startup framework
68
69  ![](figures/kernel-startup-framework.jpg "kernel-startup-framework")
70
71  **Table  2**  Startup framework layers
72
73| Layer                         | Description                                                  |
74| ----------------------------- | ------------------------------------------------------------ |
75| LOS_INIT_LEVEL_EARLIEST       | Earliest initialization.<br>This layer does not depend on the architecture. The board and subsequent modules, such as the Trace module, will initialize the software-only modules on which they depend. |
76| LOS_INIT_LEVEL_ARCH_EARLY     | Early initialization of the architecture.<br/>This layer depends on the architecture. Subsequent modules will initialize the modules on which they depend. It is recommended that functions not required for startup be placed at the **LOS_INIT_LEVEL_ARCH** layer. |
77| LOS_INIT_LEVEL_PLATFORM_EARLY | Early initialization of the platform.<br/>This layer depends on the board platform and drivers. Subsequent modules will initialize the modules on which they depend. It is recommended that functions required for startup be placed at the **LOS_INIT_LEVEL_PLATFORM** layer.<br/>Example: UART module |
78| LOS_INIT_LEVEL_KMOD_PREVM     | Kernel module initialization before memory initialization.<br/>This layer involves initialization of the modules that need to be enabled before memory initialization. |
79| LOS_INIT_LEVEL_VM_COMPLETE    | Initialization after the basic memory is ready.<br/>This layer involves initialization of the modules that need to be enabled and do not depend on the inter-process communication mechanism and system processes.<br/>Example: shared memory function |
80| LOS_INIT_LEVEL_ARCH           | Late initialization of the architecture.<br/>This layer depends on the architecture extension function. Subsequent modules will initialize the modules on which they depend. |
81| LOS_INIT_LEVEL_PLATFORM       | Late initialization of the platform.<br/>This layer depends on the board platform and drivers. Subsequent modules will initialize the modules on which they depend.<br/>Example: initialization of the driver kernel abstraction layer (MMC and MTD) |
82| LOS_INIT_LEVEL_KMOD_BASIC     | Initialization of the kernel basic modules.<br/>This layer is used to initialize the basic modules that can be detached from the kernel.<br/>Example: VFS initialization |
83| LOS_INIT_LEVEL_KMOD_EXTENDED  | Initialization of the kernel extended modules.<br/>This layer is used to initialize the extended modules that can be detached from the kernel.<br/>Example: system call initialization, ProcFS initialization, Futex initialization, HiLog initialization, HiEvent initialization, and LiteIPC initialization |
84| LOS_INIT_LEVEL_KMOD_TASK      | Kernel task creation.<br/>This layer can be used to create kernel tasks (kernel thread and software timer tasks).<br/>Example: creation of the resident resource reclaiming task, SystemInit task, and CPU usage statistics task |
85
86Adaptation for board porting. Focus on layers between  **LOS\_INIT\_LEVEL\_ARCH**  and  **LOS\_INIT\_LEVEL\_KMOD\_TASK**  and try to divide the initialization process into as many phases as possible for refined registration.
87
88  >![](../public_sys-resources/icon-note.gif) **NOTE**
89  >
90  >Modules at the same layer cannot depend on each other. It is recommended that a new module be split based on the preceding startup phase and be registered and started as required.
91  >
92  >You can view the symbol table in the **.rodata.init.kernel.\*** segment of the **OHOS\_Image.map** file generated after the build is complete, so as to learn about the initialization entry of each module that has been registered with the kernel startup framework and check whether the newly registered initialization entry takes effect.
93
94
95## Programming Example
96
97In the board SDK file:
98
99```
100/* Header file of the kernel startup framework */
101#include "los_init.h"
102......
103
104/* Initialization function of the new module */
105unsigned int OsSampleModInit(void)
106{
107    PRINTK("OsSampleModInit SUCCESS!\n");
108    ......
109}
110......
111/* Register the new module at the target layer of the startup framework. */
112LOS_MODULE_INIT(OsSampleModInit, LOS_INIT_LEVEL_KMOD_EXTENDED);
113```
114
115## Verification
116
117```
118main core booting up...
119OsSampleModInit SUCCESS!
120releasing 1 secondary cores
121cpu 1 entering scheduler
122cpu 0 entering scheduler
123```
124
125According to the preceding information displayed during the system startup, the kernel calls the initialization function of the registered module during the startup to initialize the module.
126
127The system enters the kernel-space shell and the task commands can be properly executed.
128
129```
130OHOS # help
131***shell commands:*
132
133arp           cat           cd            chgrp         chmod         chown         cp            cpup
134date          dhclient      dmesg         dns           format        free          help          hwi
135ifconfig      ipdebug       kill          log           ls            lsfd          memcheck      mkdir
136mount         netstat       oom           partinfo      partition     ping          ping6         pmm
137pwd           reset         rm            rmdir         sem           shm           stack         statfs
138su            swtmr         sync          systeminfo    task          telnet        touch         umount
139uname         v2p           virstatfs     vmm           watch         writeproc
140
141```
142
143