From c5c5f1687a14a44b59483727d7332c3c29a198fe Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 2 Nov 2023 13:43:24 +0000 Subject: [PATCH] patch qemu to load uncompressed ARM kernels at correct offset --- overlay.nix | 7 +++++ pkgs/qemu/arm-image-friendly-load-addr.patch | 31 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 pkgs/qemu/arm-image-friendly-load-addr.patch diff --git a/overlay.nix b/overlay.nix index a55ce1f..dbc9671 100644 --- a/overlay.nix +++ b/overlay.nix @@ -183,5 +183,12 @@ extraPkgs // { "\nsed -i.bak 's/linux.*-mips/linux-mops/' Configure\n"); }); + qemu = prev.qemu.overrideAttrs (o: { + patches = o.patches ++ [ + ./pkgs/qemu/arm-image-friendly-load-addr.patch + + ]; + }); + pppBuild = prev.ppp; } diff --git a/pkgs/qemu/arm-image-friendly-load-addr.patch b/pkgs/qemu/arm-image-friendly-load-addr.patch new file mode 100644 index 0000000..057de9c --- /dev/null +++ b/pkgs/qemu/arm-image-friendly-load-addr.patch @@ -0,0 +1,31 @@ +Loading kernel at offset 0x10000 works only for zImage, but not for Image, +because the kernel expect the start of decompressed kernel (.head.text) to be +at an address that's a distance that's 16MB aligned from PAGE_OFFSET + +TEXT_OFFSET (see vmlinux.lds.S). This check is enfornced in __fixup_pv_table in +arch/arm/kernel/head.S TEXT_OFFSET is 0x00008000, so a 16MB alignment needs to +have a "0x8000" in the lower 16 bits so that they cancel out. Currently the +offset Qemu loads it at is 0x10000. + +With zImage, this need is met because zImage loads the uncompressed Image +correctly, however when loading an Image and executing directly Qemu is +required it to load it at the correct location. Doing so, doesn't break Qemu's +zImage loading. With this patch, both zImage and Image work correctly. + +Original patch from https://patchwork.kernel.org/project/linux-arm-kernel/patch/1395718484-20424-1-git-send-email-joelf@ti.com/ was +Signed-off-by: Joel Fernandes + +(Edited by Daniel Barlow to apply cleanly to more recent QEMU) + +diff --git a/hw/arm/boot.c b/hw/arm/boot.c +index ada2717f76..18bcdd45d2 100644 +--- a/hw/arm/boot.c ++++ b/hw/arm/boot.c +@@ -32,7 +32,7 @@ + */ + #define KERNEL_ARGS_ADDR 0x100 + #define KERNEL_NOLOAD_ADDR 0x02000000 +-#define KERNEL_LOAD_ADDR 0x00010000 ++#define KERNEL_LOAD_ADDR 0x00008000 + #define KERNEL64_LOAD_ADDR 0x00080000 + + #define ARM64_TEXT_OFFSET_OFFSET 8