mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
mips
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# CONTRIBUTING
|
||||
|
||||
Testing you should do before pushing:
|
||||
Testing you should do before pushing: new modules:
|
||||
|
||||
- `/insrm.sh module 5`. Helps catch simple insert remove problems.
|
||||
|
||||
New arch:
|
||||
|
||||
- `./run -a ARCH`
|
||||
- `wget google.com` for Internet
|
||||
- `./runqemu -a ARCH -d` and `./rungdb -a ARCH`
|
||||
|
||||
20
README.md
20
README.md
@@ -1,6 +1,6 @@
|
||||
# Linux Kernel Module Cheat
|
||||
|
||||
Run one command, get into QEMU Buildroot BusyBox virtual machine with several minimal Linux kernel 4.9 module development example tutorials with GDB and KGDB debug. Tested in x86 and ARM guests, Ubuntu 14.04 - 16.10 hosts.
|
||||
Run one command, get a QEMU Buildroot BusyBox virtual machine with several minimal Linux kernel 4.9 module development example tutorials with GDB and KGDB debug. Tested in x86, ARM and MIPS guests, Ubuntu 14.04 - 17.04 hosts.
|
||||
|
||||

|
||||
|
||||
@@ -139,9 +139,7 @@ To GDB the Linux kernel, first run:
|
||||
|
||||
./runqemu -d
|
||||
|
||||
This starts QEMU on the background of the shell, to prepare for running GDB.
|
||||
|
||||
If you want to break immediately at a symbol, e.g. `start_kernel` of the boot sequence, run:
|
||||
If you want to break immediately at a symbol, e.g. `start_kernel` of the boot sequence, run on another shell:
|
||||
|
||||
./rungdb start_kernel
|
||||
|
||||
@@ -234,11 +232,13 @@ And then tell GDB where the module was loaded with:
|
||||
Ctrl + C
|
||||
add-symbol-file ../kernel_module-1.0/fops.ko 0xfffffffa00000000
|
||||
|
||||
## ARM
|
||||
## Other architectures
|
||||
|
||||
The portability of the kernel and toolchains is amazing.
|
||||
The portability of the kernel and toolchains is amazing: change an option and most things magically work on completely different hardware.
|
||||
|
||||
First ARM build:
|
||||
### ARM
|
||||
|
||||
First build:
|
||||
|
||||
./run -a arm
|
||||
|
||||
@@ -252,11 +252,15 @@ Debug:
|
||||
# On another terminal.
|
||||
./rungdb -a arm
|
||||
|
||||
ARM TODOs:
|
||||
TODOs:
|
||||
|
||||
- only managed to run in the terminal interface (but weirdly a blank QEMU window is still opened)
|
||||
- GDB not connecting to KGDB. Possibly linked to `-serial stdio`. See also: <https://stackoverflow.com/questions/14155577/how-to-use-kgdb-on-arm>
|
||||
|
||||
### MIPS
|
||||
|
||||
./run -a mips64
|
||||
|
||||
## KGDB
|
||||
|
||||
KGDB is kernel dark magic that allows you to GDB the kernel on real hardware without any extra hardware support.
|
||||
|
||||
9
run
9
run
@@ -4,18 +4,21 @@ arch='x86_64'
|
||||
while getopts a: OPT > /dev/null 2>&1; do
|
||||
case "$OPT" in
|
||||
'a')
|
||||
arch=$OPTARG
|
||||
arch="$OPTARG"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
case "$arch" in
|
||||
'x86_64')
|
||||
defconfig=qemu_x86_64_defconfig
|
||||
defconfig='qemu_x86_64_defconfig'
|
||||
;;
|
||||
'arm')
|
||||
# qemu_arm_vexpress_defconfig required a newer QEMU than 2.0.0 on a Ubuntu host.
|
||||
# so let's stick to versatile for now.
|
||||
defconfig=qemu_arm_versatile_defconfig
|
||||
defconfig='qemu_arm_versatile_defconfig'
|
||||
;;
|
||||
'mips64')
|
||||
defconfig='qemu_mips64r6_malta_defconfig'
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
9
rungdb
9
rungdb
@@ -7,7 +7,7 @@ kgdb=false
|
||||
while getopts a:k OPT; do
|
||||
case "$OPT" in
|
||||
a)
|
||||
arch=$OPTARG
|
||||
arch="$OPTARG"
|
||||
;;
|
||||
k)
|
||||
kgdb=true
|
||||
@@ -18,7 +18,7 @@ shift "$(($OPTIND - 1))"
|
||||
if [ "$#" -gt 0 ]; then
|
||||
brk="-ex 'break $1'"
|
||||
else
|
||||
brk=""
|
||||
brk=''
|
||||
fi
|
||||
|
||||
buildroot_out_dir="$(pwd)/buildroot/output.${arch}~"
|
||||
@@ -51,13 +51,14 @@ else
|
||||
-ex 'lx-symbols ../kernel_module-1.0/'
|
||||
"
|
||||
;;
|
||||
'arm')
|
||||
'arm'|'mips64')
|
||||
cmd="$gdb \
|
||||
-q \
|
||||
-ex 'add-auto-load-safe-path $(pwd)' \
|
||||
-ex 'file vmlinux' \
|
||||
-ex 'target remote localhost:1234' \
|
||||
-ex 'lx-symbols ../kernel_module-1.0/'
|
||||
-ex 'lx-symbols ../kernel_module-1.0/' \
|
||||
$brk \
|
||||
"
|
||||
;;
|
||||
esac
|
||||
|
||||
32
runqemu
32
runqemu
@@ -3,7 +3,7 @@
|
||||
set -e
|
||||
|
||||
# CLI handling.
|
||||
arch=x86_64
|
||||
arch='x86_64'
|
||||
debug=false
|
||||
debug_qemu=''
|
||||
kgdb=false
|
||||
@@ -13,7 +13,7 @@ extra_flags=''
|
||||
while getopts a:de:knq OPT; do
|
||||
case "$OPT" in
|
||||
a)
|
||||
arch=$OPTARG
|
||||
arch="$OPTARG"
|
||||
;;
|
||||
d)
|
||||
debug=true
|
||||
@@ -47,14 +47,15 @@ buildroot_out_dir="./buildroot/output.${arch}~"
|
||||
images_dir="$buildroot_out_dir/images"
|
||||
qemu_common="\
|
||||
$debug_qemu \
|
||||
$buildroot_out_dir/host/usr/bin/qemu-system-$arch \
|
||||
$buildroot_out_dir/host/usr/bin/qemu-system-${arch} \
|
||||
-m 128M \
|
||||
-monitor telnet::45454,server,nowait \
|
||||
-net user \
|
||||
-smp 1 \
|
||||
"
|
||||
# The base QEMU commands are found under board/qemu/*/readme.tx
|
||||
case "$arch" in
|
||||
x86_64)
|
||||
'x86_64')
|
||||
if $kgdb; then
|
||||
extra_append="$extra_append kgdboc=ttyS0,115200"
|
||||
fi
|
||||
@@ -68,7 +69,7 @@ case "$arch" in
|
||||
$extra_flags
|
||||
"
|
||||
;;
|
||||
arm)
|
||||
'arm')
|
||||
if $kgdb; then
|
||||
extra_append="$extra_append kgdboc=ttyAMA0,115200"
|
||||
fi
|
||||
@@ -83,14 +84,17 @@ case "$arch" in
|
||||
$extra_flags
|
||||
"
|
||||
;;
|
||||
'mips64')
|
||||
cmd="$qemu_common \
|
||||
-M malta \
|
||||
-append 'root=/dev/hda $extra_append' \
|
||||
-cpu I6400 \
|
||||
-drive file=${images_dir}/rootfs.ext2,format=raw \
|
||||
-kernel ${images_dir}/vmlinux \
|
||||
-nographic \
|
||||
-net nic,model=pcnet \
|
||||
$extra_flags
|
||||
"
|
||||
;;
|
||||
esac
|
||||
if "$debug" && ! "$nographic" && [ ! "$arch" = 'arm' ]; then
|
||||
eval "$cmd" &>/dev/null &
|
||||
# TODO: Ctrl +C gets sent to QEMU? Why? Does not happen if I run
|
||||
# ./rungdb manually from outside this script!!! But why?!?!
|
||||
# eval has nothing to do with it, minimized example with explicit
|
||||
# commands also fails in the same way...
|
||||
#./rungdb
|
||||
else
|
||||
eval "$cmd"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user