[PATCH 12/30] efi: factor out errno translation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The errno translation will come in handy for the EFI loader support, so
factor that out.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 common/efi/Makefile       |  1 +
 common/efi/errno.c        | 90 +++++++++++++++++++++++++++++++++++++++
 common/efi/payload/init.c | 86 -------------------------------------
 include/efi/efi-util.h    | 10 +++++
 include/efi/efi.h         |  5 +--
 5 files changed, 102 insertions(+), 90 deletions(-)
 create mode 100644 common/efi/errno.c
 create mode 100644 include/efi/efi-util.h

diff --git a/common/efi/Makefile b/common/efi/Makefile
index 1ed5d45c1f5e..ed110f5a6899 100644
--- a/common/efi/Makefile
+++ b/common/efi/Makefile
@@ -3,3 +3,4 @@
 obj-$(CONFIG_EFI_BOOTUP)	+= payload/
 obj-$(CONFIG_EFI_GUID)		+= guid.o
 obj-$(CONFIG_EFI_DEVICEPATH)	+= devicepath.o
+obj-y				+= errno.o
diff --git a/common/efi/errno.c b/common/efi/errno.c
new file mode 100644
index 000000000000..3bb68e7781e6
--- /dev/null
+++ b/common/efi/errno.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <efi/efi-util.h>
+#include <errno.h>
+
+const char *efi_strerror(efi_status_t err)
+{
+	const char *str;
+
+	switch (err) {
+	case EFI_SUCCESS: str = "Success"; break;
+	case EFI_LOAD_ERROR: str = "Load Error"; break;
+	case EFI_INVALID_PARAMETER: str = "Invalid Parameter"; break;
+	case EFI_UNSUPPORTED: str = "Unsupported"; break;
+	case EFI_BAD_BUFFER_SIZE: str = "Bad Buffer Size"; break;
+	case EFI_BUFFER_TOO_SMALL: str = "Buffer Too Small"; break;
+	case EFI_NOT_READY: str = "Not Ready"; break;
+	case EFI_DEVICE_ERROR: str = "Device Error"; break;
+	case EFI_WRITE_PROTECTED: str = "Write Protected"; break;
+	case EFI_OUT_OF_RESOURCES: str = "Out of Resources"; break;
+	case EFI_VOLUME_CORRUPTED: str = "Volume Corrupt"; break;
+	case EFI_VOLUME_FULL: str = "Volume Full"; break;
+	case EFI_NO_MEDIA: str = "No Media"; break;
+	case EFI_MEDIA_CHANGED: str = "Media changed"; break;
+	case EFI_NOT_FOUND: str = "Not Found"; break;
+	case EFI_ACCESS_DENIED: str = "Access Denied"; break;
+	case EFI_NO_RESPONSE: str = "No Response"; break;
+	case EFI_NO_MAPPING: str = "No mapping"; break;
+	case EFI_TIMEOUT: str = "Time out"; break;
+	case EFI_NOT_STARTED: str = "Not started"; break;
+	case EFI_ALREADY_STARTED: str = "Already started"; break;
+	case EFI_ABORTED: str = "Aborted"; break;
+	case EFI_ICMP_ERROR: str = "ICMP Error"; break;
+	case EFI_TFTP_ERROR: str = "TFTP Error"; break;
+	case EFI_PROTOCOL_ERROR: str = "Protocol Error"; break;
+	case EFI_INCOMPATIBLE_VERSION: str = "Incompatible Version"; break;
+	case EFI_SECURITY_VIOLATION: str = "Security Violation"; break;
+	case EFI_CRC_ERROR: str = "CRC Error"; break;
+	case EFI_END_OF_MEDIA: str = "End of Media"; break;
+	case EFI_END_OF_FILE: str = "End of File"; break;
+	case EFI_INVALID_LANGUAGE: str = "Invalid Language"; break;
+	case EFI_COMPROMISED_DATA: str = "Compromised Data"; break;
+	default: str = "unknown error";
+	}
+
+	return str;
+}
+
+int efi_errno(efi_status_t err)
+{
+	int ret;
+
+	switch (err) {
+	case EFI_SUCCESS: ret = 0; break;
+	case EFI_LOAD_ERROR: ret = EIO; break;
+	case EFI_INVALID_PARAMETER: ret = EINVAL; break;
+	case EFI_UNSUPPORTED: ret = ENOTSUPP; break;
+	case EFI_BAD_BUFFER_SIZE: ret = EINVAL; break;
+	case EFI_BUFFER_TOO_SMALL: ret = EINVAL; break;
+	case EFI_NOT_READY: ret = EAGAIN; break;
+	case EFI_DEVICE_ERROR: ret = EIO; break;
+	case EFI_WRITE_PROTECTED: ret = EROFS; break;
+	case EFI_OUT_OF_RESOURCES: ret = ENOMEM; break;
+	case EFI_VOLUME_CORRUPTED: ret = EIO; break;
+	case EFI_VOLUME_FULL: ret = ENOSPC; break;
+	case EFI_NO_MEDIA: ret = ENOMEDIUM; break;
+	case EFI_MEDIA_CHANGED: ret = ENOMEDIUM; break;
+	case EFI_NOT_FOUND: ret = ENODEV; break;
+	case EFI_ACCESS_DENIED: ret = EACCES; break;
+	case EFI_NO_RESPONSE: ret = ETIMEDOUT; break;
+	case EFI_NO_MAPPING: ret = EINVAL; break;
+	case EFI_TIMEOUT: ret = ETIMEDOUT; break;
+	case EFI_NOT_STARTED: ret = EINVAL; break;
+	case EFI_ALREADY_STARTED: ret = EINVAL; break;
+	case EFI_ABORTED: ret = EINTR; break;
+	case EFI_ICMP_ERROR: ret = EINVAL; break;
+	case EFI_TFTP_ERROR: ret = EINVAL; break;
+	case EFI_PROTOCOL_ERROR: ret = EPROTO; break;
+	case EFI_INCOMPATIBLE_VERSION: ret = EINVAL; break;
+	case EFI_SECURITY_VIOLATION: ret = EINVAL; break;
+	case EFI_CRC_ERROR: ret = EINVAL; break;
+	case EFI_END_OF_MEDIA: ret = EINVAL; break;
+	case EFI_END_OF_FILE: ret = EINVAL; break;
+	case EFI_INVALID_LANGUAGE: ret = EINVAL; break;
+	case EFI_COMPROMISED_DATA: ret = EINVAL; break;
+	default: ret = EINVAL;
+	}
+
+	return ret;
+}
diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c
index 0e672a6b56d2..5149b5b5d0d3 100644
--- a/common/efi/payload/init.c
+++ b/common/efi/payload/init.c
@@ -163,92 +163,6 @@ static int misc_init(void)
 }
 late_initcall(misc_init);
 
-const char *efi_strerror(efi_status_t err)
-{
-	const char *str;
-
-	switch (err) {
-	case EFI_SUCCESS: str = "Success"; break;
-	case EFI_LOAD_ERROR: str = "Load Error"; break;
-	case EFI_INVALID_PARAMETER: str = "Invalid Parameter"; break;
-	case EFI_UNSUPPORTED: str = "Unsupported"; break;
-	case EFI_BAD_BUFFER_SIZE: str = "Bad Buffer Size"; break;
-	case EFI_BUFFER_TOO_SMALL: str = "Buffer Too Small"; break;
-	case EFI_NOT_READY: str = "Not Ready"; break;
-	case EFI_DEVICE_ERROR: str = "Device Error"; break;
-	case EFI_WRITE_PROTECTED: str = "Write Protected"; break;
-	case EFI_OUT_OF_RESOURCES: str = "Out of Resources"; break;
-	case EFI_VOLUME_CORRUPTED: str = "Volume Corrupt"; break;
-	case EFI_VOLUME_FULL: str = "Volume Full"; break;
-	case EFI_NO_MEDIA: str = "No Media"; break;
-	case EFI_MEDIA_CHANGED: str = "Media changed"; break;
-	case EFI_NOT_FOUND: str = "Not Found"; break;
-	case EFI_ACCESS_DENIED: str = "Access Denied"; break;
-	case EFI_NO_RESPONSE: str = "No Response"; break;
-	case EFI_NO_MAPPING: str = "No mapping"; break;
-	case EFI_TIMEOUT: str = "Time out"; break;
-	case EFI_NOT_STARTED: str = "Not started"; break;
-	case EFI_ALREADY_STARTED: str = "Already started"; break;
-	case EFI_ABORTED: str = "Aborted"; break;
-	case EFI_ICMP_ERROR: str = "ICMP Error"; break;
-	case EFI_TFTP_ERROR: str = "TFTP Error"; break;
-	case EFI_PROTOCOL_ERROR: str = "Protocol Error"; break;
-	case EFI_INCOMPATIBLE_VERSION: str = "Incompatible Version"; break;
-	case EFI_SECURITY_VIOLATION: str = "Security Violation"; break;
-	case EFI_CRC_ERROR: str = "CRC Error"; break;
-	case EFI_END_OF_MEDIA: str = "End of Media"; break;
-	case EFI_END_OF_FILE: str = "End of File"; break;
-	case EFI_INVALID_LANGUAGE: str = "Invalid Language"; break;
-	case EFI_COMPROMISED_DATA: str = "Compromised Data"; break;
-	default: str = "unknown error";
-	}
-
-	return str;
-}
-
-int efi_errno(efi_status_t err)
-{
-	int ret;
-
-	switch (err) {
-	case EFI_SUCCESS: ret = 0; break;
-	case EFI_LOAD_ERROR: ret = EIO; break;
-	case EFI_INVALID_PARAMETER: ret = EINVAL; break;
-	case EFI_UNSUPPORTED: ret = ENOTSUPP; break;
-	case EFI_BAD_BUFFER_SIZE: ret = EINVAL; break;
-	case EFI_BUFFER_TOO_SMALL: ret = EINVAL; break;
-	case EFI_NOT_READY: ret = EAGAIN; break;
-	case EFI_DEVICE_ERROR: ret = EIO; break;
-	case EFI_WRITE_PROTECTED: ret = EROFS; break;
-	case EFI_OUT_OF_RESOURCES: ret = ENOMEM; break;
-	case EFI_VOLUME_CORRUPTED: ret = EIO; break;
-	case EFI_VOLUME_FULL: ret = ENOSPC; break;
-	case EFI_NO_MEDIA: ret = ENOMEDIUM; break;
-	case EFI_MEDIA_CHANGED: ret = ENOMEDIUM; break;
-	case EFI_NOT_FOUND: ret = ENODEV; break;
-	case EFI_ACCESS_DENIED: ret = EACCES; break;
-	case EFI_NO_RESPONSE: ret = ETIMEDOUT; break;
-	case EFI_NO_MAPPING: ret = EINVAL; break;
-	case EFI_TIMEOUT: ret = ETIMEDOUT; break;
-	case EFI_NOT_STARTED: ret = EINVAL; break;
-	case EFI_ALREADY_STARTED: ret = EINVAL; break;
-	case EFI_ABORTED: ret = EINTR; break;
-	case EFI_ICMP_ERROR: ret = EINVAL; break;
-	case EFI_TFTP_ERROR: ret = EINVAL; break;
-	case EFI_PROTOCOL_ERROR: ret = EPROTO; break;
-	case EFI_INCOMPATIBLE_VERSION: ret = EINVAL; break;
-	case EFI_SECURITY_VIOLATION: ret = EINVAL; break;
-	case EFI_CRC_ERROR: ret = EINVAL; break;
-	case EFI_END_OF_MEDIA: ret = EINVAL; break;
-	case EFI_END_OF_FILE: ret = EINVAL; break;
-	case EFI_INVALID_LANGUAGE: ret = EINVAL; break;
-	case EFI_COMPROMISED_DATA: ret = EINVAL; break;
-	default: ret = EINVAL;
-	}
-
-	return ret;
-}
-
 static struct NS16550_plat ns16550_plat = {
 	.clock = 115200 * 16,
 };
diff --git a/include/efi/efi-util.h b/include/efi/efi-util.h
new file mode 100644
index 000000000000..0645af270769
--- /dev/null
+++ b/include/efi/efi-util.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __EFI_UTIL_H
+#define __EFI_UTIL_H
+
+#include <efi.h>
+
+const char *efi_strerror(efi_status_t err);
+int efi_errno(efi_status_t err);
+
+#endif
diff --git a/include/efi/efi.h b/include/efi/efi.h
index c7679b4b8f28..e77b1c5feb52 100644
--- a/include/efi/efi.h
+++ b/include/efi/efi.h
@@ -3,16 +3,13 @@
 #define __MACH_EFI_H
 
 #include <efi.h>
-
-const char *efi_strerror(efi_status_t err);
+#include <efi/efi-util.h>
 
 extern efi_system_table_t *efi_sys_table;
 extern efi_handle_t efi_parent_image;
 extern struct efi_device_path *efi_device_path;
 extern efi_loaded_image_t *efi_loaded_image;
 
-int efi_errno(efi_status_t err);
-
 void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
 
 static inline void *efi_get_global_var(char *name, int *var_size)
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux