diff --git a/pmb/helpers/devices.py b/pmb/helpers/devices.py index 3f426dd7..d5c54e78 100644 --- a/pmb/helpers/devices.py +++ b/pmb/helpers/devices.py @@ -9,6 +9,7 @@ from pathlib import Path import pmb.config from pmb.core.pkgrepo import pkgrepo_glob_one, pkgrepo_iglob from pmb.helpers import logging +import pmb.helpers.pmaports def find_path(codename: str, file: str = "") -> Path | None: @@ -164,3 +165,26 @@ def get_device_category_by_apkbuild_path(apkbuild_path: Path) -> DeviceCategory: raise RuntimeError(f'Unknown device category "{category_str}"') from exception return device_category + + +def get_device_category_by_directory_path(device_directory: Path) -> DeviceCategory: + """Get the category of a device based on the path to its directory inside of pmaports. + + :device_directory: Path to the device package directory for a particular device. + :returns: The device category of the provided device directory. + """ + device_apkbuild_path = device_directory / "APKBUILD" + + return get_device_category_by_apkbuild_path(device_apkbuild_path) + + +def get_device_category_by_name(device_name: str) -> DeviceCategory: + """Get the category of a device based on its name. + + :device_name: Name of a particular device to determine the category of. + Format should be "vendor-codename". + :returns: The device category of the provided device name. + """ + device_directory = pmb.helpers.pmaports.find(f"device-{device_name}") + + return get_device_category_by_directory_path(device_directory) diff --git a/pmb/install/format.py b/pmb/install/format.py index 1b1db4cd..8e898a82 100644 --- a/pmb/install/format.py +++ b/pmb/install/format.py @@ -1,8 +1,10 @@ # Copyright 2023 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later from pmb.helpers import logging +from pmb.helpers.devices import get_device_category_by_name, DeviceCategory import pmb.chroot from pmb.core import Chroot +from pmb.core.context import get_context from pmb.types import PartitionLayout, PmbArgs, PathString import os import tempfile @@ -173,10 +175,17 @@ def format_and_mount_root( filesystem = get_root_filesystem(args) if filesystem == "ext4": - # Some downstream kernels don't support metadata_csum (#1364). - # When changing the options of mkfs.ext4, also change them in the - # recovery zip code (see 'grep -r mkfs\.ext4')! - mkfs_root_args = ["mkfs.ext4", "-O", "^metadata_csum", "-F", "-q", "-L", root_label] + device_category = get_device_category_by_name(get_context().config.device) + + if device_category == DeviceCategory.DOWNSTREAM: + # Some downstream kernels don't support metadata_csum (#1364). + # When changing the options of mkfs.ext4, also change them in the + # recovery zip code (see 'grep -r mkfs\.ext4')! + category_opts = ["-O", "^metadata_csum"] + else: + category_opts = [] + + mkfs_root_args = ["mkfs.ext4", *category_opts, "-F", "-q", "-L", root_label] if not disk: # pmb#2568: tell mkfs.ext4 to make a filesystem with enough # indoes that we don't run into "out of space" errors