mboxd: Introduce a new DEBUG log level

Currently there is no output on the console unless -v is specified on
the command line which enables error output. A second -v will provide
info output.

We probably want error output irrespective of whether a -v was given
on the command line because people generally want to know why their
program stopped working.

Make error output unconditional.

A single -v will give minimal informational output which is a good
level to see what the daemon is doing without barfing all over the
console.

A second -v will enable debug output which will print highly verbose
information which will be useful for debugging. Probably don't enable
this under normal circumstances.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Change-Id: I3da25f7e4e9e976c17389fcceb1d85ef98de7e0a
diff --git a/mboxd_flash.c b/mboxd_flash.c
index 7ef834a..1e1b7a0 100644
--- a/mboxd_flash.c
+++ b/mboxd_flash.c
@@ -55,7 +55,7 @@
 		return -1;
 	}
 
-	MSG_OUT("Opening %s\n", filename);
+	MSG_DBG("Opening %s\n", filename);
 
 	/* Open Flash Device */
 	fd = open(filename, O_RDWR);
@@ -105,6 +105,7 @@
 	context->flash_bmap = calloc(context->flash_size >>
 				     context->erase_size_shift,
 				     sizeof(*context->flash_bmap));
+	MSG_DBG("Flash erase size: 0x%.8x\n", context->mtd_info.erasesize);
 
 out:
 	free(filename);
@@ -135,8 +136,8 @@
 {
 	int32_t size_read;
 
-	MSG_OUT("Loading flash at %p for 0x%08x bytes from offset 0x%.8x\n",
-							mem, size, offset);
+	MSG_DBG("Copy flash to %p for size 0x%.8x from offset 0x%.8x\n",
+		mem, size, offset);
 	if (lseek(context->fds[MTD_FD].fd, offset, SEEK_SET) != offset) {
 		MSG_ERR("Couldn't seek flash at pos: %u %s\n", offset,
 			strerror(errno));
@@ -192,6 +193,8 @@
 		return -MBOX_R_PARAM_ERROR;
 	}
 
+	MSG_DBG("Set flash bytemap @ 0x%.8x for 0x%.8x to %s\n",
+		offset, count, val ? "ERASED" : "DIRTY");
 	memset(context->flash_bmap + (offset >> context->erase_size_shift),
 	       val,
 	       align_up(count, 1 << context->erase_size_shift) >>
@@ -214,7 +217,7 @@
 	struct erase_info_user erase_info = { 0 };
 	int rc;
 
-	MSG_OUT("Erasing 0x%.8x for 0x%.8x\n", offset, count);
+	MSG_DBG("Erase flash @ 0x%.8x for 0x%.8x\n", offset, count);
 
 	/*
 	 * We have an erased_bytemap for the flash so we want to avoid erasing
@@ -231,6 +234,8 @@
 			erase_info.length += erase_size;
 		} else if (erase_info.length) { /* Already erased|end of run? */
 			/* Erase the previous run which just ended */
+			MSG_DBG("Erase flash @ 0x%.8x for 0x%.8x\n",
+				erase_info.start, erase_info.length);
 			rc = ioctl(context->fds[MTD_FD].fd, MEMERASE,
 				   &erase_info);
 			if (rc < 0) {
@@ -250,6 +255,8 @@
 	}
 
 	if (erase_info.length) {
+		MSG_DBG("Erase flash @ 0x%.8x for 0x%.8x\n",
+			erase_info.start, erase_info.length);
 		rc = ioctl(context->fds[MTD_FD].fd, MEMERASE, &erase_info);
 		if (rc < 0) {
 			MSG_ERR("Couldn't erase flash at 0x%.8x\n",
@@ -279,7 +286,7 @@
 	uint32_t buf_offset = 0;
 	int rc;
 
-	MSG_OUT("Writing 0x%.8x for 0x%.8x from %p\n", offset, count, buf);
+	MSG_DBG("Write flash @ 0x%.8x for 0x%.8x from %p\n", offset, count, buf);
 
 	if (lseek(context->fds[MTD_FD].fd, offset, SEEK_SET) != offset) {
 		MSG_ERR("Couldn't seek flash at pos: %u %s\n", offset,