[HarmonyOS HiSpark IPC DIY Camera Trial Series 4] How does the HarmonyOS kernel liteos-a start the first user process init_lite

[HarmonyOS HiSpark IPC DIY Camera Trial Series 4] How does the HarmonyOS kernel liteos-a start the first user process init_lite

1. Hongmeng OS compilation knowledge

(The principle is quoted from the essential interpretation of the Hongmeng OS open source code of Chuangda OpenHarmony Research Group - init) The
OpenHarmony source code compilation system uses the gn tool developed by Google and ninjia. The combination of the two is more efficient than the traditional makefile compilation system, especially suitable for parallel compilation of large systems. For developers, if they want to participate in the development of OpenHarmony, they need to have some understanding of the syntax of gn. This article only makes some basic introductions:
1. If using the gn tool, the developer writes the compilation rules in a file named BUILD.gn. Like Makefile, gn file has its own grammar rules and belongs to domain language (Domain Specific Language, DSL). The gn grammar is not difficult, but the compilation rules themselves have a lot of content, so it is not easy to grasp all the content at once.
2.gn supports custom template functions, which can be placed in a file named .gni. The most common gn template file in OpenHarmony is ./build/lite/config/component/lite_component.gni. The gni template file can be imported through import in the .gn file. OpenHarmony defines template functions such as lite_component and lite_library.
3. In gn, the compile function entry of the executable file is exectuable("file name"), and the compile rule function of the shared library is shared_library("file name"). Therefore, if you want to search for the compilation rules corresponding to a certain file, you can first search for all BUILD.gn files, and then grep executable. The following is a screenshot of the results of our grep for all executables.
insert image description here

2. Looking at the code structure of Hongmeng OS from the compilation process

The compilation command of Hi3518EV300 is as follows:
python build.py ipcamera_hi3518ev300 -b debug
How is this compilation command executed?
insert image description here

The compiled main file is the Build\lite\BUILD.gn file, and the content is intercepted as follows:
insert image description here

First compile the kernel and depend on the library; finally compile rootfs, the compilation process of rootfs \build\lite\gen_rootfs.py is to compile userfs first, and then compile rootfs.

The configuration file used:
insert image description here
insert image description here

Open ipcamera_hi3518ev300.json, where:
1. Configure the kernel as liteos_a;
2. Specify the compiler as clang;
3. List all OS subsystems and source code locations, including kernel and startup subsystems. init_lite in Startup is the first user-mode process called by the kernel;
insert image description here
insert image description here

3. The first user mode process init_lite

Init_lite location:
insert image description here

The introduction to init in the official manual (init boot refers to init_lite)
startup recovery is responsible for starting the middle layer of the operating system after the kernel starts and before the application starts. The following modules are involved:

  • init boot

Platforms that support the LiteOS-A kernel currently include: Hi3516DV300 platform and Hi3518EV300 platform.

Responsible for handling the system service process startup process from the kernel loading the first user mode process to the first application program startup. In addition to loading the key processes of each system, the startup recovery subsystem also needs to set its corresponding permissions at the same time of startup, and keep alive the specified process after the sub-process starts (if the process exits unexpectedly, it needs to be restarted), for special processes When exiting unexpectedly, starting the recovery subsystem also performs a system reset.

  • appspawn application incubation

    Platforms that support the LiteOS-A kernel currently include: Hi3516DV300 platform and Hi3518EV300 platform.

    Responsible for accepting the command of the application framework to incubate the application process, setting its corresponding permissions, and calling the entry of the application framework.

  • bootstrap startup service module

    Platforms that support the LiteOS-M kernel currently include: Hi3861 platform.

    Provides the startup entry identifiers of various services and functions. When SAMGR starts, the entry function identified by boostrap will be called and the system service will be started.

  • system property

    Support platforms using LiteOS-M kernel and LiteOS-A kernel, including: Hi3861 platform, Hi3516DV300 platform, Hi3518EV300 platform.

    Responsible for providing access to system properties related to setting the operating system.

    System properties include: default system properties, OEM manufacturer system properties and custom system properties. The OEM manufacturer part only provides the default value, and the specific value needs to be adjusted by the OEM product side as needed, see the "Usage" part for details.

base
├──startup startup recovery subsystem root directory
├──── frameworks
│ └── syspara_lite
│ ├── LICENSE open source LICENSE file
│ ├── parameter system property module source file directory
│ │ ├── BUILD.gn
│ ...
_
_
_
_
_ ── BUILD.gn
│ └── src
│ ├── token_impl_hal
│ └── token_impl_posix
├──── hals
│ └── syspara_lite system attribute module hardware abstraction layer header file directory
├──── interfaces
│ └── kits
│ └── syspara_lite system attribute module external interface directory
└──── services
├── appspawn_lite application incubation module
│ ├── BUILD.gn application incubation module compilation configuration
│ ├── include application incubation module header file directory
│ ├── LICENSE open source LICENSE file
│ ├── moduletest application incubation module self-test code directory
│ └── src application incubation block source file directory
├── bootstrap_lite start service module
│ ├── BUILD.gn start service module compilation Configuration
│ ├── LICENSE open source LICENSE file
│ └── source start service module source file directory
└── init_lite start boot module
├── BUILD.gn start boot module compilation configuration
├── include start boot module header file directory
├─ ─ LICENSE open-source license file
├── moduletest boot module self-test code directory
└── src boot module source file directory
vendor
└──huawei
└──camera
└──init_configs boot module configuration file directory (json format, deployment in the /etc/ directory)

Init_lite uses the configuration file init_configs;
insert image description here
insert image description here

The main.c of Init_lite will read and execute the command line of the configuration file above, and its function is InitReadCfg;
insert image description here

Init_lite generates "/bin/init" after compilation;
the bin directory is configured in \build\lite\BUILD.gn;
insert image description here

The init name is specified in base\startup\services\init_lite\BUILD.gn;
insert image description here

4. How is Init_lite called by the kernel?

The startup sequence of liteos-a is:
1) reset_vector_up.s
2) \kernel\liteos_a\platform\main.c
3) OsMain
4) OsSystemInit
5) OsSystemInitTaskCreate
6) SystemInit

SystemInit will be called during the startup process of Hi3518 kernel:
insert image description here
insert image description here

The SystemInit function will finally call the OsUserInitProcess function to start the init process;
insert image description here

The OsUserInitProcess function is defined in \kernel\liteos_a\kernel\base\core\los_process.c:
insert image description here

The address of the first user-mode process defined in OsUserInitProcess is __user_init_entry;
__user_init_entry is defined by the macro definition LITE_USER_SEC_ENTRY, and its file is \kernel\liteos_a\kernel\user\src\los_user_init.c;
this is the entry for Kernel to call init_lite :
insert image description here

insert image description here

For more information about me, please refer to : Harmony OS high-quality data collection, which is being continuously updated

Guess you like

Origin blog.csdn.net/qq_31765191/article/details/109839380