82bdd4e7ed69511de60e5b0bba7b1fdb7d45b953
[openwrt/openwrt.git] / package / boot / kexec-tools / patches / 001-arm-do-not-copy-magic-4-bytes-of-appended-DTB-in-zIm.patch
1 From 9817ec81968a5eec7863902833fb77680544eae4 Mon Sep 17 00:00:00 2001
2 From: Alexander Egorenkov <egorenar-dev@posteo.net>
3 Date: Mon, 12 Apr 2021 13:18:05 +0200
4 Subject: [PATCH 1/1] arm: do not copy magic 4 bytes of appended DTB in zImage
5
6 If the passed zImage happens to have a DTB appended, then the magic 4 bytes
7 of the DTB are copied together with the kernel image. This leads to
8 failed kexec boots because the decompressor finds the aforementioned
9 DTB magic and falsely tries to replace the DTB passed in the register r2
10 with the non-existent appended one.
11
12 Signed-off-by: Alexander Egorenkov <egorenar-dev@posteo.net>
13 Signed-off-by: Simon Horman <horms@verge.net.au>
14 ---
15 kexec/arch/arm/kexec-zImage-arm.c | 12 +++++++++++-
16 1 file changed, 11 insertions(+), 1 deletion(-)
17
18 --- a/kexec/arch/arm/kexec-zImage-arm.c
19 +++ b/kexec/arch/arm/kexec-zImage-arm.c
20 @@ -382,6 +382,7 @@ int zImage_arm_load(int argc, char **arg
21 unsigned int atag_offset = 0x1000; /* 4k offset from memory start */
22 unsigned int extra_size = 0x8000; /* TEXT_OFFSET */
23 const struct zimage_tag *tag;
24 + size_t kernel_buf_size;
25 size_t kernel_mem_size;
26 const char *command_line;
27 char *modified_cmdline = NULL;
28 @@ -538,6 +539,15 @@ int zImage_arm_load(int argc, char **arg
29 }
30
31 /*
32 + * Save the length of the compressed kernel image w/o the appended DTB.
33 + * This will be required later on when the kernel image contained
34 + * in the zImage will be loaded into a kernel memory segment.
35 + * And we want to load ONLY the compressed kernel image from the zImage
36 + * and discard the appended DTB.
37 + */
38 + kernel_buf_size = len;
39 +
40 + /*
41 * Always extend the zImage by four bytes to ensure that an appended
42 * DTB image always sees an initialised value after _edata.
43 */
44 @@ -759,7 +769,7 @@ int zImage_arm_load(int argc, char **arg
45 add_segment(info, dtb_buf, dtb_length, dtb_offset, dtb_length);
46 }
47
48 - add_segment(info, buf, len, kernel_base, kernel_mem_size);
49 + add_segment(info, buf, kernel_buf_size, kernel_base, kernel_mem_size);
50
51 info->entry = (void*)kernel_base;
52