From 5e83660e8672b6ba000061ad7762c36423cb0071 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Wed, 12 Sep 2018 12:35:19 +0100 Subject: [PATCH] readme: add an awesome and simple qemu hack --- README.adoc | 130 ++++++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 59 deletions(-) diff --git a/README.adoc b/README.adoc index 4e0af9b..202fb96 100644 --- a/README.adoc +++ b/README.adoc @@ -160,65 +160,6 @@ All available modules can be found in the link:packages/kernel_modules/[`kernel_ See also: <>. -Now try to modify link:packages/kernel_modules/hello.c[] to contain: - -.... -pr_info("hello init hacked\n"); -.... - -and then rebuild the kernel modules and re-run to see it take effect: - -.... -./build --kernel-modules -./run -F 'insmod /hello.ko' -.... - -Congratulations, you are now officially a kernel module hacker! - -The reboot after rebuild is annoying. We don't have a perfect solution for it yet, but there are some ideas cooking at: <>. - -Not satisfied with kernel modules? OK then, let's hack up the <> Linux kernel itself. - -Open the file `submodules/linux/init/main.c` on your text editor, find the `start_kernel` function, and then add there a: - -.... -pr_info("I'VE HACKED THE LINUX KERNEL!!!"); -.... - -Then rebuild the Linux kernel and reboot: - -.... -./build && ./run -.... - -and, surely enough, your message has appeared at the beginning of the boot. - -So you are now officially a kernel hacker, way to go! - -Not satisfied with mere software? OK then, let's hack up the QEMU entry point. - -First find it with GDB: - -.... -./run --debug-vm -.... - -which leaves us at `submodules/qemu/vl.c`, so hack up the `main` there with: - -.... -puts("I'VE HACKED QEMU"); -.... - -and as usual rebuild and re-run: - -..... -./build-qemu && ./run -..... - -and once again, there is your message. - -You have now gone from newb to hardware hacker in a mere 15 minutes, your rate of progress is truly astounding!!! - I now urge you to read the following sections which contain widely applicable information: * <> @@ -269,6 +210,77 @@ hello /root/.profile │(gdb) .... +==== Your first kernel hack + +Modify link:packages/kernel_modules/hello.c[] to contain: + +.... +pr_info("hello init hacked\n"); +.... + +and then rebuild the kernel modules and re-run to see it take effect: + +.... +./build --kernel-modules +./run -F 'insmod /hello.ko' +.... + +Congratulations, you are now officially a kernel module hacker! + +The reboot after rebuild is annoying. We don't have a perfect solution for it yet, but there are some ideas cooking at: <>. + +Not satisfied with kernel modules? OK then, let's hack up the <> Linux kernel itself. + +Open the file: + +.... +vim submodules/linux/init/main.c +.... + +and find the `start_kernel` function, then add there a: + +.... +pr_info("I'VE HACKED THE LINUX KERNEL!!!"); +.... + +Then rebuild the Linux kernel and reboot: + +.... +./build && ./run +.... + +and, surely enough, your message has appeared at the beginning of the boot. + +So you are now officially a kernel hacker, way to go! + +Not satisfied with mere software? OK then, let's hack up the QEMU x86 CPU identification: + +.... +vim submodules/qemu/target/i386/cpu.c +.... + +and modify: + +.... +.model_id = "QEMU Virtual CPU version " QEMU_HW_VERSION, +.... + +to contain: + +.... +.model_id = "QEMU Virtual CPU version HACKED " QEMU_HW_VERSION, +.... + +then as usual rebuild and re-run: + +..... +./build-qemu && ./run -F 'grep "model name" /proc/cpuinfo' +..... + +and once again, there is your message: QEMU communicated it to the Linux kernel, which printed it out. + +You have now gone from newb to hardware hacker in a mere 15 minutes, your rate of progress is truly astounding!!! + ==== About the QEMU Buildroot setup link:https://en.wikipedia.org/wiki/Buildroot[Buildroot] is a set of `make` scripts that downloads from source and compiles compatible versions of: