Skip to content

Commit 2fe8ea3

Browse files
dczhupaulburton
authored andcommitted
MIPS: kexec: Use prepare method from Generic for UHI platforms
Out-of-tree platforms may not be based on Generic as shown in customer communication. Share the prepare method with all using UHI boot protocol, and put into machine_kexec.c. The benefit is that, when having kexec_args related problems, developers will naturally look into machine_kexec.c, where "CONFIG_UHI_BOOT" will be found, prompting them to add "select UHI_BOOT" to the platform Kconfig. It would otherwise require a lot debugging or online searching to be aware that the solution is in Generic code. Tested-by: Rachel Mozes <rachel.mozes@intel.com> Reported-by: Rachel Mozes <rachel.mozes@intel.com> Signed-off-by: Dengcheng Zhu <dzhu@wavecomp.com> Signed-off-by: Paul Burton <paul.burton@mips.com> Patchwork: https://patchwork.linux-mips.org/patch/20569/ Cc: pburton@wavecomp.com Cc: ralf@linux-mips.org Cc: linux-mips@linux-mips.org
1 parent a6da4d6 commit 2fe8ea3

4 files changed

Lines changed: 45 additions & 46 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ config MIPS_GENERIC
133133
select USB_UHCI_BIG_ENDIAN_DESC if CPU_BIG_ENDIAN
134134
select USB_UHCI_BIG_ENDIAN_MMIO if CPU_BIG_ENDIAN
135135
select USE_OF
136+
select UHI_BOOT
136137
help
137138
Select this to build a kernel which aims to support multiple boards,
138139
generally using a flattened device tree passed from the bootloader
@@ -2899,6 +2900,9 @@ config USE_OF
28992900
select OF_EARLY_FLATTREE
29002901
select IRQ_DOMAIN
29012902

2903+
config UHI_BOOT
2904+
bool
2905+
29022906
config BUILTIN_DTB
29032907
bool
29042908

‎arch/mips/generic/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ obj-y += proc.o
1515
obj-$(CONFIG_YAMON_DT_SHIM) += yamon-dt.o
1616
obj-$(CONFIG_LEGACY_BOARD_SEAD3) += board-sead3.o
1717
obj-$(CONFIG_LEGACY_BOARD_OCELOT) += board-ocelot.o
18-
obj-$(CONFIG_KEXEC) += kexec.o
1918
obj-$(CONFIG_VIRT_BOARD_RANCHU) += board-ranchu.o

‎arch/mips/generic/kexec.c‎

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎arch/mips/kernel/machine_kexec.c‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/kexec.h>
1010
#include <linux/mm.h>
1111
#include <linux/delay.h>
12+
#include <linux/libfdt.h>
1213

1314
#include <asm/cacheflush.h>
1415
#include <asm/page.h>
@@ -28,7 +29,6 @@ atomic_t kexec_ready_to_reboot = ATOMIC_INIT(0);
2829
void (*_crash_smp_send_stop)(void) = NULL;
2930
#endif
3031

31-
int (*_machine_kexec_prepare)(struct kimage *) = NULL;
3232
void (*_machine_kexec_shutdown)(void) = NULL;
3333
void (*_machine_crash_shutdown)(struct pt_regs *regs) = NULL;
3434

@@ -52,6 +52,46 @@ static void kexec_image_info(const struct kimage *kimage)
5252
}
5353
}
5454

55+
#ifdef CONFIG_UHI_BOOT
56+
57+
static int uhi_machine_kexec_prepare(struct kimage *kimage)
58+
{
59+
int i;
60+
61+
/*
62+
* In case DTB file is not passed to the new kernel, a flat device
63+
* tree will be created by kexec tool. It holds modified command
64+
* line for the new kernel.
65+
*/
66+
for (i = 0; i < kimage->nr_segments; i++) {
67+
struct fdt_header fdt;
68+
69+
if (kimage->segment[i].memsz <= sizeof(fdt))
70+
continue;
71+
72+
if (copy_from_user(&fdt, kimage->segment[i].buf, sizeof(fdt)))
73+
continue;
74+
75+
if (fdt_check_header(&fdt))
76+
continue;
77+
78+
kexec_args[0] = -2;
79+
kexec_args[1] = (unsigned long)
80+
phys_to_virt((unsigned long)kimage->segment[i].mem);
81+
break;
82+
}
83+
84+
return 0;
85+
}
86+
87+
int (*_machine_kexec_prepare)(struct kimage *) = uhi_machine_kexec_prepare;
88+
89+
#else
90+
91+
int (*_machine_kexec_prepare)(struct kimage *) = NULL;
92+
93+
#endif /* CONFIG_UHI_BOOT */
94+
5595
int
5696
machine_kexec_prepare(struct kimage *kimage)
5797
{

0 commit comments

Comments
 (0)