]> git.saurik.com Git - apple/system_cmds.git/commitdiff
system_cmds-790.30.1.tar.gz macos-10132 macos-10133 v790.30.1
authorApple <opensource@apple.com>
Sat, 3 Feb 2018 22:02:36 +0000 (22:02 +0000)
committerApple <opensource@apple.com>
Sat, 3 Feb 2018 22:02:36 +0000 (22:02 +0000)
nvram.tproj/nvram.c
system_cmds.xcodeproj/project.pbxproj

index 89f27fc1f93ea1e1ba7c4b6b6c4980ee038859ec..3711499da8ed8bb12dc13f37592720b316ece198 100644 (file)
@@ -56,6 +56,27 @@ static io_registry_entry_t gOptionsRef;
 static bool                gUseXML;
 static bool                gUseForceSync;
 
+#if TARGET_OS_BRIDGE /* Stuff for nvram bridge -> intel */
+#include <dlfcn.h>
+#include <libMacEFIManager/MacEFIHostInterfaceAPI.h>
+
+static kern_return_t LinkMacNVRAMSymbols(void);
+static kern_return_t GetMacOFVariable(char *name, char **value);
+static kern_return_t SetMacOFVariable(char *name, char *value);
+static void DeleteMacOFVariable(char *name);
+
+static bool gBridgeToIntel;
+static void *gDL_handle;
+static void *gNvramInterface;
+
+static void (*hostInterfaceInitialize_fptr)(void);
+static void *(*createNvramHostInterface_fptr)(const char *handle);
+static kern_return_t (*destroyNvramHostInterface_fptr)(void *interface);
+static kern_return_t (*getNVRAMVariable_fptr)(void *interface, char *name, char **buffer, uint32_t *size);
+static kern_return_t (*setNVRAMVariable_fptr)(void *interface, char *name, char *buffer, uint32_t size);
+static void (*hostInterfaceDeinitialize_fptr)(void); /* may not need? */
+
+#endif /* TARGET_OS_BRIDGE */
 
 int main(int argc, char **argv)
 {
@@ -88,6 +109,12 @@ int main(int argc, char **argv)
       for (str += 1 ; *str; str++) {
        switch (*str) {
        case 'p' :
+#if TARGET_OS_BRIDGE
+        if (gBridgeToIntel) {
+          fprintf(stderr, "-p not supported for Mac NVRAM store.\n");
+          return 1;
+        }
+#endif
          PrintOFVariables();
          break;
 
@@ -96,6 +123,12 @@ int main(int argc, char **argv)
           break;
 
        case 'f':
+#if TARGET_OS_BRIDGE
+        if (gBridgeToIntel) {
+          fprintf(stderr, "-f not supported for Mac NVRAM store.\n");
+          return 1;
+        }
+#endif
          cnt++;
          if (cnt < argc && *argv[cnt] != '-') {
            ParseFile(argv[cnt]);
@@ -105,6 +138,12 @@ int main(int argc, char **argv)
          break;
 
        case 'd':
+#if TARGET_OS_BRIDGE
+        if (gBridgeToIntel) {
+          fprintf(stderr, "-d not supported for Mac NVRAM store.\n");
+          return 1;
+        }
+#endif
          cnt++;
          if (cnt < argc && *argv[cnt] != '-') {
            DeleteOFVariable(argv[cnt]);
@@ -114,6 +153,12 @@ int main(int argc, char **argv)
          break;
 
        case 'c':
+#if TARGET_OS_BRIDGE
+        if (gBridgeToIntel) {
+          fprintf(stderr, "-c not supported for Mac NVRAM store.\n");
+          return 1;
+        }
+#endif
          ClearOFVariables();
          break;
        case 's':
@@ -121,6 +166,17 @@ int main(int argc, char **argv)
          // commit the variable to nonvolatile storage
          gUseForceSync = true;
          break;
+#if TARGET_OS_BRIDGE
+       case 'm':
+         // -m option is unadvertised -- used to set nvram variables on the Intel side
+         // from the ARM side (Bridge -> Mac)
+      fprintf(stdout, "Using Mac NVRAM store.\n");
+
+      LinkMacNVRAMSymbols();
+         gBridgeToIntel = true;
+         break;
+#endif
+
        default:
          strcpy(errorMessage, "no such option as --");
          errorMessage[strlen(errorMessage)-1] = *str;
@@ -405,18 +461,39 @@ static void SetOrGetOFVariable(char *str)
   if (set == 1) {
     // On sets, the OF variable's value follows the equal sign.
     value = str;
-
-    result = SetOFVariable(name, value);
-       NVRamSyncNow(name);                     /* Try syncing the new data to device, best effort! */
+#if TARGET_OS_BRIDGE
+    if (gBridgeToIntel) {
+      result = SetMacOFVariable(name, value);
+    }
+    else
+#endif
+    {
+      result = SetOFVariable(name, value);
+      NVRamSyncNow(name);            /* Try syncing the new data to device, best effort! */
+    }
     if (result != KERN_SUCCESS) {
       errx(1, "Error setting variable - '%s': %s", name,
            mach_error_string(result));
     }
   } else {
-    result = GetOFVariable(name, &nameRef, &valueRef);
-    if (result != KERN_SUCCESS) {
-      errx(1, "Error getting variable - '%s': %s", name,
-           mach_error_string(result));
+#if TARGET_OS_BRIDGE
+    if (gBridgeToIntel) {
+      result = GetMacOFVariable(name, &value);
+      if (result != KERN_SUCCESS) {
+        errx(1, "Error getting variable - '%s': %s", name,
+             mach_error_string(result));
+      }
+      nameRef = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8);
+      valueRef = CFStringCreateWithCString(kCFAllocatorDefault, value, kCFStringEncodingUTF8);
+    }
+    else
+#endif
+    {
+      result = GetOFVariable(name, &nameRef, &valueRef);
+      if (result != KERN_SUCCESS) {
+        errx(1, "Error getting variable - '%s': %s", name,
+             mach_error_string(result));
+      }
     }
 
     PrintOFVariable(nameRef, valueRef, 0);
@@ -425,6 +502,47 @@ static void SetOrGetOFVariable(char *str)
   }
 }
 
+#if TARGET_OS_BRIDGE
+static kern_return_t LinkMacNVRAMSymbols()
+{
+  gDL_handle = dlopen("libMacEFIHostInterface.dylib", RTLD_LAZY);
+  if (gDL_handle == NULL) {
+    errx(errno, "Failed to dlopen libMacEFIHostInterface.dylib");
+    return KERN_FAILURE; /* NOTREACHED */
+  }
+
+  hostInterfaceInitialize_fptr = dlsym(gDL_handle, "hostInterfaceInitialize");
+  if (hostInterfaceInitialize_fptr == NULL) {
+    errx(errno, "failed to link hostInterfaceInitialize");
+  }
+  createNvramHostInterface_fptr = dlsym(gDL_handle, "createNvramHostInterface");
+  if (createNvramHostInterface_fptr == NULL) {
+    errx(errno, "failed to link createNvramHostInterface");
+  }
+  destroyNvramHostInterface_fptr = dlsym(gDL_handle, "destroyNvramHostInterface");
+  if (destroyNvramHostInterface_fptr == NULL) {
+    errx(errno, "failed to link destroyNvramHostInterface");
+  }
+  getNVRAMVariable_fptr = dlsym(gDL_handle, "getNVRAMVariable");
+  if (getNVRAMVariable_fptr == NULL) {
+    errx(errno, "failed to link getNVRAMVariable");
+  }
+  setNVRAMVariable_fptr = dlsym(gDL_handle, "setNVRAMVariable");
+  if (setNVRAMVariable_fptr == NULL) {
+    errx(errno, "failed to link setNVRAMVariable");
+  }
+  hostInterfaceDeinitialize_fptr = dlsym(gDL_handle, "hostInterfaceDeinitialize");
+  if (hostInterfaceDeinitialize_fptr == NULL) {
+    errx(errno, "failed to link hostInterfaceDeinitialize");
+  }
+
+  /* also do the initialization */
+  hostInterfaceInitialize_fptr();
+  gNvramInterface = createNvramHostInterface_fptr(NULL);
+
+  return KERN_SUCCESS;
+}
+#endif
 
 // GetOFVariable(name, nameRef, valueRef)
 //
@@ -446,6 +564,23 @@ static kern_return_t GetOFVariable(char *name, CFStringRef *nameRef,
   return KERN_SUCCESS;
 }
 
+#if TARGET_OS_BRIDGE
+// GetMacOFVariable(name, value)
+//
+// Get the named firmware variable from the Intel side.
+// Return the value in value
+//
+static kern_return_t GetMacOFVariable(char *name, char **value)
+{
+  uint32_t value_size;
+  kern_return_t result = KERN_FAILURE;
+  assert(getNVRAMVariable_fptr != NULL);
+
+  result = getNVRAMVariable_fptr(gNvramInterface, name, value, &value_size);
+
+  return result;
+}
+#endif
 
 // SetOFVariable(name, value)
 //
@@ -510,6 +645,17 @@ static kern_return_t SetOFVariable(char *name, char *value)
   return result;
 }
 
+#if TARGET_OS_BRIDGE
+static kern_return_t SetMacOFVariable(char *name, char *value)
+{
+  kern_return_t result = KERN_FAILURE;
+  assert(setNVRAMVariable_fptr != NULL);
+
+  result = setNVRAMVariable_fptr(gNvramInterface, name, value, strlen(value));
+
+  return result;
+}
+#endif
 
 // DeleteOFVariable(name)
 //
@@ -521,6 +667,13 @@ static void DeleteOFVariable(char *name)
   SetOFVariable(kIONVRAMDeletePropertyKey, name);
 }
 
+#if TARGET_OS_BRIDGE
+static void DeleteMacOFVariable(char *name)
+{
+  /* Not yet implementable */
+}
+#endif
+
 static void NVRamSyncNow(char *name)
 {
   if (!gUseForceSync) {
index 4611e1b6bb1d34872ec41e0ac22fb3688a4e9874..06d5b8dbfcf7edffb7d9dd9a33e9c59c44110d65 100644 (file)
                1873300218CBD4A700275344 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/local/include";
                                INSTALL_PATH = /usr/sbin;
                                PRODUCT_NAME = nvram;
                        };
                BAE589A4137836A00049DD3B /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/local/include";
                                INSTALL_PATH = /usr/sbin;
                                PRODUCT_NAME = nvram;
                        };