Skip to content

Commit

Permalink
libfprint-2-tod1-broadcom: init at 5.12.018
Browse files Browse the repository at this point in the history
  • Loading branch information
pitkling committed Aug 1, 2024
1 parent 994cf81 commit 25e042c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
85 changes: 85 additions & 0 deletions pkgs/by-name/li/libfprint-2-tod1-broadcom/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
autoPatchelfHook,
fetchzip,
lib,
libfprint-tod,
openssl,
patchelfUnstable, # have to use patchelfUnstable to support --rename-dynamic-symbols
stdenv,
}:

# Based on ideas from (using a wrapper library to redirect fopen() calls to firmware files):
# * https://tapesoftware.net/replace-symbol/
# * https://github.com/NixOS/nixpkgs/pull/260715
let
pname = "libfprint-2-tod1-broadcom";
version = "5.12.018";

src = fetchzip {
url = "http://dell.archive.canonical.com/updates/pool/public/libf/${pname}/${pname}_${version}.orig.tar.gz";
hash = "sha256-0C2PpYpEJNrU+8NT95w4QV0J5nHQisMY94Czw3jQOzw=";
pname = "${pname}-unpacked";
inherit version;
};

# wraps `fopen()` for finding firmware files
wrapperLibName = "wrapper-lib.so";
wrapperLib = stdenv.mkDerivation {
pname = "${pname}-wrapper-lib";
inherit version;

src = ./.;

postPatch = ''
substitute wrapper-lib.c lib.c \
--subst-var-by to "${src}/var/lib/fprint/fw"
cc -fPIC -shared lib.c -o ${wrapperLibName}
'';

installPhase = ''
runHook preInstall
install -D -t $out/lib ${wrapperLibName}
runHook postInstall
'';
};
in
stdenv.mkDerivation {
inherit src pname version;

buildInputs = [
libfprint-tod
openssl
wrapperLib
];

nativeBuildInputs = [
autoPatchelfHook
patchelfUnstable
];

installPhase = ''
runHook preInstall
install -D -t "$out/lib/libfprint-2/tod-1/" -m 644 -v usr/lib/x86_64-linux-gnu/libfprint-2/tod-1/libfprint-2-tod-1-broadcom.so
install -D -t "$out/lib/udev/rules.d/" -m 644 -v lib/udev/rules.d/60-libfprint-2-device-broadcom.rules
runHook postInstall
'';

postFixup = ''
echo fopen64 fopen_wrapper > fopen_name_map
patchelf \
--rename-dynamic-symbols fopen_name_map \
--add-needed ${wrapperLibName} \
"$out/lib/libfprint-2/tod-1/libfprint-2-tod-1-broadcom.so"
'';

passthru.driverPath = "/lib/libfprint-2/tod-1";

meta = with lib; {
description = "Broadcom driver module for libfprint-2-tod Touch OEM Driver (from Dell)";
homepage = "http://dell.archive.canonical.com/updates/pool/public/libf/libfprint-2-tod1-broadcom/";
license = licenses.unfree;
maintainers = with maintainers; [ pitkling ];
platforms = [ "x86_64-linux" ];
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
};
}
23 changes: 23 additions & 0 deletions pkgs/by-name/li/libfprint-2-tod1-broadcom/wrapper-lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const char from[] = "/var/lib/fprint/fw";
static const char to[] = "@to@";

FILE* fopen_wrapper(const char* fn, const char* mode) {
size_t fn_len = strlen(fn);
size_t from_len = strlen(from);
if (fn_len > from_len && memcmp(fn, from, from_len) == 0) {
size_t to_len = strlen(to);
char* rewritten = calloc(fn_len + (to_len - from_len) + 1, 1);
memcpy(rewritten, to, to_len);
memcpy(rewritten + to_len, fn + from_len, fn_len - from_len);

printf("fopen_wrapper.c: Replacing path '%s' with '%s'\n", fn, rewritten);
FILE* result = fopen(rewritten, mode);
free(rewritten);
return result;
}
return fopen(fn, mode);
}

6 comments on commit 25e042c

@ahydronous
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pitkling the current libfprint-2-tod1-broadcom doesn't work from a Dell 7300 (typing it on one right now), even on NixOS-unstable. Reading this AUR post it seems an older upstream commit needs to be pulled in for it work correctly.

@pitkling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up, @ahydronous! Can you open an issue for this?

In the meantime: I was actually not aware that Dell uses a git repository on launchpad for their fingerprint drivers but thought that http://dell.archive.canonical.com/updates/pool/public/libf/libfprint-2-tod1-broadcom/ is the official driver source. But from what I can see in the launchpad repository, there is a new driver version (6.1.26, on the upstream branch) that adds support for some new devices. I assume your Dell 7300 uses a fingerprint sensor with one of the new model numbers 0a5c:5864, 0a5c:5865, 0a5c:5866, or 0a5c:5867? (You can check with lsusb | grep Broadcom.)

I did a quick update of the driver package on my fork under the branch libfprint-2-tod1-broadcom-update to pull in the new drivers. They added a new dynamic library for the new drivers, which I patched with my wrapper (not yet sure whether that's actually needed).

I cannot test it myself, since I don't have one of the new devices at hand. Could you give it a try and let me know whether it works?

@ahydronous
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My device is Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200.

However, with the current package with fprintd-verify I get Impossible to verify: GDBus.Error:net.reactivated.Fprint.Error.NoSuchDevice: No devices available, even if rebooted after a rebuild.

# Fingerprint sensor
## https://wiki.archlinux.org/title/Fprint
services.fprintd = {
  enable = true;
  package = pkgs.fprintd-tod;
  tod.enable = true;
  # Search for "libfprint" in packages to find other drivers
  tod.driver = pkgs.libfprint-2-tod1-broadcom;
};

This is the full piece of code I use in my configuration.nix

I'll test your branch and see if that fixes it!

@pitkling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange, 0a5c:5842 should actually work, it's not one of the new devices. Your config looks fine, although you can omit the package = … part, since it's default value takes services.fprintd.tod.enable into account and adjusts accordingly.

Please test the branch anyway, just to be sure. But I suspect it won't work either.

@ahydronous
Copy link

@ahydronous ahydronous commented on 25e042c Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps its because I have secure boot turned off or something, I'll dig in my BIOs settings. Checking dmesg I get

[    6.198839] usb 1-8: new high-speed USB device number 3 using xhci_hcd
[    6.327177] BTRFS: device label root devid 1 transid 13382 /dev/nvme0n1p2 (259:2) scanned by mount (224)
[    6.328084] usb 1-8: New USB device found, idVendor=0a5c, idProduct=5842, bcdDevice= 1.01
[    6.328120] usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    6.328138] usb 1-8: Product: 58200
[    6.328152] usb 1-8: Manufacturer: Broadcom Corp
[    6.328165] usb 1-8: SerialNumber: 0123456789ABCD (lolwut)

I must admit I'm still a bit of a nixos neophyte, seems I can't get your package to work with an override..

I tried doing

environment.systemPackages = with pkgs; [
  (pkgs.libfprint-2-tod1-broadcom.overrideAttrs (old: {
      src = pkgs.fetchFromGitHub {
        owner = "pitkling";
        repo = "nixpkgs";
        rev = "f8690dcfd4f8fbbdd58eb8599f9610218e1882fa";
        sha256 = "sha256-6NV1l0pHVKMaGQPjMdbI9GxQB8J7MXMy+noB6I4dOCA=";
        fetchSubmodules = true;
      };
  }))
];

along with the config I did earlier, but it breaks down with the error

Running phase: installPhase
install: creating directory '/nix/store/9vca3x7i4kbw7dpc0zwawwfqkkpmppw5-libfprint-2-tod1-broadcom-5.12.018'
install: creating directory '/nix/store/9vca3x7i4kbw7dpc0zwawwfqkkpmppw5-libfprint-2-tod1-broadcom-5.12.018/lib'
install: creating directory '/nix/store/9vca3x7i4kbw7dpc0zwawwfqkkpmppw5-libfprint-2-tod1-broadcom-5.12.018/lib/libfprint-2'
install: creating directory '/nix/store/9vca3x7i4kbw7dpc0zwawwfqkkpmppw5-libfprint-2-tod1-broadcom-5.12.018/lib/libfprint-2/tod-1'
install: cannot stat 'usr/lib/x86_64-linux-gnu/libfprint-2/tod-1/libfprint-2-tod-1-broadcom.so': No such file or directory
error: builder for '/nix/store/2x4kz28g6wn5j74g89d1x8dxvm9yd7d7-libfprint-2-tod1-broadcom-5.12.018.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/ng1sw0g6mhjja309lcd8gvm8bny2wvba-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/95m6jpp9w4005xqcj34dl1x7aj069jz7-nixos-system-lapjv-24.11pre681973.99dc8785f6a0.drv' failed to build

I understand if this is getting too much of a bother for you haha..

@pitkling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. If it turns out to be a general issue with the package I'll fix it, but right now I'm not sure whether the problem lies somewhere else. The overrideAttrs-Method you're using won't work here. The src attribute your overwriting is actually referring to the driver package, it's not the source of my package. If you're using a flake-based configuration, you should be able to use my fork as an input and import the package. Otherwise, the easiest road might be to download the whole package directory nixpkgs/pkgs/by-name/li/libfprint-2-tod1-broadcom and add the derivation yourself via an appropriate callPackage ./<path-to-downloaded-dir>/pacakge.nix { } call.

Anyway, given that the fork adds only drivers for new devices (not your 0a5c:5842) it's probably not worth the hassle. I think it's better to first check for some other potential problems. Anything else in dmesg that might be related? What about lsusb -v -d 0a5c:5842 and journalctl -u fprintd (maybe after a manual fprintd-list / fprintd-enroll)?

Please sign in to comment.