test: mbox: Add mbox_rspcpy()

mbox_rspcpy() copies the mboxd response into a struct mbox_msg for use
by the caller. This is useful in test cases that want to read contiguous
chunks of the flash. mbox_rspcpy() allows them to extract the current
window's offset and length to dynamically construct the
CREATE_READ_WINDOW request for the subsequent blocks.

Change-Id: I4d35889a0785b2d9ab737eba6755892caed53270
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/mbox.c b/test/mbox.c
index 3dc1611..6c62ddb 100644
--- a/test/mbox.c
+++ b/test/mbox.c
@@ -87,6 +87,24 @@
 	return rc;
 }
 
+void mbox_rspcpy(struct mbox_context *context, struct mbox_msg *msg)
+{
+	struct stat details;
+	uint8_t *map;
+	int fd;
+
+	fd = context->fds[MBOX_FD].fd;
+	fstat(fd, &details);
+
+	map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	assert(map != MAP_FAILED);
+	assert(details.st_size >= (RESPONSE_OFFSET + RESPONSE_SIZE));
+
+	memcpy(msg, &map[RESPONSE_OFFSET], RESPONSE_SIZE);
+
+	munmap(map, details.st_size);
+}
+
 int mbox_command_write(struct mbox_context *context, const uint8_t *command,
 		size_t len)
 {