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