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