Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 1 | From 7bd94a64cd5424e74ad49dbda65a15e83670268f Mon Sep 17 00:00:00 2001 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2 | From: Andrea Adami <andrea.adami@gmail.com> |
| 3 | Date: Mon, 17 Dec 2018 11:25:20 +0100 |
| 4 | Subject: [PATCH] kexec-tools: fix non-device tree devices on mips |
| 5 | |
| 6 | Add additional argument '--no-dtb' which disables device tree |
| 7 | search in currently loaded kernel. |
| 8 | |
| 9 | Taken from LEDE-DEV: |
| 10 | https://patchwork.ozlabs.org/patch/852961/ |
| 11 | |
| 12 | Rebased for kexec-tools 2.0.18 |
| 13 | Removed ppc change (unwanted ?) |
| 14 | |
| 15 | Signed-off-by: Konstantin Kuzov <master.nosferatu@gmail.com> |
| 16 | Signed-off-by: Andrea Adami <andrea.adami@gmail.com> |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 17 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 18 | --- |
| 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 25 | --- 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 45 | --- a/kexec/arch/mips/kexec-elf-mips.c |
| 46 | +++ b/kexec/arch/mips/kexec-elf-mips.c |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 47 | @@ -141,45 +141,49 @@ int elf_mips_load(int argc, char **argv, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | 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 Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 62 | - |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 63 | - if (arch_options.initrd_file) { |
| 64 | - initrd_buf = slurp_file(arch_options.initrd_file, &initrd_size); |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 65 | |
| 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 78 | + 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 Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 90 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 91 | + if (arch_options.initrd_file) { |
| 92 | + initrd_buf = slurp_file(arch_options.initrd_file, &initrd_size); |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 93 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 94 | + /* Create initrd entries in dtb - although at this time |
| 95 | + * they would not point to the correct location */ |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 96 | + dtb_set_initrd(&dtb_buf, &dtb_length, (off_t)initrd_buf, (off_t)initrd_buf + initrd_size); |
| 97 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 98 | + 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 Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 102 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 103 | + /* 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 Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 107 | } |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 108 | |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 109 | - |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 110 | /* This is a legacy method for commandline passing used |
| 111 | * currently by Octeon CPUs only */ |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 112 | add_buffer(info, cmdline_buf, sizeof(cmdline_buf), |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 113 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 127 | --- 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 Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 137 | @@ -121,6 +122,9 @@ int arch_process_options(int argc, char |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 138 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 147 | --- 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; |