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

相关文章

深度解析Java DTO(最新推荐)

《深度解析JavaDTO(最新推荐)》DTO(DataTransferObject)是一种用于在不同层(如Controller层、Service层)之间传输数据的对象设计模式,其核心目的是封装数据,... 目录一、什么是DTO?DTO的核心特点:二、为什么需要DTO?(对比Entity)三、实际应用场景解析

深度解析Java项目中包和包之间的联系

《深度解析Java项目中包和包之间的联系》文章浏览阅读850次,点赞13次,收藏8次。本文详细介绍了Java分层架构中的几个关键包:DTO、Controller、Service和Mapper。_jav... 目录前言一、各大包1.DTO1.1、DTO的核心用途1.2. DTO与实体类(Entity)的区别1

Java中的雪花算法Snowflake解析与实践技巧

《Java中的雪花算法Snowflake解析与实践技巧》本文解析了雪花算法的原理、Java实现及生产实践,涵盖ID结构、位运算技巧、时钟回拨处理、WorkerId分配等关键点,并探讨了百度UidGen... 目录一、雪花算法核心原理1.1 算法起源1.2 ID结构详解1.3 核心特性二、Java实现解析2.

java实现docker镜像上传到harbor仓库的方式

《java实现docker镜像上传到harbor仓库的方式》:本文主要介绍java实现docker镜像上传到harbor仓库的方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 前 言2. 编写工具类2.1 引入依赖包2.2 使用当前服务器的docker环境推送镜像2.2

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

使用Python绘制3D堆叠条形图全解析

《使用Python绘制3D堆叠条形图全解析》在数据可视化的工具箱里,3D图表总能带来眼前一亮的效果,本文就来和大家聊聊如何使用Python实现绘制3D堆叠条形图,感兴趣的小伙伴可以了解下... 目录为什么选择 3D 堆叠条形图代码实现:从数据到 3D 世界的搭建核心代码逐行解析细节优化应用场景:3D 堆叠图

深度解析Python装饰器常见用法与进阶技巧

《深度解析Python装饰器常见用法与进阶技巧》Python装饰器(Decorator)是提升代码可读性与复用性的强大工具,本文将深入解析Python装饰器的原理,常见用法,进阶技巧与最佳实践,希望可... 目录装饰器的基本原理函数装饰器的常见用法带参数的装饰器类装饰器与方法装饰器装饰器的嵌套与组合进阶技巧

解析C++11 static_assert及与Boost库的关联从入门到精通

《解析C++11static_assert及与Boost库的关联从入门到精通》static_assert是C++中强大的编译时验证工具,它能够在编译阶段拦截不符合预期的类型或值,增强代码的健壮性,通... 目录一、背景知识:传统断言方法的局限性1.1 assert宏1.2 #error指令1.3 第三方解决

全面解析MySQL索引长度限制问题与解决方案

《全面解析MySQL索引长度限制问题与解决方案》MySQL对索引长度设限是为了保持高效的数据检索性能,这个限制不是MySQL的缺陷,而是数据库设计中的权衡结果,下面我们就来看看如何解决这一问题吧... 目录引言:为什么会有索引键长度问题?一、问题根源深度解析mysql索引长度限制原理实际场景示例二、五大解决

深度解析Spring Boot拦截器Interceptor与过滤器Filter的区别与实战指南

《深度解析SpringBoot拦截器Interceptor与过滤器Filter的区别与实战指南》本文深度解析SpringBoot中拦截器与过滤器的区别,涵盖执行顺序、依赖关系、异常处理等核心差异,并... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现