mboxd: Cleanup errnos not captured by tests

Change-Id: I95d1eee536e4113867fceb5dcda45e15dc032002
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/flash.c b/flash.c
index 6fb9c2c..ee527dc 100644
--- a/flash.c
+++ b/flash.c
@@ -135,7 +135,7 @@
 		      uint32_t count, uint8_t val)
 {
 	if ((offset + count) > context->flash_size) {
-		return -MBOX_R_PARAM_ERROR;
+		return -EINVAL;
 	}
 
 	MSG_DBG("Set flash bytemap @ 0x%.8x for 0x%.8x to %s\n",
@@ -186,7 +186,7 @@
 			if (rc < 0) {
 				MSG_ERR("Couldn't erase flash at 0x%.8x\n",
 						erase_info.start);
-				return -MBOX_R_SYSTEM_ERROR;
+				return -errno;
 			}
 			/* Mark ERASED where we just erased */
 			flash_set_bytemap(context, erase_info.start,
@@ -206,7 +206,7 @@
 		if (rc < 0) {
 			MSG_ERR("Couldn't erase flash at 0x%.8x\n",
 					erase_info.start);
-			return -MBOX_R_SYSTEM_ERROR;
+			return -errno;
 		}
 		/* Mark ERASED where we just erased */
 		flash_set_bytemap(context, erase_info.start, erase_info.length,
@@ -239,7 +239,7 @@
 	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));
-		return -MBOX_R_SYSTEM_ERROR;
+		return -errno;
 	}
 
 	do {
@@ -248,14 +248,14 @@
 		if (size_read < 0) {
 			MSG_ERR("Couldn't copy mtd into ram: %s\n",
 				strerror(errno));
-			return -MBOX_R_SYSTEM_ERROR;
+			return -errno;
 		}
 
 		size -= size_read;
 		mem += size_read;
 	} while (size && size_read);
 
-	return size_read ? mem - start : -MBOX_R_SYSTEM_ERROR;
+	return size_read ? mem - start : -EIO;
 }
 
 /*
@@ -278,7 +278,7 @@
 	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));
-		return -MBOX_R_SYSTEM_ERROR;
+		return -errno;
 	}
 
 	while (count) {
@@ -286,7 +286,7 @@
 		if (rc < 0) {
 			MSG_ERR("Couldn't write to flash, write lost: %s\n",
 				strerror(errno));
-			return -MBOX_R_WRITE_ERROR;
+			return -errno;
 		}
 		/* Mark *NOT* erased where we just wrote */
 		flash_set_bytemap(context, offset + buf_offset, rc,
diff --git a/lpc.c b/lpc.c
index 4b9d384..f64e5d1 100644
--- a/lpc.c
+++ b/lpc.c
@@ -119,7 +119,7 @@
 	/* Don't let the host access flash while we're suspended */
 	if (context->state & STATE_SUSPENDED) {
 		MSG_ERR("Can't point lpc mapping to flash while suspended\n");
-		return -MBOX_R_PARAM_ERROR;
+		return -EBUSY;
 	}
 
 	MSG_INFO("Pointing HOST LPC bus at the flash\n");
@@ -130,7 +130,7 @@
 			== -1) {
 		MSG_ERR("Failed to point the LPC BUS at the actual flash: %s\n",
 			strerror(errno));
-		return -MBOX_R_SYSTEM_ERROR;
+		return -errno;
 	}
 
 	context->state = ACTIVE_MAPS_FLASH;
diff --git a/vpnor/flash.cpp b/vpnor/flash.cpp
index 3756141..f7e0713 100644
--- a/vpnor/flash.cpp
+++ b/vpnor/flash.cpp
@@ -126,7 +126,7 @@
     if (!(context && context->vpnor && context->vpnor->table))
     {
         MSG_ERR("Trying to copy data with uninitialised context!\n");
-        return -MBOX_R_SYSTEM_ERROR;
+        return -EINVAL;
     }
 
     table = context->vpnor->table;
@@ -171,7 +171,7 @@
     {
         MSG_ERR("%s\n", e.what());
         phosphor::logging::commit<err::InternalFailure>();
-        rc = -MBOX_R_SYSTEM_ERROR;
+        rc = -EIO;
     }
     return rc;
 }
@@ -193,7 +193,7 @@
     if (!(context && context->vpnor && context->vpnor->table))
     {
         MSG_ERR("Trying to write data with uninitialised context!\n");
-        return -MBOX_R_SYSTEM_ERROR;
+        return -EINVAL;
     }
 
     vpnor::partition::Table* table = context->vpnor->table;
@@ -206,7 +206,7 @@
             MSG_ERR("Unreachable: Host attempted to write to read-only "
                     "partition %s\n",
                     part.data.name);
-            return -MBOX_R_WRITE_ERROR;
+            return -EPERM;
         }
 
         MSG_DBG("Write flash @ 0x%.8x for 0x%.8x from %p\n", offset, count,
@@ -219,18 +219,18 @@
         MSG_ERR("Unreachable: Host attempted to write %" PRIu32
                 " bytes to unmapped offset 0x%" PRIx32 "\n",
                 count, offset);
-        return -MBOX_R_WRITE_ERROR;
+        return -EACCES;
     }
     catch (const vpnor::OutOfBoundsOffset& e)
     {
         MSG_ERR("%s\n", e.what());
-        return -MBOX_R_PARAM_ERROR;
+        return -EINVAL;
     }
     catch (const std::exception& e)
     {
         MSG_ERR("%s\n", e.what());
         phosphor::logging::commit<err::InternalFailure>();
-        return -MBOX_R_SYSTEM_ERROR;
+        return -EIO;
     }
     return 0;
 }
diff --git a/vpnor/mboxd_pnor_partition_table.cpp b/vpnor/mboxd_pnor_partition_table.cpp
index f787fc8..329e065 100644
--- a/vpnor/mboxd_pnor_partition_table.cpp
+++ b/vpnor/mboxd_pnor_partition_table.cpp
@@ -57,7 +57,7 @@
         {
             MSG_ERR("%s\n", e.what());
             phosphor::logging::commit<err::InternalFailure>();
-            return -MBOX_R_SYSTEM_ERROR;
+            return -EINVAL;
         }
     }
 
@@ -112,13 +112,13 @@
     catch (err::InternalFailure &e)
     {
         phosphor::logging::commit<err::InternalFailure>();
-        return -MBOX_R_SYSTEM_ERROR;
+        return -EIO;
     }
     catch (vpnor::ReasonedError &e)
     {
         MSG_ERR("%s\n", e.what());
         phosphor::logging::commit<err::InternalFailure>();
-        return -MBOX_R_SYSTEM_ERROR;
+        return -EIO;
     }
 
     return 0;
diff --git a/windows.c b/windows.c
index 26fd37b..a126365 100644
--- a/windows.c
+++ b/windows.c
@@ -189,7 +189,7 @@
 		low_mem.mem = malloc(low_mem.size);
 		if (!low_mem.mem) {
 			MSG_ERR("Unable to allocate memory\n");
-			return -MBOX_R_SYSTEM_ERROR;
+			return -ENOMEM;
 		}
 		rc = flash_copy(context, low_mem.flash_offset,
 				low_mem.mem, low_mem.size);
@@ -203,7 +203,7 @@
 		high_mem.mem = malloc(high_mem.size);
 		if (!high_mem.mem) {
 			MSG_ERR("Unable to allocate memory\n");
-			rc = -MBOX_R_SYSTEM_ERROR;
+			rc = -ENOMEM;
 			goto out;
 		}
 		rc = flash_copy(context, high_mem.flash_offset,
@@ -322,7 +322,7 @@
 	default:
 		/* We shouldn't be able to get here */
 		MSG_ERR("Write from window with invalid type: %d\n", type);
-		return -MBOX_R_SYSTEM_ERROR;
+		return -EPERM;
 	}
 
 	return 0;
@@ -594,7 +594,7 @@
 
 	if (offset > context->flash_size) {
 		MSG_ERR("Tried to open read window past flash limit\n");
-		return -MBOX_R_PARAM_ERROR;
+		return -EINVAL;
 	} else if ((offset + cur->size) > context->flash_size) {
 		/*
 		 * There is V1 skiboot implementations out there which don't