[U-Boot,v2,07/10] bootstage: Avoid conflicts between stash/unstash
diff mbox series

Message ID 20191021232652.132164-8-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show
Series
  • bootstage: TPL and SPL improvements
Related show

Commit Message

Simon Glass Oct. 21, 2019, 11:26 p.m. UTC
At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/bootstage.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Simon Glass Oct. 29, 2019, 11:21 p.m. UTC | #1
At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/bootstage.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

Patch
diff mbox series

diff --git a/common/bootstage.c b/common/bootstage.c
index fe36bac0474..4557ed4508c 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -10,9 +10,10 @@ 
  */
 
 #include <common.h>
-#include <linux/libfdt.h>
 #include <malloc.h>
+#include <spl.h>
 #include <linux/compiler.h>
+#include <linux/libfdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -472,6 +473,8 @@  int bootstage_unstash(const void *base, int size)
 	for (rec = data->record + data->next_id, i = 0; i < hdr->count;
 	     i++, rec++) {
 		rec->name = ptr;
+		if (spl_phase() == PHASE_SPL)
+			rec->name = strdup(ptr);
 
 		/* Assume no data corruption here */
 		ptr += strlen(ptr) + 1;