diff options
| author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:38:32 +0100 |
|---|---|---|
| committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:50:20 +0100 |
| commit | e2e6f6fe07049f33cb6348780fa975162752e421 (patch) | |
| tree | b1813295411235d1297a0ed642b1346b24fdfb12 /scripts/lib/mic/kickstart/custom_commands | |
| download | poky-e2e6f6fe07049f33cb6348780fa975162752e421.tar.gz | |
initial commit of Enea Linux 3.1
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'scripts/lib/mic/kickstart/custom_commands')
7 files changed, 778 insertions, 0 deletions
diff --git a/scripts/lib/mic/kickstart/custom_commands/__init__.py b/scripts/lib/mic/kickstart/custom_commands/__init__.py new file mode 100644 index 0000000000..6aed0ff6fa --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/__init__.py | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | from desktop import Mic_Desktop | ||
| 2 | from micrepo import Mic_Repo, Mic_RepoData | ||
| 3 | from micpartition import Mic_Partition | ||
| 4 | from micpartition import Mic_PartData | ||
| 5 | from installerfw import Mic_installerfw | ||
| 6 | from partition import Wic_Partition | ||
| 7 | |||
| 8 | __all__ = ( | ||
| 9 | "Mic_Desktop", | ||
| 10 | "Mic_Repo", | ||
| 11 | "Mic_RepoData", | ||
| 12 | "Mic_Partition", | ||
| 13 | "Mic_PartData", | ||
| 14 | "Mic_installerfw", | ||
| 15 | "Wic_Partition", | ||
| 16 | "Wic_PartData", | ||
| 17 | ) | ||
diff --git a/scripts/lib/mic/kickstart/custom_commands/desktop.py b/scripts/lib/mic/kickstart/custom_commands/desktop.py new file mode 100644 index 0000000000..c8bd647ae3 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/desktop.py | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | #!/usr/bin/python -tt | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008, 2009, 2010 Intel, Inc. | ||
| 4 | # | ||
| 5 | # Yi Yang <yi.y.yang@intel.com> | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify it | ||
| 8 | # under the terms of the GNU General Public License as published by the Free | ||
| 9 | # Software Foundation; version 2 of the License | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, but | ||
| 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 13 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | # for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., 59 | ||
| 18 | # Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | |||
| 20 | from pykickstart.base import * | ||
| 21 | from pykickstart.errors import * | ||
| 22 | from pykickstart.options import * | ||
| 23 | |||
| 24 | class Mic_Desktop(KickstartCommand): | ||
| 25 | def __init__(self, writePriority=0, | ||
| 26 | defaultdesktop=None, | ||
| 27 | defaultdm=None, | ||
| 28 | autologinuser=None, | ||
| 29 | session=None): | ||
| 30 | |||
| 31 | KickstartCommand.__init__(self, writePriority) | ||
| 32 | |||
| 33 | self.__new_version = False | ||
| 34 | self.op = self._getParser() | ||
| 35 | |||
| 36 | self.defaultdesktop = defaultdesktop | ||
| 37 | self.autologinuser = autologinuser | ||
| 38 | self.defaultdm = defaultdm | ||
| 39 | self.session = session | ||
| 40 | |||
| 41 | def __str__(self): | ||
| 42 | retval = "" | ||
| 43 | |||
| 44 | if self.defaultdesktop != None: | ||
| 45 | retval += " --defaultdesktop=%s" % self.defaultdesktop | ||
| 46 | if self.session != None: | ||
| 47 | retval += " --session=\"%s\"" % self.session | ||
| 48 | if self.autologinuser != None: | ||
| 49 | retval += " --autologinuser=%s" % self.autologinuser | ||
| 50 | if self.defaultdm != None: | ||
| 51 | retval += " --defaultdm=%s" % self.defaultdm | ||
| 52 | |||
| 53 | if retval != "": | ||
| 54 | retval = "# Default Desktop Settings\ndesktop %s\n" % retval | ||
| 55 | |||
| 56 | return retval | ||
| 57 | |||
| 58 | def _getParser(self): | ||
| 59 | try: | ||
| 60 | op = KSOptionParser(lineno=self.lineno) | ||
| 61 | except TypeError: | ||
| 62 | # the latest version has not lineno argument | ||
| 63 | op = KSOptionParser() | ||
| 64 | self.__new_version = True | ||
| 65 | |||
| 66 | op.add_option("--defaultdesktop", dest="defaultdesktop", | ||
| 67 | action="store", | ||
| 68 | type="string", | ||
| 69 | nargs=1) | ||
| 70 | op.add_option("--autologinuser", dest="autologinuser", | ||
| 71 | action="store", | ||
| 72 | type="string", | ||
| 73 | nargs=1) | ||
| 74 | op.add_option("--defaultdm", dest="defaultdm", | ||
| 75 | action="store", | ||
| 76 | type="string", | ||
| 77 | nargs=1) | ||
| 78 | op.add_option("--session", dest="session", | ||
| 79 | action="store", | ||
| 80 | type="string", | ||
| 81 | nargs=1) | ||
| 82 | return op | ||
| 83 | |||
| 84 | def parse(self, args): | ||
| 85 | if self.__new_version: | ||
| 86 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
| 87 | else: | ||
| 88 | (opts, extra) = self.op.parse_args(args=args) | ||
| 89 | |||
| 90 | if extra: | ||
| 91 | m = _("Unexpected arguments to %(command)s command: %(options)s") \ | ||
| 92 | % {"command": "desktop", "options": extra} | ||
| 93 | raise KickstartValueError, formatErrorMsg(self.lineno, msg=m) | ||
| 94 | |||
| 95 | self._setToSelf(self.op, opts) | ||
diff --git a/scripts/lib/mic/kickstart/custom_commands/installerfw.py b/scripts/lib/mic/kickstart/custom_commands/installerfw.py new file mode 100644 index 0000000000..2466f1dc07 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/installerfw.py | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | #!/usr/bin/python -tt | ||
| 2 | # | ||
| 3 | # Copyright (c) 2013 Intel, Inc. | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify it | ||
| 6 | # under the terms of the GNU General Public License as published by the Free | ||
| 7 | # Software Foundation; version 2 of the License | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, but | ||
| 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 11 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 12 | # for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with this program; if not, write to the Free Software Foundation, Inc., 59 | ||
| 16 | # Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | |||
| 18 | from pykickstart.base import * | ||
| 19 | from pykickstart.options import * | ||
| 20 | |||
| 21 | class Mic_installerfw(KickstartCommand): | ||
| 22 | """ This class implements the "installerfw" KS option. The argument | ||
| 23 | of the option is a comman-separated list of MIC features which have to be | ||
| 24 | disabled and instead, will be done in the installer. For example, | ||
| 25 | "installerfw=extlinux" disables all the MIC code which installs extlinux to | ||
| 26 | the target images, and instead, the extlinux or whatever boot-loader will | ||
| 27 | be installed by the installer instead. | ||
| 28 | |||
| 29 | The installer is a tool which is external to MIC, it comes from the | ||
| 30 | installation repositories and can be executed by MIC in order to perform | ||
| 31 | various configuration actions. The main point here is to make sure MIC has | ||
| 32 | no hard-wired knoledge about the target OS configuration. """ | ||
| 33 | |||
| 34 | removedKeywords = KickstartCommand.removedKeywords | ||
| 35 | removedAttrs = KickstartCommand.removedAttrs | ||
| 36 | |||
| 37 | def __init__(self, *args, **kwargs): | ||
| 38 | KickstartCommand.__init__(self, *args, **kwargs) | ||
| 39 | self.op = self._getParser() | ||
| 40 | self.features = kwargs.get("installerfw", None) | ||
| 41 | |||
| 42 | def __str__(self): | ||
| 43 | retval = KickstartCommand.__str__(self) | ||
| 44 | |||
| 45 | if self.features: | ||
| 46 | retval += "# Enable installer framework features\ninstallerfw\n" | ||
| 47 | |||
| 48 | return retval | ||
| 49 | |||
| 50 | def _getParser(self): | ||
| 51 | op = KSOptionParser() | ||
| 52 | return op | ||
| 53 | |||
| 54 | def parse(self, args): | ||
| 55 | (_, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
| 56 | |||
| 57 | if len(extra) != 1: | ||
| 58 | msg = "Kickstart command \"installerfw\" requires one " \ | ||
| 59 | "argumet - a list of legacy features to disable" | ||
| 60 | raise KickstartValueError, formatErrorMsg(self.lineno, msg = msg) | ||
| 61 | |||
| 62 | self.features = extra[0].split(",") | ||
| 63 | return self | ||
diff --git a/scripts/lib/mic/kickstart/custom_commands/micboot.py b/scripts/lib/mic/kickstart/custom_commands/micboot.py new file mode 100644 index 0000000000..66d1678aa7 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/micboot.py | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | #!/usr/bin/python -tt | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008, 2009, 2010 Intel, Inc. | ||
| 4 | # | ||
| 5 | # Anas Nashif | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify it | ||
| 8 | # under the terms of the GNU General Public License as published by the Free | ||
| 9 | # Software Foundation; version 2 of the License | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, but | ||
| 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 13 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | # for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., 59 | ||
| 18 | # Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | |||
| 20 | from pykickstart.base import * | ||
| 21 | from pykickstart.errors import * | ||
| 22 | from pykickstart.options import * | ||
| 23 | from pykickstart.commands.bootloader import * | ||
| 24 | |||
| 25 | class Mic_Bootloader(F8_Bootloader): | ||
| 26 | def __init__(self, writePriority=10, appendLine="", driveorder=None, | ||
| 27 | forceLBA=False, location="", md5pass="", password="", | ||
| 28 | upgrade=False, menus=""): | ||
| 29 | F8_Bootloader.__init__(self, writePriority, appendLine, driveorder, | ||
| 30 | forceLBA, location, md5pass, password, upgrade) | ||
| 31 | |||
| 32 | self.menus = "" | ||
| 33 | self.ptable = "msdos" | ||
| 34 | |||
| 35 | def _getArgsAsStr(self): | ||
| 36 | ret = F8_Bootloader._getArgsAsStr(self) | ||
| 37 | |||
| 38 | if self.menus == "": | ||
| 39 | ret += " --menus=%s" %(self.menus,) | ||
| 40 | if self.ptable: | ||
| 41 | ret += " --ptable=\"%s\"" %(self.ptable,) | ||
| 42 | return ret | ||
| 43 | |||
| 44 | def _getParser(self): | ||
| 45 | op = F8_Bootloader._getParser(self) | ||
| 46 | op.add_option("--menus", dest="menus") | ||
| 47 | op.add_option("--ptable", dest="ptable", type="string") | ||
| 48 | return op | ||
| 49 | |||
diff --git a/scripts/lib/mic/kickstart/custom_commands/micpartition.py b/scripts/lib/mic/kickstart/custom_commands/micpartition.py new file mode 100644 index 0000000000..59a87fb486 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/micpartition.py | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #!/usr/bin/python -tt | ||
| 2 | # | ||
| 3 | # Marko Saukko <marko.saukko@cybercom.com> | ||
| 4 | # | ||
| 5 | # Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
| 6 | # | ||
| 7 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
| 8 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
| 9 | # General Public License v.2. This program is distributed in the hope that it | ||
| 10 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
| 11 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 12 | # See the GNU General Public License for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along with | ||
| 15 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
| 16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 17 | |||
| 18 | from pykickstart.commands.partition import * | ||
| 19 | |||
| 20 | class Mic_PartData(FC4_PartData): | ||
| 21 | removedKeywords = FC4_PartData.removedKeywords | ||
| 22 | removedAttrs = FC4_PartData.removedAttrs | ||
| 23 | |||
| 24 | def __init__(self, *args, **kwargs): | ||
| 25 | FC4_PartData.__init__(self, *args, **kwargs) | ||
| 26 | self.deleteRemovedAttrs() | ||
| 27 | self.align = kwargs.get("align", None) | ||
| 28 | self.extopts = kwargs.get("extopts", None) | ||
| 29 | self.part_type = kwargs.get("part_type", None) | ||
| 30 | |||
| 31 | def _getArgsAsStr(self): | ||
| 32 | retval = FC4_PartData._getArgsAsStr(self) | ||
| 33 | |||
| 34 | if self.align: | ||
| 35 | retval += " --align" | ||
| 36 | if self.extopts: | ||
| 37 | retval += " --extoptions=%s" % self.extopts | ||
| 38 | if self.part_type: | ||
| 39 | retval += " --part-type=%s" % self.part_type | ||
| 40 | |||
| 41 | return retval | ||
| 42 | |||
| 43 | class Mic_Partition(FC4_Partition): | ||
| 44 | removedKeywords = FC4_Partition.removedKeywords | ||
| 45 | removedAttrs = FC4_Partition.removedAttrs | ||
| 46 | |||
| 47 | def _getParser(self): | ||
| 48 | op = FC4_Partition._getParser(self) | ||
| 49 | # The alignment value is given in kBytes. e.g., value 8 means that | ||
| 50 | # the partition is aligned to start from 8096 byte boundary. | ||
| 51 | op.add_option("--align", type="int", action="store", dest="align", | ||
| 52 | default=None) | ||
| 53 | op.add_option("--extoptions", type="string", action="store", dest="extopts", | ||
| 54 | default=None) | ||
| 55 | op.add_option("--part-type", type="string", action="store", dest="part_type", | ||
| 56 | default=None) | ||
| 57 | return op | ||
diff --git a/scripts/lib/mic/kickstart/custom_commands/micrepo.py b/scripts/lib/mic/kickstart/custom_commands/micrepo.py new file mode 100644 index 0000000000..b31576e400 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/micrepo.py | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | #!/usr/bin/python -tt | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008, 2009, 2010 Intel, Inc. | ||
| 4 | # | ||
| 5 | # Yi Yang <yi.y.yang@intel.com> | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify it | ||
| 8 | # under the terms of the GNU General Public License as published by the Free | ||
| 9 | # Software Foundation; version 2 of the License | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, but | ||
| 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 13 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | # for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., 59 | ||
| 18 | # Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | |||
| 20 | from pykickstart.base import * | ||
| 21 | from pykickstart.errors import * | ||
| 22 | from pykickstart.options import * | ||
| 23 | from pykickstart.commands.repo import * | ||
| 24 | |||
| 25 | class Mic_RepoData(F8_RepoData): | ||
| 26 | |||
| 27 | def __init__(self, baseurl="", mirrorlist=None, name="", priority=None, | ||
| 28 | includepkgs=(), excludepkgs=(), save=False, proxy=None, | ||
| 29 | proxy_username=None, proxy_password=None, debuginfo=False, | ||
| 30 | source=False, gpgkey=None, disable=False, ssl_verify="yes", | ||
| 31 | nocache=False): | ||
| 32 | kw = {} | ||
| 33 | # F8_RepoData keywords | ||
| 34 | if includepkgs: | ||
| 35 | kw['includepkgs'] = includepkgs | ||
| 36 | if excludepkgs: | ||
| 37 | kw['excludepkgs'] = excludepkgs | ||
| 38 | |||
| 39 | #FC6_RepoData keywords | ||
| 40 | if baseurl: | ||
| 41 | kw['baseurl'] = baseurl | ||
| 42 | if mirrorlist: | ||
| 43 | kw['mirrorlist'] = mirrorlist | ||
| 44 | if name: | ||
| 45 | kw['name'] = name | ||
| 46 | |||
| 47 | F8_RepoData.__init__(self, **kw) | ||
| 48 | self.save = save | ||
| 49 | self.proxy = proxy | ||
| 50 | self.proxy_username = proxy_username | ||
| 51 | self.proxy_password = proxy_password | ||
| 52 | self.debuginfo = debuginfo | ||
| 53 | self.disable = disable | ||
| 54 | self.source = source | ||
| 55 | self.gpgkey = gpgkey | ||
| 56 | self.ssl_verify = ssl_verify.lower() | ||
| 57 | self.priority = priority | ||
| 58 | self.nocache = nocache | ||
| 59 | |||
| 60 | def _getArgsAsStr(self): | ||
| 61 | retval = F8_RepoData._getArgsAsStr(self) | ||
| 62 | |||
| 63 | if self.save: | ||
| 64 | retval += " --save" | ||
| 65 | if self.proxy: | ||
| 66 | retval += " --proxy=%s" % self.proxy | ||
| 67 | if self.proxy_username: | ||
| 68 | retval += " --proxyuser=%s" % self.proxy_username | ||
| 69 | if self.proxy_password: | ||
| 70 | retval += " --proxypasswd=%s" % self.proxy_password | ||
| 71 | if self.debuginfo: | ||
| 72 | retval += " --debuginfo" | ||
| 73 | if self.source: | ||
| 74 | retval += " --source" | ||
| 75 | if self.gpgkey: | ||
| 76 | retval += " --gpgkey=%s" % self.gpgkey | ||
| 77 | if self.disable: | ||
| 78 | retval += " --disable" | ||
| 79 | if self.ssl_verify: | ||
| 80 | retval += " --ssl_verify=%s" % self.ssl_verify | ||
| 81 | if self.priority: | ||
| 82 | retval += " --priority=%s" % self.priority | ||
| 83 | if self.nocache: | ||
| 84 | retval += " --nocache" | ||
| 85 | |||
| 86 | return retval | ||
| 87 | |||
| 88 | class Mic_Repo(F8_Repo): | ||
| 89 | def __init__(self, writePriority=0, repoList=None): | ||
| 90 | F8_Repo.__init__(self, writePriority, repoList) | ||
| 91 | |||
| 92 | def __str__(self): | ||
| 93 | retval = "" | ||
| 94 | for repo in self.repoList: | ||
| 95 | retval += repo.__str__() | ||
| 96 | |||
| 97 | return retval | ||
| 98 | |||
| 99 | def _getParser(self): | ||
| 100 | def list_cb (option, opt_str, value, parser): | ||
| 101 | for d in value.split(','): | ||
| 102 | parser.values.ensure_value(option.dest, []).append(d) | ||
| 103 | |||
| 104 | op = F8_Repo._getParser(self) | ||
| 105 | op.add_option("--save", action="store_true", dest="save", | ||
| 106 | default=False) | ||
| 107 | op.add_option("--proxy", type="string", action="store", dest="proxy", | ||
| 108 | default=None, nargs=1) | ||
| 109 | op.add_option("--proxyuser", type="string", action="store", | ||
| 110 | dest="proxy_username", default=None, nargs=1) | ||
| 111 | op.add_option("--proxypasswd", type="string", action="store", | ||
| 112 | dest="proxy_password", default=None, nargs=1) | ||
| 113 | op.add_option("--debuginfo", action="store_true", dest="debuginfo", | ||
| 114 | default=False) | ||
| 115 | op.add_option("--source", action="store_true", dest="source", | ||
| 116 | default=False) | ||
| 117 | op.add_option("--disable", action="store_true", dest="disable", | ||
| 118 | default=False) | ||
| 119 | op.add_option("--gpgkey", type="string", action="store", dest="gpgkey", | ||
| 120 | default=None, nargs=1) | ||
| 121 | op.add_option("--ssl_verify", type="string", action="store", | ||
| 122 | dest="ssl_verify", default="yes") | ||
| 123 | op.add_option("--priority", type="int", action="store", dest="priority", | ||
| 124 | default=None) | ||
| 125 | op.add_option("--nocache", action="store_true", dest="nocache", | ||
| 126 | default=False) | ||
| 127 | return op | ||
diff --git a/scripts/lib/mic/kickstart/custom_commands/partition.py b/scripts/lib/mic/kickstart/custom_commands/partition.py new file mode 100644 index 0000000000..302cace234 --- /dev/null +++ b/scripts/lib/mic/kickstart/custom_commands/partition.py | |||
| @@ -0,0 +1,370 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (c) 2013, Intel Corporation. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # DESCRIPTION | ||
| 21 | # This module provides the OpenEmbedded partition object definitions. | ||
| 22 | # | ||
| 23 | # AUTHORS | ||
| 24 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 25 | # | ||
| 26 | |||
| 27 | import shutil | ||
| 28 | |||
| 29 | from pykickstart.commands.partition import * | ||
| 30 | from mic.utils.oe.misc import * | ||
| 31 | |||
| 32 | from mic.kickstart.custom_commands import * | ||
| 33 | |||
| 34 | BOOTDD_EXTRA_SPACE = 16384 | ||
| 35 | |||
| 36 | class Wic_PartData(Mic_PartData): | ||
| 37 | removedKeywords = Mic_PartData.removedKeywords | ||
| 38 | removedAttrs = Mic_PartData.removedAttrs | ||
| 39 | |||
| 40 | def __init__(self, *args, **kwargs): | ||
| 41 | Mic_PartData.__init__(self, *args, **kwargs) | ||
| 42 | self.deleteRemovedAttrs() | ||
| 43 | self.source = kwargs.get("source", None) | ||
| 44 | self.source_file = "" | ||
| 45 | self.size = 0 | ||
| 46 | |||
| 47 | def _getArgsAsStr(self): | ||
| 48 | retval = Mic_PartData._getArgsAsStr(self) | ||
| 49 | |||
| 50 | if self.source: | ||
| 51 | retval += " --source=%s" % self.source | ||
| 52 | |||
| 53 | return retval | ||
| 54 | |||
| 55 | def prepare(self, cr_workdir, oe_builddir, boot_type, rootfs_dir, | ||
| 56 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 57 | """ | ||
| 58 | Prepare content for individual partitions, depending on | ||
| 59 | partition command parameters. | ||
| 60 | """ | ||
| 61 | if not self.source: | ||
| 62 | if self.fstype and self.fstype == "swap": | ||
| 63 | self.prepare_swap_partition(cr_workdir, oe_builddir, | ||
| 64 | native_sysroot) | ||
| 65 | elif self.fstype: | ||
| 66 | self.prepare_empty_partition(cr_workdir, oe_builddir, | ||
| 67 | native_sysroot) | ||
| 68 | return | ||
| 69 | |||
| 70 | if self.source == "bootimg" and boot_type == "pcbios": | ||
| 71 | self.prepare_bootimg_pcbios(cr_workdir, oe_builddir, bootimg_dir, | ||
| 72 | kernel_dir, native_sysroot) | ||
| 73 | elif self.source == "bootimg" and boot_type == "efi": | ||
| 74 | self.prepare_bootimg_efi(cr_workdir, oe_builddir, bootimg_dir, | ||
| 75 | kernel_dir, native_sysroot) | ||
| 76 | elif self.source.startswith("rootfs"): | ||
| 77 | self.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, | ||
| 78 | native_sysroot) | ||
| 79 | |||
| 80 | def prepare_bootimg_pcbios(self, cr_workdir, oe_builddir, bootimg_dir, | ||
| 81 | kernel_dir, native_sysroot): | ||
| 82 | """ | ||
| 83 | Prepare content for a legacy bios boot partition. | ||
| 84 | """ | ||
| 85 | staging_kernel_dir = kernel_dir | ||
| 86 | staging_data_dir = bootimg_dir | ||
| 87 | |||
| 88 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 89 | |||
| 90 | install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \ | ||
| 91 | % (staging_kernel_dir, hdddir) | ||
| 92 | tmp = exec_cmd(install_cmd) | ||
| 93 | |||
| 94 | install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \ | ||
| 95 | % (staging_data_dir, hdddir) | ||
| 96 | tmp = exec_cmd(install_cmd) | ||
| 97 | |||
| 98 | du_cmd = "du -bks %s" % hdddir | ||
| 99 | rc, out = exec_cmd(du_cmd) | ||
| 100 | blocks = int(out.split()[0]) | ||
| 101 | |||
| 102 | blocks += BOOTDD_EXTRA_SPACE | ||
| 103 | |||
| 104 | # Ensure total sectors is an integral number of sectors per | ||
| 105 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 106 | # generate images with 32 sectors per track. This calculation is | ||
| 107 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 108 | blocks += (16 - (blocks % 16)) | ||
| 109 | |||
| 110 | # dosfs image, created by mkdosfs | ||
| 111 | bootimg = "%s/boot.img" % cr_workdir | ||
| 112 | |||
| 113 | dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks) | ||
| 114 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 115 | |||
| 116 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 117 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 118 | |||
| 119 | syslinux_cmd = "syslinux %s" % bootimg | ||
| 120 | exec_native_cmd(syslinux_cmd, native_sysroot) | ||
| 121 | |||
| 122 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 123 | exec_cmd(chmod_cmd) | ||
| 124 | |||
| 125 | du_cmd = "du -Lbms %s" % bootimg | ||
| 126 | rc, out = exec_cmd(du_cmd) | ||
| 127 | bootimg_size = out.split()[0] | ||
| 128 | |||
| 129 | self.size = bootimg_size | ||
| 130 | self.source_file = bootimg | ||
| 131 | |||
| 132 | def prepare_bootimg_efi(self, cr_workdir, oe_builddir, bootimg_dir, | ||
| 133 | kernel_dir, native_sysroot): | ||
| 134 | """ | ||
| 135 | Prepare content for an EFI (grub) boot partition. | ||
| 136 | """ | ||
| 137 | staging_kernel_dir = kernel_dir | ||
| 138 | staging_data_dir = bootimg_dir | ||
| 139 | |||
| 140 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 141 | |||
| 142 | install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" % \ | ||
| 143 | (staging_kernel_dir, hdddir) | ||
| 144 | tmp = exec_cmd(install_cmd) | ||
| 145 | |||
| 146 | shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, | ||
| 147 | "%s/grub.cfg" % cr_workdir) | ||
| 148 | |||
| 149 | cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (staging_data_dir, hdddir) | ||
| 150 | exec_cmd(cp_cmd, True) | ||
| 151 | |||
| 152 | shutil.move("%s/grub.cfg" % cr_workdir, | ||
| 153 | "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) | ||
| 154 | |||
| 155 | du_cmd = "du -bks %s" % hdddir | ||
| 156 | rc, out = exec_cmd(du_cmd) | ||
| 157 | blocks = int(out.split()[0]) | ||
| 158 | |||
| 159 | blocks += BOOTDD_EXTRA_SPACE | ||
| 160 | |||
| 161 | # Ensure total sectors is an integral number of sectors per | ||
| 162 | # track or mcopy will complain. Sectors are 512 bytes, and we | ||
| 163 | # generate images with 32 sectors per track. This calculation is | ||
| 164 | # done in blocks, thus the mod by 16 instead of 32. | ||
| 165 | blocks += (16 - (blocks % 16)) | ||
| 166 | |||
| 167 | # dosfs image, created by mkdosfs | ||
| 168 | bootimg = "%s/boot.img" % cr_workdir | ||
| 169 | |||
| 170 | dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) | ||
| 171 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 172 | |||
| 173 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 174 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 175 | |||
| 176 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 177 | exec_cmd(chmod_cmd) | ||
| 178 | |||
| 179 | du_cmd = "du -Lbms %s" % bootimg | ||
| 180 | rc, out = exec_cmd(du_cmd) | ||
| 181 | bootimg_size = out.split()[0] | ||
| 182 | |||
| 183 | self.size = bootimg_size | ||
| 184 | self.source_file = bootimg | ||
| 185 | |||
| 186 | def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir, | ||
| 187 | rootfs_dir): | ||
| 188 | """ | ||
| 189 | Handle an already-created partition e.g. xxx.ext3 | ||
| 190 | """ | ||
| 191 | rootfs = oe_builddir | ||
| 192 | du_cmd = "du -Lbms %s" % rootfs | ||
| 193 | rc, out = exec_cmd(du_cmd) | ||
| 194 | rootfs_size = out.split()[0] | ||
| 195 | |||
| 196 | self.size = rootfs_size | ||
| 197 | self.source_file = rootfs | ||
| 198 | |||
| 199 | def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir, | ||
| 200 | native_sysroot): | ||
| 201 | """ | ||
| 202 | Prepare content for a rootfs partition i.e. create a partition | ||
| 203 | and fill it from a /rootfs dir. | ||
| 204 | |||
| 205 | Currently handles ext2/3/4 and btrfs. | ||
| 206 | """ | ||
| 207 | if self.fstype.startswith("ext"): | ||
| 208 | return self.prepare_rootfs_ext(cr_workdir, oe_builddir, | ||
| 209 | rootfs_dir, native_sysroot) | ||
| 210 | elif self.fstype.startswith("btrfs"): | ||
| 211 | return self.prepare_rootfs_btrfs(cr_workdir, oe_builddir, | ||
| 212 | rootfs_dir, native_sysroot) | ||
| 213 | |||
| 214 | def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir, | ||
| 215 | native_sysroot): | ||
| 216 | """ | ||
| 217 | Prepare content for an ext2/3/4 rootfs partition. | ||
| 218 | """ | ||
| 219 | populate_script = "%s/usr/bin/populate-extfs.sh" % native_sysroot | ||
| 220 | image_extra_space = 10240 | ||
| 221 | |||
| 222 | image_rootfs = rootfs_dir | ||
| 223 | rootfs = "%s/rootfs.%s" % (cr_workdir, self.fstype) | ||
| 224 | |||
| 225 | du_cmd = "du -ks %s" % image_rootfs | ||
| 226 | rc, out = exec_cmd(du_cmd) | ||
| 227 | actual_rootfs_size = out.split()[0] | ||
| 228 | |||
| 229 | rootfs_size = int(actual_rootfs_size) + image_extra_space | ||
| 230 | |||
| 231 | dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ | ||
| 232 | (rootfs, rootfs_size) | ||
| 233 | rc, out = exec_cmd(dd_cmd) | ||
| 234 | |||
| 235 | extra_imagecmd = "-i 8192" | ||
| 236 | |||
| 237 | mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, rootfs) | ||
| 238 | rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) | ||
| 239 | |||
| 240 | populate_cmd = populate_script + " " + image_rootfs + " " + rootfs | ||
| 241 | rc, out = exec_native_cmd(populate_cmd, native_sysroot) | ||
| 242 | |||
| 243 | # get the rootfs size in the right units for kickstart (Mb) | ||
| 244 | du_cmd = "du -Lbms %s" % rootfs | ||
| 245 | rc, out = exec_cmd(du_cmd) | ||
| 246 | rootfs_size = out.split()[0] | ||
| 247 | |||
| 248 | self.size = rootfs_size | ||
| 249 | self.source_file = rootfs | ||
| 250 | |||
| 251 | return 0 | ||
| 252 | |||
| 253 | def prepare_rootfs_btrfs(self, cr_workdir, oe_builddir, rootfs_dir, | ||
| 254 | native_sysroot): | ||
| 255 | """ | ||
| 256 | Prepare content for a btrfs rootfs partition. | ||
| 257 | |||
| 258 | Currently handles ext2/3/4 and btrfs. | ||
| 259 | """ | ||
| 260 | image_extra_space = 10240 | ||
| 261 | |||
| 262 | image_rootfs = rootfs_dir | ||
| 263 | rootfs = "%s/rootfs.%s" % (cr_workdir, self.fstype) | ||
| 264 | |||
| 265 | du_cmd = "du -ks %s" % image_rootfs | ||
| 266 | rc, out = exec_cmd(du_cmd) | ||
| 267 | actual_rootfs_size = out.split()[0] | ||
| 268 | |||
| 269 | rootfs_size = int(actual_rootfs_size) + image_extra_space | ||
| 270 | |||
| 271 | dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ | ||
| 272 | (rootfs, rootfs_size) | ||
| 273 | rc, out = exec_cmd(dd_cmd) | ||
| 274 | |||
| 275 | mkfs_cmd = "mkfs.%s -b %d -r %s %s" % \ | ||
| 276 | (self.fstype, rootfs_size * 1024, image_rootfs, rootfs) | ||
| 277 | rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) | ||
| 278 | |||
| 279 | # get the rootfs size in the right units for kickstart (Mb) | ||
| 280 | du_cmd = "du -Lbms %s" % rootfs | ||
| 281 | rc, out = exec_cmd(du_cmd) | ||
| 282 | rootfs_size = out.split()[0] | ||
| 283 | |||
| 284 | self.size = rootfs_size | ||
| 285 | self.source_file = rootfs | ||
| 286 | |||
| 287 | def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot): | ||
| 288 | """ | ||
| 289 | Prepare an empty partition. | ||
| 290 | """ | ||
| 291 | if self.fstype.startswith("ext"): | ||
| 292 | return self.prepare_empty_partition_ext(cr_workdir, oe_builddir, | ||
| 293 | native_sysroot) | ||
| 294 | elif self.fstype.startswith("btrfs"): | ||
| 295 | return self.prepare_empty_partition_btrfs(cr_workdir, oe_builddir, | ||
| 296 | native_sysroot) | ||
| 297 | |||
| 298 | def prepare_empty_partition_ext(self, cr_workdir, oe_builddir, | ||
| 299 | native_sysroot): | ||
| 300 | """ | ||
| 301 | Prepare an empty ext2/3/4 partition. | ||
| 302 | """ | ||
| 303 | fs = "%s/fs.%s" % (cr_workdir, self.fstype) | ||
| 304 | |||
| 305 | dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \ | ||
| 306 | (fs, self.size) | ||
| 307 | rc, out = exec_cmd(dd_cmd) | ||
| 308 | |||
| 309 | extra_imagecmd = "-i 8192" | ||
| 310 | |||
| 311 | mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs) | ||
| 312 | rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) | ||
| 313 | |||
| 314 | self.source_file = fs | ||
| 315 | |||
| 316 | return 0 | ||
| 317 | |||
| 318 | def prepare_empty_partition_btrfs(self, cr_workdir, oe_builddir, | ||
| 319 | native_sysroot): | ||
| 320 | """ | ||
| 321 | Prepare an empty btrfs partition. | ||
| 322 | """ | ||
| 323 | fs = "%s/fs.%s" % (cr_workdir, self.fstype) | ||
| 324 | |||
| 325 | dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \ | ||
| 326 | (fs, self.size) | ||
| 327 | rc, out = exec_cmd(dd_cmd) | ||
| 328 | |||
| 329 | mkfs_cmd = "mkfs.%s -b %d %s" % (self.fstype, self.size * 1024, rootfs) | ||
| 330 | rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) | ||
| 331 | |||
| 332 | mkfs_cmd = "mkfs.%s -F %s %s" % (self.fstype, extra_imagecmd, fs) | ||
| 333 | rc, out = exec_native_cmd(mkfs_cmd, native_sysroot) | ||
| 334 | |||
| 335 | self.source_file = fs | ||
| 336 | |||
| 337 | return 0 | ||
| 338 | |||
| 339 | def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot): | ||
| 340 | """ | ||
| 341 | Prepare a swap partition. | ||
| 342 | """ | ||
| 343 | fs = "%s/fs.%s" % (cr_workdir, self.fstype) | ||
| 344 | |||
| 345 | dd_cmd = "dd if=/dev/zero of=%s bs=1M seek=%d count=0" % \ | ||
| 346 | (fs, self.size) | ||
| 347 | rc, out = exec_cmd(dd_cmd) | ||
| 348 | |||
| 349 | import uuid | ||
| 350 | label_str = "" | ||
| 351 | if self.label: | ||
| 352 | label_str = "-L %s" % self.label | ||
| 353 | mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs) | ||
| 354 | rc, out = exec_native_cmd(mkswap_cmd, native_sysroot) | ||
| 355 | |||
| 356 | self.source_file = fs | ||
| 357 | |||
| 358 | return 0 | ||
| 359 | |||
| 360 | class Wic_Partition(Mic_Partition): | ||
| 361 | removedKeywords = Mic_Partition.removedKeywords | ||
| 362 | removedAttrs = Mic_Partition.removedAttrs | ||
| 363 | |||
| 364 | def _getParser(self): | ||
| 365 | op = Mic_Partition._getParser(self) | ||
| 366 | # use specified source file to fill the partition | ||
| 367 | # and calculate partition size | ||
| 368 | op.add_option("--source", type="string", action="store", | ||
| 369 | dest="source", default=None) | ||
| 370 | return op | ||
