Commit 4c9fff36 authored by Marcin Nowakowski's avatar Marcin Nowakowski Committed by Ralf Baechle

MIPS: relocate: Optionally relocate the DTB

If the DTB is located in the target memory area for the relocated kernel
it needs to be relocated as well before kernel relocation takes place.

After copying the DTB use the new plat_fdt_relocated() API from the
relocated kernel to ensure the relocated kernel updates any information
that it may have cached about the location of the DTB.

plat_fdt_relocated is declared as a weak symbol so that platforms that
do not require it do not need to implement the method.
Signed-off-by: default avatarMarcin Nowakowski <marcin.nowakowski@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/14616/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 0063fded
...@@ -31,6 +31,8 @@ extern u32 _relocation_end[]; /* End relocation table */ ...@@ -31,6 +31,8 @@ extern u32 _relocation_end[]; /* End relocation table */
extern long __start___ex_table; /* Start exception table */ extern long __start___ex_table; /* Start exception table */
extern long __stop___ex_table; /* End exception table */ extern long __stop___ex_table; /* End exception table */
extern void __weak plat_fdt_relocated(void *new_location);
/* /*
* This function may be defined for a platform to perform any post-relocation * This function may be defined for a platform to perform any post-relocation
* fixup necessary. * fixup necessary.
...@@ -41,7 +43,6 @@ int __weak plat_post_relocation(long offset) ...@@ -41,7 +43,6 @@ int __weak plat_post_relocation(long offset)
return 0; return 0;
} }
static inline u32 __init get_synci_step(void) static inline u32 __init get_synci_step(void)
{ {
u32 res; u32 res;
...@@ -302,12 +303,14 @@ void *__init relocate_kernel(void) ...@@ -302,12 +303,14 @@ void *__init relocate_kernel(void)
int res = 1; int res = 1;
/* Default to original kernel entry point */ /* Default to original kernel entry point */
void *kernel_entry = start_kernel; void *kernel_entry = start_kernel;
void *fdt = NULL;
/* Get the command line */ /* Get the command line */
fw_init_cmdline(); fw_init_cmdline();
#if defined(CONFIG_USE_OF) #if defined(CONFIG_USE_OF)
/* Deal with the device tree */ /* Deal with the device tree */
early_init_dt_scan(plat_get_fdt()); fdt = plat_get_fdt();
early_init_dt_scan(fdt);
if (boot_command_line[0]) { if (boot_command_line[0]) {
/* Boot command line was passed in device tree */ /* Boot command line was passed in device tree */
strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE); strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE);
...@@ -327,6 +330,29 @@ void *__init relocate_kernel(void) ...@@ -327,6 +330,29 @@ void *__init relocate_kernel(void)
arcs_cmdline[0] = '\0'; arcs_cmdline[0] = '\0';
if (offset) { if (offset) {
void (*fdt_relocated_)(void *) = NULL;
#if defined(CONFIG_USE_OF)
unsigned long fdt_phys = virt_to_phys(fdt);
/*
* If built-in dtb is used then it will have been relocated
* during kernel _text relocation. If appended DTB is used
* then it will not be relocated, but it should remain
* intact in the original location. If dtb is loaded by
* the bootloader then it may need to be moved if it crosses
* the target memory area
*/
if (fdt_phys >= virt_to_phys(RELOCATED(&_text)) &&
fdt_phys <= virt_to_phys(RELOCATED(&_end))) {
void *fdt_relocated =
RELOCATED(ALIGN((long)&_end, PAGE_SIZE));
memcpy(fdt_relocated, fdt, fdt_totalsize(fdt));
fdt = fdt_relocated;
fdt_relocated_ = RELOCATED(&plat_fdt_relocated);
}
#endif /* CONFIG_USE_OF */
/* Copy the kernel to it's new location */ /* Copy the kernel to it's new location */
memcpy(loc_new, &_text, kernel_length); memcpy(loc_new, &_text, kernel_length);
...@@ -349,6 +375,14 @@ void *__init relocate_kernel(void) ...@@ -349,6 +375,14 @@ void *__init relocate_kernel(void)
*/ */
memcpy(RELOCATED(&__bss_start), &__bss_start, bss_length); memcpy(RELOCATED(&__bss_start), &__bss_start, bss_length);
/*
* If fdt was stored outside of the kernel image and
* had to be moved then update platform's state data
* with the new fdt location
*/
if (fdt_relocated_)
fdt_relocated_(fdt);
/* /*
* Last chance for the platform to abort relocation. * Last chance for the platform to abort relocation.
* This may also be used by the platform to perform any * This may also be used by the platform to perform any
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment