本文主要是介绍OK6410A 开发板 (三) 9 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 bootcmd,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
url : git@github.com:lisider/u-boot.git
branch : ok6410a
commit id : e63a4077ad3aea53107495b0b68b95e720fe6033
config : ok6410a_mini_defconfig
// 涉及的 .S .s .c 文件 有 223个
reset arch/arm/cpu/arm1176/start.S 39lowlevel_init(108) board/samsung/ok6410a/lowlevel_init.S 72_main(110) arch/arm/lib/crt0.S 91board_init_f(117) common/board_f.c 954initcall_run_list(init_sequence_f)(959) include/initcall.h 21init_sequence_f common/board_f.c 818board_init_r(177) common/board_r.c 901initcall_run_list(init_sequence_r)(927) include/initcall.h 21init_sequence_r common/board_f.c 695run_main_loop(898) common/board_r.c 678main_loop(685) common/main.c 39s = bootdelay_process// bootdelay 优先级// 1. 最高 fdt// 2. env// 3. 最低 CONFIG_BOOTDELAYs = env_get("bootdelay");bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;bootdelay = fdtdec_get_config_int(gd->fdt_blob, "bootdelay", bootdelay);s = env_get("bootcmd");return s;autoboot_command(s)(60) common/autoboot.c 362run_command_list(376) common/cli.c 84cli_simple_run_command_list(118) common/cli_simple.c 311cli_simple_run_command(338) common/cli_simple.c 177cmd_process(251) common/command.c 587cmd_call(636) common/command.c 576cmdtp->cmd_rep(cmdtp, flag, argc, argv, repeatable)(581)
bootargs=root=/dev/mmcblk0p2 rw rootfstype=ext3 init=/linuxrc console=ttySAC0,115200 rootwait
bootcmd=fatload mmc 0:1 0x50008000 uImage;bootm 0x50008000;
U-boot 加载内核进ddr
fatload mmc 0:1 0x50008000 uImage;
SUDEBUG : ../common/command.c,cmd_call,line = 581
1828792 bytes read in 205 ms (8.5 MiB/s)
SUDEBUG : ../common/command.c,cmd_call,line = 584 // cmd_call 返回
U-boot 解析并执行内核
- 命令
bootm 0x50008000;
- log
SUDEBUG : ../common/command.c,cmd_call,line = 581 // cmd_call 没有返回
## Booting kernel from Legacy Image at 50008000 ...Image Name: Linux-5.11.0-00001-gd64fe683e8d-Image Type: ARM Linux Kernel Image (uncompressed)Data Size: 1828728 Bytes = 1.7 MiBLoad Address: 50008000Entry Point: 50008000Verifying Checksum ... OKLoading Kernel ImageStarting kernel ...SUDEBUG : ../arch/arm/lib/bootm.c,boot_jump_linux,line = 416,r0 = 0
SUDEBUG : ../arch/arm/lib/bootm.c,boot_jump_linux,line = 417,r1 machid = 1626
// 1626 这个 board id 是 SMDK 板子的,后期要改掉
SUDEBUG : ../arch/arm/lib/bootm.c,boot_jump_linux,line = 418,r2 atags = 0x50000100
// 这个有 152 字节
SUDEBUG : ../arch/arm/lib/bootm.c,boot_jump_linux,line = 419,kernel_entry = 0x50008000
// 此时 0x50008000-0x50008000+0x1be778 中是 zImage(1.744M)// 状态解析1. 内存atags : 0x50000100 - 0x50000100+152 : 152字节zImage : 0x50008000 - 0x50008000+0x1be778 : 1.74M字节
2.cpu寄存器r0 : 0r1 : 1626r2 : 0x50000100 // atags 的地址pc : 0x50008000 // arch/arm/boot/compressed/head.S 中 start标号的地址cpsr[7] : irq offcpsr[6] : fiq off3. cp15协处理器寄存器 Register 1:控制寄存器icache : offdcache : offmmu : off
- atags 的建立
在 bootm命令执行过程中建立,搜索 setup_start_tag
- bootm命令加载uImage
// uImage 头的数据结构体 image_header_t
// 整个bootm 过程中需要填充的结构体 变量 bootm_headers_t images;// 其中包含了 image_header_t
// bootm_headers_t 是一个更大的结构体
// bootm 过程中需要填充该结构体do_bootm cmd/bootm.c 93do_bootm_subcommand(124) cmd/bootm.c 59do_bootm_states(84) common/bootm.c 553bootm_startbootm_find_os // 读取 os 镜像(linux) uImage 头,填充到 bootm_headers_t imagesos_hdr = boot_get_kernel(cmdtp, flag, argc, argv, &images, &images.os.image_start, &images.os.image_len); // bootm_headers_t *images // 读取 img_addr = genimg_get_kernel_addr_fit = 0x50008000buf = map_sysmem(img_addr, 0);## Booting kernel from Legacy Image at 50008000 ...image_header_t *hdr;hdr = image_get_kernel(img_addr, images->verify);image_print_contents(hdr);Image Name: Linux-5.11.0-00001-gd64fe683e8d-Image Type: ARM Linux Kernel Image (uncompressed)Data Size: 1828728 Bytes = 1.7 MiBLoad Address: 50008000Entry Point: 50008000Verifying Checksum ... OK*os_data = image_get_data(hdr);*os_len = image_get_data_size(hdr);memmove(&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));images->legacy_hdr_os = hdr;images->legacy_hdr_valid = 1;return buf;bootm_find_other // 查找 其他的镜像(ramdisk/initramfs/fdt)bootm_find_imagesboot_get_ramdiskbootstage_mark(BOOTSTAGE_ID_NO_RAMDISK);boot_get_fdtset_working_fdt_addrbootm_disable_interruptsbootm_load_os // 加载zImage 到 内核要求的位置image_decompprint_decomp_msgLoading Kernel ImageorXIP Kernel Image memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);memmove(to, from, len);if (dest <= src) memcpy(dest, src, count); // arch/arm/lib/memcpy.Selsetmp = (char *) dest + count;s = (char *) src + count;while (count--)*--tmp = *--s;if (!no_overlap && load < blob_end && load_end > blob_start)images.os.start = 0x50008000, images.os.end = 0x501c67b8images.os.load = 0x50008000, load_end = 0x501c6778if (images->legacy_hdr_valid)return BOOTM_ERR_OVERLAP;boot_fn = bootm_os_get_boot_funcboot_fn()/do_bootm_linux // 设置 ATAGSif (flag & BOOTM_STATE_OS_PREP) boot_prep_linux(images);char *commandline = env_get("bootargs");// 0x50000100 - 0x50000114-1setup_start_tag(gd->bd)(254) arch/arm/lib/bootm.c 127// 0x50000114 - 0x50000174-1setup_commandline_tag(gd->bd, commandline);(258) arch/arm/lib/bootm.c 156// 0x50000174 - 0x50000184-1setup_memory_tags(gd->bd);// 0x50000184 - 0x50000198-1setup_end_tag(gd->bd)(280) arch/arm/lib/bootm.c 221boot_selected_os(657) common/bootm_os.c 610arch_preboot_osboard_preboot_osboot_fn/do_bootm_linux(615) arch/arm/lib/bootm.c 427 // 移交控制权给内核if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO))boot_jump_linux(445) arch/arm/lib/bootm.c 337announce_and_cleanupStarting kernel ...---------------------------------------------------------- 以下是 为满足 load kernel 条件做的事情cleanup_before_linuxdisable_interruptsicache_disabledcache_disablecache_flush// kernel 跳转ip : // arch/arm/boot/compressed/head.S 中的 start标号 即 zImage 镜像中 0 地址处的指令kernel_entry = (void (*)(int, int, uint))images->ep;// r1unsigned long machid = gd->bd->bi_arch_number;(378)char *s = env_get("machid");if (s) strict_strtoul(s, 16, &machid);// r2if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)r2 = (unsigned long)images->ft_addr;elser2 = gd->bd->bi_boot_params;// 将控制权交给zImagekernel_entry(0, machid, r2);(416)
内核对U-boot的要求
//虽然uImage被加载后 执行的第一条 linux命令 在 arch/arm/boot/compressed/head.S 中,
//但是 arch/arm/boot/compressed/head.S 把 linux对u-boot的要求透传给了 arch/arm/kernel/head.Slinux-5.11 arch/arm/kernel/head.S 中
/** Kernel startup entry point.* ---------------------------** This is normally called from the decompressor code. The requirements* are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,* r1 = machine nr, r2 = atags or dtb pointer.** This code is mostly position independent, so if you link the kernel at* 0xc0008000, you call this at __pa(0xc0008000).** See linux/arch/arm/tools/mach-types for the complete list of machine* numbers for r1.** We're trying to keep crap to a minimum; DO NOT add any machine specific* crap here - that's what the boot loader (or in extreme, well justified* circumstances, zImage) is for.*/
这篇关于OK6410A 开发板 (三) 9 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 bootcmd的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!