02e919858d87d478155352be5bf023e70dabdc61
[openwrt/openwrt.git] / target / linux / generic / patches-4.4 / 332-arc-add-OWRTDTB-section.patch
1 From 690e7f2cad271595ff68cace1c45fb10779bde41 Mon Sep 17 00:00:00 2001
2 From: Alexey Brodkin <abrodkin@synopsys.com>
3 Date: Fri, 15 Jan 2016 00:34:01 +0300
4 Subject: [PATCH 2/2] openwrt: 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: Alexey Brodkin <abrodkin@synopsys.com>
16 ---
17 arch/arc/kernel/head.S | 10 ++++++++++
18 arch/arc/kernel/setup.c | 4 +++-
19 arch/arc/kernel/vmlinux.lds.S | 13 +++++++++++++
20 3 files changed, 26 insertions(+), 1 deletion(-)
21
22 diff --git a/arch/arc/kernel/head.S b/arch/arc/kernel/head.S
23 index 689dd86..51154ae 100644
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 diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
44 index e1b8744..9481c9d 100644
45 --- a/arch/arc/kernel/setup.c
46 +++ b/arch/arc/kernel/setup.c
47 @@ -370,6 +370,8 @@ static inline int is_kernel(unsigned long addr)
48 return 0;
49 }
50
51 +extern struct boot_param_header __image_dtb;
52 +
53 void __init setup_arch(char **cmdline_p)
54 {
55 #ifdef CONFIG_ARC_UBOOT_SUPPORT
56 @@ -383,7 +385,7 @@ void __init setup_arch(char **cmdline_p)
57 #endif
58 {
59 /* No, so try the embedded one */
60 - machine_desc = setup_machine_fdt(__dtb_start);
61 + machine_desc = setup_machine_fdt(&__image_dtb);
62 if (!machine_desc)
63 panic("Embedded DT invalid\n");
64
65 diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
66 index 894e696..ecfc284 100644
67 --- a/arch/arc/kernel/vmlinux.lds.S
68 +++ b/arch/arc/kernel/vmlinux.lds.S
69 @@ -30,6 +30,19 @@ SECTIONS
70
71 . = CONFIG_LINUX_LINK_BASE;
72
73 + /*
74 + * In OpenWRT we want to patch built binary embedding .dtb of choice.
75 + * This is implemented with "patch-dtb" utility which searches for
76 + * "OWRTDTB:" string in first 16k of image and if it is found
77 + * copies .dtb right after mentioned string.
78 + *
79 + * Note: "OWRTDTB:" won't be overwritten with .dtb, .dtb will follow it.
80 + */
81 + .owrt : {
82 + *(.owrt)
83 + . = ALIGN(PAGE_SIZE);
84 + }
85 +
86 _int_vec_base_lds = .;
87 .vector : {
88 *(.vector)
89 --
90 2.4.3
91