Skip to content
Snippets Groups Projects
Commit e0d581bd authored by HenriDellal's avatar HenriDellal Committed by Anri Dellal
Browse files

WIP: Use config fragments for kernel configuration

Adds support for config fragments - small diffs which define what
kernel config options must be disabled/enabled.
Use $_kconfig_name to define the config to change.
parent 2406597f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.build.init import init, init_compiler
from pmb.build.envkernel import package_kernel
from pmb.build.menuconfig import menuconfig
from pmb.build.menuconfig import get_outputdir
from pmb.build.newapkbuild import newapkbuild
from pmb.build.other import copy_to_buildpath, is_necessary, \
index_repo
......
......@@ -62,15 +62,20 @@ def get_outputdir(args, pkgname, apkbuild):
ret = pmb.chroot.user(args, ["sh", "-c", cmd],
"native", "/home/pmos/build",
output_return=True).rstrip()
if os.path.exists(chroot + ret + "/.config"):
if (os.path.exists(f"{chroot}{ret}/.config") or
get_kconfig_name(args, apkbuild['arch'][0], f"{chroot}{ret}")):
return ret
# Some Mediatek kernels use a 'kernel' subdirectory
if os.path.exists(chroot + ret + "/kernel/.config"):
if os.path.exists(f"{chroot}{ret}/kernel/.config"):
return os.path.join(ret, "kernel")
# Out-of-tree builds ($_outdir)
if os.path.exists(chroot + ret + "/" + apkbuild["_outdir"] + "/.config"):
return os.path.join(ret, apkbuild["_outdir"])
outdir = apkbuild['_outdir']
if (os.path.exists(f"{chroot}{ret}/{outdir}/.config") or
get_kconfig_name(args, apkbuild['arch'][0],
f"{chroot}{ret}/{outdir}")):
return os.path.join(ret, outdir)
# Not found
raise RuntimeError("Could not find the kernel config. Consider making a"
......@@ -78,18 +83,26 @@ def get_outputdir(args, pkgname, apkbuild):
" template with: pmbootstrap aportgen " + pkgname)
def get_kconfig_name(args, arch, path):
if (os.path.exists(path)):
for f in os.listdir(path):
if f.endswith(f".{arch}") and not f.startswith("config"):
return f.split(".")[0]
return None
def menuconfig(args, pkgname):
# Pkgname: allow omitting "linux-" prefix
if pkgname.startswith("linux-"):
pkgname_ = pkgname.split("linux-")[1]
logging.info("PROTIP: You can simply do 'pmbootstrap kconfig edit " +
pkgname_ + "'")
logging.info(f"PROTIP: You can simply do 'pmbootstrap kconfig edit "
f"{pkgname_}'")
else:
pkgname = "linux-" + pkgname
pkgname = f"linux-{pkgname}"
# Read apkbuild
aport = pmb.helpers.pmaports.find(args, pkgname)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
apkbuild = pmb.parse.apkbuild(args, f"{aport}/APKBUILD")
arch = args.arch or get_arch(args, apkbuild)
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
......@@ -110,6 +123,8 @@ def menuconfig(args, pkgname):
depends += ["ncurses-dev"]
else:
depends += ["ncurses-dev"]
depends += ["diffconfig", "mergeconfig"]
pmb.chroot.apk.install(args, depends)
# Copy host's .xauthority into native
......@@ -125,29 +140,52 @@ def menuconfig(args, pkgname):
"/home/pmos/build", output="interactive",
env={"CARCH": arch})
# Run make menuconfig
outputdir = get_outputdir(args, pkgname, apkbuild)
logging.info("(native) make " + kopt)
arch_kernel = pmb.parse.arch.alpine_to_kernel(arch)
kconfig_name = get_kconfig_name(args, arch,
f"{args.work}/chroot_native/{outputdir}")
kconfig_diff = f"{kconfig_name}.{arch}"
# Run make menuconfig
logging.info(f"(native) make {kopt}")
pmb.chroot.user(args, ["make", kopt], "native",
outputdir, output="tui",
env={"ARCH": pmb.parse.arch.alpine_to_kernel(arch),
env={"ARCH": arch_kernel,
"DISPLAY": os.environ.get("DISPLAY"),
"XAUTHORITY": "/home/pmos/.Xauthority",
"CROSS_COMPILE": hostspec + "-",
"CC": hostspec + "-gcc"})
# Find the updated config
source = args.work + "/chroot_native" + outputdir + "/.config"
if not os.path.exists(source):
raise RuntimeError("No kernel config generated: " + source)
# Update the aport (config and checksum)
if kconfig_name:
logging.info("(native) diffconfig")
cmd = f"diffconfig -m .config.old .config > {kconfig_diff}.temp"
pmb.chroot.user(args, ["sh", "-c", cmd], "native", outputdir)
logging.info("(native) mergeconfig")
pmb.chroot.user(args, ["mergeconfig", "-m", kconfig_diff,
f"{kconfig_diff}.temp"],
"native", outputdir,
env={"KCONFIG_CONFIG": kconfig_diff})
pmb.chroot.user(args, ["chmod", "644", kconfig_diff], "native",
outputdir)
# Update the aport (config or config diff and checksum)
logging.info("Copy kernel config back to aport-folder")
config = "config-" + apkbuild["_flavor"] + "." + arch
target = aport + "/" + config
pmb.helpers.run.user(args, ["cp", source, target])
pmb.build.checksum.update(args, pkgname)
if kconfig_name:
source = f"{args.work}/chroot_native{outputdir}/{kconfig_diff}"
diff_target = f"{aport}/{kconfig_diff}"
pmb.helpers.run.user(args, ["cp", source, diff_target])
config_path = f"{args.work}/chroot_native{outputdir}/.config"
pmb.parse.kconfig.check_file(args, config_path, anbox=False,
details=True)
else:
# Find the updated config
source = f"{args.work}/chroot_native{outputdir}/.config"
if not os.path.exists(source):
raise RuntimeError(f"No kernel config generated: {source}")
config = f"config-{apkbuild['_flavor']}.{arch}"
config_target = f"{aport}/{config}"
pmb.helpers.run.user(args, ["cp", source, config_target])
pmb.parse.kconfig.check(args, apkbuild["_flavor"],
force_anbox_check=False, details=True)
# Check config
pmb.parse.kconfig.check(args, apkbuild["_flavor"], force_anbox_check=False,
details=True)
pmb.build.checksum.update(args, pkgname)
......@@ -339,6 +339,7 @@ apkbuild_attributes = {
"_kernver": {},
"_outdir": {},
"_config": {},
"_kconfig_name": {},
# mesa
"_llvmver": {},
......
......@@ -405,7 +405,7 @@ def kconfig(args):
pkgname = args.package
else:
pkgname = args.deviceinfo["codename"]
pmb.build.menuconfig(args, pkgname)
pmb.build.menuconfig.menuconfig(args, pkgname)
def deviceinfo_parse(args):
......
......@@ -6,6 +6,8 @@ import re
import os
import pmb.build
from pmb.build.menuconfig import get_outputdir, get_kconfig_name
import pmb.chroot
import pmb.config
import pmb.parse
import pmb.helpers.pmaports
......@@ -57,10 +59,10 @@ def check_option(component, details, config, config_path_pretty, option,
logging.warning(warning_no_details)
return False
else:
raise RuntimeError("kconfig check code can only handle True/False and"
" arrays now, given value '" + str(option_value) +
"' is not supported. If you need this, please open"
" an issue.")
raise RuntimeError(f"kconfig check code can only handle True/False"
f" and arrays now, given value '{option_value}'"
f" is not supported. If you need this, please"
f" open an issue.")
return True
......@@ -87,9 +89,9 @@ def check_config(config_path, config_path_pretty, config_arch, pkgver,
for archs, options in archs_options.items():
if archs != "all":
# Split and check if the device's architecture architecture has
# special config options. If option does not contain the
# architecture of the device kernel, then just skip the option.
# Split and check if the device's architecture has special
# config options. If option does not contain the architecture
# of the device kernel, then just skip the option.
architectures = archs.split(" ")
if config_arch not in architectures:
continue
......@@ -112,27 +114,60 @@ def check(args, pkgname, force_anbox_check=False, details=False):
# Pkgname: allow omitting "linux-" prefix
if pkgname.startswith("linux-"):
flavor = pkgname.split("linux-")[1]
logging.info("PROTIP: You can simply do 'pmbootstrap kconfig check " +
flavor + "'")
logging.info(f"PROTIP: You can simply do 'pmbootstrap kconfig check "
f"{flavor}'")
else:
flavor = pkgname
# Read all kernel configs in the aport
ret = True
aport = pmb.helpers.pmaports.find(args, "linux-" + flavor)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
aport = pmb.helpers.pmaports.find(args, f"linux-{flavor}")
apkbuild = pmb.parse.apkbuild(args, f"{aport}/APKBUILD")
pkgver = apkbuild["pkgver"]
check_anbox = force_anbox_check or (
"pmb:kconfigcheck-anbox" in apkbuild["options"])
for config_path in glob.glob(aport + "/config-*"):
kconfig_name = None
paths = None
if not apkbuild["_config"]:
depends = apkbuild["makedepends"]
depends += ["diffconfig", "mergeconfig"]
paths = []
# setup chroot
pmb.build.init(args)
pmb.chroot.apk.install(args, depends)
pmb.build.copy_to_buildpath(args, f"linux-{flavor}")
logging.info("(native) extract kernel source")
pmb.chroot.user(args, ["abuild", "unpack"], "native",
"/home/pmos/build")
for arch in apkbuild["arch"]:
logging.info("(native) apply patches")
pmb.chroot.user(args, ["abuild", "prepare"], "native",
"/home/pmos/build", output="interactive",
env={"CARCH": arch})
outputdir = get_outputdir(args, f"linux-{flavor}", apkbuild)
kconfig_name = get_kconfig_name(args, arch, f"{args.work}/"
"chroot_native/"
f"{outputdir}")
cfg_filename = f"{kconfig_name}.{arch}"
pmb.chroot.user(args, ["cp", ".config", f"/tmp/{cfg_filename}"],
"native", outputdir)
paths += [f"{args.work}/chroot_native/tmp/{cfg_filename}"]
else:
paths = glob.glob(f"{aport}/config-*")
for config_path in paths:
# The architecture of the config is in the name, so it just needs to be
# extracted
config_arch = os.path.basename(config_path).split(".")[1]
config_path_pretty = f"linux-{flavor}/{os.path.basename(config_path)}"
ret &= check_config(config_path, config_path_pretty, config_arch,
name, arch = os.path.basename(config_path).split(".")
if kconfig_name:
config_path_pretty = f"{aport}/{name}.{arch}"
else:
config_path_pretty = f"linux-{flavor}/" \
f"{name}.{arch}"
ret &= check_config(config_path, config_path_pretty, arch,
pkgver, details=details)
if check_anbox:
ret &= check_config(config_path, config_path_pretty, config_arch,
ret &= check_config(config_path, config_path_pretty, arch,
pkgver, anbox=True, details=details)
return ret
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment