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

相关文章

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.

全面解析HTML5中Checkbox标签

《全面解析HTML5中Checkbox标签》Checkbox是HTML5中非常重要的表单元素之一,通过合理使用其属性和样式自定义方法,可以为用户提供丰富多样的交互体验,这篇文章给大家介绍HTML5中C... 在html5中,Checkbox(复选框)是一种常用的表单元素,允许用户在一组选项中选择多个项目。本

Python包管理工具核心指令uvx举例详细解析

《Python包管理工具核心指令uvx举例详细解析》:本文主要介绍Python包管理工具核心指令uvx的相关资料,uvx是uv工具链中用于临时运行Python命令行工具的高效执行器,依托Rust实... 目录一、uvx 的定位与核心功能二、uvx 的典型应用场景三、uvx 与传统工具对比四、uvx 的技术实

SpringBoot排查和解决JSON解析错误(400 Bad Request)的方法

《SpringBoot排查和解决JSON解析错误(400BadRequest)的方法》在开发SpringBootRESTfulAPI时,客户端与服务端的数据交互通常使用JSON格式,然而,JSON... 目录问题背景1. 问题描述2. 错误分析解决方案1. 手动重新输入jsON2. 使用工具清理JSON3.

Redis过期删除机制与内存淘汰策略的解析指南

《Redis过期删除机制与内存淘汰策略的解析指南》在使用Redis构建缓存系统时,很多开发者只设置了EXPIRE但却忽略了背后Redis的过期删除机制与内存淘汰策略,下面小编就来和大家详细介绍一下... 目录1、简述2、Redis http://www.chinasem.cn的过期删除策略(Key Expir

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

Spring Boot 整合 Apache Flink 的详细过程

《SpringBoot整合ApacheFlink的详细过程》ApacheFlink是一个高性能的分布式流处理框架,而SpringBoot提供了快速构建企业级应用的能力,下面给大家介绍Spri... 目录Spring Boot 整合 Apache Flink 教程一、背景与目标二、环境准备三、创建项目 & 添

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

深入解析 Java Future 类及代码示例

《深入解析JavaFuture类及代码示例》JavaFuture是java.util.concurrent包中用于表示异步计算结果的核心接口,下面给大家介绍JavaFuture类及实例代码,感兴... 目录一、Future 类概述二、核心工作机制代码示例执行流程2. 状态机模型3. 核心方法解析行为总结:三