From 457cfdb049a39670f15df8cae1d78a2479962ef9 Mon Sep 17 00:00:00 2001
From: Romuald JEANNE <romuald.jeanne@st.com>
Date: Fri, 21 Dec 2018 16:57:38 +0100
Subject: [PATCH 48/52] ARM: stm32mp1-r0-rc4: REMOTEPROC RPMSG

---
 drivers/remoteproc/rproc_srm_core.c |  2 +-
 drivers/remoteproc/stm32_rproc.c    | 40 +++++++++++++++++++++++++++----------
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/drivers/remoteproc/rproc_srm_core.c b/drivers/remoteproc/rproc_srm_core.c
index 66be92e..fc61e8b 100644
--- a/drivers/remoteproc/rproc_srm_core.c
+++ b/drivers/remoteproc/rproc_srm_core.c
@@ -189,7 +189,7 @@ static int rproc_srm_core_prepare(struct rproc_subdev *subdev)
 	/* Wait for every child to be bound */
 	if (!wait_for_completion_timeout(&rproc_srm_core->all_bound,
 					 msecs_to_jiffies(BIND_TIMEOUT))) {
-		dev_err(dev, "bind timeout\n");
+		dev_err(dev, "failed to bind one or more system resource device(s)\n");
 		ret = -ETIMEDOUT;
 		goto master;
 	}
diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
index 9a7e034..70b7e55c 100644
--- a/drivers/remoteproc/stm32_rproc.c
+++ b/drivers/remoteproc/stm32_rproc.c
@@ -196,22 +196,12 @@ static int stm32_rproc_mbox_idx(struct rproc *rproc, const unsigned char *name)
 static int stm32_rproc_elf_load_rsc_table(struct rproc *rproc,
 					  const struct firmware *fw)
 {
-	int status, i;
+	int status;
 	struct resource_table *table = NULL;
 	struct stm32_rproc *ddata = rproc->priv;
 	size_t tablesz = 0;
-	const struct elf32_hdr *ehdr;
-	const struct elf32_phdr *phdr;
 
 	if (!rproc->early_boot) {
-		/* set coredump segments */
-		ehdr = (const struct elf32_hdr *)fw->data;
-		phdr = (const struct elf32_phdr *)(fw->data + ehdr->e_phoff);
-		for (i = 0; i < ehdr->e_phnum; i++, phdr++)
-			rproc_coredump_add_segment(rproc, phdr->p_paddr,
-						   phdr->p_memsz);
-
-		/* load resource table */
 		status = rproc_elf_load_rsc_table(rproc, fw);
 		if (status)
 			goto no_rsc_table;
@@ -276,6 +266,10 @@ static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 						   stm32_rproc_mem_alloc,
 						   stm32_rproc_mem_release,
 						   it.node->name);
+
+			if (mem)
+				rproc_coredump_add_segment(rproc, da,
+							   rmem->size);
 		} else {
 			/* Register reserved memory for vdev buffer alloc */
 			mem = rproc_of_resm_mem_entry_init(dev, index,
@@ -436,10 +430,34 @@ static int stm32_rproc_set_hold_boot(struct rproc *rproc, bool hold)
 	return err;
 }
 
+static void stm32_rproc_add_coredump_trace(struct rproc *rproc)
+{
+	struct rproc_debug_trace *trace;
+	struct rproc_dump_segment *segment;
+	bool already_added;
+
+	list_for_each_entry(trace, &rproc->traces, node) {
+		already_added = false;
+
+		list_for_each_entry(segment, &rproc->dump_segments, node) {
+			if (segment->da == trace->trace_mem.da) {
+				already_added = true;
+				break;
+			}
+		}
+
+		if (!already_added)
+			rproc_coredump_add_segment(rproc, trace->trace_mem.da,
+						   trace->trace_mem.len);
+	}
+}
+
 static int stm32_rproc_start(struct rproc *rproc)
 {
 	int err;
 
+	stm32_rproc_add_coredump_trace(rproc);
+
 	/*
 	 * If M4 previously started by bootloader, just guarantee holdboot
 	 *  is set to catch any crash.
-- 
2.7.4

