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)
{
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;
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]);
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]);
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':
// 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;
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);
}
}
+#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)
//
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)
//
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)
//
SetOFVariable(kIONVRAMDeletePropertyKey, name);
}
+#if TARGET_OS_BRIDGE
+static void DeleteMacOFVariable(char *name)
+{
+ /* Not yet implementable */
+}
+#endif
+
static void NVRamSyncNow(char *name)
{
if (!gUseForceSync) {