Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amdgpu: cannot set modified EDID binaries. "Requesting EDID firmware ... failed (err=-2)" #279739

Open
soupglasses opened this issue Jan 9, 2024 · 12 comments · May be fixed by #279789 or #299300
Open

amdgpu: cannot set modified EDID binaries. "Requesting EDID firmware ... failed (err=-2)" #279739

soupglasses opened this issue Jan 9, 2024 · 12 comments · May be fixed by #279789 or #299300

Comments

@soupglasses
Copy link
Member

soupglasses commented Jan 9, 2024

Describe the bug

When using drm.edid_firmware on NixOS, amdgpu fails to find the relevant firmware file specified, even if it exists. Loading the EDID manually from /run/current-system/firmware works correctly.

% journalctl -b0 | grep edid
Jan 09 06:05:22 desktop kernel: Command line: initrd=\efi\nixos\3r63xc80969amx1mldhh18jn39807i4r-initrd-linux-6.6.8-initrd.efi init=/nix/store/ix3vqm06g4s8s97yb2givdx0yas5zwaq-nixos-system-desktop-24.05.20240109.dirty/init drm.edid_firmware=edid/MSI-1462.bin mitigations=auto split_lock_detect=off loglevel=4
Jan 09 06:05:22 desktop kernel: Kernel command line: initrd=\efi\nixos\3r63xc80969amx1mldhh18jn39807i4r-initrd-linux-6.6.8-initrd.efi init=/nix/store/ix3vqm06g4s8s97yb2givdx0yas5zwaq-nixos-system-desktop-24.05.20240109.dirty/init drm.edid_firmware=edid/MSI-1462.bin mitigations=auto split_lock_detect=off loglevel=4
Jan 09 06:05:22 desktop kernel: amdgpu 0000:03:00.0: Direct firmware load for edid/MSI-1462.bin failed with error -2
Jan 09 06:05:22 desktop kernel: amdgpu 0000:03:00.0: [drm] *ERROR* [CONNECTOR:121:DP-2] Requesting EDID firmware "edid/MSI-1462.bin" failed (err=-2)

Steps To Reproduce

NixOS configuration should have the following set somewhere:

{pkgs, lib, ...}: let
  edid-custom = pkgs.runCommandNoCC "edid-custom" {} ''
    mkdir -p $out/lib/firmware/edid
    base64 -d > "$out/lib/firmware/edid/custom.bin" <<EOF
    <insert your base64 encoded EDID file here `base64 < /sys/class/drm/card0-.../edid`>
    EOF
  '';
in {
  boot.kernelParams = ["drm.edid_firmware=edid/custom.bin"];
  hardware.firmware = [edid-custom];
}

My EDID file looks like this for comparison:

AP///////wA2aWIUAQAAABMdAQSlUCF4O44FrU8zsCYNUFSvzwCBgIGolQCVKLMAsyjR6NHAQ9Bw
oNCgKVAwIDUAHU0xAAAaAAAA/QAwZKKiAgEAAAAAAAAAAAAA/ABNU0kgTUFHMzQxQ1EKgvBwUNCg
UVAIIPgACLBBAAAaATICAxh1S5CfhZQEEwMSAQIRIwkHB4MBAAACOoDQcjgtQBAsNYAdTTEAABj+
fHCg0KApUDAgNQAdTTEAABhWXgCgoKApUDAgNQAdTTEAAB46nQCgoKApUDBANQAdTTEAAB6uYIAY
cTgtQDAsNQAdTTEAABgAAAAAAAAAAAAAAAAAEg==
  1. Rebuild and switch configuration.
  2. Reboot.
  3. See edid errors in journalctl -b0.

Expected behavior

Applies the EDID file correctly on boot.

Applying it manually, for example as sudo bash -c "unxz -dc /run/current-system/firmware/edid/custom.bin.xz > /sys/kernel/debug/dri/0/DP-2/edid_override" to apply it to DP-2 works correctly. This can work as a pseudo workaround, but requires you to disconnect and reconnect your monitor to apply the modified edid file.

Additional context

Open Discourse about the issue: https://discourse.nixos.org/t/copying-custom-edid/31593

Attempted to look for upstream issues in amdgpu, but nothing seemed relevant. Google only shows other NixOS users having this issue that i can find.

Notify maintainers

Unsure, @RaitoBezarius as latest editor of stage-1.nix.
@flokli @nazarewk may have insight as maintainers of edid-generator.nix.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

% nix-shell -p nix-info --run "nix-info -m"

 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.8-zen1, NixOS, 24.05 (Uakari), 24.05.20240109.dirty`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/yxld2qw84ka591fay1xkh5jflbgxjqa1-source`

Add a 👍 reaction to issues you find important.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/copying-custom-edid/31593/24

@nazarewk
Copy link
Member

nazarewk commented Jan 9, 2024

Not sure it is the same issue, but I had to resort to some ugly hacks that I had no time to straigthen out:
https://github.com/nazarewk-iac/nix-configs/blob/48e93a44b9cca863868294db38036d3debd980da/modules/hardware/edid/default.nix

I'm on full-amd (CPU & GPU) myself and at the end got it to work just fine eventually.

As far as I remember I had 2 issues:

  1. hardware.firmware gets compressed by default and it cannot be loaded because of that
  2. hardware.firmware does not make /lib/firmware/edid available to the initrd, this is most likely your issue
I think this is the critical part to fix point 2

    # TODO: remove this "fix" at some point?
    #   see https://github.com/NixOS/nixpkgs/blob/5e4c2ada4fcd54b99d56d7bd62f384511a7e2593/nixos/modules/system/boot/systemd/initrd.nix#L383-L385
    boot.initrd.systemd.contents."/lib/firmware".source =
      let
        # "/lib/modules".source = "${modulesClosure}/lib/modules";
        modulesClosure = lib.strings.removeSuffix "/lib/modules" config.boot.initrd.systemd.contents."/lib/modules".source;

        joined = pkgs.symlinkJoin {
          name = "kdn-initrd-firmware";
          paths = [ modulesClosure generated ];
        };
      in
      lib.mkForce "${joined}/lib/firmware";

nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 9, 2024
@nazarewk nazarewk linked a pull request Jan 9, 2024 that will close this issue
13 tasks
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 9, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
@nazarewk
Copy link
Member

nazarewk commented Jan 9, 2024

thanks for motivating me to finally dig into the issue and upstream changes :)

@nazarewk
Copy link
Member

nazarewk commented Jan 9, 2024

note (for now?) you will need to add compressFirmware = false; to pkgs.runCommandNoCC "edid-custom" {} to make it work, otherwise it will not be included in initrd.

nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 9, 2024
this allows us not to pass `compressFirmware = false;`
 inside EDID derivations as this mechanic very tricky to discover.

related to NixOS#279789
related to NixOS#279739
@soupglasses
Copy link
Member Author

Applied https://github.com/NixOS/nixpkgs/commit/11e9e9bb70f8d09494ccbfbc7a6192bf733356ec.patch to my nixpkgs. It did not help. Also doing compressFirmware = false; together with it also did not help.

The boot.initrd.systemd.contents workaround also seems to not work, and does not even generate a new binary (likely because they are equivalent).

Running binwalk --verbose --term --rm against the built -initrd.efi only shows amdgpu and GenuineIntel being added to the initrd. Amdgpu comes from a linux-6.6.8-modules-shrunk which I find curious.

@nazarewk
Copy link
Member

nazarewk commented Jan 9, 2024

indeed, i must have tested it the wrong way

nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 9, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
@soupglasses
Copy link
Member Author

@nazarewk I found something interesting! While the boot fails:

% journalctl -b0 | grep edid
Jan 09 14:10:13 desktop kernel: Command line: initrd=\efi\nixos\00grk6kdy8rmcsga2lpl070hfg7w2s4m-initrd-linux-6.6.8-initrd.efi init=/nix/store/pkaql82r8ga0iad8048mg4c1j9qhhxs6-nixos-system-desktop-24.05.20240109.dirty/init drm.edid_firmware=edid/msi1462.bin mitigations=auto split_lock_detect=off loglevel=4
Jan 09 14:10:13 desktop kernel: Kernel command line: initrd=\efi\nixos\00grk6kdy8rmcsga2lpl070hfg7w2s4m-initrd-linux-6.6.8-initrd.efi init=/nix/store/pkaql82r8ga0iad8048mg4c1j9qhhxs6-nixos-system-desktop-24.05.20240109.dirty/init drm.edid_firmware=edid/msi1462.bin mitigations=auto split_lock_detect=off loglevel=4
Jan 09 14:10:13 desktop kernel: amdgpu 0000:03:00.0: Direct firmware load for edid/msi1462.bin failed with error -2
Jan 09 14:10:13 desktop kernel: amdgpu 0000:03:00.0: [drm] *ERROR* [CONNECTOR:121:DP-2] Requesting EDID firmware "edid/msi1462.bin" failed (err=-2)

Disconnecting and reconnecting the display after boot has finished does apply the custom EDID file without logging to journalctl.

@soupglasses
Copy link
Member Author

https://github.com/nazarewk/nixpkgs/commit/44b70ebd07798d94130e87cc3edd948fd1f8aebe.patch

Does function correctly for me and allows it to apply without reconnecting my monitor after boot. Thank you for figuring it out! ❤️

@nazarewk
Copy link
Member

nazarewk commented Jan 9, 2024

Disconnecting and reconnecting the display after boot has finished does apply the custom EDID file without logging to journalctl.

I am quite sure it "just works" because on a live system it's available at ls -la /run/current-system/firmware/edid/ while still missing from initrd (during boot), it gave me quite a headache when originally debugging.

@nazarewk
Copy link
Member

nazarewk commented Jan 9, 2024

there is also second PR removing need to pass compressFirmware #279828

@soupglasses
Copy link
Member Author

Here's my commit with a functional EDID loaded from initrd 🎉
soupglasses/coturnix@2c22165

@RaitoBezarius
Copy link
Member

I can review PRs but I cannot help much here, apologies.

nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 25, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 26, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 26, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 26, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 26, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jan 29, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Feb 6, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Feb 12, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Mar 11, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Mar 14, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Mar 26, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
@nazarewk nazarewk linked a pull request Mar 26, 2024 that will close this issue
13 tasks
ffinkdevs pushed a commit to ffinkdevs/nixpkgs that referenced this issue Mar 27, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Apr 2, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Apr 16, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Apr 18, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Apr 18, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue May 7, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jun 4, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
nazarewk added a commit to nazarewk/nixpkgs that referenced this issue Jun 24, 2024
modules-closure.sh seems to consider everything under
 /lib/firmware to be a kernel module,
 this change adds a special handling of `edid` directory,
 which does not contain kernel modules

fixes NixOS#279739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants