uboot重点代码分析

本文详细分析了UBoot启动过程中的关键代码,包括start.s和main.c的执行,倒计时与命令解析的步骤,如autoboot_command、abortboot系列函数,以及进入命令模式后的指令解析流程,如mian_loop、cli_loop和parse_stream_outer等。同时,探讨了UBoot的指令注册机制,说明了如何在cmd目录下添加和实现新的命令。
摘要由CSDN通过智能技术生成

目录

 

start.s

 main.c

倒计时与完成后的命令解析:

 autoboot_command(s)

 abortboot(stored_bootdelay)

 __abortboot(bootdelay)

进入命令模式后的指令解析流程:

mian_loop()

cli_loop()

parse_file_outer() 

parse_stream_outer(&input, FLAG_PARSE_SEMICOLON) 

注册指令流程:

uboot的指令注册


start.s

/*
 * (C) Copyright 2013
 * David Feng <fenghua@phytium.com.cn>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <asm-offsets.h>
#include <config.h>
#include <linux/linkage.h>
#include <asm/macro.h>
#include <asm/armv8/mmu.h>

/*************************************************************************
 *
 * Startup Code (reset vector)
 *
 *************************************************************************/

.globl	_start
_start:
/*
  globl就是相当于C语言中的Extern,声明此变量,并且告诉链接器此变量是全局的,外部可以访问
  指定入口为_start
  u-boot.lds里面定义了ENTRY(_start),即指定入口为_start 
 */
#ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
/*
 * Various SoCs need something special and SoC-specific up front in
 * order to boot, allow them to set that in their boot0.h file and then
 * use it here.
对于某些芯片需要特殊的一些初始配置的话,可以通过配置CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK并执行相应boot0.h中的代码来进行一些boot之前的操作。对于绝大多数CPU来说,这部分都是不需要的。
 */
#include <asm/arch/boot0.h>
#else
/* 跳转到reset,这里的代码地址是00000010 */
	b	reset
#endif

#if !CONFIG_IS_ENABLED(TINY_FRAMEWORK)
	.align 3    							 //定义8字节对齐,可以从汇编文件中看出来

.globl	_TEXT_BASE
_TEXT_BASE:
#if defined(CONFIG_SPL_BUILD)
	.quad   CONFIG_SPL_TEXT_BASE
#else
	.quad	CONFIG_SYS_TEXT_BASE
#endif

/*
 * These are defined in the linker script.
 */
.globl	_end_ofs
_end_ofs:
	.quad	_end - _start

.globl	_bss_start_ofs
_bss_start_ofs:
	.quad	__bss_start - _start

.globl	_bss_end_ofs
_bss_end_ofs:
	.quad	__bss_end - _start

reset:
	/* Allow the board to save important registers */
	b	save_boot_params
.globl	save_boot_params_ret
save_boot_params_ret:

#if CONFIG_POSITION_INDEPENDENT
	/*
	 * Fix .rela.dyn relocations. This allows U-Boot to be loaded to and
	 * executed at a different address than it was linked at.
	 */
pie_fixup:
	adr	x0, _start		/* x0 <- Runtime value of _start */
	ldr	x1, _TEXT_BASE		/* x1 <- Linked value of _start */
	sub	x9, x0, x1		/* x9 <- Run-vs-link offset */
	adr	x2, __rel_dyn_start	/* x2 <- Runtime &__rel_dyn_start */
	adr	x3, __rel_dyn_end	/* x3 <- Runtime &__rel_dyn_end */
pie_fix_loop:
	ldp	x0, x1, [x2], #16	/* (x0, x1) <- (Link location, fixup) */
	ldr	x4, [x2], #8		/* x4 <- addend */
	cmp	w1, #1027		/* relative fixup? */
	bne	pie_skip_reloc
	/* relative fix: store addend plus offset at dest location */
	add	x0, x0, x9
	add	x4, x4, x9
	str	x4, [x0]
pie_skip_reloc:
	cmp	x2, x3
	b.lo	pie_fix_loop
pie_fixup_done:
#endif

#ifdef CONFIG_SYS_RESET_SCTRL
	bl reset_sctrl
#endif
	/*
	 * Could be EL3/EL2/EL1, Initial State:
	 * Little Endian, MMU Disabled, i/dCache Disabled
	 */
	adr	x0, vectors
	switch_el x1, 3f, 2f, 1f
3:	msr	vbar_el3, x0
	mrs	x0, scr_el3
	orr	x0, x0, #0xf			/* SCR_EL3.NS|IRQ|FIQ|EA */
	msr	scr_el3, x0
	msr	cptr_el3, xzr			/* Enable FP/SIMD */
#ifdef COUNTER_FREQUENCY
	ldr	x0, =COUNTER_FREQUENCY
	msr	cntfrq_el0, x0			/* Initialize CNTFRQ */
#endif
	b	0f
2:	msr	vbar_el2, x0
	mov	x0, #0x33ff
	msr	cptr_el2, x0			/* Enable FP/SIMD */
	b	0f
1:	msr	vbar_el1, x0
	mov	x0, #3 << 20
	msr	cpacr_el1, x0			/* Enable FP/SIMD */
0:

	/*
	 * Enable SMPEN bit for coherency.
	 * This register is not architectural but at the moment
	 * this bit should be set for A53/A57/A72.
	 */
#ifdef CONFIG_ARMV8_SET_SMPEN
	switch_el x1, 3f, 1f, 1f
3:
	mrs     x0, S3_1_c15_c2_1               /* cpuectlr_el1 */
	orr     x0, x0, #0x40
	msr     S3_1_c15_c2_1, x0
1:
#endif

	/* Apply ARM core specific erratas */
	bl	apply_core_errata

	/*
	 * Cache/BPB/TLB Invalidate
	 * i-cache is invalidated before enabled in icache_enable()
	 * tlb is invalidated before mmu is enabled in dcache_enable()
	 * d-cache is invalidated before enabled in dcache_enable()
	 */

	/* Processor specific initialization */
	bl	lowlevel_init

#if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
	branch_if_master x0, x1, master_cpu
	b	spin_table_secondary_jump
	/* never return */
#elif defined(CONFIG_ARMV8_MULTIENTRY)
	branch_if_master x0, x1, master_cpu

	/*
	 * Slave CPUs
	 */
slave_cpu:
	wfe
	ldr	x1, =CPU_RELEASE_ADDR
	ldr	x0, [x1]
	cbz	x0, slave_cpu
	br	x0			/* branch to the given address */
#endif /* CONFIG_ARMV8_MULTIENTRY */
master_cpu:
	bl	_main

#ifdef CONFIG_SYS_RESET_SCTRL
reset_sctrl:
	switch_el x1, 3f, 2f, 1f
3:
	mrs	x0, sctlr_el3
	b	0f
2:
	mrs	x0, sctlr_el2
	b	0f
1:
	mrs	x0, sctlr_el1

0:
	ldr	x1, =0xfdfffffa
	and	x0, x0, x1

	switch_el x1, 6f, 5f, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录 u-boot-1.1.6 之 cpu/arm920t/start.s分析 ........................................................................................... 2 u-boot 中.lds连接脚本文件的分析 ...................................................................................................12 分享一篇我总结的 uboot 学习笔记(转) .....................................................................................15 U-BOOT内存布局及启动过程浅析 ...................................................................................................22 u-boot 中的命令实现 .......................................................................................................................... 25 U-BOOT环境变量实现 ........................................................................................................................28 1.相关文件 ....................................................................................................................................28 2.数据结构 ....................................................................................................................................28 3.ENV 的初始化...........................................................................................................................30 3.1env_init ............................................................................................................................30 3.2 env_relocate ...................................................................................................................30 3.3*env_relocate_spec ........................................................................................................31 4. ENV 的保存 ..............................................................................................................................31 U-Boot 环境变量 ..........................................................................................................................32 u-boot 代码链接的问题 ......................................................................................................................35 ldr 和 adr 在使用标号表达式作为操作数的区别 ............................................................................40 start_armboot 浅析 ..............................................................................................................................42 1.全局数据结构的初始化 ..........................................................................................................42 2.调用通用初始化函数...............................................................................................................43 3.初始化具体设备 .......................................................................................................................44 4.初始化环境变量 .......................................................................................................................44 5.进入主循环 ...............................................................................................................................44 u-boot 编译过程 ...................................................................................................................................44 mkconfig文件的分析 .......................................................................................................................... 47 从 NAND闪存中启动 U-BOOT的设计 ..............................................................................................50 引言 ...............................................................................................................................................50 NAND闪存工作原理 ................................................................................................................... 51 从 NAND闪存启动 U-BOOT的设计思路.................................................................................. 51 具体设计 ....................................................................................................................................... 51 支持 NAND闪存的启动程序设计 ..................................................................................... 51 支持 U-BOOT命令设计 ...................................................................................................... 52 结语 ............................................................................................................................................... 53 参考文献 ....................................................................................................................................... 53 U-boot 给 kernel 传参数和 kernel 读取参数—struct tag (以及补充) ............................................ 53 1 、u-boot 给 kernel 传 RAM 参数 ........................................................................................54 2 、Kernel 读取 U-boot 传递的相关参数 .............................................................................56 3 、关于 U-boot 中的 bd 和 gd...............................................................................................59 U-BOOT源码分析及移植 ....................................................................................................................60 一、 u-boot 工程的总体结构: ..................................................................................................61 1、源代码组织 ....................................................................................................................61 2.makefile简要分析 ............................................................................................................61 3、u-boot 的通用目录是怎么做到与平台无关的?......................................................63 4、smkd2410 其余重要的文件 : ...................................................................................63 二、u-boot 的流程、主要的数据结构、内存分配 ................................................................64 1、u-boot 的启动流程: ...................................................................................................64 2、u-boot 主要的数据结构 ...............................................................................................66 3、u-boot 重定位后的内存分布: ...................................................................................68 三、u-boot 的重要细节 。 ........................................................................................................68 关于 U-boot 中命令相关的编程 : ................................................................................. 73 四、U-boot 在 ST2410 的移植,基于 NOR FLASH和 NAND FLASH启动。......................... 76 1、从 smdk2410 到 ST2410: .............................................................................................. 76 2、移植过程: .................................................................................................................... 76 3、移植要考虑的问题: ...................................................................................................77 4、SST39VF1601: .................................................................................................................77 5、我实现的 flash.c主要部分: ...................................................................................... 78 6、增加从 Nand 启动的代码 : ..................................................................................... 82 7、添加网络命令。 ............................................................................................................ 87
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值