uboot源码分析

2019-04-14 08:34发布

class="markdown_views prism-github-gist">

uboot源码分析

1、ARM SOC启动流程

  • BL0:第一阶段启动代码,固化在SOC片内ROM中,不可修改;
  • BL1:上电启动第二阶段,在BL0阶段被加载至SRAM中,对应于u-boot的SPL阶段;
  • BL2:上电启动第三阶段,在BL1阶段被加载至SDRAM中,对应于u-boot的uboot阶段。
Created with Raphaël 2.2.0上电启动BL0(IROM)BL0(IROM):初始化(系统时钟、SRAM等)BL0(IROM):验证BL1镜像BL0(IROM):加载BL1镜像至SRAMBL0(IROM):跳转至BL1BL1(IRAM):u-boot-SPLBL1(IRAM)BL1(IRAM):初始化SDRAM、堆栈BL1(IRAM):验证、加载BL2镜像至SDRAMBL1(IRAM):跳转至BL2BL2(SDRAM):u-boot-BootLoaderBL2(SDRAM):加载内核文件系统启动运行应用程序

2、main_loop()调用流程概述

/* u-boot-2019.04 */ u-boot-spl.lds(/arch/arm/cpu) ..............|_start(/arch/arm/lib/vectors.S) ......................|reset(/arch/arm/cpu/arm920t/start.S) .............................|cpu_init_crit(/arch/arm/cpu/arm920t/start.S) ............................................|lowlevel_init(/arch/arm/cpu/mach-xx/lowlevel_init.S) .............................|_main(/arch/arm/lib/crt0.S) ....................................|board_init_f_alloc_reserve(/common/init/board_init.c) ....................................|board_init_f_init_reserve(/common/init/board_init.c) ....................................|→board_init_f ....................................|→board_init_r .................................................|→initcall_run_list ...................................................................|→run_main_loop .................................................................................|→main_loop /* u-boot-2010.03 */ u-boot.lds .........|_start(/cpu/arm920t/start.S) ................|start_code(/cpu/arm920t/start.S) ...........................|cpu_init_crit(/cpu/arm920t/start.S) .........................................|lowlevel_init(lowlevel_init.S) ...........................|_start_armboot(/cpu/arm920t/start.S) ..........................................|start_armboot(/lib_arm/board.c) ........................................................|main_loop(/common/main.c)

3、uboot解析用户命令的两种方式分析

/* u-boot-2010.03代码片段 */ #ifdef CONFIG_SYS_HUSH_PARSER //用户命令解析方式一:hush方式 parse_file_outer(); /* This point is never reached */ for (;;); #else //用户命令解析方式二 for (;;) { ... ... ... len = readline (CONFIG_SYS_PROMPT); flag = 0; /* assume no special flags for now */ if (len > 0) strcpy (lastcommand, console_buffer); else if (len == 0) flag |= CMD_FLAG_REPEAT; ... ... ... if (len == -1) puts (" "); else rc = run_command (lastcommand, flag); if (rc <= 0) { /* invalid command or not repeatable, forget it */ lastcommand[0] = 0; } } #endif /*CONFIG_SYS_HUSH_PARSER*/

3.1、方式一

parse_file_outer ...............|→parse_stream_outer ..................................|→run_list ............................................|→run_list_real ..........................................................|→run_pipe_real ........................................................................|→cmdtp->cmd

3.2、方式二

readline .......|→readline_into_buffer //read data to consol_buffer run_command ..........|→parse_line //parse command line ..........