diff mbox series

[U-Boot,06/21] sandbox: Zero the ram buffer on startup

Message ID 20181124042944.239106-7-sjg@chromium.org
State Accepted
Commit a65d1a06c9f76d3285948a059b861d7534589cfc
Delegated to: Simon Glass
Headers show
Series Various patches for verified boot support | expand

Commit Message

Simon Glass Nov. 24, 2018, 4:29 a.m. UTC
At present the RAM buffer is not inited unless it is read from a file,
likely produced by an earlier phase of U-Boot. This causes valgrind
warnings whenever the RAM buffer is used. Correct this by initing it if
needed.

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

 arch/sandbox/cpu/start.c         | 7 +++++++
 arch/sandbox/include/asm/state.h | 1 +
 2 files changed, 8 insertions(+)

Comments

Simon Glass Dec. 5, 2018, 11:10 p.m. UTC | #1
At present the RAM buffer is not inited unless it is read from a file,
likely produced by an earlier phase of U-Boot. This causes valgrind
warnings whenever the RAM buffer is used. Correct this by initing it if
needed.

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

 arch/sandbox/cpu/start.c         | 7 +++++++
 arch/sandbox/include/asm/state.h | 1 +
 2 files changed, 8 insertions(+)

Applied to u-boot-dm/master, thanks!
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index b1566a81435..2f5e6e95182 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -180,6 +180,7 @@  static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
 		printf("Failed to read RAM buffer '%s': %d\n", arg, err);
 		return err;
 	}
+	state->ram_buf_read = true;
 
 	return 0;
 }
@@ -301,6 +302,12 @@  int board_run_command(const char *cmdline)
 
 static void setup_ram_buf(struct sandbox_state *state)
 {
+	/* Zero the RAM buffer if we didn't read it, to keep valgrind happy */
+	if (!state->ram_buf_read) {
+		memset(state->ram_buf, '\0', state->ram_size);
+		printf("clear %p %x\n", state->ram_buf, state->ram_size);
+	}
+
 	gd->arch.ram_buf = state->ram_buf;
 	gd->ram_size = state->ram_size;
 }
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index 8fabe70a86d..5a144851025 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -90,6 +90,7 @@  struct sandbox_state {
 	bool show_test_output;		/* Don't suppress stdout in tests */
 	int default_log_level;		/* Default log level for sandbox */
 	bool show_of_platdata;		/* Show of-platdata in SPL */
+	bool ram_buf_read;		/* true if we read the RAM buffer */
 
 	/* Pointer to information for each SPI bus/cs */
 	struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]