Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4 | from abc import ABCMeta, abstractmethod |
| 5 | from oe.utils import execute_pre_post_process |
| 6 | from oe.package_manager import * |
| 7 | from oe.manifest import * |
| 8 | import oe.path |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | import shutil |
| 10 | import os |
| 11 | import subprocess |
| 12 | import re |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 13 | from oe.package_manager.rpm.manifest import RpmManifest |
| 14 | from oe.package_manager.ipk.manifest import OpkgManifest |
| 15 | from oe.package_manager.deb.manifest import DpkgManifest |
| 16 | from oe.package_manager.rpm import RpmPkgsList |
| 17 | from oe.package_manager.ipk import OpkgPkgsList |
| 18 | from oe.package_manager.deb import DpkgPkgsList |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | class Rootfs(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | """ |
| 22 | This is an abstract class. Do not instantiate this directly. |
| 23 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | def __init__(self, d, progress_reporter=None, logcatcher=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | self.d = d |
| 27 | self.pm = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 28 | self.image_rootfs = self.d.getVar('IMAGE_ROOTFS') |
| 29 | self.deploydir = self.d.getVar('IMGDEPLOYDIR') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 30 | self.progress_reporter = progress_reporter |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | self.logcatcher = logcatcher |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | |
| 33 | self.install_order = Manifest.INSTALL_ORDER |
| 34 | |
| 35 | @abstractmethod |
| 36 | def _create(self): |
| 37 | pass |
| 38 | |
| 39 | @abstractmethod |
| 40 | def _get_delayed_postinsts(self): |
| 41 | pass |
| 42 | |
| 43 | @abstractmethod |
| 44 | def _save_postinsts(self): |
| 45 | pass |
| 46 | |
| 47 | @abstractmethod |
| 48 | def _log_check(self): |
| 49 | pass |
| 50 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | def _log_check_common(self, type, match): |
| 52 | # Ignore any lines containing log_check to avoid recursion, and ignore |
| 53 | # lines beginning with a + since sh -x may emit code which isn't |
| 54 | # actually executed, but may contain error messages |
| 55 | excludes = [ 'log_check', r'^\+' ] |
| 56 | if hasattr(self, 'log_check_expected_regexes'): |
| 57 | excludes.extend(self.log_check_expected_regexes) |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 58 | # Insert custom log_check excludes |
| 59 | excludes += [x for x in (self.d.getVar("IMAGE_LOG_CHECK_EXCLUDES") or "").split(" ") if x] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 60 | excludes = [re.compile(x) for x in excludes] |
| 61 | r = re.compile(match) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | log_path = self.d.expand("${T}/log.do_rootfs") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 63 | messages = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | with open(log_path, 'r') as log: |
| 65 | for line in log: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 66 | if self.logcatcher and self.logcatcher.contains(line.rstrip()): |
| 67 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | for ee in excludes: |
| 69 | m = ee.search(line) |
| 70 | if m: |
| 71 | break |
| 72 | if m: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | continue |
| 74 | |
| 75 | m = r.search(line) |
| 76 | if m: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | messages.append('[log_check] %s' % line) |
| 78 | if messages: |
| 79 | if len(messages) == 1: |
| 80 | msg = '1 %s message' % type |
| 81 | else: |
| 82 | msg = '%d %s messages' % (len(messages), type) |
| 83 | msg = '[log_check] %s: found %s in the logfile:\n%s' % \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 84 | (self.d.getVar('PN'), msg, ''.join(messages)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 85 | if type == 'error': |
| 86 | bb.fatal(msg) |
| 87 | else: |
| 88 | bb.warn(msg) |
| 89 | |
| 90 | def _log_check_warn(self): |
| 91 | self._log_check_common('warning', '^(warn|Warn|WARNING:)') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | |
| 93 | def _log_check_error(self): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 94 | self._log_check_common('error', self.log_check_regex) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | |
| 96 | def _insert_feed_uris(self): |
| 97 | if bb.utils.contains("IMAGE_FEATURES", "package-management", |
| 98 | True, False, self.d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 99 | self.pm.insert_feeds_uris(self.d.getVar('PACKAGE_FEED_URIS') or "", |
| 100 | self.d.getVar('PACKAGE_FEED_BASE_PATHS') or "", |
| 101 | self.d.getVar('PACKAGE_FEED_ARCHS')) |
| 102 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | """ |
| 105 | The _cleanup() method should be used to clean-up stuff that we don't really |
| 106 | want to end up on target. For example, in the case of RPM, the DB locks. |
| 107 | The method is called, once, at the end of create() method. |
| 108 | """ |
| 109 | @abstractmethod |
| 110 | def _cleanup(self): |
| 111 | pass |
| 112 | |
| 113 | def _setup_dbg_rootfs(self, dirs): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 114 | gen_debugfs = self.d.getVar('IMAGE_GEN_DEBUGFS') or '0' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | if gen_debugfs != '1': |
| 116 | return |
| 117 | |
| 118 | bb.note(" Renaming the original rootfs...") |
| 119 | try: |
| 120 | shutil.rmtree(self.image_rootfs + '-orig') |
| 121 | except: |
| 122 | pass |
| 123 | os.rename(self.image_rootfs, self.image_rootfs + '-orig') |
| 124 | |
| 125 | bb.note(" Creating debug rootfs...") |
| 126 | bb.utils.mkdirhier(self.image_rootfs) |
| 127 | |
| 128 | bb.note(" Copying back package database...") |
| 129 | for dir in dirs: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 130 | if not os.path.isdir(self.image_rootfs + '-orig' + dir): |
| 131 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | bb.utils.mkdirhier(self.image_rootfs + os.path.dirname(dir)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 133 | shutil.copytree(self.image_rootfs + '-orig' + dir, self.image_rootfs + dir, symlinks=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 134 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | # Copy files located in /usr/lib/debug or /usr/src/debug |
| 136 | for dir in ["/usr/lib/debug", "/usr/src/debug"]: |
| 137 | src = self.image_rootfs + '-orig' + dir |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 138 | if os.path.exists(src): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | dst = self.image_rootfs + dir |
| 140 | bb.utils.mkdirhier(os.path.dirname(dst)) |
| 141 | shutil.copytree(src, dst) |
| 142 | |
| 143 | # Copy files with suffix '.debug' or located in '.debug' dir. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 144 | for root, dirs, files in os.walk(self.image_rootfs + '-orig'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | relative_dir = root[len(self.image_rootfs + '-orig'):] |
| 146 | for f in files: |
| 147 | if f.endswith('.debug') or '/.debug' in relative_dir: |
| 148 | bb.utils.mkdirhier(self.image_rootfs + relative_dir) |
| 149 | shutil.copy(os.path.join(root, f), |
| 150 | self.image_rootfs + relative_dir) |
| 151 | |
| 152 | bb.note(" Install complementary '*-dbg' packages...") |
| 153 | self.pm.install_complementary('*-dbg') |
| 154 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 155 | if self.d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-with-srcpkg': |
| 156 | bb.note(" Install complementary '*-src' packages...") |
| 157 | self.pm.install_complementary('*-src') |
| 158 | |
| 159 | """ |
| 160 | Install additional debug packages. Possibility to install additional packages, |
| 161 | which are not automatically installed as complementary package of |
| 162 | standard one, e.g. debug package of static libraries. |
| 163 | """ |
| 164 | extra_debug_pkgs = self.d.getVar('IMAGE_INSTALL_DEBUGFS') |
| 165 | if extra_debug_pkgs: |
| 166 | bb.note(" Install extra debug packages...") |
| 167 | self.pm.install(extra_debug_pkgs.split(), True) |
| 168 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | bb.note(" Rename debug rootfs...") |
| 170 | try: |
| 171 | shutil.rmtree(self.image_rootfs + '-dbg') |
| 172 | except: |
| 173 | pass |
| 174 | os.rename(self.image_rootfs, self.image_rootfs + '-dbg') |
| 175 | |
| 176 | bb.note(" Restoreing original rootfs...") |
| 177 | os.rename(self.image_rootfs + '-orig', self.image_rootfs) |
| 178 | |
| 179 | def _exec_shell_cmd(self, cmd): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 180 | fakerootcmd = self.d.getVar('FAKEROOT') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | if fakerootcmd is not None: |
| 182 | exec_cmd = [fakerootcmd, cmd] |
| 183 | else: |
| 184 | exec_cmd = cmd |
| 185 | |
| 186 | try: |
| 187 | subprocess.check_output(exec_cmd, stderr=subprocess.STDOUT) |
| 188 | except subprocess.CalledProcessError as e: |
| 189 | return("Command '%s' returned %d:\n%s" % (e.cmd, e.returncode, e.output)) |
| 190 | |
| 191 | return None |
| 192 | |
| 193 | def create(self): |
| 194 | bb.note("###### Generate rootfs #######") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 195 | pre_process_cmds = self.d.getVar("ROOTFS_PREPROCESS_COMMAND") |
| 196 | post_process_cmds = self.d.getVar("ROOTFS_POSTPROCESS_COMMAND") |
| 197 | rootfs_post_install_cmds = self.d.getVar('ROOTFS_POSTINSTALL_COMMAND') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 198 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | bb.utils.mkdirhier(self.image_rootfs) |
| 200 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 201 | bb.utils.mkdirhier(self.deploydir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 203 | execute_pre_post_process(self.d, pre_process_cmds) |
| 204 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 205 | if self.progress_reporter: |
| 206 | self.progress_reporter.next_stage() |
| 207 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | # call the package manager dependent create method |
| 209 | self._create() |
| 210 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 211 | sysconfdir = self.image_rootfs + self.d.getVar('sysconfdir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 212 | bb.utils.mkdirhier(sysconfdir) |
| 213 | with open(sysconfdir + "/version", "w+") as ver: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 214 | ver.write(self.d.getVar('BUILDNAME') + "\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 216 | execute_pre_post_process(self.d, rootfs_post_install_cmds) |
| 217 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 218 | self.pm.run_intercepts() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 219 | |
| 220 | execute_pre_post_process(self.d, post_process_cmds) |
| 221 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 222 | if self.progress_reporter: |
| 223 | self.progress_reporter.next_stage() |
| 224 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | if bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", |
| 226 | True, False, self.d): |
| 227 | delayed_postinsts = self._get_delayed_postinsts() |
| 228 | if delayed_postinsts is not None: |
| 229 | bb.fatal("The following packages could not be configured " |
| 230 | "offline and rootfs is read-only: %s" % |
| 231 | delayed_postinsts) |
| 232 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | if self.d.getVar('USE_DEVFS') != "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | self._create_devfs() |
| 235 | |
| 236 | self._uninstall_unneeded() |
| 237 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 238 | if self.progress_reporter: |
| 239 | self.progress_reporter.next_stage() |
| 240 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | self._insert_feed_uris() |
| 242 | |
| 243 | self._run_ldconfig() |
| 244 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | if self.d.getVar('USE_DEPMOD') != "0": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | self._generate_kernel_module_deps() |
| 247 | |
| 248 | self._cleanup() |
| 249 | self._log_check() |
| 250 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 251 | if self.progress_reporter: |
| 252 | self.progress_reporter.next_stage() |
| 253 | |
| 254 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 255 | def _uninstall_unneeded(self): |
| 256 | # Remove unneeded init script symlinks |
| 257 | delayed_postinsts = self._get_delayed_postinsts() |
| 258 | if delayed_postinsts is None: |
| 259 | if os.path.exists(self.d.expand("${IMAGE_ROOTFS}${sysconfdir}/init.d/run-postinsts")): |
| 260 | self._exec_shell_cmd(["update-rc.d", "-f", "-r", |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | self.d.getVar('IMAGE_ROOTFS'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | "run-postinsts", "remove"]) |
| 263 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | image_rorfs = bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 265 | True, False, self.d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 266 | image_rorfs_force = self.d.getVar('FORCE_RO_REMOVE') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 267 | |
| 268 | if image_rorfs or image_rorfs_force == "1": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 269 | # Remove components that we don't need if it's a read-only rootfs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 270 | unneeded_pkgs = self.d.getVar("ROOTFS_RO_UNNEEDED").split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 271 | pkgs_installed = image_list_installed_packages(self.d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 272 | # Make sure update-alternatives is removed last. This is |
| 273 | # because its database has to available while uninstalling |
| 274 | # other packages, allowing alternative symlinks of packages |
| 275 | # to be uninstalled or to be managed correctly otherwise. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 276 | provider = self.d.getVar("VIRTUAL-RUNTIME_update-alternatives") |
| 277 | pkgs_to_remove = sorted([pkg for pkg in pkgs_installed if pkg in unneeded_pkgs], key=lambda x: x == provider) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 279 | # update-alternatives provider is removed in its own remove() |
| 280 | # call because all package managers do not guarantee the packages |
| 281 | # are removed in the order they given in the list (which is |
| 282 | # passed to the command line). The sorting done earlier is |
| 283 | # utilized to implement the 2-stage removal. |
| 284 | if len(pkgs_to_remove) > 1: |
| 285 | self.pm.remove(pkgs_to_remove[:-1], False) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 286 | if len(pkgs_to_remove) > 0: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 287 | self.pm.remove([pkgs_to_remove[-1]], False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 288 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 289 | if delayed_postinsts: |
| 290 | self._save_postinsts() |
| 291 | if image_rorfs: |
| 292 | bb.warn("There are post install scripts " |
| 293 | "in a read-only rootfs") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 295 | post_uninstall_cmds = self.d.getVar("ROOTFS_POSTUNINSTALL_COMMAND") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 296 | execute_pre_post_process(self.d, post_uninstall_cmds) |
| 297 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 298 | runtime_pkgmanage = bb.utils.contains("IMAGE_FEATURES", "package-management", |
| 299 | True, False, self.d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | if not runtime_pkgmanage: |
| 301 | # Remove the package manager data files |
| 302 | self.pm.remove_packaging_data() |
| 303 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 304 | def _run_ldconfig(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 305 | if self.d.getVar('LDCONFIGDEPEND'): |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 306 | bb.note("Executing: ldconfig -r " + self.image_rootfs + " -c new -v -X") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 307 | self._exec_shell_cmd(['ldconfig', '-r', self.image_rootfs, '-c', |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 308 | 'new', '-v', '-X']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | |
| 310 | def _check_for_kernel_modules(self, modules_dir): |
| 311 | for root, dirs, files in os.walk(modules_dir, topdown=True): |
| 312 | for name in files: |
| 313 | found_ko = name.endswith(".ko") |
| 314 | if found_ko: |
| 315 | return found_ko |
| 316 | return False |
| 317 | |
| 318 | def _generate_kernel_module_deps(self): |
| 319 | modules_dir = os.path.join(self.image_rootfs, 'lib', 'modules') |
| 320 | # if we don't have any modules don't bother to do the depmod |
| 321 | if not self._check_for_kernel_modules(modules_dir): |
| 322 | bb.note("No Kernel Modules found, not running depmod") |
| 323 | return |
| 324 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 325 | kernel_abi_ver_file = oe.path.join(self.d.getVar('PKGDATA_DIR'), "kernel-depmod", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 326 | 'kernel-abiversion') |
| 327 | if not os.path.exists(kernel_abi_ver_file): |
| 328 | bb.fatal("No kernel-abiversion file found (%s), cannot run depmod, aborting" % kernel_abi_ver_file) |
| 329 | |
| 330 | kernel_ver = open(kernel_abi_ver_file).read().strip(' \n') |
| 331 | versioned_modules_dir = os.path.join(self.image_rootfs, modules_dir, kernel_ver) |
| 332 | |
| 333 | bb.utils.mkdirhier(versioned_modules_dir) |
| 334 | |
| 335 | self._exec_shell_cmd(['depmodwrapper', '-a', '-b', self.image_rootfs, kernel_ver]) |
| 336 | |
| 337 | """ |
| 338 | Create devfs: |
| 339 | * IMAGE_DEVICE_TABLE is the old name to an absolute path to a device table file |
| 340 | * IMAGE_DEVICE_TABLES is a new name for a file, or list of files, seached |
| 341 | for in the BBPATH |
| 342 | If neither are specified then the default name of files/device_table-minimal.txt |
| 343 | is searched for in the BBPATH (same as the old version.) |
| 344 | """ |
| 345 | def _create_devfs(self): |
| 346 | devtable_list = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 347 | devtable = self.d.getVar('IMAGE_DEVICE_TABLE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 348 | if devtable is not None: |
| 349 | devtable_list.append(devtable) |
| 350 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 351 | devtables = self.d.getVar('IMAGE_DEVICE_TABLES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 352 | if devtables is None: |
| 353 | devtables = 'files/device_table-minimal.txt' |
| 354 | for devtable in devtables.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 355 | devtable_list.append("%s" % bb.utils.which(self.d.getVar('BBPATH'), devtable)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 356 | |
| 357 | for devtable in devtable_list: |
| 358 | self._exec_shell_cmd(["makedevs", "-r", |
| 359 | self.image_rootfs, "-D", devtable]) |
| 360 | |
| 361 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | def get_class_for_type(imgtype): |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 363 | from oe.package_manager.rpm.rootfs import RpmRootfs |
| 364 | from oe.package_manager.ipk.rootfs import OpkgRootfs |
| 365 | from oe.package_manager.deb.rootfs import DpkgRootfs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 366 | return {"rpm": RpmRootfs, |
| 367 | "ipk": OpkgRootfs, |
| 368 | "deb": DpkgRootfs}[imgtype] |
| 369 | |
| 370 | def variable_depends(d, manifest_dir=None): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 371 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | cls = get_class_for_type(img_type) |
| 373 | return cls._depends_list() |
| 374 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 375 | def create_rootfs(d, manifest_dir=None, progress_reporter=None, logcatcher=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | env_bkp = os.environ.copy() |
| 377 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 378 | from oe.package_manager.rpm.rootfs import RpmRootfs |
| 379 | from oe.package_manager.ipk.rootfs import OpkgRootfs |
| 380 | from oe.package_manager.deb.rootfs import DpkgRootfs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 381 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 382 | if img_type == "rpm": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 383 | RpmRootfs(d, manifest_dir, progress_reporter, logcatcher).create() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 384 | elif img_type == "ipk": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 385 | OpkgRootfs(d, manifest_dir, progress_reporter, logcatcher).create() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 386 | elif img_type == "deb": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 387 | DpkgRootfs(d, manifest_dir, progress_reporter, logcatcher).create() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 388 | |
| 389 | os.environ.clear() |
| 390 | os.environ.update(env_bkp) |
| 391 | |
| 392 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 393 | def image_list_installed_packages(d, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 394 | if not rootfs_dir: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 395 | rootfs_dir = d.getVar('IMAGE_ROOTFS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 396 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 397 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 398 | if img_type == "rpm": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 399 | return RpmPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 400 | elif img_type == "ipk": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 401 | return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET")).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 402 | elif img_type == "deb": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 403 | return DpkgPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 404 | |
| 405 | if __name__ == "__main__": |
| 406 | """ |
| 407 | We should be able to run this as a standalone script, from outside bitbake |
| 408 | environment. |
| 409 | """ |
| 410 | """ |
| 411 | TBD |
| 412 | """ |