BLSetEFIBootDevice.c [plain text]
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include "bless.h"
#include "bless_private.h"
kern_return_t
BLSetEFIBootDevice(BLContextPtr context, char *bsdName)
{
kern_return_t rval = KERN_FAILURE;
char *errmsg;
CFStringRef xmlString = NULL;
io_registry_entry_t optionsNode = IO_OBJECT_NULL;
errmsg = "unable to create objects";
if (BLCreateEFIXMLRepresentationForDevice(NULL, bsdName, NULL,&xmlString,0))
goto finish;
contextprintf(context, kBLLogLevelVerbose,
"setting NVRAM to boot from '%s'\n", bsdName);
#if 0
contextprintf(context, kBLLogLevelNormal, "XML for device:\n");
CFShow(xmlString);
#endif
errmsg = "unable to find /options node";
optionsNode = IORegistryEntryFromPath(kIOMasterPortDefault,
kIODeviceTreePlane ":/options");
if (IO_OBJECT_NULL == optionsNode) goto finish;
errmsg = "error setting efi-boot-device";
rval = IORegistryEntrySetCFProperty(optionsNode,
CFSTR("efi-boot-device"), xmlString);
finish:
if (rval != KERN_SUCCESS) {
contextprintf(context, kBLLogLevelError,
"setEFIBootDevice(): %s\n", errmsg);
}
if (optionsNode != IO_OBJECT_NULL)
IOObjectRelease(optionsNode);
if (xmlString) CFRelease(xmlString);
return rval;
}