FORM:https://blog.csdn.net/xichangbao/article/details/51484603
1 bootstrap2()。
static int bootstrap2(void *arg)
{
dprintf(SPEW, "top of bootstrap2()\n");
arch_init(); // 目前为空函数
// XXX put this somewhere else
#if WITH_LIB_BIO
bio_init(); // 目前没有用到
#endif
#if WITH_LIB_FS
fs_init(); // 目前没有用到
#endif
// initialize the rest of the platform
dprintf(SPEW, "initializing platform\n");
platform_init(); // 目前只打印了一句log
// initialize the target
dprintf(SPEW, "initializing target\n");
target_init(); // 目标板级初始化,初始存储设备等
dprintf(SPEW, "calling apps_init()\n");
apps_init(); // 应用功能初始化
return 0;
}
target_init()。
void target_init(void)
{
int ret = 0;
dprintf(INFO, "target_init()\n");
pmic_info_populate(); // 从共享内存中读取xbl提供的pmic信息
spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); // 初始化spmi总线,用于cpu与pmic通信
/* Initialize Glink */
rpm_glink_init(); // 初始化ap与rpm通信通道
target_keystatus(); // 初始化按键
disable_s3_reset(); // 禁用s3复位功能
#if defined(LONG_PRESS_POWER_ON) || defined(PON_VIB_SUPPORT)
switch(board_hardware_id())
{
case HW_PLATFORM_QRD:
#if LONG_PRESS_POWER_ON
shutdown_detect(); // 将xbl中的按power键开机延时检查移到lk,节省忙等时间
#endif
#if PON_VIB_SUPPORT
vib_timed_turn_on(VIBRATE_TIME); // 震动马达震动250ms,给用户提供开机反馈
#endif
break;
}
#endif
if (target_use_signed_kernel())
target_crypto_init_params(); // 当使用的是签名的kernel时,需要初始加密解密引擎
platform_read_boot_config(); // 获取boot config信息
#ifdef MMC_SDHCI_SUPPORT
if (platform_boot_dev_isemmc()) // 是emmc启动
{
target_sdc_init();
}
#endif
#ifdef UFS_SUPPORT
if (!platform_boot_dev_isemmc()) // 是ufs启动
{
ufs_device.base = UFS_BASE;
ufs_init(&ufs_device); // 初始化ufs
}
#endif
/* Storage initialization is complete, read the partition table info */
mmc_read_partition_table(0); // 获取分区表信息
#if ENABLE_WBC
/* Look for battery voltage and make sure we have enough to bootup
* Otherwise initiate battery charging
* Charging should happen as early as possible, any other driver
* initialization before this should consider the power impact
*/
switch(board_hardware_id())
{
case HW_PLATFORM_MTP:
case HW_PLATFORM_FLUID:
case HW_PLATFORM_QRD:
pm_appsbl_chg_check_weak_battery_status(1); // 判断电池电压是否过低,过低则进入预充电
break;
default:
/* Charging not supported */
break;
};
#endif
/* Initialize Qseecom */
ret = qseecom_init(); // 和tz通信
if (ret < 0)
{
dprintf(CRITICAL, "Failed to initialize qseecom, error: %d\n", ret);
ASSERT(0);
}
/* Start Qseecom */
ret = qseecom_tz_init(); // 和tz通信
if (ret < 0)
{
dprintf(CRITICAL, "Failed to start qseecom, error: %d\n", ret);
ASSERT(0);
}
if (rpmb_init() < 0) // 初始化emmc或ufs中的rpmb用户加解密认证分区
{
dprintf(CRITICAL, "RPMB init failed\n");
ASSERT(0);
}
/*
* Load the sec app for first time
*/
if (load_sec_app() < 0) // 运行keymaster
{
dprintf(CRITICAL, "Failed to load App for verified\n");
ASSERT(0);
}
}
apps_init()。
void apps_init(void)
{
const struct app_descriptor *app;
/* call all the init routines */
for (app = &__apps_start; app != &__apps_end; app++) { // __apps_start和__apps_end都是在连接脚本中定义的
if (app->init)
app->init(app); // 调到aboot_init
}
/* start any that want to start on boot */
for (app = &__apps_start; app != &__apps_end; app++) {
if (app->entry && (app->flags & APP_FLAG_DONT_START_ON_BOOT) == 0) {
start_app(app);
}
}
}
__apps_start = .; // 链接地址
KEEP (*(.apps)) // 所有.apps段链接在__apps_start和__apps_end之间
__apps_end = .; // 链接地址
// 在代码中搜索.apps段
#define APP_START(appname) struct app_descriptor _app_##appname __SECTION(".apps") = { .name = #appname,
#define APP_END };
// 使用APP_START和APP_END两个宏定义了一个结构体struct app_descriptor变量, __SECTION(".apps")表示这个结构体属于.apps段;
typedef void (*app_init)(const struct app_descriptor *);
typedef void (*app_entry)(const struct app_descriptor *, void *args);
/* app startup flags */
#define APP_FLAG_DONT_START_ON_BOOT 0x1
/* each app needs to define one of these to define its startup conditions */
struct app_descriptor {
const char *name; // 名字
app_init init; // 初始化函数
app_entry entry; // 入口函数
unsigned int flags; // 标志
};
// 在代码中搜索APP_SATRT宏的使用,找到
APP_START(aboot)
.init = aboot_init,
APP_END
相当于定义了一个结构体
struct app_descriptor __app_aboot_init {
const char *name = "aboot_init";
app_init init = aboot_init;
app_entry entry = NULL;
unsigned int flags = 0;
};
---------------------
作者:xichangbao
来源:CSDN
原文:https://blog.csdn.net/xichangbao/article/details/51484603
版权声明:本文为博主原创文章,转载请附上博文链接!