From 9ea0a1ee9309054102e61a29e746db672494d385 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Fri, 20 Mar 2020 10:59:24 +0100 Subject: [PATCH] cmd: Fixup DT to pass PStore Ramoops parameters MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To simplify configuration and keep synchronized the PStore/Ramoops between U-Boot and the Linux kernel, this commit dynamically adds the Ramoops parameters defined in the U-Boot session to the Device Tree. Signed-off-by: Frédéric Danis Cc: Tom Rini Cc: Heinrich Schuchardt Cc: Wolfgang Denk Cc: Heiko Schocher --- cmd/pstore.c | 38 ++++++++++++++++++++++++++++++++++++++ common/image-fdt.c | 4 ++++ doc/pstore.rst | 2 ++ include/fdt_support.h | 3 +++ 4 files changed, 47 insertions(+) diff --git a/cmd/pstore.c b/cmd/pstore.c index 530eb03b18..9a8b38c7f2 100644 --- a/cmd/pstore.c +++ b/cmd/pstore.c @@ -480,6 +480,44 @@ static int do_pstore(struct cmd_tbl *cmdtp, int flag, int argc, char * const arg return c->cmd(cmdtp, flag, argc, argv); } +void fdt_fixup_pstore(void *blob) +{ + char node[32]; + int nodeoffset; /* node offset from libfdt */ + + nodeoffset = fdt_path_offset(blob, "/"); + if (nodeoffset < 0) { + /* Not found or something else bad happened. */ + log_err("fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset)); + return; + } + + nodeoffset = fdt_add_subnode(blob, nodeoffset, "reserved-memory"); + if (nodeoffset < 0) { + log_err("Add 'reserved-memory' node failed: %s\n", + fdt_strerror(nodeoffset)); + return; + } + fdt_setprop_u32(blob, nodeoffset, "#address-cells", 2); + fdt_setprop_u32(blob, nodeoffset, "#size-cells", 2); + fdt_setprop_empty(blob, nodeoffset, "ranges"); + + sprintf(node, "ramoops@%llx", (unsigned long long)pstore_addr); + nodeoffset = fdt_add_subnode(blob, nodeoffset, node); + if (nodeoffset < 0) { + log_err("Add '%s' node failed: %s\n", node, fdt_strerror(nodeoffset)); + return; + } + fdt_setprop_string(blob, nodeoffset, "compatible", "ramoops"); + fdt_setprop_u64(blob, nodeoffset, "reg", pstore_addr); + fdt_appendprop_u64(blob, nodeoffset, "reg", pstore_length); + fdt_setprop_u32(blob, nodeoffset, "record-size", pstore_record_size); + fdt_setprop_u32(blob, nodeoffset, "console-size", pstore_console_size); + fdt_setprop_u32(blob, nodeoffset, "ftrace-size", pstore_ftrace_size); + fdt_setprop_u32(blob, nodeoffset, "pmsg-size", pstore_pmsg_size); + fdt_setprop_u32(blob, nodeoffset, "ecc-size", pstore_ecc_size); +} + U_BOOT_CMD(pstore, 10, 0, do_pstore, "Manage Linux Persistent Storage", "set [record-size] [console-size] [ftrace-size] [pmsg_size] [ecc-size]\n" diff --git a/common/image-fdt.c b/common/image-fdt.c index 3d6935ad40..327a8c4c39 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -567,6 +567,10 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob, /* Update ethernet nodes */ fdt_fixup_ethernet(blob); +#if CONFIG_IS_ENABLED(CMD_PSTORE) + /* Append PStore configuration */ + fdt_fixup_pstore(blob); +#endif if (IMAGE_OF_BOARD_SETUP) { fdt_ret = ft_board_setup(blob, gd->bd); if (fdt_ret) { diff --git a/doc/pstore.rst b/doc/pstore.rst index 4fceb2dd99..8427d8fd97 100644 --- a/doc/pstore.rst +++ b/doc/pstore.rst @@ -25,6 +25,8 @@ i.e.:: The same values should be set in U-Boot to be able to retrieve the records. This values can be set at build time in U-Boot configuration file, or at runtime. +U-Boot automatically patches the Device Tree to pass the Ramoops parameters to +the kernel. The PStore configuration parameters are: diff --git a/include/fdt_support.h b/include/fdt_support.h index 9684cffe80..dbbac0fb6a 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -359,4 +359,7 @@ int fdt_update_ethernet_dt(void *blob); #ifdef CONFIG_FSL_MC_ENET void fdt_fixup_board_enet(void *blob); #endif +#ifdef CONFIG_CMD_PSTORE +void fdt_fixup_pstore(void *blob); +#endif #endif /* ifndef __FDT_SUPPORT_H */ -- 2.39.5