blob: 6e347c048e4f22449d37af4a195b119e86eb390a [file] [log] [blame]
Brad Bishop26bdd442019-08-16 17:08:17 -04001From 7bd94a64cd5424e74ad49dbda65a15e83670268f Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Andrea Adami <andrea.adami@gmail.com>
3Date: Mon, 17 Dec 2018 11:25:20 +0100
4Subject: [PATCH] kexec-tools: fix non-device tree devices on mips
5
6Add additional argument '--no-dtb' which disables device tree
7search in currently loaded kernel.
8
9Taken from LEDE-DEV:
10https://patchwork.ozlabs.org/patch/852961/
11
12Rebased for kexec-tools 2.0.18
13Removed ppc change (unwanted ?)
14
15Signed-off-by: Konstantin Kuzov <master.nosferatu@gmail.com>
16Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
Brad Bishop26bdd442019-08-16 17:08:17 -040017
Brad Bishop19323692019-04-05 15:28:33 -040018---
19 kexec/arch/mips/include/arch/options.h | 4 +-
20 kexec/arch/mips/kexec-elf-mips.c | 58 ++++++++++++++------------
21 kexec/arch/mips/kexec-mips.c | 4 ++
22 kexec/arch/mips/kexec-mips.h | 1 +
23 4 files changed, 39 insertions(+), 28 deletions(-)
24
Brad Bishop19323692019-04-05 15:28:33 -040025--- a/kexec/arch/mips/include/arch/options.h
26+++ b/kexec/arch/mips/include/arch/options.h
27@@ -5,6 +5,7 @@
28 #define OPT_APPEND (OPT_ARCH_MAX+0)
29 #define OPT_DTB (OPT_ARCH_MAX+1)
30 #define OPT_RAMDISK (OPT_ARCH_MAX+2)
31+#define OPT_NO_DTB (OPT_ARCH_MAX+3)
32
33 /* Options relevant to the architecture (excluding loader-specific ones),
34 * in this case none:
35@@ -14,7 +15,8 @@
36 {"command-line", 1, 0, OPT_APPEND}, \
37 {"append", 1, 0, OPT_APPEND}, \
38 {"dtb", 1, 0, OPT_DTB }, \
39- {"initrd", 1, 0, OPT_RAMDISK },
40+ {"initrd", 1, 0, OPT_RAMDISK }, \
41+ {"no-dtb", 0, 0, OPT_NO_DTB },
42
43
44 #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR ""
Brad Bishop19323692019-04-05 15:28:33 -040045--- a/kexec/arch/mips/kexec-elf-mips.c
46+++ b/kexec/arch/mips/kexec-elf-mips.c
Andrew Geissler87f5cff2022-09-30 13:13:31 -050047@@ -141,45 +141,49 @@ int elf_mips_load(int argc, char **argv,
Brad Bishop19323692019-04-05 15:28:33 -040048 else
49 cmdline_addr = 0;
50
51- /* MIPS systems that have been converted to use device tree
52- * passed through UHI will use commandline in the DTB and
53- * the DTB passed as a separate buffer. Note that
54- * CMDLINE_PREFIX is skipped here intentionally, as it is
55- * used only in the legacy method */
56-
57- if (arch_options.dtb_file) {
58- dtb_buf = slurp_file(arch_options.dtb_file, &dtb_length);
59- } else {
60- create_flatten_tree(&dtb_buf, &dtb_length, cmdline_buf + strlen(CMDLINE_PREFIX));
61- }
Andrew Geissler87f5cff2022-09-30 13:13:31 -050062-
Brad Bishop19323692019-04-05 15:28:33 -040063- if (arch_options.initrd_file) {
64- initrd_buf = slurp_file(arch_options.initrd_file, &initrd_size);
Andrew Geissler87f5cff2022-09-30 13:13:31 -050065
66- /* Create initrd entries in dtb - although at this time
67- * they would not point to the correct location */
68- dtb_set_initrd(&dtb_buf, &dtb_length, initrd_buf, initrd_buf + initrd_size);
69-
70- initrd_base = add_buffer(info, initrd_buf, initrd_size,
71- initrd_size, sizeof(void *),
72- _ALIGN_UP(kernel_addr + kernel_size + dtb_length,
73- pagesize), 0x0fffffff, 1);
74-
75- /* Now that the buffer for initrd is prepared, update the dtb
76- * with an appropriate location */
77- dtb_set_initrd(&dtb_buf, &dtb_length, initrd_base, initrd_base + initrd_size);
Brad Bishop19323692019-04-05 15:28:33 -040078+ if (!arch_options.no_dtb) {
79+ /* MIPS systems that have been converted to use device tree
80+ * passed through UHI will use commandline in the DTB and
81+ * the DTB passed as a separate buffer. Note that
82+ * CMDLINE_PREFIX is skipped here intentionally, as it is
83+ * used only in the legacy method */
84+
85+ if (arch_options.dtb_file) {
86+ dtb_buf = slurp_file(arch_options.dtb_file, &dtb_length);
87+ } else {
88+ create_flatten_tree(&dtb_buf, &dtb_length, cmdline_buf + strlen(CMDLINE_PREFIX));
89+ }
Andrew Geissler87f5cff2022-09-30 13:13:31 -050090+
Brad Bishop19323692019-04-05 15:28:33 -040091+ if (arch_options.initrd_file) {
92+ initrd_buf = slurp_file(arch_options.initrd_file, &initrd_size);
Andrew Geissler87f5cff2022-09-30 13:13:31 -050093+
Brad Bishop19323692019-04-05 15:28:33 -040094+ /* Create initrd entries in dtb - although at this time
95+ * they would not point to the correct location */
Andrew Geissler87f5cff2022-09-30 13:13:31 -050096+ dtb_set_initrd(&dtb_buf, &dtb_length, (off_t)initrd_buf, (off_t)initrd_buf + initrd_size);
97+
Brad Bishop19323692019-04-05 15:28:33 -040098+ initrd_base = add_buffer(info, initrd_buf, initrd_size,
99+ initrd_size, sizeof(void *),
100+ _ALIGN_UP(kernel_addr + kernel_size + dtb_length,
101+ pagesize), 0x0fffffff, 1);
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500102+
Brad Bishop19323692019-04-05 15:28:33 -0400103+ /* Now that the buffer for initrd is prepared, update the dtb
104+ * with an appropriate location */
105+ dtb_set_initrd(&dtb_buf, &dtb_length, initrd_base, initrd_base + initrd_size);
106+ }
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500107 }
Brad Bishop19323692019-04-05 15:28:33 -0400108
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500109-
Brad Bishop19323692019-04-05 15:28:33 -0400110 /* This is a legacy method for commandline passing used
111 * currently by Octeon CPUs only */
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500112 add_buffer(info, cmdline_buf, sizeof(cmdline_buf),
Brad Bishop19323692019-04-05 15:28:33 -0400113 sizeof(cmdline_buf), sizeof(void *),
114 cmdline_addr, 0x0fffffff, 1);
115
116- add_buffer(info, dtb_buf, dtb_length, dtb_length, 0,
117- _ALIGN_UP(kernel_addr + kernel_size, pagesize),
118- 0x0fffffff, 1);
119+ if (!arch_options.no_dtb) {
120+ add_buffer(info, dtb_buf, dtb_length, dtb_length, 0,
121+ _ALIGN_UP(kernel_addr + kernel_size, pagesize),
122+ 0x0fffffff, 1);
123+ }
124
125 return 0;
126 }
Brad Bishop19323692019-04-05 15:28:33 -0400127--- a/kexec/arch/mips/kexec-mips.c
128+++ b/kexec/arch/mips/kexec-mips.c
129@@ -89,6 +89,7 @@ void arch_usage(void)
130 " --append=STRING Set the kernel command line to STRING.\n"
131 " --dtb=FILE Use FILE as the device tree blob.\n"
132 " --initrd=FILE Use FILE as initial ramdisk.\n"
133+ " --no-dtb Don't try to find device tree\n"
134 );
135 }
136
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500137@@ -121,6 +122,9 @@ int arch_process_options(int argc, char
Brad Bishop19323692019-04-05 15:28:33 -0400138 case OPT_RAMDISK:
139 arch_options.initrd_file = optarg;
140 break;
141+ case OPT_NO_DTB:
142+ arch_options.no_dtb = 1;
143+ break;
144 default:
145 break;
146 }
Brad Bishop19323692019-04-05 15:28:33 -0400147--- a/kexec/arch/mips/kexec-mips.h
148+++ b/kexec/arch/mips/kexec-mips.h
149@@ -22,6 +22,7 @@ struct arch_options_t {
150 char *dtb_file;
151 char *initrd_file;
152 int core_header_type;
153+ int no_dtb;
154 };
155
156 extern struct memory_ranges usablemem_rgns;