list-udev-rules: Add udev rule generation for SPI

This commit is contained in:
Benjamin Berg 2021-06-22 14:51:26 +02:00 committed by Benjamin Berg
parent 4bcb55e412
commit 9dd72611bf
4 changed files with 128 additions and 1 deletions

View File

@ -0,0 +1,93 @@
/*
* Copyright (C) 2009 Red Hat <mjg@redhat.com>
* Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
* Copyright (C) 2008 Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
* Coypright (C) 2019 Benjamin Berg <bberg@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "fpi-context.h"
#include "fpi-device.h"
GHashTable *printed = NULL;
static void
print_driver (const FpDeviceClass *cls)
{
const FpIdEntry *entry;
gint num_printed = 0;
if (cls->type != FP_DEVICE_TYPE_UDEV)
return;
for (entry = cls->id_table; entry->udev_types != 0; entry++)
{
/* We only add rules for spidev right now. */
if ((entry->udev_types & FPI_DEVICE_UDEV_SUBTYPE_SPIDEV) == 0)
continue;
if (g_hash_table_lookup (printed, entry->spi_acpi_id) != NULL)
continue;
g_hash_table_insert (printed, g_strdup (entry->spi_acpi_id), GINT_TO_POINTER (1));
if (num_printed == 0)
g_print ("# %s\n", cls->full_name);
g_print ("ACTION==\"add|change\", SUBSYSTEM==\"spi\", ENV{MODALIAS}==\"acpi:%s:\", RUN{builtin}+=\"kmod load spi:spidev\", RUN+=\"/bin/sh -c 'echo spidev > %%S%%p/driver_override && echo %%k > %%S%%p/subsystem/drivers/spidev/bind'\"\n",
entry->spi_acpi_id);
num_printed++;
}
if (num_printed > 0)
g_print ("\n");
}
int
main (int argc, char **argv)
{
g_autoptr(GArray) drivers = fpi_get_driver_types ();
guint i;
printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
g_print ("# This file is part of libfprint\n");
g_print ("# Do not modify this file, it will get overwritten on updates.\n");
g_print ("# To override or extend the rules place a file in /etc/udev/rules.d\n");
g_print ("\n");
for (i = 0; i < drivers->len; i++)
{
GType driver = g_array_index (drivers, GType, i);
FpDeviceClass *cls = FP_DEVICE_CLASS (g_type_class_ref (driver));
if (cls->type != FP_DEVICE_TYPE_UDEV)
{
g_type_class_unref (cls);
continue;
}
print_driver (cls);
g_type_class_unref (cls);
}
g_hash_table_destroy (printed);
return 0;
}

View File

@ -329,6 +329,23 @@ udev_hwdb_generator = custom_target('udev-hwdb',
install: false,
)
if udev_rules
udev_rules = executable('fprint-list-udev-rules',
'fprint-list-udev-rules.c',
dependencies: libfprint_private_dep,
link_with: libfprint_drivers,
install: false)
custom_target('udev-rules',
output: '70-@0@.rules'.format(versioned_libname),
depend_files: drivers_sources,
capture: true,
command: [ udev_rules ],
install: true,
install_dir: udev_rules_dir,
)
endif
custom_target('sync-udev-hwdb',
depends: udev_hwdb_generator,
output: 'sync-udev-hwdb',

View File

@ -164,6 +164,9 @@ nss_dep = dependency('', required: false)
imaging_dep = dependency('', required: false)
gudev_dep = dependency('', required: false)
libfprint_conf.set10('HAVE_PIXMAN', false)
udev_rules = false
foreach driver: drivers
if driver == 'uru4000'
nss_dep = dependency('nss', required: false)
@ -180,6 +183,8 @@ foreach driver: drivers
libfprint_conf.set10('HAVE_PIXMAN', true)
endif
if udev_drivers.contains(driver)
udev_rules = true
gudev_dep = dependency('gudev-1.0', required: false)
if not gudev_dep.found()
error('udev is required for SPI support')
@ -192,6 +197,14 @@ foreach driver: drivers
endif
endforeach
if udev_rules
udev_rules_dir = get_option('udev_rules_dir')
if udev_rules_dir == 'auto'
udev_dep = dependency('udev')
udev_rules_dir = udev_dep.get_pkgconfig_variable('udevdir') + '/hwdb.d'
endif
endif
supported_drivers = []
foreach driver: drivers
if build_machine.endian() == 'little' or driver in endian_independent_drivers

View File

@ -6,8 +6,12 @@ option('introspection',
description: 'Build GObject Introspection repository',
type: 'boolean',
value: true)
option('udev_rules_dir',
description: 'Installation path for udev rules',
type: 'string',
value: 'auto')
option('udev_hwdb',
description: 'Whether to create a udev hwdb',
description: 'Whether to create a udev hwdb for autosuspend (included in systemd v248 and later)',
type: 'feature',
value: 'auto')
option('udev_hwdb_dir',