OK6410A 开发板 (三) 9 u-boot-2021.01 boot 解析 U-boot 镜像运行部分 bootcmd

2024-05-27 15:58

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1007929

相关文章

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

docker如何删除悬空镜像

《docker如何删除悬空镜像》文章介绍了如何使用Docker命令删除悬空镜像,以提高服务器空间利用率,通过使用dockerimage命令结合filter和awk工具,可以过滤出没有Tag的镜像,并将... 目录docChina编程ker删除悬空镜像前言悬空镜像docker官方提供的方式自定义方式总结docker

Spring Boot整合log4j2日志配置的详细教程

《SpringBoot整合log4j2日志配置的详细教程》:本文主要介绍SpringBoot项目中整合Log4j2日志框架的步骤和配置,包括常用日志框架的比较、配置参数介绍、Log4j2配置详解... 目录前言一、常用日志框架二、配置参数介绍1. 日志级别2. 输出形式3. 日志格式3.1 PatternL

如何使用Spring boot的@Transactional进行事务管理

《如何使用Springboot的@Transactional进行事务管理》这篇文章介绍了SpringBoot中使用@Transactional注解进行声明式事务管理的详细信息,包括基本用法、核心配置... 目录一、前置条件二、基本用法1. 在方法上添加注解2. 在类上添加注解三、核心配置参数1. 传播行为(

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

Spring Boot Actuator使用说明

《SpringBootActuator使用说明》SpringBootActuator是一个用于监控和管理SpringBoot应用程序的强大工具,通过引入依赖并配置,可以启用默认的监控接口,... 目录项目里引入下面这个依赖使用场景总结说明:本文介绍Spring Boot Actuator的使用,关于Spri

MySQL 缓存机制与架构解析(最新推荐)

《MySQL缓存机制与架构解析(最新推荐)》本文详细介绍了MySQL的缓存机制和整体架构,包括一级缓存(InnoDBBufferPool)和二级缓存(QueryCache),文章还探讨了SQL... 目录一、mysql缓存机制概述二、MySQL整体架构三、SQL查询执行全流程四、MySQL 8.0为何移除查

在Rust中要用Struct和Enum组织数据的原因解析

《在Rust中要用Struct和Enum组织数据的原因解析》在Rust中,Struct和Enum是组织数据的核心工具,Struct用于将相关字段封装为单一实体,便于管理和扩展,Enum用于明确定义所有... 目录为什么在Rust中要用Struct和Enum组织数据?一、使用struct组织数据:将相关字段绑

通过prometheus监控Tomcat运行状态的操作流程

《通过prometheus监控Tomcat运行状态的操作流程》文章介绍了如何安装和配置Tomcat,并使用Prometheus和TomcatExporter来监控Tomcat的运行状态,文章详细讲解了... 目录Tomcat安装配置以及prometheus监控Tomcat一. 安装并配置tomcat1、安装

使用Java实现一个解析CURL脚本小工具

《使用Java实现一个解析CURL脚本小工具》文章介绍了如何使用Java实现一个解析CURL脚本的工具,该工具可以将CURL脚本中的Header解析为KVMap结构,获取URL路径、请求类型,解析UR... 目录使用示例实现原理具体实现CurlParserUtilCurlEntityICurlHandler