LiangShuang's ...

I'm not a programmer...

"Uncompressing Linux......................."

shuang posted @ 2010年12月04日 09:31 in 嵌入式linux , 4752 阅读

    最近看了一本超级强大的书Embeded Linux Primer,里面介绍了内核调试的一种方法可以通过转储printk日志缓冲区的方法来查看内核的打印内容。开始还有些奇怪,为什么start_kernel中的printk一直不起作用呢?难道是程序没有跳转到这里,但是自己都检查几遍之前的代码了,应该没什么问题。这才知道原来printk在终端设备初始化之前是先把打印的内容暂存到自己的日志缓冲区中的,只有等终端设备初始化后才一起投放到我们面前,所以console_init()函数执行之前我们不会看到任何printk打印的信息,最多只能看到内核自解压时打印的那句"Uncompressing Linux.......................",不过这已经让我兴奋不已了<^_^>,为了定位到程序的出错位置,我首先使用串口控制台的打印函数printascii(),这个函数是.../arch/arm/kernel/debug.S中定义的,非常有趣的是在文件的注释处有这么一段英文描述:

/*
 * Some debugging routines (useful if you've got MM problems and
 * printk isn't working).  For DEBUGGING ONLY!!!  Do not leave
 * references to these in a production kernel!
 */


     看来内核的设计者早就知道我们会遇到“MM problems”了,这些函数足够我们debug用的了,printascii函数还是在内核启动早期的.../arch/arm/kernel/head-common.S中用到过,不过此时MMU已经打开了,怎么还能使用IO地址空间打印东西呢,不用担心,这个在早期的建立页表的函数head.S中的__create_page_tables()中就完成了映射工作,不过需要在内核配置时打开CONFIG_DEBUG_LL配置开关,通过这种方法我定位到了内核死在了setup_arch()->paging_init()->bootmem_init()处。接下来就是通过转储printk的日志缓冲区来显示panic()的信息了,首先我们必须知道日志缓冲区的在内存中的地址,这个可以通过查看System.map中的__log_buf得到,通过查找我得到了这样一条记录c025e018 b __log_buf,其中__log_buf是在.../kernel/printk.c中定义的,还有一个问题就是我们需要将c025e018这个地址转化一下,因为很显然这是一个虚拟地址,然后就可以利用u-boot的工具md打印内存地址上的内容了,md 3025e018,虽然显示的都是ascii码,读起来不是很方便,但是还是能够看到"bootmem alloc of 32768 bytes failed!"的错误信息。。。

    说到了这里,那内核为什么停在了bootmem_init()处了呢?

Avatar_small
wallace 说:
2010年12月31日 05:50

真给力啊,小爽子

run 3 说:
2019年2月21日 16:04

I enjoyed over read your blog post. This was actually what i was looking for and i am glad to came here!

civaget 说:
2023年12月11日 07:51

While content is essential, don't overlook the technical aspects of SEO. Site speed, mobile optimization, and clean code all contribute to your 구글 상위노출 success.

civaget 说:
2023年12月17日 08:15

The journey of self-discovery through 일본인안마 is profound. It's soul-nourishing.

civaget 说:
2023年12月19日 06:13

wonderful issues altogether, you just gained a logo reader. What would you recommend about your publish that you made a few days ago? Any sure? 유튜브 프리미엄 무료보기

civaget 说:
2023年12月20日 04:38 The interface of 누누티비 is so intuitive; I didn't need any tutorials to get started.
civaget 说:
2023年12月23日 20:33

슈어맨's detailed reviews are a valuable resource for parents like me.

civaget 说:
2023年12月23日 23:48 I've explored other webtoon platforms, but 툰코 stands out with its legality.
civaget 说:
2023年12月25日 03:05

해외축구중계 is a game-changer for expats like me. It helps me stay connected to my home team, no matter where I am.

civaget 说:
2023年12月31日 00:10

I trust 안전한 바카라 사이트 for a secure baccarat experience.

civaget 说:
2024年1月13日 20:52

I have been exploring for a little bit for any high-quality articles or blog posts in this kind of space . Exploring in Yahoo I ultimately stumbled upon this site. Reading this information So i’m satisfied to show that I’ve a very just right uncanny feeling I found out just what I needed. I such a lot indisputably will make certain to do not forget this web site and give it a glance a continuing. คืนยอดเสีย

civaget 说:
2024年1月15日 04:07

I used to be recommended this website through my cousin. I am now not certain whether this put up is written by him as nobody else recognize such special about my difficulty. You are incredible! Thank you! Lahore Sky

seo 说:
2024年1月19日 21:04

This is an excellent article and I totally understand where your coming from in the third section. Perfect read, I’ll regularly follow the other reads. free local classified ads

seo 说:
2024年1月20日 00:54

Sweet internet site , super design , really clean and utilize genial . accounting services

seo 说:
2024年1月21日 00:18

My plate is real full and your tryna give me more food, boy what the fuck is wrong wit’ you?!|guruisthebomb| supplier of singapore umbrella


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter