]> err.no Git - systemd/commitdiff
builtin: firmware - move 'firmware' tool to builtins
authorKay Sievers <kay.sievers@vrfy.org>
Sun, 25 Dec 2011 16:58:30 +0000 (17:58 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Sun, 25 Dec 2011 16:58:30 +0000 (17:58 +0100)
Makefile.am
NEWS
extras/firmware/.gitignore [deleted file]
extras/firmware/50-firmware.rules [deleted file]
extras/firmware/firmware.c [deleted file]
rules/rules.d/50-udev-default.rules
udev/udev-builtin-kmod.c
udev/udev-builtin.c
udev/udev.h

index 8c4ea4b0fb204647ec997873dd2c667c156237c8..769a6f5001a192500fe4454592bd97499fb49a27 100644 (file)
@@ -201,11 +201,12 @@ udev_common_sources = \
        udev/udev-rules.c \
        udev/udev-ctrl.c \
        udev/udev-builtin.c \
-       udev/udev-builtin-path_id.c \
-       udev/udev-builtin-usb_id.c \
-       udev/udev-builtin-input_id.c \
        udev/udev-builtin-blkid.c \
-       udev/udev-builtin-kmod.c
+       udev/udev-builtin-firmware.c \
+       udev/udev-builtin-input_id.c \
+       udev/udev-builtin-kmod.c \
+       udev/udev-builtin-path_id.c \
+       udev/udev-builtin-usb_id.c
 
 udev_common_CFLAGS = \
        $(BLKID_CFLAGS) \
@@ -216,6 +217,10 @@ udev_common_LDADD = \
        $(BLKID_LIBS) \
        $(KMOD_LIBS)
 
+udev_common_CPPFLAGS = \
+       $(AM_CPPFLAGS) \
+       -DFIRMWARE_PATH="$(FIRMWARE_PATH)"
+
 udev_udevd_SOURCES = \
        $(udev_common_sources) \
        udev/udevd.c \
@@ -223,6 +228,7 @@ udev_udevd_SOURCES = \
        udev/sd-daemon.c
 udev_udevd_CFLAGS = $(udev_common_CFLAGS)
 udev_udevd_LDADD = $(udev_common_LDADD)
+udev_udevd_CPPFLAGS = $(udev_common_CPPFLAGS)
 
 udev_udevadm_SOURCES = \
        $(udev_common_sources) \
@@ -236,6 +242,7 @@ udev_udevadm_SOURCES = \
        udev/udevadm-test-builtin.c
 udev_udevadm_CFLAGS = $(udev_common_CFLAGS)
 udev_udevadm_LDADD = $(udev_common_LDADD)
+udev_udevadm_CPPFLAGS = $(udev_common_CPPFLAGS)
 
 # ------------------------------------------------------------------------------
 # udev man pages
@@ -278,15 +285,7 @@ udev_test_udev_SOURCES = \
        udev/test-udev.c
 udev_test_udev_CFLAGS = $(udev_common_CFLAGS)
 udev_test_udev_LDADD = $(udev_common_LDADD)
-
-# ------------------------------------------------------------------------------
-# firmware - firmware loading
-# ------------------------------------------------------------------------------
-extras_firmware_firmware_SOURCES = extras/firmware/firmware.c
-extras_firmware_firmware_LDADD = libudev/libudev-private.la
-extras_firmware_firmware_CPPFLAGS = $(AM_CPPFLAGS) -DFIRMWARE_PATH="$(FIRMWARE_PATH)"
-dist_udevrules_DATA += extras/firmware/50-firmware.rules
-libexec_PROGRAMS += extras/firmware/firmware
+udev_test_udev_CPPFLAGS = $(udev_common_CPPFLAGS)
 
 # ------------------------------------------------------------------------------
 # ata_id - ATA identify
diff --git a/NEWS b/NEWS
index f51b811f0d79a73b09921ddccc1b72040b7cdb6e..11b3883155a9012cb1208ffe16ced35bfc4fdf6d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,11 @@ The /sbin/modprobe tool is no longer executed by udev.
 The /sbin/blkid tool is no longer executed from udev rules. Udev links
 directly to libblkid now.
 
+Firmware is loaded natively by udev now, the external firmware loading
+binary is no longer used.
+
+All built-in tools can be listed and tested with 'udevadm test-builtin'.
+
 The 'udevadm control --reload-rules' option has been renamed to '--reload'.
 It reloads the kernel module configuration.
 
diff --git a/extras/firmware/.gitignore b/extras/firmware/.gitignore
deleted file mode 100644 (file)
index 2b8800b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-firmware
diff --git a/extras/firmware/50-firmware.rules b/extras/firmware/50-firmware.rules
deleted file mode 100644 (file)
index a193adb..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# do not edit this file, it will be overwritten on update
-
-# firmware-class requests, copies files into the kernel
-SUBSYSTEM=="firmware", ACTION=="add", RUN+="firmware --firmware=$env{FIRMWARE} --devpath=$env{DEVPATH}"
diff --git a/extras/firmware/firmware.c b/extras/firmware/firmware.c
deleted file mode 100644 (file)
index 36ce790..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * firmware - Load firmware device
- *
- * Copyright (C) 2009 Piter Punk <piterpunk@slackware.com>
- * Copyright (C) 2009 Kay Sievers <kay.sievers@vrfy.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program 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
- * General Public License for more details:*
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <getopt.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <sys/utsname.h>
-#include <sys/stat.h>
-#include "libudev-private.h"
-
-static bool set_loading(struct udev *udev, char *loadpath, const char *state)
-{
-       FILE *ldfile;
-
-       ldfile = fopen(loadpath, "w");
-       if (ldfile == NULL) {
-               err(udev, "error: can not open '%s'\n", loadpath);
-               return false;
-       };
-       fprintf(ldfile, "%s\n", state);
-       fclose(ldfile);
-       return true;
-}
-
-static bool copy_firmware(struct udev *udev, const char *source, const char *target, size_t size)
-{
-       char *buf;
-       FILE *fsource = NULL, *ftarget = NULL;
-       bool ret = false;
-
-       buf = malloc(size);
-       if (buf == NULL) {
-               err(udev,"No memory available to load firmware file");
-               return false;
-       }
-
-       fsource = fopen(source, "r");
-       if (fsource == NULL)
-               goto exit;
-       ftarget = fopen(target, "w");
-       if (ftarget == NULL)
-               goto exit;
-       if (fread(buf, size, 1, fsource) != 1)
-               goto exit;
-       if (fwrite(buf, size, 1, ftarget) == 1)
-               ret = true;
-exit:
-       if (ftarget != NULL)
-               fclose(ftarget);
-       if (fsource != NULL)
-               fclose(fsource);
-       free(buf);
-       return ret;
-}
-
-int main(int argc, char **argv)
-{
-       static const struct option options[] = {
-               { "firmware", required_argument, NULL, 'f' },
-               { "devpath", required_argument, NULL, 'p' },
-               { "help", no_argument, NULL, 'h' },
-               {}
-       };
-       static const char *searchpath[] = { FIRMWARE_PATH };
-       char fwencpath[UTIL_PATH_SIZE];
-       char misspath[UTIL_PATH_SIZE];
-       char loadpath[UTIL_PATH_SIZE];
-       char datapath[UTIL_PATH_SIZE];
-       char fwpath[UTIL_PATH_SIZE];
-       char *devpath = NULL;
-       char *firmware = NULL;
-       FILE *fwfile;
-       struct utsname kernel;
-       struct stat statbuf;
-       struct udev *udev = NULL;
-       unsigned int i;
-       int rc = 0;
-
-       udev_log_init("firmware");
-
-       for (;;) {
-               int option;
-
-               option = getopt_long(argc, argv, "f:p:h", options, NULL);
-               if (option == -1)
-                       break;
-
-               switch (option) {
-               case 'f':
-                       firmware = optarg;
-                       break;
-               case 'p':
-                       devpath = optarg;
-                       break;
-               case 'h':
-                       printf("Usage: firmware --firmware=<fwfile> --devpath=<path> [--help]\n\n");
-                       goto exit;
-               }
-       }
-
-       if (devpath == NULL || firmware == NULL) {
-               fprintf(stderr, "firmware or devpath parameter missing\n\n");
-               rc = 1;
-               goto exit;
-       }
-
-       udev = udev_new();
-       if (udev == NULL) {
-               rc = 1;
-               goto exit;
-       };
-
-       /* lookup firmware file */
-       uname(&kernel);
-       for (i = 0; i < ARRAY_SIZE(searchpath); i++) {
-               util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
-               dbg(udev, "trying %s\n", fwpath);
-               fwfile = fopen(fwpath, "r");
-               if (fwfile != NULL)
-                       break; 
-
-               util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
-               dbg(udev, "trying %s\n", fwpath);
-               fwfile = fopen(fwpath, "r");
-               if (fwfile != NULL)
-                       break;
-       }
-
-       util_path_encode(firmware, fwencpath, sizeof(fwencpath));
-       util_strscpyl(misspath, sizeof(misspath), udev_get_run_path(udev), "/firmware-missing/", fwencpath, NULL);
-       util_strscpyl(loadpath, sizeof(loadpath), udev_get_sys_path(udev), devpath, "/loading", NULL);
-
-       if (fwfile == NULL) {
-               int err;
-
-               /* This link indicates the missing firmware file and the associated device */
-               info(udev, "did not find firmware file '%s'\n", firmware);
-               do {
-                       err = util_create_path(udev, misspath);
-                       if (err != 0 && err != -ENOENT)
-                               break;
-                       err = symlink(devpath, misspath);
-                       if (err != 0)
-                               err = -errno;
-               } while (err == -ENOENT);
-               rc = 2;
-               set_loading(udev, loadpath, "-1");
-               goto exit;
-       }
-
-       if (stat(fwpath, &statbuf) < 0 || statbuf.st_size == 0) {
-               rc = 3;
-               goto exit;
-       }
-       if (unlink(misspath) == 0)
-               util_delete_path(udev, misspath);
-
-       if (!set_loading(udev, loadpath, "1"))
-               goto exit;
-
-       util_strscpyl(datapath, sizeof(datapath), udev_get_sys_path(udev), devpath, "/data", NULL);
-       if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {
-               err(udev, "error sending firmware '%s' to device\n", firmware);
-               set_loading(udev, loadpath, "-1");
-               rc = 4;
-               goto exit;
-       };
-
-       set_loading(udev, loadpath, "0");
-exit:
-       udev_unref(udev);
-       udev_log_close();
-       return rc;
-}
index c47cdeceb1012d58b08b700df4a599a96f180060..353e31d8b96e4e63a0e935ed5e50bc8e24a45304 100644 (file)
@@ -103,3 +103,5 @@ SUBSYSTEM=="rtc", DRIVERS=="rtc_cmos", SYMLINK+="rtc"
 KERNEL=="mmtimer",             MODE="0644"
 KERNEL=="rflash[0-9]*",                MODE="0400"
 KERNEL=="rrom[0-9]*",          MODE="0400"
+
+SUBSYSTEM=="firmware", ACTION=="add", IMPORT{builtin}="firmware"
index 6f3e2589c242333e895de79e0522db4edff754b4..e6c4d95109f365076c35175f57d8252c2c0a2024 100644 (file)
@@ -336,7 +336,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
        }
 
        for (i = 2; argv[i]; i++) {
-               info(udev, "%s '%s'\n", argv[1], argv[i]);
+               info(udev, "execute '%s' '%s'\n", argv[1], argv[i]);
                insmod(ctx, argv[i], NULL);
        }
 
index baf09b91b9c61c86af9838dea34d3b603edea68c..cf62d57e23283b07e244abe624cb1f9046c9db9e 100644 (file)
 #include "udev.h"
 
 static const struct udev_builtin *builtins[] = {
-       [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
-       [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
-       [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
        [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
+       [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
+       [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
        [UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
+       [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
+       [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
 };
 
 int udev_builtin_init(struct udev *udev)
index 7bd2228a6b6267f5c6467f9a331f175e0c78e956..3327031e879ea4a7fbbbc2de4c4dd21f216d7f77 100644 (file)
@@ -148,11 +148,12 @@ extern const struct udevadm_cmd udevadm_test_builtin;
 
 /* built-in commands */
 enum udev_builtin_cmd {
-       UDEV_BUILTIN_PATH_ID,
-       UDEV_BUILTIN_USB_ID,
-       UDEV_BUILTIN_INPUT_ID,
        UDEV_BUILTIN_BLKID,
+       UDEV_BUILTIN_FIRMWARE,
+       UDEV_BUILTIN_INPUT_ID,
        UDEV_BUILTIN_KMOD,
+       UDEV_BUILTIN_PATH_ID,
+       UDEV_BUILTIN_USB_ID,
        UDEV_BUILTIN_MAX
 };
 struct udev_builtin {
@@ -163,11 +164,12 @@ struct udev_builtin {
        int (*exit)(struct udev *udev);
        bool run_once;
 };
-extern const struct udev_builtin udev_builtin_path_id;
-extern const struct udev_builtin udev_builtin_usb_id;
-extern const struct udev_builtin udev_builtin_input_id;
 extern const struct udev_builtin udev_builtin_blkid;
+extern const struct udev_builtin udev_builtin_firmware;
+extern const struct udev_builtin udev_builtin_input_id;
 extern const struct udev_builtin udev_builtin_kmod;
+extern const struct udev_builtin udev_builtin_path_id;
+extern const struct udev_builtin udev_builtin_usb_id;
 int udev_builtin_load(struct udev *udev);
 int udev_builtin_unload(struct udev *udev);
 enum udev_builtin_cmd udev_builtin_lookup(const char *command);