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 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

Golang HashMap实现原理解析

《GolangHashMap实现原理解析》HashMap是一种基于哈希表实现的键值对存储结构,它通过哈希函数将键映射到数组的索引位置,支持高效的插入、查找和删除操作,:本文主要介绍GolangH... 目录HashMap是一种基于哈希表实现的键值对存储结构,它通过哈希函数将键映射到数组的索引位置,支持

Spring Boot中JSON数值溢出问题从报错到优雅解决办法

《SpringBoot中JSON数值溢出问题从报错到优雅解决办法》:本文主要介绍SpringBoot中JSON数值溢出问题从报错到优雅的解决办法,通过修改字段类型为Long、添加全局异常处理和... 目录一、问题背景:为什么我的接口突然报错了?二、为什么会发生这个错误?1. Java 数据类型的“容量”限制

Spring Boot 整合 SSE的高级实践(Server-Sent Events)

《SpringBoot整合SSE的高级实践(Server-SentEvents)》SSE(Server-SentEvents)是一种基于HTTP协议的单向通信机制,允许服务器向浏览器持续发送实... 目录1、简述2、Spring Boot 中的SSE实现2.1 添加依赖2.2 实现后端接口2.3 配置超时时

Spring Boot读取配置文件的五种方式小结

《SpringBoot读取配置文件的五种方式小结》SpringBoot提供了灵活多样的方式来读取配置文件,这篇文章为大家介绍了5种常见的读取方式,文中的示例代码简洁易懂,大家可以根据自己的需要进... 目录1. 配置文件位置与加载顺序2. 读取配置文件的方式汇总方式一:使用 @Value 注解读取配置方式二

Python使用getopt处理命令行参数示例解析(最佳实践)

《Python使用getopt处理命令行参数示例解析(最佳实践)》getopt模块是Python标准库中一个简单但强大的命令行参数处理工具,它特别适合那些需要快速实现基本命令行参数解析的场景,或者需要... 目录为什么需要处理命令行参数?getopt模块基础实际应用示例与其他参数处理方式的比较常见问http

Python利用ElementTree实现快速解析XML文件

《Python利用ElementTree实现快速解析XML文件》ElementTree是Python标准库的一部分,而且是Python标准库中用于解析和操作XML数据的模块,下面小编就来和大家详细讲讲... 目录一、XML文件解析到底有多重要二、ElementTree快速入门1. 加载XML的两种方式2.

Python如何精准判断某个进程是否在运行

《Python如何精准判断某个进程是否在运行》这篇文章主要为大家详细介绍了Python如何精准判断某个进程是否在运行,本文为大家整理了3种方法并进行了对比,有需要的小伙伴可以跟随小编一起学习一下... 目录一、为什么需要判断进程是否存在二、方法1:用psutil库(推荐)三、方法2:用os.system调用