关闭

uboot第一阶段启动流程

146人阅读 评论(0) 收藏 举报
分类:
.globl _start
_start: b	reset
	ldr	pc, _undefined_instruction
	ldr	pc, _software_interrupt
	ldr	pc, _prefetch_abort
	ldr	pc, _data_abort
	ldr	pc, _not_used
	ldr	pc, _irq
	ldr	pc, _fiq

_undefined_instruction: .word undefined_instruction
_software_interrupt:	.word software_interrupt
_prefetch_abort:	.word prefetch_abort
_data_abort:		.word data_abort
_not_used:		.word not_used
_irq:			.word irq
_fiq:			.word fiq
_pad:			.word 0x12345678 /* now 16*4=64 */
	
.balignl 16,0xdeadbeef


/*----------------------------------------
 *board/samsung/fsc100/config.mk 
 *TEXT_BASE = 0x20f00000
 *
 */
_TEXT_BASE:
	.word	TEXT_BASE

//-Ttext 0x20f00000 
_armboot_start:
	.word _start 


/*----------------------------------------
 *__bss_start 和 _end 在链接脚本u-boot.lds中定义
 *分别表示bss段的起始地址和结束地址
 *
 */
_bss_start:
	.word __bss_start 

_bss_end:
	.word _end


/*
 * the actual reset code
 */
reset:
	/*
	 * 设置ARM核为SVC模式
	 */
	mrs	r0, cpsr
	bic	r0, r0, #0x1f
	orr	r0, r0, #0xd3
	msr	cpsr,r0

	bl	cpu_init_crit


#ifndef CONFIG_NAND_FLASH_BOOT  
	//Nor Flash 启动的时候代码搬移
relocate:				@ relocate U-Boot to RAM
	//用r0保存当前代码加载地址 
	adr	r0, _start		@ r0 <- current position of code
	
	//用r1保存代码的运行地址:链接的时候指定的代码段地址 -Ttext 
	ldr	r1, _TEXT_BASE		@ test if we run from flash or RAM
	
	//比较加载地址和运行地址是否相等
	cmp	r0, r1			@ don't reloc during debug
	
	//相等则跳跳转到栈设置代码
	beq	stack_setup
	
	//获得代码段的起始地址
	ldr	r2, _armboot_start
	
	//获得BSS段的起始地址 
	ldr	r3, _bss_start
	//获得txt +  data + rodata + got + cmd段 大小 
	sub	r2, r3, r2		@ r2 <- size of armboot
	
	//用r2保存当前代码段在存储器中的结束地址  
	add	r2, r0, r2		@ r2 <- source end address
	
	//将Nor Flash代码搬移到指定的代码运行地址
copy_loop:				@ copy 32 bytes at a time
	ldmia	r0!, {r3 - r10}		@ copy from source address [r0]
	stmia	r1!, {r3 - r10}		@ copy to   target address [r1]
	cmp	r0, r2			@ until source end addreee [r2]
	ble	copy_loop

#else 
	
	//Nand Flash 启动的时候代码搬移
relocate:				@ relocate U-Boot to RAM
	adr	r0, _start		@ r0 <- current position of code
	ldr	r1, _TEXT_BASE	@ test if we run from DRAM or SRAM
	cmp	r0, r1			@ don't reloc during debug
	beq	stack_setup
	
	ldr sp,_TEXT_BASE 
	
	ldr r0,_TEXT_BASE	
	mov r1,#0x0 
	mov r2,#0x50000
	
	//从Nand Flash中代码搬移到指定的代码运行地址
	bl  copy_uboot_to_dram
	
#endif	/* CONFIG_NAND_FLASH_BOOT*/


	/*设置栈空间*/
stack_setup:
	ldr	r0, _TEXT_BASE		@ upper 128 KiB: relocated uboot
	sub	r0, r0, #CONFIG_SYS_MALLOC_LEN @ malloc area
	sub	r0, r0, #CONFIG_SYS_GBL_DATA_SIZE @ bdinfo
	sub	sp, r0, #12		@ leave 3 words for abort-stack
	and	sp, sp, #~7		@ 8 byte alinged for (ldr/str)d

	/*将bss段所在的内存空间初始化为0*/
clear_bss:
	ldr	r0, _bss_start		@ find start of bss segment
	ldr	r1, _bss_end		@ stop here
	mov	r2, #0x00000000		@ clear value
clbss_l:
	str	r2, [r0]		@ clear BSS location
	cmp	r0, r1			@ are we at the end yet
	add	r0, r0, #4		@ increment clear index pointer
	bne	clbss_l			@ keep clearing till at end

	
	//跳到C语言代码,即uboot的第二阶段代码,此时PC指针修改到DRAM地址
	ldr	pc, _start_armboot	@ jump to C code

_start_armboot: .word start_armboot

cpu_init_crit:
	/*
	 *使指令cache和数据cache无效
	 */
	mov	r0, #0			@ set up for MCR
	mcr	p15, 0, r0, c8, c7, 0	@ invalidate TLBs
	mcr	p15, 0, r0, c7, c5, 0	@ invalidate icache

	/*
	 *关MMU
	 */
	mrc	p15, 0, r0, c1, c0, 0
	bic	r0, r0, #0x00002000	@ clear bits 13 (--V-)
	bic	r0, r0, #0x00000007	@ clear bits 2:0 (-CAM)
	orr	r0, r0, #0x00000002	@ set bit 1 (--A-) Align
	orr	r0, r0, #0x00000800	@ set bit 12 (Z---) BTB
	mcr	p15, 0, r0, c1, c0, 0

	/*
	 * Jump to board specific initialization...
	 * The Mask ROM will have already initialized
	 * basic memory. Go here to bump up clock rate and handle
	 * wake up conditions.
	 */
	mov	ip, lr			@ persevere link reg across call
	bl	lowlevel_init		@ go setup pll,mux,memory
	mov	lr, ip			@ restore link
	mov	pc, lr			@ back to my caller


lowlevel_init:
	mov	r9, lr

	/* r5 has always zero */
	mov	r5, #0

	ldr	r8, =S5PC100_GPIO_BASE

	/* 关开门狗 */
	ldr	r0, =S5PC100_WATCHDOG_BASE		@0xEA200000
	orr	r0, r0, #0x0
	str	r5, [r0]

	/* 设置SMC 控制器 */
	ldr	r0, =S5PC100_SROMC_BASE
	ldr	r1, =0x9
	str	r1, [r0]

	//关中断
	/* S5PC100 has 3 groups of interrupt sources */
	ldr	r0, =S5PC100_VIC0_BASE			@0xE4000000
	ldr	r1, =S5PC100_VIC1_BASE			@0xE4000000
	ldr	r2, =S5PC100_VIC2_BASE			@0xE4000000

	/* Disable all interrupts (VIC0, VIC1 and VIC2) */
	mvn	r3, #0x0
	str	r3, [r0, #0x14]				@INTENCLEAR
	str	r3, [r1, #0x14]				@INTENCLEAR
	str	r3, [r2, #0x14]				@INTENCLEAR

	//设置所有中断为IRQ类型
	/* Set all interrupts as IRQ */
	str	r5, [r0, #0xc]				@INTSELECT
	str	r5, [r1, #0xc]				@INTSELECT
	str	r5, [r2, #0xc]				@INTSELECT
	
	//清除向量地址寄存器值
	/* Pending Interrupt Clear */
	str	r5, [r0, #0xf00]			@INTADDRESS
	str	r5, [r1, #0xf00]			@INTADDRESS
	str	r5, [r2, #0xf00]			@INTADDRESS


	/*初始化UART的GPIO口 */
	bl uart_asm_init

	/*初始化安全访问控制器*/
	bl tzpc_asm_init

	/*初始化系统时钟*/
	bl	system_clock_init
	
	/*初始化DRAM控制器*/
	bl	mem_ctrl_asm_init

1:
	mov	lr, r9
	mov	pc, lr

/*
 * uart_asm_init: Initialize UART's pins
 */
uart_asm_init:
	mov	r0, r8
	ldr	r1, =0x22222222
	str	r1, [r0, #0x0]			@ GPA0_CON
	ldr	r1, =0x00022222
	str	r1, [r0, #0x20]			@ GPA1_CON

	mov	pc, lr


 * tzpc_asm_init: Initialize TZPC
 */
tzpc_asm_init:
	ldr	r0, =0xE3800000
	mov	r1, #0x0
	str	r1, [r0]
	mov	r1, #0xff
	str	r1, [r0, #0x804]
	str	r1, [r0, #0x810]

	ldr	r0, =0xE2800000
	str	r1, [r0, #0x804]
	str	r1, [r0, #0x810]
	str	r1, [r0, #0x81C]

	ldr	r0, =0xE2900000
	str	r1, [r0, #0x804]
	str	r1, [r0, #0x810]

	mov	pc, lr
0
0

猜你在找
【套餐】Hadoop生态系统零基础入门
【套餐】嵌入式Linux C编程基础
【套餐】2017软考系统集成项目——任铄
【套餐】Android 5.x顶级视频课程——李宁
【套餐】深度学习入门视频课程——唐宇迪
【直播】广义线性模型及其应用——李科
【直播】从0到1 区块链的概念到实践
【直播】计算机视觉原理及实战——屈教授
【直播】机器学习之凸优化——马博士
【直播】机器学习&数据挖掘7周实训--韦玮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:84271次
    • 积分:2774
    • 等级:
    • 排名:第12915名
    • 原创:101篇
    • 转载:27篇
    • 译文:100篇
    • 评论:6条