參考鏈接
https://blog.csdn.net/kill150/article/details/129929641
https://blog.csdn.net/Harrison509/article/details/108659469
https://www.cnblogs.com/pngcui/p/4665106.html
系統啟動流程概覽
高通Android設備的啟動流程通常遵循以下步驟:
-
PBL (Primary Boot Loader):
- 設備上電后,首先執行的是PBL,它固化在ROM中。
- PBL負責初始化DDR,加載SBL1(Secondary Boot Loader)。
-
SBL1:
- SBL1繼續硬件初始化,包括CPU、內存控制器等。
- 加載并初始化TrustZone、QSEE(Qualcomm Secure Execution Environment)等安全組件。
-
TrustZone/QSEE:
- TrustZone是ARM技術,用于提供系統級的安全解決方案。
- QSEE是高通的安全執行環境,負責執行安全敏感的代碼。
-
Bootloader:
- 在SBL1之后,設備加載Bootloader。
- Bootloader負責加載并驗證內核(Linux Kernel)。
-
內核啟動:
- 內核自解壓并初始化硬件平臺。
- 設置內存管理單元(MMU),加載必要的驅動程序。
-
init進程:
init
是Linux系統中的第一個用戶空間進程。- 它負責掛載根文件系統,啟動系統服務和守護進程。
-
Zygote進程:
- 在Android系統中,Zygote是所有應用程序的父進程。
- 它啟動并為Android框架和應用程序提供服務。
-
SystemServer:
- SystemServer是Android系統的核心服務進程。
- 它啟動包括窗口管理器、活動管理器、電源管理器等關鍵服務。
-
UEFI啟動(如果設備支持UEFI):
- UEFI(統一可擴展固件接口)提供了一種新的啟動方法。
- 它包括SEC(安全環境配置)、PEI(EFI前期初始化)、DXE(驅動執行環境)、BDS(啟動設備選擇)等階段。
-
顯示子系統啟動:
- 在顯示設備準備好之后,啟動顯示管理器和相關的顯示服務。
-
用戶界面:
- 最后,啟動Home Launcher,用戶界面完全加載,設備準備就緒供用戶使用。
請注意,這個流程可能會根據不同的硬件平臺、Android版本和制造商的定制有所變化。上述步驟提供了一個高通Android設備從上電到操作系統完全啟動的一般概述。
源碼分析
1、啟動文件 sbl1_Aarch64.s(對應架構的.s)
fibo/bp_code/BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/Library/XBLLoaderLib/sbl1_Aarch64.s
sbl1_entry_init_stack: // -------------------------------// add more assembly init code here for entering sbl1_main_ctl// // restore PBL parameter and enter sbl1_main_ctl// -------------------------------MOV w0, w7BL sbl1_main_ctl// For safetyBL boot_loop_here // never returns
2、sbl1_main_ctl :restore PBL parameter and enter sbl1_main_ctl
fibo/bp_code/BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/Library/XBLLoaderLib/sbl1_mc.c
/*!
*
* @brief
* The Main Controller performs the following functions:
* - Initializes ram
* - And so on...
*
* @param[in] pbl_shared Pointer to shared data
*
* @par Dependencies
* None
*
* @retval
* None
*
* @par Side Effects
* This function never returns.
*
*/
void sbl1_main_ctl(boot_pbl_shared_data_type *pbl_shared)
{DALResult bsy_wait_init;/* Configure Domain access control register */mmu_set_dacr(DACR_ALL_DOMAIN_CLIENTS);/* Retrieve info passed from PBL*/sbl1_retrieve_shared_info_from_pbl(pbl_shared);/* Initialize shared functions structure - provides other images with function pointers in Loader */boot_shared_functions_register();/* Initialize SBL memory map */sbl1_populate_initial_mem_map(&bl_shared_data); /* Calculate the SBL start time for use during boot logger initialization. */sbl_start_time = CALCULATE_TIMESTAMP(HWIO_IN(TIMETICK_QTIMER_CLK));sbl_start_time_mpm = CALCULATE_MPM_TIMESTAMP(HWIO_IN(TIMETICK_CLK));/* Initialize busywait module Note: required before logger init due to uart driver dependency on busywait */BL_VERIFY((bsy_wait_init=boot_busywait_init()) == DAL_SUCCESS, (uint16)bsy_wait_init|BL_ERROR_GROUP_BUSYWAIT);/* Enable qdss workaround*/BL_VERIFY(boot_clock_debug_init() == TRUE, FALSE|BL_ERROR_GROUP_CLK );/* Enter debug mode if debug cookie is set */sbl1_debug_mode_enter();/* Initialize the stack protection canary */boot_init_stack_chk_canary();/* Initialize boot shared imem */boot_shared_imem_init(&bl_shared_data);/* Initialize the ChipInfo driver */ChipInfo_Init();/* Initialize the QSEE interface */sbl1_init_sbl_qsee_interface(&bl_shared_data, &sbl_verified_info);/* Initialize dal heap using internal memory */boot_DALSYS_HeapInit(boot_internal_heap, BOOT_INTERNAL_HEAP_SIZE, FALSE);/*Initialize DAL, needs to be called before modules that uses DAL */ boot_DALSYS_InitMod(NULL); /* Initialize boot logger and start the log timer.This must be done after sbl1_retrieve_shared_info_from_pbland boot_secboot_ftbl_init. */sbl1_boot_logger_init(&boot_log_data, pbl_shared); boot_log_set_meta_info(boot_log_data.meta_info_start);/* Set hash algorithm */BL_VERIFY(boot_set_hash_algo(SBL_HASH_SHA256) == BL_ERR_NONE, BL_ERR_UNSUPPORTED_HASH_ALGO|BL_ERROR_GROUP_BOOT);/* Call sbl1_hw_init to config pmic device so we can use PS_HOLD to reset */sbl1_hw_init();#if defined (FEATURE_DEVICEPROGRAMMER_IMAGE) || defined (FEATURE_DDI_IMAGE)/* Enter device programmer does not return */device_programmer_init(&bl_shared_data, pbl_shared);
#else/* Store the sbl1 hash to shared imem */boot_store_tpm_hash_block(&bl_shared_data, &sbl_verified_info);/*-----------------------------------------------------------------------Process the target-dependent SBL1 procedures-----------------------------------------------------------------------*/boot_config_process_bl(&bl_shared_data, SBL1_IMG, sbl1_config_table);
#endif} /* sbl1_main_ctl() */
3、boot_config.c
sbl1_config_table 執行的回調函數table
fibo/bp_code/BOOT.XF.4.1/boot_images/QcomPkg/SocPkg/Library/XBLLoaderLib/sbl1_config.c
/*==========================================================================DEFINE TARGET BOOT CONFIG TABLE
===========================================================================*/
boot_configuration_table_entry sbl1_config_table[] =
{
/* host_img_id host_img_type target_img_id target_img_type target_img_sec_type load auth exec jump exec_func jump_func pre_procs post_procs load_cancel target_img_partition_id target_img_str boot_ssa_enabled enable_xpu xpu_proc_id sbl_qsee_interface_index seg_elf_entry_point whitelist_ptr */{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_APDP_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, apdp_pre_procs, apdp_post_procs, apdp_load_cancel, apdp_partition_id, APDP_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, apdp_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_OEM_MISC_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, NULL, NULL, oem_misc_load_cancel, multi_image_partition_id, OEM_MISC_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, oem_misc_img_whitelist},{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_QTI_MISC_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, NULL, NULL, qti_misc_load_cancel, multi_image_qti_partition_id, QTI_MISC_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, qti_misc_img_whitelist},{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_RPM_FW_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, rpm_pre_procs, NULL, rpm_load_cancel, rpm_partition_id, RPM_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, rpm_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_QSEE_DEVCFG_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, NULL, NULL, qsee_devcfg_load_cancel, qsee_devcfg_image_partition_id, QSEE_DEVCFG_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, devcfg_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_QSEE_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, NULL, qsee_post_procs, NULL, qsee_partition_id, QSEE_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, qsee_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_SEC_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, NULL, NULL, sec_load_cancel, secdata_partition_id, SEC_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, sec_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_QHEE_SW_TYPE, TRUE, TRUE, FALSE, FALSE, NULL, NULL, NULL, NULL, NULL, qhee_partition_id, QHEE_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, qhee_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_WDT_SW_TYPE, TRUE, TRUE, FALSE, TRUE, NULL, sti_jump_func, NULL, NULL, sti_load_cancel, sti_partition_id, STI_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, 0x0, sti_img_whitelist },{SBL1_IMG, CONFIG_IMG_QC, GEN_IMG, CONFIG_IMG_ELF, SECBOOT_APPSBL_SW_TYPE, TRUE, TRUE, FALSE, TRUE, NULL, qsee_jump_func, NULL, appsbl_post_procs, appsbl_load_cancel, appsbl_partition_id, APPSBL_BOOT_LOG_STR, FALSE, FALSE, 0x0, 0x0, SCL_XBL_CORE_CODE_BASE, xbl_core_img_whitelist},{NONE_IMG, }
};
fibo/bp_code/BOOT.XF.4.1/boot_images/QcomPkg/XBLLoader/boot_config.c
boot_config_process_bl 處理每一個 sbl1_config_table 回調函數列表
/*!
*
* @brief
* Function to process and execute boot code based on information from the
* configuration table. This parses through the entire table and calls
* boot_config_process_entry() on each entry corresponding to the host
* image in order.
*
* @param[in] bl_shared_data - Pointer to the shared data structure
* @param[in] host_img - Image ID of the host boot loader
* @param[in] boot_config_table - Bootloader specific configuration table
*
* @par Dependencies
* None
*
* @retval
* None
*
* @par Side Effects
* None
*/
void boot_config_process_bl
( bl_shared_data_type *bl_shared_data, image_type host_img, boot_configuration_table_entry * boot_config_table
)
{boot_configuration_table_entry *curr_entry = NULL;BL_VERIFY( bl_shared_data != NULL && boot_config_table != NULL,BL_ERR_NULL_PTR_PASSED|BL_ERROR_GROUP_BOOT);/* For every entry in the boot configuration table */for(curr_entry = boot_config_table