앞에서 작성된 글이 커널 버젼이 변경되어서 정상동작 하지 않는것 같아서 현재까지 확인한 사항 업데이트해서 문서를 만들었습니다.
내용은 앞쪽 글과 동일하며 단지 커널소스를 가져오는 부분 정도만 업데이트 했습니다.
-분석내용
인터넷에 확인해 보면 마지막으로 QEMU 에뮬레이션 되었던 kernel version이 2015년 11월 버젼인것 같습니다.
최선 커널 버젼으로 하면 emmc, rng driver가 정상적으로 에뮬레이션 되지 않아서 문제가 발생하는것 같습니다
kernel source를 2015년 11월 버젼(tag5)가져와서 사용하면 정상동작 합니다.
원본 URL :
http://www.iamroot.org/xe/index.php?mid=Knowledge&document_srl=179241
https://github.com/iamroot12CD/linux/wiki/raspberrypi2_kernel_debug
QEMU를 이용한 라즈베리파이2 커널 디버깅
QEMU 컴파일
-
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용 커널 컴파일
- 참고 URL Raspberry Pi Kernel Building
- 라즈베리파이2 이미지 다운로드 Raspberry PI 2 Image download
-
압축을 푼뒤 raspbian-jessie.img 파일명으로 변경한다
-
라즈베리파이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 https://github.com/raspberrypi/linux
$ cd linux
$ git checkout tag5
$ make bcm2709_defconfig
$ make menuconfig
Kernel hacking --> Compile-time checks and compiler option -->
Compile the kernel with debug info --> Enable
Generate dwarf4 debuginfo --> Enable
Provide GDB scripts for kernel debuffing--> 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
$ ddd --debugger arm-linux-gnueabihf-gdb ./vmlinux
# GDB shell에서 target remote localhost:1234 명령을 친다.
(gdb) target remote localhost:1234
# start_kernel 에 브레이크 포인트 셋팅
(gdb) b start_kernel
# 디버깅 시작.
(gdb) c
댓글 2
-
mkernel
2017.06.25 12:57
-
mkernel
2017.07.23 15:12
일단 위의 작업을 모두 마친뒤에...
$ cd ~/git/pi2/linux
$ scripts/mkknlimg arch/arm/boot/compressed/vmlinux ~/git/pi2/kernel7.img
$ sh ~/git/pi2/run_qemu.sh
$ ddd --debugger arm-linux-gnueabihf-gdb ~/git/pi2/linux/arch/arm/boot/compressed/vmlinux
이렇게 하면 심볼이 제대로 잡히는것 같아요. 한번 해보세요.
.
우분투가 아닌 배포판에서는 다음 오류가 날 가능성이 있으니 참조해 주시기 바랍니다.
qemu configure시
* python경로를 못 찾을 경우 (파이선 경로는 시스템마다 다르므로 유의)
--python=/path 추가
* warnning으로 컴파일 실패시
--disable-werror 추가
결국 저는 다음 명령줄로 컴파일까지 완료했습니다.
./configure --python=/usr/bin/python2.7 --target-list=arm-softmmu --disable-werror