You are not logged in.

#1 2021-11-16 10:24:22

SenecaRising
Member
Registered: 2021-11-16
Posts: 2

[SOLVED] Kernel compile fails after updating source, patching issues.

Hello all, I am attempting to compile a patched version of the stock stable kernel in order to work around an issue with the amdgpu driver. (Specifically #1403 and #1709.) I am following the instructions from here and here and can get a clean build from source to work with the desired patch successfully applied. When trying to update the source I have with the Wiki instructions, however, I run into an issue in compilation right at the end at the '# remove build and source links' step. I get:

rm: cannot remove '/home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.1-arch1-1-patched/source': No such file or directory
rm: cannot remove '/home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.1-arch1-1-patched/build': No such file or directory

Note: I put it in .cache/yay/ only because that is where it stores other built package caches, so it made sense to me to basically use it as my general build cache folder.

Now, I admit fully to being very new to Linux and likely in over my head with this. I really dove into the deep end with Arch, but I feel like I have managed well so far. The 'pkg' folder gets locked during the build so I am not sure what is going on in there or why the listed folders do not exist. I tried before modifying the PKGBUILD at the '# remove build and source links' step to skip that but predictably this resulted in an incorrectly built kernel. I am at a loss as to where to go next. If I completely clear the cache and start fresh, it builds just fine. It is only after following the "Updating" section on the Wiki page that this happens.

The other issue is definitely due to me being new. I cannot seem to get my patch to reliably apply. Sometimes the PKGBUILD takes it, other times it does not. I so far can see no rhyme nor reason to this and am fully confused. Surely the section in the PKGBUILD specifically for applying patches would take my patch reliably, no? The patch does work manually from the src/ directory, but maybe that is the wrong place? What am I missing here? It is included in the source array so it gets copied in with the 'config' file, but I have only once seen "Applying Patch 'linux-amdpatch.patch'" when watching the build process. It seems to otherwise completely ignore the patch file, as there is no error with patching, be it files not found or reverse patch detected.

My steps:

  1. Did the 'asp update/export linux step.

  2. Nano'd the PKGBUILD to make my changes.

  3. ran 'updpkgsums' for my .patch file.

  4. Compiled the kernel with 'ccache makepkg -si' the first time, which succeeds.

  5. After a new kernel came out, I undid my patch, because git complains about the uncommited changes if I do not.

  6. I then ran, in order,

    cd ~/.cache/yay/linux-patched/linux/archlinux-linux/
    git fetch --verbose
    cd ~/.cache/yay/linux-patched/linux/src/archlinux-linux/
    git checkout master
    git pull
    git fetch --tags --verbose
    git branch --verbose 5.15.2-arch1 v5.15.2-arch1
    git checkout 5.15.2-arch1
    git log --oneline 5.15.2-arch1 --max-count=8
    cd ~/.cache/yay/linux-patched/linux/
    asp update linux
    asp export linux
  7. Replaced my modified files (config, PKGBUILD) with the new ones.

  8. Made my modifications to PKGBUILD again.

  9. Ran 'makepkg --verifysource' which succeeds.

  10. Attempted to compile again with 'ccache makepkg -si --noextract', which fails.  (I think ccache may have something to do with it, but running just makepkg also fails.)

My PKGBUILD:

# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgbase=linux-patched
pkgver=5.15.2.arch1
pkgrel=1
pkgdesc='Linux'
_srctag=v${pkgver%.*}-${pkgver##*.}
url="https://github.com/archlinux/linux/commits/$_srctag"
arch=(x86_64)
license=(GPL2)
makedepends=(
  bc kmod libelf pahole cpio perl tar xz
  xmlto python-sphinx python-sphinx_rtd_theme graphviz imagemagick
  git
)
options=('!strip')
_srcname=archlinux-linux
source=(
  "$_srcname::git+https://github.com/archlinux/linux?signed#tag=$_srctag"
  config         # the main kernel config file
  linux-amdpatch.patch
)
validpgpkeys=(
  'ABAF11C65A2970B130ABE3C479BE3E4300411886'  # Linus Torvalds
  '647F28654894E3BD457199BE38DBBDC86092693E'  # Greg Kroah-Hartman
  'A2FF3A36AAA56654109064AB19802F8B0D70FC30'  # Jan Alexander Steffens (heftig)
  'C7E7849466FE2358343588377258734B41C31549'  # David Runge <dvzrv@archlinux.org>
)
sha256sums=('SKIP'
            '0eecdc29b3bde4bccda282c4c04ef114250fedddcf3dbf07a3cc201dce35838f'
            '4dd3f7e74a9931bbb8b44dcd57a97724097a21fb9a4e62d397e6d75009990268')

export KBUILD_BUILD_HOST=archlinux
export KBUILD_BUILD_USER=$pkgbase
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"

prepare() {
  cd $_srcname
  cp ../linux-amdpatch.patch linux-amdpatch.patch

  echo "Setting version..."
  scripts/setlocalversion --save-scmversion
  echo "-$pkgrel" > localversion.10-pkgrel
  echo "${pkgbase#linux}" > localversion.20-pkgname

  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done

  echo "Setting config..."
  cp ../config .config
  make olddefconfig
  diff -u ../config .config || :

  make -s kernelrelease > version
  echo "Prepared $pkgbase version $(<version)"
}

build() {
  cd $_srcname
  make all
}

_package() {
  pkgdesc="The $pkgdesc kernel and modules"
  depends=(coreutils kmod initramfs)
  optdepends=('crda: to set the correct wireless channels of your country'
              'linux-firmware: firmware images needed for some devices')
  provides=(VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE)
  replaces=(virtualbox-guest-modules-arch wireguard-arch)

  cd $_srcname
  local kernver="$(<version)"
  local modulesdir="$pkgdir/usr/lib/modules/$kernver"

  echo "Installing boot image..."
  # systemd expects to find the kernel here to allow hibernation
  # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"

  # Used by mkinitcpio to name the kernel
  echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"

  echo "Installing modules..."
  make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 modules_install

  # remove build and source links
  rm "$modulesdir"/{source,build}
}

_package-headers() {
  pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
  depends=(pahole)

  cd $_srcname
  local builddir="$pkgdir/usr/lib/modules/$(<version)/build"

  echo "Installing build files..."
  install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
    localversion.* version vmlinux
  install -Dt "$builddir/kernel" -m644 kernel/Makefile
  install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
  cp -t "$builddir" -a scripts

  # add objtool for external module building and enabled VALIDATION_STACK option
  install -Dt "$builddir/tools/objtool" tools/objtool/objtool

  # add xfs and shmem for aufs building
  mkdir -p "$builddir"/{fs/xfs,mm}

  echo "Installing headers..."
  cp -t "$builddir" -a include
  cp -t "$builddir/arch/x86" -a arch/x86/include
  install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s

  install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h

  # https://bugs.archlinux.org/task/13146
  install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h

  # https://bugs.archlinux.org/task/20402
  install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h

  # https://bugs.archlinux.org/task/71392
  install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h

  echo "Installing KConfig files..."
  find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;

  echo "Removing unneeded architectures..."
  local arch
  for arch in "$builddir"/arch/*/; do
    [[ $arch = */x86/ ]] && continue
    echo "Removing $(basename "$arch")"
    rm -r "$arch"
  done

  echo "Removing documentation..."
  rm -r "$builddir/Documentation"

  echo "Removing broken symlinks..."
  find -L "$builddir" -type l -printf 'Removing %P\n' -delete

  echo "Removing loose objects..."
  find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete

  echo "Stripping build tools..."
  local file
  while read -rd '' file; do
    case "$(file -bi "$file")" in
      application/x-sharedlib\;*)      # Libraries (.so)
        strip -v $STRIP_SHARED "$file" ;;
      application/x-archive\;*)        # Libraries (.a)
        strip -v $STRIP_STATIC "$file" ;;
      application/x-executable\;*)     # Binaries
        strip -v $STRIP_BINARIES "$file" ;;
      application/x-pie-executable\;*) # Relocatable binaries
        strip -v $STRIP_SHARED "$file" ;;
    esac
  done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)

  echo "Stripping vmlinux..."
  strip -v $STRIP_STATIC "$builddir/vmlinux"

  echo "Adding symlink..."
  mkdir -p "$pkgdir/usr/src"
  ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
}

_package-docs() {
  pkgdesc="Documentation for the $pkgdesc kernel"

  cd $_srcname
  local builddir="$pkgdir/usr/lib/modules/$(<version)/build"

  echo "Installing documentation..."
  local src dst
  while read -rd '' src; do
    dst="${src#Documentation/}"
    dst="$builddir/Documentation/${dst#output/}"
    install -Dm644 "$src" "$dst"
  done < <(find Documentation -name '.*' -prune -o ! -type d -print0)

  echo "Adding symlink..."
  mkdir -p "$pkgdir/usr/share/doc"
  ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
}

pkgname=("$pkgbase" "$pkgbase-headers")
for _p in "${pkgname[@]}"; do
  eval "package_$_p() {
    $(declare -f "_package${_p#$pkgbase}")
    _package${_p#$pkgbase}
  }"
done

# vim:set ts=8 sts=2 sw=2 et:

My kernel patch:

diff --unified --recursive --text a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c
--- a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c	2021-10-24 15:28:12.062163512 -0700
+++ b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c	2021-10-24 15:45:29.623796625 -0700
@@ -1067,7 +1067,7 @@
 		.timing_trace = false,
 		.clock_trace = true,
 		.disable_pplib_clock_request = true,
-		.pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
+		.pipe_split_policy = MPC_SPLIT_DYNAMIC,
 		.force_single_disp_pipe_split = false,
 		.disable_dcc = DCC_ENABLE,
 		.vsr_support = true,
diff --unified --recursive --text a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c
--- a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c	2021-10-24 15:28:12.065496883 -0700
+++ b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c	2021-10-24 15:46:01.226309546 -0700
@@ -840,7 +840,7 @@
 	.timing_trace = false,
 	.clock_trace = true,
 	.disable_pplib_clock_request = true,
-	.pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
+	.pipe_split_policy = MPC_SPLIT_DYNAMIC,
 	.force_single_disp_pipe_split = false,
 	.disable_dcc = DCC_ENABLE,
 	.vsr_support = true,
diff --unified --recursive --text a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c
--- a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c	2021-10-24 15:28:12.068830254 -0700
+++ b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c	2021-10-24 15:46:31.885202338 -0700
@@ -211,7 +211,7 @@
 		.timing_trace = false,
 		.clock_trace = true,
 		.disable_pplib_clock_request = true,
-		.pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
+		.pipe_split_policy = MPC_SPLIT_DYNAMIC,
 		.force_single_disp_pipe_split = false,
 		.disable_dcc = DCC_ENABLE,
 		.vsr_support = true,
diff --unified --recursive --text a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c
--- a/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c	2021-10-24 15:28:12.068830254 -0700
+++ b/archlinux-linux/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c	2021-10-24 15:46:49.987921237 -0700
@@ -193,7 +193,7 @@
 		.timing_trace = false,
 		.clock_trace = true,
 		.disable_pplib_clock_request = true,
-		.pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
+		.pipe_split_policy = MPC_SPLIT_DYNAMIC,
 		.force_single_disp_pipe_split = false,
 		.disable_dcc = DCC_ENABLE,
 		.vsr_support = true,

'tail' of the output for 'makepkg -si' and the error:

  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/usb/misc/snd-ua101.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/usb/snd-usb-audio.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/usb/snd-usbmidi-lib.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/usb/usx2y/snd-usb-us122l.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/usb/usx2y/snd-usb-usx2y.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/virtio/virtio_snd.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/x86/snd-hdmi-lpe-audio.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/sound/xen/snd_xen_front.ko.zst
  ZSTD    /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched/kernel/virt/lib/irqbypass.ko.zst
  DEPMOD  /home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.2-arch1-1-patched
rm: cannot remove '/home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.1-arch1-1-patched/source': No such file or directory
rm: cannot remove '/home/<me>/.cache/yay/linux-patched/linux/pkg/linux-patched/usr/lib/modules/5.15.1-arch1-1-patched/build': No such file or directory
==> ERROR: A failure occurred in package_linux-patched().
    Aborting...

Thanks in advance for your help with this and patience with me, and apologies in advance if I forgot some important info or really did just forget to RTFM!

Edit: It looks like my suspicions were correct and using ccache messed up the cleanup. I was able to successfully build an updated kernel source without using ccache. It also seems like makepkg is smart enough to cache itself anyway, so ccache would be redundant. In case anyone took advice for traditional kernel compilation, where ccache would be helpful, do not use it for the ABS method of kernel compilation.

Also, using --noextract seems to prevent any patches from being applied. Omitting --noextract does not otherwise affect compilation; it does not redownload the source. So it seems that both of my issues are solved.

Last edited by SenecaRising (2021-12-05 20:37:22)

Offline

Board footer

Powered by FluxBB