little kernel做为Android系统的bootloader,最早用google工程师实现,其后由高通,MTK等芯片厂商做了各自平台的适配。
lk的主要功能:

    初始化硬件模块,如时钟,中断,UART,USB,LCD,PMIC,eMMC/UFS等。更新cmdline。其中重要的是区分启动模式。选择和更新device tree。设置好系统状态,跳转到kernel。 MMU = off, D-cache = off, I-cache = on or off,x0 = physical address to the FDT blob。fastboot功能。鉴权。
           LK 代码结构+app              // 应用相关+arch             // arm 体系 +dev              // 设备相关+include          // 头文件+kernel           // lk系统相关   +platform         // 相关驱动+projiect         // makefile文件+scripts          // Jtag 脚本+target           // 具体板子相关
在 bootable/bootloadler/lk/arch/arm/ssystem-onesegment.ld 连接文件中 ENTRY(_start)指定 LK 从_start 函数开始,_start 在 lk/arch/crt0.S中 。
crt0.S 主要做一些基本的 CPU 的初始化再通过 bl  kmain ;
跳转到 C 代码中。kmain 在 lk/kernel/main.c 中转自https://www.cnblogs.com/LoongEmbedded/p/5298331.html

c语言的入口函数为kmain,在lk/kernel/main.c:

kmain 主要做两件事:1、本身 lk 这个系统模块的初始化;2、boot 的启动初始化动作。

/* called from crt0.S */
void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE;
void kmain(void)
{thread_t *thr;// get us into some sort of thread contextthread_init_early();  /*1.初始化进程(lk 中的简单进程)相关结构体。*/// early arch stuffarch_early_init();    /*2.使能 mmu 的 arm 相关工作。其中会开关cache,这里分x86或者arm架构。*/// do any super early platform initializationplatform_early_init();/*3.相关平台的早期初始化     board_init();platform_clock_init();qgic_init();qtimer_init();scm_init();不同平台大同小异*/// do any super early target initializationtarget_early_init();  /*  4.现在就一个函数跳转,初始化UART(板子相关)uart_dm_init*/dprintf(INFO, "welcome to lk\n\n");bs_set_timestamp(BS_BL_START);/*5.背光点亮时间戳?*/// deal with any static constructorsdprintf(SPEW, "calling constructors\n");call_constructors();/*6.构造函数初始化*/// bring up the kernel heapdprintf(SPEW, "initializing heap\n");heap_init();            /*7.lk系统相关的堆栈初始化*/__stack_chk_guard_setup();/*8.初始化堆栈保护*/// initialize the threading systemdprintf(SPEW, "initializing threads\n");thread_init();        /*9.简短的初始化定时器对象*/// initialize the dpc systemdprintf(SPEW, "initializing dpc\n");dpc_init();            /*10.lk系统控制器初始化(相关事件初始化)*/// initialize kernel timersdprintf(SPEW, "initializing timers\n");timer_init();            /*11.初始化lk中的定时器*/#if (!ENABLE_NANDWRITE)// create a thread to complete system initializationdprintf(SPEW, "creating bootstrap completion thread\n");thr = thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);if (!thr){panic("failed to create thread bootstrap2\n");}thread_resume(thr);/* 12.新建线程入口函数 bootstrap2 用于boot 工作(重点)arch_init platform_int target_init apps_init*/// enable interruptsexit_critical_section();// become the idle threadthread_become_idle();
#elsebootstrap_nandwrite();
#endif
}
static int bootstrap2(void *arg)
{dprintf(SPEW, "top of bootstrap2()\n");arch_init();// XXX put this somewhere else
#if WITH_LIB_BIObio_init();
#endif
#if WITH_LIB_FSfs_init();
#endif// initialize the rest of the platformdprintf(SPEW, "initializing platform\n");platform_init();// initialize the targetdprintf(SPEW, "initializing target\n");target_init();dprintf(SPEW, "calling apps_init()\n");apps_init();return 0;
}bootstrap2 bootstrap2 在kmain的末尾以线程方式开启。主要分三步:platform_init、target_init、apps_init。1.platform_initplatform_init 中主要是函数 acpu_clock_init。在 acpu_clock_init 对 arm11 进行系统时钟设置,超频 2.target_init针对硬件平台进行设置。主要对 arm9 和 arm11 的分区表进行整合,初始化flash和读取FLASH信息3.apps_init  apps_init 是关键,对 LK 中所谓 app 初始化并运行起来,而 aboot_init 就将在这里开始被运行,android linux 内核的加载工作就在 aboot_init 中完成的 。
grep -rn "APP_START"  //这个宏用来往app_descriptor塞入需要启动的进程include/app.h:45:#define APP_START(appname) struct app_descriptor _app_##appname __SECTION(".apps") = { .name = #appname,app/stringtests/string_tests.c:283:APP_START(stringtests)
app/clocktests/clock_tests.c:119:APP_START(clocktests)
app/pcitests/pci_tests.c:247:APP_START(pcitests)
app/shell/shell.c:37:APP_START(shell)
app/aboot/aboot.c:4690:APP_START(aboot)   ///这个是我们的aboot
app/tests/tests.c:42:APP_START(tests)

然后用apps_init()函数调用lk中的另一个关键的c语言函数aboot_init()。由aboot_init()调用boot_linux_from_mmc()。
再由boot_linux_from_mmc()调用boot_linux()。
最后由boot_linux()调用entry()函数(32位kernel)或者scm_elexec_call()(64位kernel),完成lk到kernel的跳转。
lk初始化调用流程如下图:


---------------------  
作者:viewsky11  
来源:CSDN  
原文:https://blog.csdn.net/viewsky11/article/details/53906070  
版权声明:本文为博主原创文章,转载请附上博文链接!

lk:littlekernel-概述相关推荐

  1. 01 LK字幕脚本工具概述

    功能概述 LK字幕脚本工具是为译学馆特效组定制的AE脚本工具,用于辅助完成特效组AE.Pr类型的任务. 该脚本提供的很多功能同样适合改进其他字幕组的工作方式及效率. 脚本功能如下: 快捷制作普通字幕 ...

  2. 2021年大数据Spark(四十四):Structured Streaming概述

    Apache Spark在2016年的时候启动了Structured Streaming项目,一个基于Spark SQL的全新流计算引擎Structured Streaming,让用户像编写批处理程序 ...

  3. android启动---lk入口文件crt0.s解析

    android启动---lk入口文件crt0.s解析 // .section 伪操作, 用户可以通过.section 伪操作来自定义一个段,每一个段以段名为开始, //以下一个段名或者文件结尾为结束, ...

  4. 1-uboot流程——概述

    [uboot] (第一章)uboot流程--概述 2016年10月26日 22:30:45 阅读数:2520 [uboot] uboot流程系列:  [project X] tiny210(s5pv2 ...

  5. 基于深度学习的图像语义分割技术概述之背景与深度网络架构

    本文为论文阅读笔记,不当之处,敬请指正.  A Review on Deep Learning Techniques Applied to Semantic Segmentation: 原文链接 摘要 ...

  6. 安卓手机Recovery概述和原理分析

    安卓手机Recovery概述 1.Recovery是用户想要刷机的过程中经常会遇到的一个词.那么什么是Recovery?Recovery模式又是什么意思?手机怎么进入Recovery模式? 2.Rec ...

  7. [LK光流法,disflow using Dense Inverse Search, VariationalRefinement变分优化 原理和代码]

    文章目录 1.Fast Optical Flow using Dense Inverse Search 1.1 W的含义: 1.2 LK光流模型 1.3 LK光流模型求解(不含迭代) 1.4 LK光流 ...

  8. 高通MDM平台-LK

    1.前言 这篇文章介绍了MDM平台的Little Kernel(LK)的启动流程.Little Kernel的作用是在启动的时候初始化硬件,从存储器中载入Linux内核和ramdisk到RAM中,配置 ...

  9. 高通平台启动log概述(PBL log、sbl1 log、kernel log)

    高通平台启动log概述(PBL log.sbl1 log.kernel log) 在嵌入式linux的调试过程中log有着至关重要的地位,等同于医生的CT报告.能够熟悉启动各个阶段的log,如PBL阶 ...

  10. qemu 下运行lk

    lk是little kernel的简称, 是一个托管在github的开源项目.作用和UBoot类似,作为bootloader进行系统的引导. QEMU是一套跑在linux下的虚拟机.具体参见wiki. ...

最新文章

  1. 青少年编程竞赛交流群周报(第035周)
  2. php种loop用法,PHP EvLoop 用法 手册 | 示例代码
  3. 在SD/MMC卡上实现hive (Implement WinCE HIVEROM system on NAND or SD system )
  4. 关于Class之深入Class
  5. Q2财报凸显“服务”,“巨人”百度正在转身
  6. java单例模式双重检查
  7. Bash中的位置参数和特殊参数
  8. Anaconda3+Python3.6搭建Tensorflow
  9. 免扣PNG图片素材,用着就是爽|png与jpg格式图片的区别
  10. nodejs路由控制图文混排
  11. JS中的事件委托/事件代理详解
  12. 【WPF】对Frame控件的Content属性做绑定时出现的一个小问题
  13. iOS 常见的URL Schemes
  14. vue particles.js 登录背景实现粒子动效
  15. ASP.NET Core 进程内(InProcess)托管
  16. yxy小蒟蒻的201111总结
  17. JavaGUI--模拟QQ聊天界面私聊群聊
  18. 解决没有配置本地nacos但是一直发生localhost8848连接异常的问题
  19. exec与sp_executesql
  20. Flink优化02--状态及Checkpoint调优

热门文章

  1. android 开发比较好的学习网站和博主
  2. 滴滴开源小程序框架 Mpx
  3. springboot+校园新闻数据化系统-计算机毕设 附源码99293
  4. 人工智能小白日记 语音情感分析探索之2 CNN相关及实验
  5. Android7.1 控制背光流程
  6. ES Module与CommonJS
  7. linux节点状态 slurm,linux – 为什么slurm中的作业在TensorFlow脚本中无限期冻结?
  8. CANOE入门:CAPL语言实现诊断发送和接收
  9. #P00603. 倒水
  10. 字符串的几种常见的反转