Skip to content

Commit f7e7ce9

Browse files
geerturobherring
authored andcommitted
of: fdt: Add generic support for handling elf core headers property
There are two methods to specify the location of the elf core headers: using the "elfcorehdr=" kernel parameter, as handled by generic code in kernel/crash_dump.c, or using the "linux,elfcorehdr" property under the "/chosen" node in the Device Tree, as handled by architecture-specific code in arch/arm64/mm/init.c. Extend support for "linux,elfcorehdr" to all platforms supporting DT by adding platform-agnostic handling for handling this property to the FDT core code. This can co-exist safely with the architecture-specific handling, until the latter has been removed. This requires moving the call to of_scan_flat_dt() up, as the code scanning the "/chosen" node now needs to be aware of the values of "#address-cells" and "#size-cells". Signed-off-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/c7e46e50aaf87ef49bdaa61358d25b122f32b7df.1628670468.git.geert+renesas@glider.be
1 parent 3370941 commit f7e7ce9

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

Documentation/devicetree/bindings/chosen.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ respectively, of the root node.
106106
linux,elfcorehdr
107107
----------------
108108

109-
This property (currently used only on arm64) holds the memory range,
110-
the address and the size, of the elf core header which mainly describes
111-
the panicked kernel's memory layout as PT_LOAD segments of elf format.
109+
This property holds the memory range, the address and the size, of the elf
110+
core header which mainly describes the panicked kernel's memory layout as
111+
PT_LOAD segments of elf format.
112112
e.g.
113113

114114
/ {

drivers/of/fdt.c

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define pr_fmt(fmt) "OF: fdt: " fmt
1010

11+
#include <linux/crash_dump.h>
1112
#include <linux/crc32.h>
1213
#include <linux/kernel.h>
1314
#include <linux/initrd.h>
@@ -597,6 +598,30 @@ static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname,
597598
return 0;
598599
}
599600

601+
/*
602+
* reserve_elfcorehdr() - reserves memory for elf core header
603+
*
604+
* This function reserves the memory occupied by an elf core header
605+
* described in the device tree. This region contains all the
606+
* information about primary kernel's core image and is used by a dump
607+
* capture kernel to access the system memory on primary kernel.
608+
*/
609+
static void __init reserve_elfcorehdr(void)
610+
{
611+
if (!IS_ENABLED(CONFIG_CRASH_DUMP) || !elfcorehdr_size)
612+
return;
613+
614+
if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
615+
pr_warn("elfcorehdr is overlapped\n");
616+
return;
617+
}
618+
619+
memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
620+
621+
pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n",
622+
elfcorehdr_size >> 10, elfcorehdr_addr);
623+
}
624+
600625
/**
601626
* early_init_fdt_scan_reserved_mem() - create reserved memory regions
602627
*
@@ -622,6 +647,7 @@ void __init early_init_fdt_scan_reserved_mem(void)
622647

623648
of_scan_flat_dt(__fdt_scan_reserved_mem, NULL);
624649
fdt_init_reserved_mem();
650+
reserve_elfcorehdr();
625651
}
626652

627653
/**
@@ -920,6 +946,32 @@ static inline void early_init_dt_check_for_initrd(unsigned long node)
920946
}
921947
#endif /* CONFIG_BLK_DEV_INITRD */
922948

949+
/**
950+
* early_init_dt_check_for_elfcorehdr - Decode elfcorehdr location from flat
951+
* tree
952+
* @node: reference to node containing elfcorehdr location ('chosen')
953+
*/
954+
static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
955+
{
956+
const __be32 *prop;
957+
int len;
958+
959+
if (!IS_ENABLED(CONFIG_CRASH_DUMP))
960+
return;
961+
962+
pr_debug("Looking for elfcorehdr property... ");
963+
964+
prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
965+
if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
966+
return;
967+
968+
elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
969+
elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &prop);
970+
971+
pr_debug("elfcorehdr_start=0x%llx elfcorehdr_size=0x%llx\n",
972+
elfcorehdr_addr, elfcorehdr_size);
973+
}
974+
923975
#ifdef CONFIG_SERIAL_EARLYCON
924976

925977
int __init early_init_dt_scan_chosen_stdout(void)
@@ -1067,6 +1119,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
10671119
return 0;
10681120

10691121
early_init_dt_check_for_initrd(node);
1122+
early_init_dt_check_for_elfcorehdr(node);
10701123

10711124
/* Retrieve command line */
10721125
p = of_get_flat_dt_prop(node, "bootargs", &l);
@@ -1190,14 +1243,14 @@ void __init early_init_dt_scan_nodes(void)
11901243
{
11911244
int rc = 0;
11921245

1246+
/* Initialize {size,address}-cells info */
1247+
of_scan_flat_dt(early_init_dt_scan_root, NULL);
1248+
11931249
/* Retrieve various information from the /chosen node */
11941250
rc = of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
11951251
if (!rc)
11961252
pr_warn("No chosen node found, continuing without\n");
11971253

1198-
/* Initialize {size,address}-cells info */
1199-
of_scan_flat_dt(early_init_dt_scan_root, NULL);
1200-
12011254
/* Setup memory, calling early_init_dt_add_memory_arch */
12021255
of_scan_flat_dt(early_init_dt_scan_memory, NULL);
12031256
}

0 commit comments

Comments
 (0)