aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <JBottomley@Parallels.com>2012-12-02 20:42:40 +0000
committerJames Bottomley <JBottomley@Parallels.com>2012-12-03 09:39:44 +0000
commite7ad016899136d4dd07a223ead29943ca1b42737 (patch)
tree0b08307a8bc8b249ac0efaef7b637381321b1671
parent1e604672d8f49739e1ee2db23b0aa6d78a5eab63 (diff)
downloadefitools-e7ad016899136d4dd07a223ead29943ca1b42737.tar.gz
PreLoader: Simple preloader
-rw-r--r--Makefile3
-rw-r--r--PreLoader.c56
2 files changed, 58 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 1885e9c..02e49b2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
EFIFILES = HelloWorld.efi LockDown.efi Loader.efi ReadVars.efi UpdateVars.efi \
- KeyTool.efi HashTool.efi
+ KeyTool.efi HashTool.efi PreLoader.efi
BINARIES = cert-to-efi-sig-list sig-list-to-certs sign-efi-sig-list
export TOPDIR := $(shell pwd)/
@@ -51,6 +51,7 @@ UpdateVars.so: lib/lib-efi.a
LockDown.so: lib/lib-efi.a
KeyTool.so: lib/lib-efi.a
HashTool.so: lib/lib-efi.a
+PreLoader.so: lib/lib-efi.a
cert-to-efi-sig-list: cert-to-efi-sig-list.o lib/lib.a
$(CC) -o $@ $< -lcrypto lib/lib.a
diff --git a/PreLoader.c b/PreLoader.c
new file mode 100644
index 0000000..d6c7f27
--- /dev/null
+++ b/PreLoader.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 <James.Bottomley@HansenPartnership.com>
+ *
+ * see COPYING file
+ *
+ * Simple elf loader based on Intel TianoCore
+ */
+
+#include <efi.h>
+#include <efilib.h>
+
+#include <pecoff.h>
+#include <console.h>
+#include <errors.h>
+
+CHAR16 *loader = L"loader.efi";
+CHAR16 *hashtool = L"HashTool.efi";
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ EFI_STATUS status;
+
+ InitializeLib(image, systab);
+
+ status = pecoff_execute_checked(image, systab, loader);
+
+ if (status == EFI_SUCCESS)
+ return status;
+
+ if (status != EFI_SECURITY_VIOLATION) {
+ CHAR16 buf[256];
+
+ StrCpy(buf, L"Failed to start ");
+ StrCat(buf, loader);
+ console_error(buf, status);
+
+ return status;
+ }
+
+ status = pecoff_execute_checked(image, systab, hashtool);
+
+ if (status != EFI_SUCCESS) {
+ CHAR16 buf[256];
+
+ StrCpy(buf, L"Failed to start backup programme ");
+ StrCat(buf, hashtool);
+ console_error(buf, status);
+ }
+
+ /* try to start the loader again */
+ status = pecoff_execute_checked(image, systab, loader);
+
+
+ return status;
+}