kernel: Fix arc kernel 4.14 build
[oweals/openwrt.git] / target / linux / generic / pending-4.14 / 332-arc-add-OWRTDTB-section.patch
1 From: Alexey Brodkin <abrodkin@synopsys.com>
2 Subject: openwrt: arc - add OWRTDTB section
3
4 This change allows OpenWRT to patch resulting kernel binary with
5 external .dtb.
6
7 That allows us to re-use exactky the same vmlinux on different boards
8 given its ARC core configurations match (at least cache line sizes etc).
9
10 ""patch-dtb" searches for ASCII "OWRTDTB:" strign and copies external
11 .dtb right after it, keeping the string in place.
12
13 Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
14 ---
15  arch/arc/kernel/head.S        | 10 ++++++++++
16  arch/arc/kernel/setup.c       |  4 +++-
17  arch/arc/kernel/vmlinux.lds.S | 13 +++++++++++++
18  3 files changed, 26 insertions(+), 1 deletion(-)
19
20 --- a/arch/arc/kernel/head.S
21 +++ b/arch/arc/kernel/head.S
22 @@ -59,6 +59,16 @@
23  #endif
24  .endm
25  
26 +; Here "patch-dtb" will embed external .dtb
27 +; Note "patch-dtb" searches for ASCII "OWRTDTB:" string
28 +; and pastes .dtb right after it, hense the string precedes
29 +; __image_dtb symbol.
30 +       .section .owrt, "aw",@progbits
31 +       .ascii  "OWRTDTB:"
32 +ENTRY(__image_dtb)
33 +       .fill   0x4000
34 +END(__image_dtb)
35 +
36         .section .init.text, "ax",@progbits
37  
38  ;----------------------------------------------------------------
39 --- a/arch/arc/kernel/setup.c
40 +++ b/arch/arc/kernel/setup.c
41 @@ -437,6 +437,8 @@ static inline bool uboot_arg_invalid(uns
42  /* We always pass 0 as magic from U-boot */
43  #define UBOOT_MAGIC_VALUE      0
44  
45 +extern struct boot_param_header __image_dtb;
46 +
47  void __init handle_uboot_args(void)
48  {
49         bool use_embedded_dtb = true;
50 @@ -477,7 +479,7 @@ ignore_uboot_args:
51  #endif
52  
53         if (use_embedded_dtb) {
54 -               machine_desc = setup_machine_fdt(__dtb_start);
55 +               machine_desc = setup_machine_fdt(&__image_dtb);
56                 if (!machine_desc)
57                         panic("Embedded DT invalid\n");
58         }
59 --- a/arch/arc/kernel/vmlinux.lds.S
60 +++ b/arch/arc/kernel/vmlinux.lds.S
61 @@ -30,6 +30,19 @@ SECTIONS
62  
63         . = CONFIG_LINUX_LINK_BASE;
64  
65 +       /*
66 +        * In OpenWRT we want to patch built binary embedding .dtb of choice.
67 +        * This is implemented with "patch-dtb" utility which searches for
68 +        * "OWRTDTB:" string in first 16k of image and if it is found
69 +        * copies .dtb right after mentioned string.
70 +        *
71 +        * Note: "OWRTDTB:" won't be overwritten with .dtb, .dtb will follow it.
72 +        */
73 +       .owrt : {
74 +               *(.owrt)
75 +               . = ALIGN(PAGE_SIZE);
76 +       }
77 +
78         _int_vec_base_lds = .;
79         .vector : {
80                 *(.vector)