前言
磨刀不误砍材工,为了方便后面开发,先对照着打印信息和代码,对启动过程进行分析,对程序执行过程有个大致了解。
程序入口点,内核启动
device/soc/esp/esp32/components/esp_system/port/cpu_start.c
call_start_cpu0
打印如下
I (370) cpu_start: Pro cpu up.
I (376) cpu_start: Single core mode
device/soc/esp/esp32/components/esp_system/startup.c
start_cpu0_default
打印如下
I (371) cpu_start: Pro cpu start user code
I (373) cpu_start: cpu freq: 160000000
I (378) cpu_start: Application information:
I (380) cpu_start: Project name: spp_client_demo
I (383) cpu_start: App version: 1
I (389) cpu_start: Compile time: Sep 23 2022 21:28:08
I (393) cpu_start: ELF file SHA256: aa63348688c93d38...
I (394) cpu_start: ESP-IDF: v4.3.1-dirty
device/soc/esp/esp32/components/heap/heap_caps_init.c
heap_caps_init
打印如下
I (94) heap_init: Initializing. RAM available for dynamic allocation:
I (118) heap_init: At 3FF80000 len 00002000 (8 KiB): RTCRAM
I (118) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (118) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (118) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (118) heap_init: At 3FFC5128 len 0001AED8 (107 KiB): DRAM
I (118) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (118) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (118) heap_init: At 400905E0 len 0000FA20 (62 KiB): IRAM
kernel/liteos_m/kernel/src/los_init.c
LOS_KernelInit
打印如下
entering kernel init...
kernel/liteos_m/kernel/src/los_sched.c
OsSchedStart
打印如下
Entering scheduler
系统初始化
\device\board\openvalley\niobeu4\liteos_m\target\src\target_startup.c
OHOS_SystemInitEntry ->
int err;
printf("Code Build Time:%s %s\n", __DATE__, __TIME__);
before_ohos_run();
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
nvs_flash_erase();
ret = nvs_flash_init();
}
DeviceWifiStart();
init_trace_system();
err = DeviceManagerStart();
if (err) {
printf("DeviceManagerStart.ret=0x%X\n", err);
}
OHOS_SystemInit();
ohos_app_main();
return NULL;
l 先打印编译时间
l before_ohos_run调用钩子函数BEFORE_OHOS_RUN_FUNC_ENTRY
该函数由#define BEFORE_OHOS_RUN(func) void *BEFORE_OHOS_RUN_FUNC_ENTRY = (func)宏定义,实际是一个全局函数指针变量
l nvs_flash_init进行flash初始化
对应打印如下
l DeviceWifiStart
l init_trace_system 注册打印输出接口g_hilogOutputProc赋值为HilogProc_Impl
OutputLog即调用该函数打印输出
l DeviceManagerStart
l OHOS_SystemInit
l ohos_app_main调用用户代码
Code Build Time:Sep 23 2022 21:52:39
I (321) spi_flash: detected chip: generic
I (218) spi_flash: flash io: dio
I (18) wifi:wifi driver task: 6, prio:23, stack:6656, core=0
I (56) system_api: Base MAC address is not set
I (156) system_api: read default base MAC address from EFUSE
I (18) wifi:wifi firmware version: 88c8747
I (28) wifi:wifi certification version: v7.0
I (28) wifi:config NVS flash: disabled
I (28) wifi:config nano formating: disabled
I (38) wifi:Init data frame dynamic rx buffer num: 32
I (38) wifi:Init management frame dynamic rx buffer num: 32
I (48) wifi:Init management short buffer num: 32
I (48) wifi:Init dynamic tx buffer num: 32
I (48) wifi:Init static rx buffer size: 1600
I (58) wifi:Init static rx buffer num: 10
I (58) wifi:Init dynamic rx buffer num: 32
I (141) wifi_init: rx ba win: 6
I (145) wifi_init: tcpip mbox: 32
I (146) wifi_init: udp mbox: 6
I (147) wifi_init: tcp mbox: 6
I (148) wifi_init: tcp tx win: 5744
I (149) wifi_init: tcp rx win: 5744
I (150) wifi_init: tcp mss: 1440
I (157) wifi_init: WiFi IRAM OP enabled
hilog will init.
hievent will init.
hievent init success.
01-01 00:00:00.247 0 48 D 0/HIVIEW: log limit init success.
Littlefs.mount=/Openvalley addr=0x312000 size=832K OK!!!
01-01 00:00:00.257 0 48 I 1/SAMGR: Bootstrap core services(count:1).
01-01 00:00:00.263 0 48 I 1/SAMGR: Init service:0x3f401224
hiview init success.
01-01 00:00:00.269 0 112 I 1/SAMGR: Init service 0x3f401224 <time: 20ms> success!
01-01 00:00:00.277 0 112 I 1/SAMGR: Initialized all core system services!
01-01 00:00:00.283 0 112 I 1/SAMGR: Goto next boot step return code:-6
用户代码执行
用户代码中,例如
OHOS_APP_RUN(Niobeu4HelloWorld);
定义全局函数指针变量OHOS_APP_FUNC_ENTRY
,并赋值。
其宏定义如下
#define OHOS_APP_RUN(func) void *OHOS_APP_FUNC_ENTRY = (func)
在如下
\device\board\openvalley\niobeu4\liteos_m\target\src\target_startup.c
ohos_app_main
调用OHOS_APP_FUNC_ENTRY
即调用Niobeu4HelloWorld
。
对应打印如下
<--------------- OHOS Application Start Here --------------->
---
* [Openvalley/Niobeu4] *
* Hello world. *
---