Source code analysis of uboot

Source code analysis of uboot

1. ARM SOC startup process

  • BL0: the first stage startup code, solidified in the SOC on-chip ROM, cannot be modified;
  • BL1: power on and start the second stage, which is loaded into SRAM in BL0 stage, corresponding to SPL stage of u-boot;
  • BL2: the third stage of power on and startup, which is loaded into SDRAM in BL1 stage, corresponding to the U boot stage of u-boot.
Created with Rapha ë l 2.2.0 power on to start BL0(IROM)BL0(IROM): Initialize (system clock, SRAM, etc.) BL0(IROM): verify BL1 image BL0(IROM): load BL1 image to SRAMBL0(IROM): jump to bl1BL1(IRAM): u-boot-splbl1 (IRAM): initialize SDRAM, stack BL1(IRAM): verify, load BL2 image to SDRAMBL1(IRAM): jump to BL2BL2(SDRAM): u-boot-bootloader BL2 (SDRAM): load Kernel file system start running application

2. Overview of main loop() call process

/* 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. Analysis of two ways of uboot parsing user commands

/* u-boot-2010.03 code snippet */
#Ifdef config sys hush parser / / user command resolution mode 1: hush mode
	parse_file_outer();
	/* This point is never reached */
	for (;;);
#else / / user command resolution mode 2
	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 ("<INTERRUPT>\n");
		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 mode 1

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

3.2 mode 2

readline
.......|→readline_into_buffer //read data to consol_buffer
run_command
..........|→parse_line //parse command line
..........|→find_cmd   //find out command from command table
..........|→cmdtp->cmd

Posted by kmutz22 on Tue, 03 Dec 2019 23:26:44 -0800