当前位置:文档之家› 2-4 UBoot源码分析1解析

2-4 UBoot源码分析1解析


struct tag_பைடு நூலகம்eader { u32 size; u32 tag; };
//每个参数的大小 //每个参数的类型
do_bootm_linux流程
• 在do_bootm_linux函数(Uboot/lib_arm/bootm.c)中定义函 数指针theKernel函数指针,并通过读取Linux的内核镜像文 件uImage前面的40字节内容获取Linux内核的入口地址 – theKernel = (void (*)(int, int, uint))images->ep;
• UBoot如何给内核传递参数?
– UBoot和内核交互是单向的,两个程序不能同时运行,那么要实 现参数传递只能通过把参数存放到一个固定内存位置然后调用 theKernel函数给对R0,R1,R2寄存器赋值。Linux启动调用 start_kernel函数读取内容即可。
do_bootm_linux函数
• UBoot如何调用Linux内核?
– UBoot通过命令把Linux内核镜像文件从Flash中读取到内存的某一 位置,然后设置PC寄存器执向该位置UBoot调用Linux内核的
前提条件是?
– R0 =0 – R1=适当的机器码 机器码的位置存放在 linux/arch/arm/tools/mach-type文件中 – R2 =启动参数标记列表在内存中的位置 – CPU必须设置为SVC模式并关闭中断 – MMU必须关闭
theKernel (0, machid, bd->bi_boot_params); //启动Linux内核
theKernel函数
• 参数 zero:设置为0 R0寄存器为0 • 参数:arch 表示机器存储于R1寄存器中 • 参数:params用于传递给Linux的参数地址 (包括命令行参数信息)
• do_bootm_linux是UBoot真正启动Linux的 函数(位于UBoot所在目录/lib_arm/bootm.c)
int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) { bd_t *bd = gd->bd; char *s; int machid = bd->bi_arch_number; void (*theKernel)(int zero, int arch, uint params); .................. theKernel = (void (*)(int, int, uint))images->ep; //传递Linux内核首地址
tag结构体
struct tag { struct tag_header hdr; union { struct tag_core struct tag_mem32 struct tag_videotext struct tag_ramdisk struct tag_initrd struct tag_serialnr struct tag_revision struct tag_videolfb struct tag_cmdline 。。。。。。。 struct tag_memclk } u; }; core; //列表的开始 mem; //描述内存信息 videotext; // ramdisk; initrd; serialnr; //串口信息 revision; //版本信息 videolfb; cmdline; //命令行 memclk; //内存时钟
tag_list参数列表
• UBoot如何组织这么多的参数信息呢?
– UBoot使用struct tag 和struct tag_head来描述这些参数信息。存放位置 (include/asm-arm/setup.h) – 相对应的在Linux内核源代码中也有完全相同的结构体定义存放位置 (linux/arch/arm/include/asm/setup.h) – – – – – – – – – #define ATAG_CORE 0x54410001 #define ATAG_MEM 0x54410002 #define ATAG_VIDEOTEXT 0x54410003 #define ATAG_RAMDISK 0x54410004 #define ATAG_INITRD 0x54410005 #define ATAG_SERIAL 0x54410006 #define ATAG_REVISION 0x54410007 #define ATAG_CMDLINE 0x54410009 #define ATAG_NONE 0x000000001
– 编译Linux内核时可以通过make menuconfig命 令进行命令行参数的配置 – Uboot引导的时候传递启动参数参数地址给内 核。
命令行参数
参数信息
• u-boot要传递给内核的参包含哪些内容?
– MACH_TYPE(即我们所说的机器码)、 – 命令行参数CommandLine – 系统根设备信息(标志,页面大小)、 – 内存信息(起始地址,大小)、 – RAMDISK信息(起始地址,大小)、压缩的 RAMDISK根文件系统信息(起始地址,大小)。 由此可见要传递的参数很多
• UBoot源码解析(一)
主要内容
• 分析UBoot是如何引导Linux内核 • UBoot Makefile分析 • UBoot源码的一阶段解析
UBoot存储空间分布
• UBoot是用来引导OS系统启动,那么它是如何引 导OS启动的呢?
启动参数
内核
根文件系统
bootloader
UBoot和内核的交互
(*theKernel)(int zero, int arch, uint params);
启动参数
• Linux内核启动的时候并不会自己去扫描硬 件的基本信息,因为它启动时都已经假设硬 件都已经准备好了,但是使用过程中不可 避免的要用到硬件信息,这些信息包括内 存大小,串口配置信息等等。那么这信息内 核是如何获的呢?
相关主题