#! /usr/bin/python2.6
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
#
"""
UEFI firmware backend for pybootmgmt (only 64-bit UEFI is supported)
"""
from bootmgmt import BootmgmtPropertyWriteError, BootmgmtError
from bootmgmt.bootinfo import SystemFirmware
from bootmgmt.bootutil import find_efi_system_partition
from bootmgmt.pysol import devfs_bootdev_set_list, libdevinfo_errdict
class UEFI64Firmware(SystemFirmware):
"""Provide an implementation for the SystemFirmware interface for 64-bit
UEFI firmware.
"""
def setprop(self, prop, value):
"""Set property values.
"""
if prop == SystemFirmware.PROP_BOOT_DEVICE:
self._uefi_set_boot_device(value)
return
super(UEFI64Firmware, self).setprop(prop, value)
def _uefi_set_boot_device(self, value):
"""Sets the UEFI Boot device via libdevinfo. The value passed here
MUST be the EFI System Partition, otherwise the resulting entry will
not be correct.
"""
if isinstance(value, basestring):
boot_list = [value]
else:
boot_list = value
efisys_devs = []
for dev in boot_list:
try:
self._debug('Converting device "%s"', dev)
espdev = find_efi_system_partition(dev)
self._debug('Converted device "%s" -> ESP dev "%s"',
(dev, espdev))
efisys_devs.append(espdev)
except BootmgmtError as bme:
raise BootmgmtPropertyWriteError(bme.msg)
retval = devfs_bootdev_set_list(efisys_devs)
self._debug('devfs_bootdev_set_list(%s) => %d', (str(efisys_devs),
retval))
if retval < 0 and libdevinfo_errdict.get(retval):
raise BootmgmtPropertyWriteError('Error updating UEFI boot '
'options: %s' % libdevinfo_errdict[retval])
elif retval != 0:
raise BootmgmtPropertyWriteError('Unknown error while updating '
'UEFI boot options: error code %d' % retval)
def firmware_backend():
"""Entry point for factory to call in and get a SystemFirmware instance.
"""
return UEFI64Firmware