您当前的位置:五五电子网电子知识单片机-工控设备嵌入式系统-技术Powerpc构架系统内核和内核模块调试 正文
Powerpc构架系统内核和内核模块调试

Powerpc构架系统内核和内核模块调试

点击数:7466 次   录入时间:03-04 11:54:41   整理:http://www.55dianzi.com   嵌入式系统-技术

    此文档的目标系统为freescale MPC8349E-mITX,对其他采用powerPC,MIPS,ARM的芯片的系统亦具有参考意义。 此文档中内核调试为了简化,采用目标系统中的UBOOT初始化目标板,并通过UBOOT或者BDI2000加载内核到目标板的RAM中。

    1. BDI2000配置:

    下面是MPC8349E-mITX的BDI2000配置文件,

    ; BDI-2000 CONfiguraTIon file for the MPC8349E-mITX

    ; Tip: If after a reset, the BDI-2000 fails to halt at 0x100,

    ; you may need to power-down the bOArd for a few seconds.

    [INIT]

    ; we use UBOOT to initialize the board

    [TARGET]

    CPUTYPE 8349

    JTAGCLOCK 1

    ;STARTUP RESET

    STARTUP RUN

    BREAKMODE HARD

    STEPMODE HWBP

    BOOTADDR 0x00000100

    ;If you're getting "Writing to worksPACe faiLED" errors during flash operations,

    ;then try uncommenting this line instead. This moves the FLASH window to

    ;high memory, leaving low memory available for DDR.

    RCW 0xb060a000 0x04040000 ;Set the HRCW to boot the image at 0xFE000000

    MMU XLAT ;0xc0000000

    PTBASE 0xf0 ;

    [HOST]

    IP 192.168.7.90

    FILE $u-boot.bin

    LOAD MANUAL

    PROMPT 8349E-mITX-GP>

    DUMP itx-dump.bin

    [Flash]

    ChipTYPE AM29BX16

    CHIPSIZE 0x800000

    BUSWIDTH 16

    ;WORKSPACE 0x1000

    FORMAT BIN 0xfe000000

    ;flash_image.bin is an image file of an entire 8MB flash region.

    ;Flash this file at 0xfe0000000 to restore all of flash.

    ;ERASE 0xFE000000 0x10000 127 ; 127 sectors @ 64KB each

    ;ERASE 0xFE7F0000 0x2000 8 ; 8 sectors @ 8KB each

    ;FILE $flash_image.bin

    ;Use these lines if you just want to flash U-Boot

    ERASE 0xfe000000 0x10000? 4; Erase 384KB, each sector is 64KB

    FILE? mpc8349e/u-boot131-mitx-gp.bin

    [REGS]

    FILE $reg8349e.def

    以上配置文件的【HOST】段的IP要改为主机IP,关键的字段MMU XLAT 和PTBASE 是POWERPC和MIPS经常需要设置的,关于PTBASE的具体设置,超出本文范围,详细情况请参考BDI2000的手册

    2.内核修改和配置

    为了能够调试内核,需要在内核中的Makefile中增加如下调试选项:

    CFLAGS 增加C代码调试选项-g –ggdb

    AFLAGS 增加汇编代码调试选项:-Wa,-L -gdwarf-2

    去掉CFLAGS编译选项中-fomit-frAME-pointer

    GCC的-fomit-frame-pointer选项是优化函数栈回溯(stack backtrace)的,我们调试的时候需要提供函数回溯能力,所以我们要去掉这个选项,当然,有的系统系统不受它的影响,或者说它不起作用,为了统一,我们统一去掉它。

    相对个案来说,我是做如下改动的:

    --- Makefile 2008-07-08 03:07:38.000000000 +0800

    +++ Makefile.debug 2008-07-08 03:06:04.000000000 +0800

    …

    -CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE)

    +ifdef CONFIG_DEBUG_INFO

    +

    + CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE) -g -ggdb

    -CFLAGS := -Wall -Wundef -WstrICt-prototypes -Wno-trigraphs

    + CFLAGS := $(CPPFLAGS) -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs

    -fno-strict-aliasing -fno-common

    -AFLAGS := -D__ASSEMBLY__

    + AFLAGS := -D__ASSEMBLY__ -Wa,-L -gdwarf-2

    +else

    + CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE)

    + CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs

    + -fno-strict-aliasing -fno-common

    + AFLAGS := -D__ASSEMBLY__

    +

    +endif

    …

    @@ -491,27 +500,33 @@

    # Defaults vmlinux but it is usually overridden in the arch makefile

    all: vmlinux

    -ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE

    -CFLAGS += -Os

    -else

    -CFLAGS += -O2

    -endif

    include $(SRCtree)/arch/$(ARCH)/Makefile

    -ifdef CONFIG_FRAME_POINTER

    -CFLAGS += -fno-omit-frame-pointer $(call cc-option,-fno-optimize-sibling-calls,)

    -else

    -CFLAGS += -fomit-frame-pointer

    -endif

    ifdef CONFIG_UNWIND_INFO

    CFLAGS += -fasynchronous-unwind-tables

    endif

    -ifdef CONFIG_DEBUG_INFO

    -CFLAGS += -g

    -endif

    +#ifdef CONFIG_DEBUG_INFO

    +CFLAGS += -fno-omit-frame-pointer $(call cc-option,-fno-optimize-sibling-calls,)

    +CFLAGS += -g -ggdb

    +CFLAGS += -O

    +#else

    +

    +# ifdef CONFIG_FRAME_POINTER

    + CFLAGS += -fno-omit-frame-pointer $(call cc-option,-fno-optimize-sibling-calls,)

    +# else

    + CFLAGS += -fomit-frame-pointer

    +# endif

    +

    +# ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE

    + CFLAGS += -Os

    +# else

    + CFLAGS += -O2

    +# endif

    +

    +#endif

    通过以上修改后,系统的的调试信息简单的通过CONFIG_DEBUG_INFO宏来控制了,那么CONFIG_DEBUG_INFO宏又是从哪里来的呢?它其实是从内核的配置文件.config里面来的。

    一般内核通过make menuconfig做配置的时候,都有

    Kernel hacking --->

    [*] Kernel debugging

    [*] Compile the kernel with debug info

    [*] Force gcc to inline functions marked 'inline' (2.6比较新的内核有这一项)



www.55dianzi.com

    [*] Include BDI-2000 user context switcher (有的系统直接提供了这个选项,它和BDI2000的PTBASE设置配合)

    通过保存后,以上选项会生成如下配置选项:

    CONFIG_DEBUG_KERNEL=y

    CONFIG_DEBUG_INFO=y

    CONFIG_FORCED_INLINING=y

    CONFIG_BDI_SWITCH=y

    值得关注的是PowerPC内核中CONFIG_BDI_SWITCH,它到底在内核中怎样起作用的?

    我们看arch/powerpc/kernel/head_32.S的关键代码:

    …

    /* Load up the kernel Context */

    2: bl load_up_mmu

    #ifdef CONFIG_BDI_SWITCH

    /* Add helper information for the Abatron bdiGDB debugger.

    * We do this here because we know the mmu is dISAbLED, and

    * will be enabled for real in just a few instructions.

    */

    lis r5, abatron_pteptrs@h

    ori r5, r5, abatron_pteptrs@l

    stw r5, 0xf0(r0)??? /* This much match your Abatron config */

    lis r6, swapper_pg_dir@h

    ori r6, r6, swapper_pg_dir@l

    tophys(r5, r5)

    stw r6, 0(r5)

    #endif /* CONFIG_BDI_SWITCH */

    /* Now turn on the MMU for real! */

    …

    它在MMU真正时能之前先增加了BDI2000帮助信息。在arch/powerpc/kernel/head_32.S的最后通过abatron_pteptrs保留了8个自己的空间给BDI2000用于保存2个页表指针,如下:

[1] [2]  下一页


本文关键字:暂无联系方式嵌入式系统-技术单片机-工控设备 - 嵌入式系统-技术