uboot 完整源码追踪注释

作者: robe.zhang
上传时间为: 2018-08-15 09:04 AM
2018-08-15
阅读:

uboot 完整的源码追踪注释,代码比较多,细节会有错误,程序走向没有问题,

从第一行代码 :b reset

到最后一行:kernel_entry(0, machid, r2);

完整源码追踪做了注释

本文格式:缩进代表是上层函数的子函数,像 python 那样。括号中是文件全路径。

u-boot.lds
(arch/arm/lib/vectors.S)
								.globl 	_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
								.globl	_undefined_instruction
								.globl	_software_interrupt
								.globl	_prefetch_abort
								.globl	_data_abort
								.globl	_not_used
								.globl	_irq
								.globl	_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
								
								.globl IRQ_STACK_START_IN
	IRQ_STACK_START_IN:
								.globl IRQ_STACK_START
	IRQ_STACK_START:
								.globl FIQ_STACK_START
	FIQ_STACK_START:
	
	中断处理函数:				寄存器压栈,处理结束,弹栈
		do_undefined_instruction
		do_software_interrupt
		do_prefetch_abort
		do_data_abort
		do_not_used
		do_irq
		do_fiq					(arch/arm/lib/interrupts.c)
	
(arch/arm/cpu/armv7/start.S)
	.reset
	.save_boot_params_ret
	reset:						
		save_boot_params_ret:	关闭FIQ/IRQ, 设置SVC32,或者进HYP模式
								设置向量表_start(定义CONFIG_SPL_BUILD)
		cpu_init_cp15:			关mmu,关caches,开i-cache
		cpu_init_crit:
			lowlevel_init:		设置sp指针=CONFIG_SYS_INIT_SP_ADDR,
								清零r9,=0(定义CONFIG_SPL_DM)
								设置r9,=gdata(定义CONFIG_SPL_BUILD)
								设置r9,放到 sp 空间上面
				 s_init:		设置PLL
		_main:
(arch/arm/lib/crt0.S:)_main
	ldr	sp, =(CONFIG_SYS_INIT_SP_ADDR):		设置sp
		#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)
		#define CONFIG_SYS_INIT_RAM_ADDR IRAM_BASE_ADDR
		#define IRAM_BASE_ADDR 0x00900000
		#define CONFIG_SYS_INIT_SP_OFFSET (CONFIG_SYS_INIT_RAM_SIZE - GENERATED_GBL_DATA_SIZE)
		#define CONFIG_SYS_INIT_RAM_SIZE IRAM_SIZE
		#define IRAM_SIZE 0x00020000
	board_init_f_alloc_reserve:
		(common/init/board_init.c:):		保留1k空间
											设置r9
	board_init_f_init_reserve:
		(common/init/board_init.c:):		设置gd->malloc_base
	board_init_f:
		(common/board_f.c:):				清零gd空间,设置gd->flags=0,gd->have_console=0
		initcall_run_list:
			init_sequence_f:
(common/board_f.c)init_sequence_f:
	setup_mon_len:							设置gd->mon_len = (ulong)&__bss_end - (ulong)_start;
	initf_malloc:							设置gd->malloc_ptr = 0;设置gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
	initf_console_record:					空
	arch_cpu_init:							(arch/arm/cpu/armv7/mx6)
		init_aips:
		clear_mmdc_ch_mask:
		init_src:
	initf_dm:
		dm_init_and_scan:							
			dm_init:							gd->dm_root存在,返回。不存在初始化gd->uclass_root
				device_bind_by_name:
				device_probe:
			dm_scan_platdata:
			dm_scan_other:
	arch_cpu_init_dm:						空
	mark_bootstage:							添加record记录(static struct bootstage_record record[BOOTSTAGE_ID_COUNT] = { {1} };)
	board_early_init_f:						(board/myir/mys_imx6ull/mys_imx6ull.c)	//修改1
		setup_iomux_uart:					设置串口
	timer_init:							(arch/arm/imx-common/syscounter.c)
											初始化启动syscounter,清零gd->arch.tbl,gd->arch.tbu
	board_postclk_init:
		set_ldo_voltage:
	get_clocks:							设置gd->arch.sdhc_clk
	env_init:								设置gd->env_addr=default_environment[]地址,(include/env_default.h)
											设置gd->env_valid=1
	init_baud_rate:							设置gd->baudrate
	serial_init:							设置gd->flags |= GD_FLG_SERIAL_READY;
		get_current:
			default_serial_console:
				mxc_serial_drv:
					struct serial_device mxc_serial_drv={
						.name	= "mxc_serial",
						.start	= mxc_serial_init,
						.stop	= NULL,
						.setbrg	= mxc_serial_setbrg,
						.putc	= mxc_serial_putc,
						.puts	= default_serial_puts,
						.getc	= mxc_serial_getc,
						.tstc	= mxc_serial_tstc,
					}
		get_current()->start():				初始化串口,并使能。(drivers/serial/serial_mxc.c)
	console_init_f:							设置gd->have_console=1,初始化console
	display_options:						[打印]u-boot第一次开始输出信息,输出版本信息															
	display_text_info:
	print_cpuinfo:							[打印]cpu信息,reset cause:por 信息
	show_board_info:						[打印]board信息,(board/myir/mys_imx6ull/mys_imx6ull.c)
	announce_dram_init:					puts打印信息
	dram_init:
		get_ram_size:						获取实际ram size,赋值给gd->ram_size
	setup_dest_addr:						重新设置内存分配内存
											设置gd->relocaddr = gd->ram_top
	reserve_round_4k:						设置gd->relocaddr 4k对齐
	reserve_mmu:							设置gd->arch.tlb_size,gd->arch.tlb_addr
	reserve_trace:							空
	reserve_uboot:							预留gd->mon_len
	reserve_malloc:						预留TOTAL_MALLOC_LEN
	reserve_board:							预留gd->bd,设置gd->bd
	setup_machine:							设置gd->bd->bi_arch_number
	reserve_global_data:					预留gd->new_gd空间,设置gd->new_gd
	reserve_fdt:							预留gd->new_fdt,设置gd->new_fdt
	arch_reserve_stacks:					预留gd->irq_sp,设置gd->irq_sp
	dram_init_banksize:					设置gd->bd->bi_dram[0].start,
											设置gd->bd->bi_dram[0].size
	show_dram_config:						[打印]dram信息
	display_new_sp:							[打印]gd->start_addr_sp信息(已设置gd->start_addr_sp)
	setup_board_extra:						设置gd->bd->bi_s_version,
											设置gd->bd->bi_r_version,
											设置gd->bd->bi_procfreq = gd->cpu_clk
											设置gd->bd->bi_plb_busfreq = gd->bus_clk
	reloc_fdt:								复制memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
											设置gd->fdt_blob = gd->new_fdt;
	setup_reloc:							复制memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
	
未完接下页

文章分页: 1 2 3 > 

全部评论 ()
条评论
写评论

创建讨论帖子

登录 后参与评论
系统提示