技术标签: Android启动流程 lk
Lk的主要功能:
1、初始化硬件模块,比如时钟,中断,UART,USB,LCD,PMIC,eMMC等。打开MMU,使能I/D-cache,加速lk执行,显示logo、充电相关。
2、从emmc的boot分区取出boot.img解压,将根文件系统(ramdisk)、zImage 加载到DRAM;
3、解析dtb,写入到DRAM指定区域;
4、关闭MMU、irq / fiq,关闭I/D-cache, 拉起 kernel;
二、详细流程分析
1、crt0.S
在system-onesegment.ld中有定义ENTRY(_start),跳转到crt0.S中的_start执行reset,它的主要功能是初始化cpu,设置 irq, fiq, abort, undefined,system/user堆栈, 设置管理模式。然后通过“bl kmain”跳转到main.c中执行。
2、main.c
void kmain(void) { /* 早期初始化线程池的上下文,包括运行队列、线程链表的建立等, lk架构支持多线程,但是此阶段只有一个cpu处于online,所以也只有一条代码执行路径. */ Thread_init_early(); /* 架构初始化,包括DRAM,MMU初始化使能,使能协处理器, preloader运行在ISRAM,属于物理地址,而lk运行在DRAM,可以选择开启MMU或者关闭,开启MMU可以加速lk的加载过程. */ Arch_early_init(); /* 平台硬件早期初始化,包括irq、timer,wdt,uart,led,pmic,i2c,gpio等, 初始化平台硬件,建立lk基本运行环境。 */ platform_early_init(); // 目前为空方法 Target_early_init(); //初始化构造函数 Call_constructors(); //内核堆链表上下文初始化等. Heap_init(); // 线程池初始化,前提是PLATFORM_HAS_DYNAMIC_TIMER需要支持. Thread_init(); // 初始化dpc 系统 Dpc_init(); // 初始化timer Timer_init(); #if (!ENABLE_NANDWRITE) // 创建系统初始化工作线程,执行app初始化,lk把业务部分当成一个app. Thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); // 使能中断 Exit_critical_section(); // 设置为一个低优先级的线程,只有系统空闲时才运行 Thread_become_idle(); #else Bootstrap_nandwrite(); #endif } static intbootstrap2(void *arg) { Arch_init(); /* 平台相关初始化,包括nand/emmc,LCM显示驱动,启动模式选择,加载logo资源. */ Platform_init(); // initialize the target Target_init(); /* app初始化,跳转到mt_boot_init入口开始执行,对应的 ".apps" 这个section. */ Apps_init(); return 0; } |
bootstrap2主要工作:平台相关初始化,包括nand/emmc,显现相关驱动,启动模式选择,加载logo资源检测是否DA模式,检测分区中是否有KE信息,如果就KE信息,就从分区load 到DRAM,点亮背光,显示logo,禁止I/D-cache和MMU,跳转到DA,配置二级cache的size 获取bat电压,判断是否低电量是否显示充电logo
2、app.c
|
void apps_init(void) { const struct app_descriptor *app; /* call all the init routines */ for (app = &__apps_start; app != &__apps_end; app++) { if (app->init) app->init(app); } /* 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); } } } |
在system-onesegment.ld中定义:
__apps_start = .;
KEEP(*(.apps))
__apps_end= .;
在app.h中有定义:
#define APP_START(appname) structapp_descriptor _app_##appname __SECTION(".apps") = { .name =#appname,
#define APP_END };
在mt_boot.c中定义:
APP_START(mt_boot)
.init = mt_boot_init,
APP_END
然后程序会转到mt_boot_init中执行。
3、mt_boot.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
void mt_boot_init(const struct app_descriptor *app) { //设置序列号 sn_buf[SN_BUF_LEN] = '\0'; surf_udc_device.serialno = sn_buf; if (g_boot_mode == FASTBOOT) goto fastboot; //检查secure boot 校验boot/recovery分区的签名 #ifdef MTK_SECURITY_SW_SUPPORT #if MTK_FORCE_VERIFIED_BOOT_SIG_VFY /* verify oem image with android verified boot signature instead of mediatek proprietary signature */ /* verification is postponed to boot image loading stage */ /* note in this case, boot/recovery image will be verified even when secure boot is disabled */ g_boot_state = BOOT_STATE_RED; #else if (0 != sec_boot_check(0)) { g_boot_state = BOOT_STATE_RED; } #endif #endif //加载boot image /* Will not return */ boot_linux_from_storage();
|
boot_linux_from_storage主要工作:
跟据g_boot_mode选择各种启动模式,例如:normal、facotry、fastboot、recovery等,然后从EMMC中的boot分区找到(解压) ramdisk跟zImage的地址通过read系统调用load到DRAM址中, kernel最终load到DRAM的地址:(DRAM_PHY_ADDR+ 0x8000);
重定位根文件系统地址;
跳转到 boot_linux,正式拉起kernel;
|
int boot_linux_from_storage(void) { switch (g_boot_mode) { case NORMAL_BOOT: // bootimg_hrd加载地址 0x40080000 ret=mboot_android_load_bootimg_hdr("boot", CFG_BOOTIMG_LOAD_ADDR); //bootimg加载地址 kimg_load_addr = 0x45000000 kimg_load_addr = (unsigned int)target_get_scratch_address(); //加载bootimg ret = mboot_android_load_bootimg("boot", kimg_load_addr); break; case RECOVERY_BOOT: ......//如果是recovery模式,加载recovery image break; …… } //获取ramdisk的大小 g_rimg_sz = g_boot_hdr->ramdisk_size; //重定位根文件系统(ramdisk)地址 0x44000000 memcpy((g_boot_hdr!=NULL) ? (char *)g_boot_hdr->ramdisk_addr : (char *)CFG_RAMDISK_LOAD_ADDR, (char *)(g_rmem_off), g_rimg_sz); g_rmem_off = (g_boot_hdr!=NULL) ? g_boot_hdr->ramdisk_addr : CFG_RAMDISK_LOAD_ADDR; // 2 weak function for mt6572 memory preserved mode platform_mem_preserved_load_img(); platform_mem_preserved_dump_mem(); custom_port_in_kernel(g_boot_mode, cmdline_get()); ......//设置cmdline,包括tembuf,seliux状态等 cmdline_append(cmdline_tmpbuf); //准备启动Linux kernel boot_linux((void*)CFG_BOOTIMG_LOAD_ADDR,(unsigned*)CFG_BOOTARGS_ADDR,(char*)cmdline_get(),board_machtype(),(void*)CFG_RAMDISK_LOAD_ADDR, g_rimg_sz); while (1) ; return 0; } |
boot_linux主要工作:
初始化DTB(device tree block);
准备各种cmdline参数传入kernel;
关闭I/D-cache、MMU;
打印关键信息,正式拉起kernel.
|
void boot_linux(void *kernel, unsigned *tags, char *cmdline, unsigned machtype, void *ramdisk, unsigned ramdisk_size) { //加载设备树 #ifdef DEVICE_TREE_SUPPORT boot_linux_fdt((void *)kernel, (unsigned *)tags, (char *)cmdline, machtype, (void *)ramdisk, ramdisk_size); while (1) ; #endif //准备各种cmdline参数传入kernel /* CORE */ *ptr++ = 2; *ptr++ = 0x54410001; ptr = target_atag_boot(ptr); ptr = target_atag_mem(ptr); if (target_atag_partition_data) { ptr = target_atag_partition_data(ptr); } #if !(defined(MTK_UFS_BOOTING) || defined(MTK_EMMC_SUPPORT)) if (target_atag_nand_data) { ptr = target_atag_nand_data(ptr); } #endif //some platform might not have this function, use weak reference for extern unsigned *target_atag_dfo(unsigned *ptr)__attribute__((weak)); if (target_atag_dfo) { ptr = target_atag_dfo(ptr); } ptr = target_atag_devinfo_data(ptr); check_hibernation(cmdline); ptr = target_atag_commmandline(ptr, cmdline); ptr = target_atag_initrd(ptr,(unsigned long) ramdisk, ramdisk_size); ptr = target_atag_videolfb(ptr); extern unsigned int *target_atag_mdinfo(unsigned *ptr)__attribute__((weak)); if (target_atag_mdinfo) { ptr = target_atag_mdinfo(ptr); } else { dprintf(CRITICAL,"DFO_MODEN_INFO Only support in MT6582/MT6592\n"); } extern unsigned int *target_atag_masp_data(unsigned *ptr)__attribute__((weak)); if (target_atag_masp_data) { ptr = (char *)target_atag_masp_data((unsigned *)ptr); } else { dprintf(CRITICAL,"masp atag not support in this platform\n"); } /* END */ *ptr++ = 0; *ptr++ = 0; enter_critical_section(); // led,irq关闭 platform_uninit(); // 关闭I/D-cache,关闭MMU arch_disable_cache(UCACHE); arch_disable_mmu(); extern void platform_sec_post_init(void)__attribute__((weak)); if (platform_sec_post_init) { platform_sec_post_init(); } arch_uninit(); //进入kernel entry(0, machtype, tags); } |
文章浏览阅读1k次。通过使用ajax方法跨域请求是浏览器所不允许的,浏览器出于安全考虑是禁止的。警告信息如下:不过jQuery对跨域问题也有解决方案,使用jsonp的方式解决,方法如下:$.ajax({ async:false, url: 'http://www.mysite.com/demo.do', // 跨域URL ty..._nginx不停的xhr
文章浏览阅读2k次。关于在 Oracle 中配置 extproc 以访问 ST_Geometry,也就是我们所说的 使用空间SQL 的方法,官方文档链接如下。http://desktop.arcgis.com/zh-cn/arcmap/latest/manage-data/gdbs-in-oracle/configure-oracle-extproc.htm其实简单总结一下,主要就分为以下几个步骤。..._extproc
文章浏览阅读1.5w次。linux下没有上面的两个函数,需要使用函数 mbstowcs和wcstombsmbstowcs将多字节编码转换为宽字节编码wcstombs将宽字节编码转换为多字节编码这两个函数,转换过程中受到系统编码类型的影响,需要通过设置来设定转换前和转换后的编码类型。通过函数setlocale进行系统编码的设置。linux下输入命名locale -a查看系统支持的编码_linux c++ gbk->utf8
文章浏览阅读750次。今天准备从生产库向测试库进行数据导入,结果在imp导入的时候遇到“ IMP-00009:导出文件异常结束” 错误,google一下,发现可能有如下原因导致imp的数据太大,没有写buffer和commit两个数据库字符集不同从低版本exp的dmp文件,向高版本imp导出的dmp文件出错传输dmp文件时,文件损坏解决办法:imp时指定..._imp-00009导出文件异常结束
文章浏览阅读143次。当下是一个大数据的时代,各个行业都离不开数据的支持。因此,网络爬虫就应运而生。网络爬虫当下最为火热的是Python,Python开发爬虫相对简单,而且功能库相当完善,力压众多开发语言。本次教程我们爬取前程无忧的招聘信息来分析Python程序员需要掌握那些编程技术。首先在谷歌浏览器打开前程无忧的首页,按F12打开浏览器的开发者工具。浏览器开发者工具是用于捕捉网站的请求信息,通过分析请求信息可以了解请..._初级python程序员能力要求
文章浏览阅读7.6k次,点赞2次,收藏6次。@Service标注的bean,类名:ABDemoService查看源码后发现,原来是经过一个特殊处理:当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致public class AnnotationBeanNameGenerator implements BeanNameGenerator { private static final String C..._@service beanname
文章浏览阅读6.9w次,点赞73次,收藏463次。1.前序创建#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>#include<iostream>#include<stack>#include<queue>using namespace std;typed_二叉树的建立
文章浏览阅读7.1k次。在Asp.net上使用Excel导出功能,如果文件名出现中文,便会以乱码视之。 解决方法: fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);_asp.net utf8 导出中文字符乱码
文章浏览阅读2.1k次,点赞4次,收藏23次。第一次实验 词法分析实验报告设计思想词法分析的主要任务是根据文法的词汇表以及对应约定的编码进行一定的识别,找出文件中所有的合法的单词,并给出一定的信息作为最后的结果,用于后续语法分析程序的使用;本实验针对 PL/0 语言 的文法、词汇表编写一个词法分析程序,对于每个单词根据词汇表输出: (单词种类, 单词的值) 二元对。词汇表:种别编码单词符号助记符0beginb..._对pl/0作以下修改扩充。增加单词
文章浏览阅读773次。我在使用adb.exe时遇到了麻烦.我想使用与bash相同的adb.exe shell提示符,所以我决定更改默认的bash二进制文件(当然二进制文件是交叉编译的,一切都很完美)更改bash二进制文件遵循以下顺序> adb remount> adb push bash / system / bin /> adb shell> cd / system / bin> chm..._adb shell mv 权限
文章浏览阅读6.8k次,点赞12次,收藏125次。1. 单目相机标定引言相机标定已经研究多年,标定的算法可以分为基于摄影测量的标定和自标定。其中,应用最为广泛的还是张正友标定法。这是一种简单灵活、高鲁棒性、低成本的相机标定算法。仅需要一台相机和一块平面标定板构建相机标定系统,在标定过程中,相机拍摄多个角度下(至少两个角度,推荐10~20个角度)的标定板图像(相机和标定板都可以移动),即可对相机的内外参数进行标定。下面介绍张氏标定法(以下也这么称呼)的原理。原理相机模型和单应矩阵相机标定,就是对相机的内外参数进行计算的过程,从而得到物体到图像的投影_相机-投影仪标定
文章浏览阅读2.2k次。文章目录Wayland 架构Wayland 渲染Wayland的 硬件支持简 述: 翻译一篇关于和 wayland 有关的技术文章, 其英文标题为Wayland Architecture .Wayland 架构若是想要更好的理解 Wayland 架构及其与 X (X11 or X Window System) 结构;一种很好的方法是将事件从输入设备就开始跟踪, 查看期间所有的屏幕上出现的变化。这就是我们现在对 X 的理解。 内核是从一个输入设备中获取一个事件,并通过 evdev 输入_wayland