kiwi.firmware

  1# Copyright (c) 2015 SUSE Linux GmbH.  All rights reserved.
  2#
  3# This file is part of kiwi.
  4#
  5# kiwi is free software: you can redistribute it and/or modify
  6# it under the terms of the GNU General Public License as published by
  7# the Free Software Foundation, either version 3 of the License, or
  8# (at your option) any later version.
  9#
 10# kiwi is distributed in the hope that it will be useful,
 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13# GNU General Public License for more details.
 14#
 15# You should have received a copy of the GNU General Public License
 16# along with kiwi.  If not, see <http://www.gnu.org/licenses/>
 17#
 18import re
 19
 20# project
 21from .defaults import Defaults
 22
 23from .exceptions import (
 24    KiwiNotImplementedError
 25)
 26
 27
 28class FirmWare:
 29    """
 30    **Implements firmware specific methods**
 31
 32    According to the selected firmware some parameters in a disk
 33    image changes. This class provides methods to provide firmware
 34    dependant information
 35
 36    * :param object xml_state: instance of :class:`XMLState`
 37    """
 38    def __init__(self, xml_state):
 39        self.arch = Defaults.get_platform_name()
 40        self.zipl_target_type = \
 41            xml_state.get_build_type_bootloader_targettype()
 42        self.firmware = xml_state.build_type.get_firmware()
 43        self.efipart_mbytes = xml_state.build_type.get_efipartsize()
 44        self.efi_partition_table = xml_state.build_type.get_efiparttable()
 45        self.gpt_hybrid_mbr = xml_state.build_type.get_gpt_hybrid_mbr()
 46        self.efi_csm = True if xml_state.build_type.get_eficsm() is None \
 47            else xml_state.build_type.get_eficsm()
 48
 49        if not self.firmware:
 50            self.firmware = Defaults.get_default_firmware(self.arch)
 51
 52        if self.firmware and self.firmware != 'custom':
 53            firmware_types = Defaults.get_firmware_types()
 54            if self.firmware not in firmware_types[self.arch]:
 55                raise KiwiNotImplementedError(
 56                    'support for firmware %s for arch %s not implemented' %
 57                    (self.firmware, self.arch)
 58                )
 59
 60    def get_partition_table_type(self):
 61        """
 62        Provides partition table type according to architecture and firmware
 63
 64        :return: partition table name
 65
 66        :rtype: str
 67        """
 68        if 's390' in self.arch:
 69            if self.zipl_target_type and 'CDL' in self.zipl_target_type:
 70                return 'dasd'
 71            elif self.zipl_target_type and 'GPT' in self.zipl_target_type:
 72                return 'gpt'
 73            else:
 74                return 'msdos'
 75        elif 'ppc64' in self.arch:
 76            return 'gpt'
 77        elif self.efi_mode():
 78            default_efi_table = Defaults.get_default_efi_partition_table_type()
 79            return self.efi_partition_table or default_efi_table
 80        else:
 81            return 'msdos'
 82
 83    def legacy_bios_mode(self) -> bool:
 84        """
 85        Check if the legacy boot from BIOS systems should be activated
 86
 87        :return: True or False
 88
 89        :rtype: bool
 90        """
 91        if self.get_partition_table_type() == 'gpt':
 92            if (self.arch == 'x86_64' or re.match('i.86', self.arch)) and \
 93               (self.firmware == 'efi' or self.firmware == 'uefi') and \
 94               self.efi_csm:
 95                return True
 96            else:
 97                return False
 98        elif self.get_partition_table_type() == 'msdos':
 99            if self.arch == 'x86_64' or re.match('i.86', self.arch):
100                return True
101            else:
102                return False
103        else:
104            return False
105
106    def efi_mode(self) -> str:
107        """
108        Check if EFI mode is requested
109
110        :return: The requested EFI mode or None if no EFI mode requested
111
112        :rtype: str
113        """
114        if self.firmware in Defaults.get_efi_capable_firmware_names():
115            return self.firmware
116        return ''
117
118    def ec2_mode(self):
119        """
120        Check if EC2 mode is requested
121
122        :return: True or False
123
124        :rtype: bool
125        """
126        if self.firmware in Defaults.get_ec2_capable_firmware_names():
127            return self.firmware
128
129    def bios_mode(self):
130        """
131        Check if BIOS mode is requested
132
133        :return: True or False
134
135        :rtype: bool
136        """
137        if self.firmware == 'bios':
138            return True
139        else:
140            return False
141
142    def ofw_mode(self):
143        """
144        Check if OFW mode is requested
145
146        :return: True or False
147
148        :rtype: bool
149        """
150        if self.firmware == 'ofw':
151            return True
152        else:
153            return False
154
155    def opal_mode(self):
156        """
157        Check if Opal mode is requested
158
159        :return: True or False
160
161        :rtype: bool
162        """
163        if self.firmware == 'opal':
164            return True
165        else:
166            return False
167
168    def get_legacy_bios_partition_size(self):
169        """
170        Size of legacy bios_grub partition if legacy BIOS mode is
171        required. Returns 0 if no such partition is needed
172
173        :return: mbsize value
174
175        :rtype: int
176        """
177        if self.legacy_bios_mode() and self.efi_mode():
178            return Defaults.get_default_legacy_bios_mbytes()
179        else:
180            return 0
181
182    def get_efi_partition_size(self):
183        """
184        Size of EFI partition.
185        Returns 0 if no such partition is needed
186
187        :return: mbsize value
188
189        :rtype: int
190        """
191        if self.efi_mode():
192            if self.efipart_mbytes:
193                return self.efipart_mbytes
194            else:
195                return Defaults.get_default_efi_boot_mbytes()
196        else:
197            return 0
198
199    def get_prep_partition_size(self):
200        """
201        Size of Prep partition if OFW mode is requested.
202        Returns 0 if no such partition is needed
203
204        :return: mbsize value
205
206        :rtype: int
207        """
208        if self.ofw_mode():
209            return Defaults.get_default_prep_mbytes()
210        else:
211            return 0
class FirmWare:
 29class FirmWare:
 30    """
 31    **Implements firmware specific methods**
 32
 33    According to the selected firmware some parameters in a disk
 34    image changes. This class provides methods to provide firmware
 35    dependant information
 36
 37    * :param object xml_state: instance of :class:`XMLState`
 38    """
 39    def __init__(self, xml_state):
 40        self.arch = Defaults.get_platform_name()
 41        self.zipl_target_type = \
 42            xml_state.get_build_type_bootloader_targettype()
 43        self.firmware = xml_state.build_type.get_firmware()
 44        self.efipart_mbytes = xml_state.build_type.get_efipartsize()
 45        self.efi_partition_table = xml_state.build_type.get_efiparttable()
 46        self.gpt_hybrid_mbr = xml_state.build_type.get_gpt_hybrid_mbr()
 47        self.efi_csm = True if xml_state.build_type.get_eficsm() is None \
 48            else xml_state.build_type.get_eficsm()
 49
 50        if not self.firmware:
 51            self.firmware = Defaults.get_default_firmware(self.arch)
 52
 53        if self.firmware and self.firmware != 'custom':
 54            firmware_types = Defaults.get_firmware_types()
 55            if self.firmware not in firmware_types[self.arch]:
 56                raise KiwiNotImplementedError(
 57                    'support for firmware %s for arch %s not implemented' %
 58                    (self.firmware, self.arch)
 59                )
 60
 61    def get_partition_table_type(self):
 62        """
 63        Provides partition table type according to architecture and firmware
 64
 65        :return: partition table name
 66
 67        :rtype: str
 68        """
 69        if 's390' in self.arch:
 70            if self.zipl_target_type and 'CDL' in self.zipl_target_type:
 71                return 'dasd'
 72            elif self.zipl_target_type and 'GPT' in self.zipl_target_type:
 73                return 'gpt'
 74            else:
 75                return 'msdos'
 76        elif 'ppc64' in self.arch:
 77            return 'gpt'
 78        elif self.efi_mode():
 79            default_efi_table = Defaults.get_default_efi_partition_table_type()
 80            return self.efi_partition_table or default_efi_table
 81        else:
 82            return 'msdos'
 83
 84    def legacy_bios_mode(self) -> bool:
 85        """
 86        Check if the legacy boot from BIOS systems should be activated
 87
 88        :return: True or False
 89
 90        :rtype: bool
 91        """
 92        if self.get_partition_table_type() == 'gpt':
 93            if (self.arch == 'x86_64' or re.match('i.86', self.arch)) and \
 94               (self.firmware == 'efi' or self.firmware == 'uefi') and \
 95               self.efi_csm:
 96                return True
 97            else:
 98                return False
 99        elif self.get_partition_table_type() == 'msdos':
100            if self.arch == 'x86_64' or re.match('i.86', self.arch):
101                return True
102            else:
103                return False
104        else:
105            return False
106
107    def efi_mode(self) -> str:
108        """
109        Check if EFI mode is requested
110
111        :return: The requested EFI mode or None if no EFI mode requested
112
113        :rtype: str
114        """
115        if self.firmware in Defaults.get_efi_capable_firmware_names():
116            return self.firmware
117        return ''
118
119    def ec2_mode(self):
120        """
121        Check if EC2 mode is requested
122
123        :return: True or False
124
125        :rtype: bool
126        """
127        if self.firmware in Defaults.get_ec2_capable_firmware_names():
128            return self.firmware
129
130    def bios_mode(self):
131        """
132        Check if BIOS mode is requested
133
134        :return: True or False
135
136        :rtype: bool
137        """
138        if self.firmware == 'bios':
139            return True
140        else:
141            return False
142
143    def ofw_mode(self):
144        """
145        Check if OFW mode is requested
146
147        :return: True or False
148
149        :rtype: bool
150        """
151        if self.firmware == 'ofw':
152            return True
153        else:
154            return False
155
156    def opal_mode(self):
157        """
158        Check if Opal mode is requested
159
160        :return: True or False
161
162        :rtype: bool
163        """
164        if self.firmware == 'opal':
165            return True
166        else:
167            return False
168
169    def get_legacy_bios_partition_size(self):
170        """
171        Size of legacy bios_grub partition if legacy BIOS mode is
172        required. Returns 0 if no such partition is needed
173
174        :return: mbsize value
175
176        :rtype: int
177        """
178        if self.legacy_bios_mode() and self.efi_mode():
179            return Defaults.get_default_legacy_bios_mbytes()
180        else:
181            return 0
182
183    def get_efi_partition_size(self):
184        """
185        Size of EFI partition.
186        Returns 0 if no such partition is needed
187
188        :return: mbsize value
189
190        :rtype: int
191        """
192        if self.efi_mode():
193            if self.efipart_mbytes:
194                return self.efipart_mbytes
195            else:
196                return Defaults.get_default_efi_boot_mbytes()
197        else:
198            return 0
199
200    def get_prep_partition_size(self):
201        """
202        Size of Prep partition if OFW mode is requested.
203        Returns 0 if no such partition is needed
204
205        :return: mbsize value
206
207        :rtype: int
208        """
209        if self.ofw_mode():
210            return Defaults.get_default_prep_mbytes()
211        else:
212            return 0

Implements firmware specific methods

According to the selected firmware some parameters in a disk image changes. This class provides methods to provide firmware dependant information

  • :param object xml_state: instance of XMLState
FirmWare(xml_state)
39    def __init__(self, xml_state):
40        self.arch = Defaults.get_platform_name()
41        self.zipl_target_type = \
42            xml_state.get_build_type_bootloader_targettype()
43        self.firmware = xml_state.build_type.get_firmware()
44        self.efipart_mbytes = xml_state.build_type.get_efipartsize()
45        self.efi_partition_table = xml_state.build_type.get_efiparttable()
46        self.gpt_hybrid_mbr = xml_state.build_type.get_gpt_hybrid_mbr()
47        self.efi_csm = True if xml_state.build_type.get_eficsm() is None \
48            else xml_state.build_type.get_eficsm()
49
50        if not self.firmware:
51            self.firmware = Defaults.get_default_firmware(self.arch)
52
53        if self.firmware and self.firmware != 'custom':
54            firmware_types = Defaults.get_firmware_types()
55            if self.firmware not in firmware_types[self.arch]:
56                raise KiwiNotImplementedError(
57                    'support for firmware %s for arch %s not implemented' %
58                    (self.firmware, self.arch)
59                )
arch
zipl_target_type
firmware
efipart_mbytes
efi_partition_table
gpt_hybrid_mbr
efi_csm
def get_partition_table_type(self):
61    def get_partition_table_type(self):
62        """
63        Provides partition table type according to architecture and firmware
64
65        :return: partition table name
66
67        :rtype: str
68        """
69        if 's390' in self.arch:
70            if self.zipl_target_type and 'CDL' in self.zipl_target_type:
71                return 'dasd'
72            elif self.zipl_target_type and 'GPT' in self.zipl_target_type:
73                return 'gpt'
74            else:
75                return 'msdos'
76        elif 'ppc64' in self.arch:
77            return 'gpt'
78        elif self.efi_mode():
79            default_efi_table = Defaults.get_default_efi_partition_table_type()
80            return self.efi_partition_table or default_efi_table
81        else:
82            return 'msdos'

Provides partition table type according to architecture and firmware

Returns

partition table name

def legacy_bios_mode(self) -> bool:
 84    def legacy_bios_mode(self) -> bool:
 85        """
 86        Check if the legacy boot from BIOS systems should be activated
 87
 88        :return: True or False
 89
 90        :rtype: bool
 91        """
 92        if self.get_partition_table_type() == 'gpt':
 93            if (self.arch == 'x86_64' or re.match('i.86', self.arch)) and \
 94               (self.firmware == 'efi' or self.firmware == 'uefi') and \
 95               self.efi_csm:
 96                return True
 97            else:
 98                return False
 99        elif self.get_partition_table_type() == 'msdos':
100            if self.arch == 'x86_64' or re.match('i.86', self.arch):
101                return True
102            else:
103                return False
104        else:
105            return False

Check if the legacy boot from BIOS systems should be activated

Returns

True or False

def efi_mode(self) -> str:
107    def efi_mode(self) -> str:
108        """
109        Check if EFI mode is requested
110
111        :return: The requested EFI mode or None if no EFI mode requested
112
113        :rtype: str
114        """
115        if self.firmware in Defaults.get_efi_capable_firmware_names():
116            return self.firmware
117        return ''

Check if EFI mode is requested

Returns

The requested EFI mode or None if no EFI mode requested

def ec2_mode(self):
119    def ec2_mode(self):
120        """
121        Check if EC2 mode is requested
122
123        :return: True or False
124
125        :rtype: bool
126        """
127        if self.firmware in Defaults.get_ec2_capable_firmware_names():
128            return self.firmware

Check if EC2 mode is requested

Returns

True or False

def bios_mode(self):
130    def bios_mode(self):
131        """
132        Check if BIOS mode is requested
133
134        :return: True or False
135
136        :rtype: bool
137        """
138        if self.firmware == 'bios':
139            return True
140        else:
141            return False

Check if BIOS mode is requested

Returns

True or False

def ofw_mode(self):
143    def ofw_mode(self):
144        """
145        Check if OFW mode is requested
146
147        :return: True or False
148
149        :rtype: bool
150        """
151        if self.firmware == 'ofw':
152            return True
153        else:
154            return False

Check if OFW mode is requested

Returns

True or False

def opal_mode(self):
156    def opal_mode(self):
157        """
158        Check if Opal mode is requested
159
160        :return: True or False
161
162        :rtype: bool
163        """
164        if self.firmware == 'opal':
165            return True
166        else:
167            return False

Check if Opal mode is requested

Returns

True or False

def get_legacy_bios_partition_size(self):
169    def get_legacy_bios_partition_size(self):
170        """
171        Size of legacy bios_grub partition if legacy BIOS mode is
172        required. Returns 0 if no such partition is needed
173
174        :return: mbsize value
175
176        :rtype: int
177        """
178        if self.legacy_bios_mode() and self.efi_mode():
179            return Defaults.get_default_legacy_bios_mbytes()
180        else:
181            return 0

Size of legacy bios_grub partition if legacy BIOS mode is required. Returns 0 if no such partition is needed

Returns

mbsize value

def get_efi_partition_size(self):
183    def get_efi_partition_size(self):
184        """
185        Size of EFI partition.
186        Returns 0 if no such partition is needed
187
188        :return: mbsize value
189
190        :rtype: int
191        """
192        if self.efi_mode():
193            if self.efipart_mbytes:
194                return self.efipart_mbytes
195            else:
196                return Defaults.get_default_efi_boot_mbytes()
197        else:
198            return 0

Size of EFI partition. Returns 0 if no such partition is needed

Returns

mbsize value

def get_prep_partition_size(self):
200    def get_prep_partition_size(self):
201        """
202        Size of Prep partition if OFW mode is requested.
203        Returns 0 if no such partition is needed
204
205        :return: mbsize value
206
207        :rtype: int
208        """
209        if self.ofw_mode():
210            return Defaults.get_default_prep_mbytes()
211        else:
212            return 0

Size of Prep partition if OFW mode is requested. Returns 0 if no such partition is needed

Returns

mbsize value