mboxd: Workaround buggy kernel flash driver

Currently when mboxd starts (and on every SIGHUP) it reads the entire
flash into RAM (typically 32 or 64M). This large read causes the kernel
to become unresponsive for an extended period of time (in the order of
10s of seconds). This period of unresponsiveness can cause misbehaviour
by the BMC, in particular it often causes SSH sessions to drop.

This patch is a temporary workaround until the kernel driver has been
fixed, at that point this patch should be reverted!
Patch originally from Michael Neuling <mikey@neuling.org>.

Change-Id: Ibd848a4074fc7bdcab194d669806589f9d274c93
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
diff --git a/mboxd.c b/mboxd.c
index cb8eaf7..8fdcc2d 100644
--- a/mboxd.c
+++ b/mboxd.c
@@ -325,9 +325,14 @@
 	return r;
 }
 
+
+#define CHUNKSIZE (64 * 1024)
+
 int copy_flash(struct mbox_context *context)
 {
 	int r;
+	int readsize = CHUNKSIZE;
+	int offset = 0;
 
 	/*
 	 * Copy flash into RAM early, same time.
@@ -342,11 +347,17 @@
 		MSG_ERR("Couldn't reset MBOX pos to zero\n");
 		return r;
 	}
-	r = read(context->fds[MTD_FD].fd, context->lpc_mem, context->size);
-	if (r != context->size) {
-		r = -errno;
-		MSG_ERR("Couldn't copy mtd into ram: %d\n", r);
-		return r;
+	while (readsize) {
+		r = read(context->fds[MTD_FD].fd, context->lpc_mem + offset, readsize);
+		if (r != readsize) {
+			r = -errno;
+			MSG_ERR("Couldn't copy mtd into ram: %d\n", r);
+			return r;
+		}
+		offset += readsize;
+		readsize = context->size - offset;
+		if (readsize > CHUNKSIZE)
+			readsize = CHUNKSIZE;
 	}
 	return 0;
 }