원본 URL :

https://github.com/iamroot12CD/linux/wiki/raspberrypi2_kernel_debug

 

 

QEMU를 이용한 라즈베리파이2 커널 디버깅

QEMU 컴파일

$ mkdir -p ~/git/pi2
$ cd ~/git/pi2

$ git clone https://github.com/0xabu/qemu.git -b raspi
$ cd qemu
$ git submodule update --init dtc
  • QEMU 커널 BASE 주소 수정
    • Qemu 소스 hw/arm/boot.c 파일 수정.
#define KERNEL_LOAD_ADDR 0x00010000

이것을 아래처럼 수정.

#define KERNEL_LOAD_ADDR 0x00008000
  • compile 및 설치
$ cd ~/git/pi2/qemu

$ ./configure --target-list=arm-softmmu
$ make -j$(nproc)
$ sudo make install

라즈베리파이2용 커널 컴파일

$ mkdir ~/git/pi2
$ cd ~/git/pi2
$ git clone https://github.com/raspberrypi/tools
  • 컴파일 환경 설정 파일 만들기
$ vi env.sh
#!/bin/sh
export PATH=~/git/pi2/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin:$PATH
export KERNEL=kernel7

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
  • 환경 설정 적용.
$ source env.sh
  • 커널 컴파일시 추가 셋팅
$ cd ~/git/pi2/
$ git clone --depth=1 https://github.com/raspberrypi/linux
$ git checkout tag5  #  2016년 11월 이후 버전에서만 실행

$ cd linux
$ make bcm2709_defconfig
$ make menuconfig

Kernel hacking --> Compile-time checks and compiler option --> Compile the kernel with debug info --> Enable

$ make -j$(nproc) zImage modules dtbs

커널 디버깅

  • 컴파일 된 커널과 DTB파일 추출
$ scripts/mkknlimg arch/arm/boot/zImage ~/git/pi2/kernel7.img
$ cp arch/arm/boot/dts/bcm2709-rpi-2-b.dtb ~/git/pi2
  • QEMNU 실행 스크립트 작성.
$ vi ~/git/pi2/run_qemu.sh
#!/bin/sh

BOOT_CMDLINE="rw earlyprintk loglevel=8 console=ttyAMA0,115200 console=tty1 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2"
DTB_FILE="bcm2709-rpi-2-b.dtb"
KERNEL_IMG="kernel7.img"
SD_IMG="raspbian-jessie.img"

echo "target remote localhost:1234"
qemu-system-arm -s -S -M raspi2 -kernel ${KERNEL_IMG} \
    -sd ${SD_IMG} \
    -append "${BOOT_CMDLINE}" \
    -dtb ${DTB_FILE} -serial stdio
  • QEMU 실행
$ sh ./run_qemu.sh
  • gdb 실행 새터미널을 띄운후 gdb 실행(디버깅)
$ cd ~/git/pi2
$ source env.sh
$ cd ~/git/pi2/linux
$ arm-linux-gnueabihf-gdb ./vmlinux
# GDB shell에서 target remote localhost:1234 명령을 친다.
(gdb) target remote localhost:1234

# start_kernel 에 브레이크 포인트 셋팅
(gdb) b start_kernel

# 디버깅 시작.
(gdb) c

# 소스 확인
(gdb) list
493 vmalloc_init();
494 ioremap_huge_init();
495 }
496
497 asmlinkage __visible void __init start_kernel(void)
498 {
499 char *command_line;
500 char *after_dashes;
501
502 /*
(gdb)
번호 제목 글쓴이 날짜 조회 수
공지 [공지] 강좌, 팁, 정보등에 대해 올리는 게시판입니다. woos 2016.04.09 246
129 여기는 팁, 기타 정보를 올리는 곳입니다. 백창우 2006.06.05 14751
128 #pragma에 관련해서.. [2] 원민수 2006.07.19 20782
127 kernel 2.6의 kzalloc함수 (원민수 씀) 백창우 2007.02.23 19337
126 누가 나를 호출했는지 찾기 + 포인터를 심볼 이름으로 변환하여 출력하기 [1] 지현구 2007.02.27 17863
125 태훈님에 이어. ARM kernel 참고자료 백창우 2007.11.05 19014
124 systemtap 관련 간단한 소개입니다. 남용우 2007.11.06 17057
123 define을 사용한 version 처리. 원민수 2008.02.09 15026
122 허접 영어 사전입니다. [3] 백창우 2008.04.22 16092
121 포토샵 웹버전입니다. [1] 강진성 2010.05.14 40685
120 막강 디버깅 매크로 DM_PRINT() [4] file 배상경 2010.11.23 12045
119 perspective of the medical industry and engineering [15] 김성현2 2011.09.16 8197
118 돈되는 이야기?! 음주운전방지 앱 [3] 김성현2 2011.10.18 6775
117 돈되는 이야기?!, 내친김에 하나더, 나는 잘 자고 있을까? [8] 김성현2 2011.10.18 7789
116 돈되는 이야기?! 삼성 손가락 혈압계 [1] 김성현2 2011.10.20 9493
115 조금은 묵직한 시스템, 뇌감시장치 김성현2 2011.11.17 10585
114 C++에서 meta class 이용하기 [2] 이경문 2012.05.06 6888
113 멀티유저 드라이빙 환경 [3] pororo 2012.08.25 7257
112 xen 4.1 설치 방법(우분투 11.04) [2] 이상철 2012.11.14 10109
111 리눅스 커널 스터디 참고자료 (x86) [4] 리누즈박 2013.05.06 18396
110 2013.05.25 ARM 아키텍쳐 세미나 1차 발표자료 - by 민홍 교수님 [5] file K 2013.05.25 4980
XE Login