跟踪内核启动过程CONFIG_DEBUG_LL【转自】

简介:
最近在调试Linux内核,跟踪启动过程。发现在没有turn on mmu之前,可以使用物理地址,通过向串口Fifo丢数据的方式输出调试信息。但是代码一旦运行到开启mmu,在汇编阶段,mmu只做了物理内存的映射,并没有映射io,所以就无法访问串口了。
 
此时应该通过串口输出的数据都保存在串口缓冲池里,直到在c语言阶段,建立io映射并初始化控制台后才进行输出。
 
但是,如果我想实时跟踪内核启动过程,应该如何才好?
这是就要提到Linux的Lowlevel Debug功能了。
 
这个选项位于:
Kernel hacking  ---> 
 [*] Kernel debugging 
 [*] Kernel low-level debugging functions 
 
打开这个选项会在.config中增加CONFIG_DEBUG_LL宏定义
初步估计,影响的地方有以下几点:
(1)arch/arm/kernel/head.s的__create_page_tables部分
(2)arch/arc/mach-处理器/处理器.c中的宏定义部分
(3)kernel/prink.c
为了提供DEBUG_LL功能,还必须完善arch/arc/mach-处理器/include/mach/debug-macro.S
 
首先说说好处,为什幺打开Kernel low-level debugging functions 功能。
打开这个宏定义后,会在head.s函数的__create_page_tables建立一部分io映射,具体代码如下:
 
#ifdef CONFIG_DEBUG_LL
ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
/*
 * Map in IO space for serial debugging.
 * This allows debug messages to be output
 * via a serial console before paging_init.
 */
ldr r3, [r8, #MACHINFO_PGOFFIO]
add r0, r4, r3
rsb r3, r3, #0x4000 @ PTRS_PER_PGD*sizeof(long)
cmp r3, #0x0800 @ limit to 512MB
movhi r3, #0x0800
add r6, r0, r3
ldr r3, [r8, #MACHINFO_PHYSIO]
orr r3, r3, r7
1:  str r3, [r0], #4
add r3, r3, #1 << 20
teq r0, r6
bne 1b
 
代码中也提到,映射io的作用是为了串口调试使用。
这段代码中使用的物理地址和虚拟地址从何而来?arch/arc/mach-处理器/处理器.c中的宏定义部分
比如以下处理器:
MACHINE_START(EASIC0718, "SEP0718 board")
 
.phys_io = 0x10005000,
.io_pg_offst = ((0xe005000) >> 18) & 0xfffc,
.boot_params = 0x30000100,
.fixup = fixup_gfd0718,
.map_io = sep0718_map_io,
.init_irq =  sep0718_init_irq,
.init_machine = sep0718_init,
.timer = &sep0718_timer,
 
MACHINE_END
 
中间
.phys_io = 0x10005000,
.io_pg_offst = ((0xe005000) >> 18) & 0xfffc,
就是供__create_page_tables的 CONFIG_DEBUG_LL中做io映射使用
 
最后就是对printk.c的改动了,主要是多定义了void printascii(char *)可以直接输出。
完善了debug-macro.S后可以用printascii了。建立了内存映射后,哪里都可以用,无论汇编还是C,无论开mmu前还是开mmu后。代码会判断有没有开mmu的。
同时prink会在缓冲池保留一份数据,也同时调用printkasii直接输出,因此内核启动后会看到信息输出了两次。
 
最后贴上debug-macro.S,writed by leeming,注意其中的io地址和处理器架构相关,不能直接使用。
/* linux/include/asm-arm/arch-sep0718/debug-macro.S
 *
 * Debugging macro include header
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
*/
#include <asm/hardware.h>
 
.macro addruart,rx
mrc p15, 0, \rx, c1, c0
tst \rx, #1 @ MMU enabled?
moveq \rx, #0x10000000
movne \rx, #0xe0000000
add  \rx, \rx, #0x5000
.endm
 
.macro senduart,rd,rx
str \rd, [\rx] @ UARTDR
.endm
            
.macro waituart,rd,rx
1001:  ldr \rd, [\rx, #0x14] @ SYSFLGx
tst \rd, #1 << 6 @ UBUSYx
beq 1001b
.endm
 
.macro busyuart,rd,rx
1001:  ldr \rd, [\rx, #0x14] @ SYSFLGx
tst \rd, #1 << 6 @ UBUSYx
beq 1001b
.endm










本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5344801.html ,如需转载请自行联系原作者
相关文章
|
6月前
|
算法 安全 Java
微服务(四)-config配置中心的配置加解密
微服务(四)-config配置中心的配置加解密
|
7月前
|
移动开发 JavaScript 前端开发
UniApp H5 跨域代理配置并使用(配置manifest.json、vue.config.js)
这篇文章介绍了在UniApp H5项目中处理跨域问题的两种方法:通过修改manifest.json文件配置h5设置,或在项目根目录创建vue.config.js文件进行代理配置,并提供了具体的配置代码示例。
UniApp H5 跨域代理配置并使用(配置manifest.json、vue.config.js)
|
5月前
|
JavaScript 前端开发 应用服务中间件
vue前端开发中,通过vue.config.js配置和nginx配置,实现多个入口文件的实现方法
vue前端开发中,通过vue.config.js配置和nginx配置,实现多个入口文件的实现方法
301 0
|
6月前
|
JavaScript
Vue3基础(19)___vite.config.js中配置路径别名
本文介绍了如何在Vue 3的Vite配置文件`vite.config.js`中设置路径别名,以及如何在页面中使用这些别名导入模块。
225 0
Vue3基础(19)___vite.config.js中配置路径别名
|
7月前
|
JSON 前端开发 JavaScript
vue.config.js配置详解
【8月更文挑战第16天】vue.config.js配置详解
314 1
vue.config.js配置详解
|
5月前
|
前端开发 JavaScript
vite vue3 config配置
【10月更文挑战第5天】
213 0
|
7月前
|
Web App开发 安全 JavaScript
【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)
【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)
117 0
|
7月前
|
缓存 NoSQL 网络协议
【Azure Redis 缓存】如何使得Azure Redis可以仅从内网访问? Config 及 Timeout参数配置
【Azure Redis 缓存】如何使得Azure Redis可以仅从内网访问? Config 及 Timeout参数配置
|
7月前
|
JavaScript Java Python
【Azure 应用服务】在Azure App Service for Windows 中部署Java/NodeJS/Python项目时,web.config的配置模板内容
【Azure 应用服务】在Azure App Service for Windows 中部署Java/NodeJS/Python项目时,web.config的配置模板内容

热门文章

最新文章