summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0015-Revert-udev-remove-userspace-firmware-loading-suppor.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/systemd/systemd/0015-Revert-udev-remove-userspace-firmware-loading-suppor.patch')
-rw-r--r--meta/recipes-core/systemd/systemd/0015-Revert-udev-remove-userspace-firmware-loading-suppor.patch357
1 files changed, 357 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd/0015-Revert-udev-remove-userspace-firmware-loading-suppor.patch b/meta/recipes-core/systemd/systemd/0015-Revert-udev-remove-userspace-firmware-loading-suppor.patch
new file mode 100644
index 0000000000..f31d211e76
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0015-Revert-udev-remove-userspace-firmware-loading-suppor.patch
@@ -0,0 +1,357 @@
1From 4d28d9a7d8d69fb429955d770e53e7a81640da24 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 9 Nov 2016 20:45:23 -0800
4Subject: [PATCH 15/19] Revert "udev: remove userspace firmware loading
5 support"
6
7This reverts commit be2ea723b1d023b3d385d3b791ee4607cbfb20ca.
8Userspace firmware loading support is needed for Linux < 3.7.
9
10Upstream-Status: Inappropriate [OE specific]
11
12Signed-off-by: Jonathan Liu <net147@gmail.com>
13Signed-off-by: Khem Raj <raj.khem@gmail.com>
14---
15 Makefile.am | 12 +++
16 README | 6 +-
17 TODO | 1 +
18 configure.ac | 18 +++++
19 src/udev/udev-builtin-firmware.c | 154 +++++++++++++++++++++++++++++++++++++++
20 src/udev/udev-builtin.c | 3 +
21 src/udev/udev.h | 6 ++
22 src/udev/udevd.c | 13 ++++
23 8 files changed, 210 insertions(+), 3 deletions(-)
24 create mode 100644 src/udev/udev-builtin-firmware.c
25
26diff --git a/Makefile.am b/Makefile.am
27index 3010b01..229492a 100644
28--- a/Makefile.am
29+++ b/Makefile.am
30@@ -3791,6 +3791,18 @@ libudev_core_la_LIBADD = \
31 $(BLKID_LIBS) \
32 $(KMOD_LIBS)
33
34+libudev_core_la_CPPFLAGS = \
35+ $(AM_CPPFLAGS) \
36+ -DFIRMWARE_PATH="$(FIRMWARE_PATH)"
37+
38+if ENABLE_FIRMWARE
39+libudev_core_la_SOURCES += \
40+ src/udev/udev-builtin-firmware.c
41+
42+dist_udevrules_DATA += \
43+ rules/50-firmware.rules
44+endif
45+
46 if HAVE_KMOD
47 libudev_core_la_SOURCES += \
48 src/udev/udev-builtin-kmod.c
49diff --git a/README b/README
50index 9f5bc93..f60ae11 100644
51--- a/README
52+++ b/README
53@@ -50,14 +50,14 @@ REQUIREMENTS:
54 CONFIG_PROC_FS
55 CONFIG_FHANDLE (libudev, mount and bind mount handling)
56
57- udev will fail to work with the legacy sysfs layout:
58+ Udev will fail to work with the legacy sysfs layout:
59 CONFIG_SYSFS_DEPRECATED=n
60
61 Legacy hotplug slows down the system and confuses udev:
62 CONFIG_UEVENT_HELPER_PATH=""
63
64- Userspace firmware loading is not supported and should
65- be disabled in the kernel:
66+ Userspace firmware loading is deprecated, will go away, and
67+ sometimes causes problems:
68 CONFIG_FW_LOADER_USER_HELPER=n
69
70 Some udev rules and virtualization detection relies on it:
71diff --git a/TODO b/TODO
72index baaac94..1ab1691 100644
73--- a/TODO
74+++ b/TODO
75@@ -658,6 +658,7 @@ Features:
76 * initialize the hostname from the fs label of /, if /etc/hostname does not exist?
77
78 * udev:
79+ - remove src/udev/udev-builtin-firmware.c (CONFIG_FW_LOADER_USER_HELPER=n)
80 - move to LGPL
81 - kill scsi_id
82 - add trigger --subsystem-match=usb/usb_device device
83diff --git a/configure.ac b/configure.ac
84index dfc0bd3..1de0066 100644
85--- a/configure.ac
86+++ b/configure.ac
87@@ -1394,6 +1394,23 @@ AM_CONDITIONAL(HAVE_MYHOSTNAME, [test "$have_myhostname" = "yes"])
88 AC_ARG_ENABLE(hwdb, [AC_HELP_STRING([--disable-hwdb], [disable hardware database support])],
89 enable_hwdb=$enableval, enable_hwdb=yes)
90 AM_CONDITIONAL(ENABLE_HWDB, [test x$enable_hwdb = xyes])
91+AC_ARG_WITH(firmware-path,
92+ AS_HELP_STRING([--with-firmware-path=DIR[[[:DIR[...]]]]],
93+ [Firmware search path (default="")]),
94+ [], [with_firmware_path=""])
95+OLD_IFS=$IFS
96+IFS=:
97+for i in $with_firmware_path; do
98+ if test "x${FIRMWARE_PATH}" = "x"; then
99+ FIRMWARE_PATH="\\\"${i}/\\\""
100+ else
101+ FIRMWARE_PATH="${FIRMWARE_PATH}, \\\"${i}/\\\""
102+ fi
103+done
104+IFS=$OLD_IFS
105+AC_SUBST(FIRMWARE_PATH)
106+AS_IF([test "x${FIRMWARE_PATH}" != "x"], [ AC_DEFINE(HAVE_FIRMWARE, 1, [Define if FIRMWARE is available]) ])
107+AM_CONDITIONAL(ENABLE_FIRMWARE, [test "x${FIRMWARE_PATH}" != "x"])
108
109 # ------------------------------------------------------------------------------
110 have_manpages=no
111@@ -1698,6 +1715,7 @@ AC_MSG_RESULT([
112 SysV init scripts: ${SYSTEM_SYSVINIT_PATH}
113 SysV rc?.d directories: ${SYSTEM_SYSVRCND_PATH}
114 Build Python: ${PYTHON}
115+ firmware path: ${FIRMWARE_PATH}
116 PAM modules dir: ${with_pamlibdir}
117 PAM configuration dir: ${with_pamconfdir}
118 D-Bus policy dir: ${with_dbuspolicydir}
119diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c
120new file mode 100644
121index 0000000..bd8c2fb
122--- /dev/null
123+++ b/src/udev/udev-builtin-firmware.c
124@@ -0,0 +1,154 @@
125+/*
126+ * firmware - Kernel firmware loader
127+ *
128+ * Copyright (C) 2009 Piter Punk <piterpunk@slackware.com>
129+ * Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org>
130+ *
131+ * This program is free software; you can redistribute it and/or
132+ * modify it under the terms of the GNU General Public License as
133+ * published by the Free Software Foundation; either version 2 of the
134+ * License, or (at your option) any later version.
135+ *
136+ * This program is distributed in the hope that it will be useful, but
137+ * WITHOUT ANY WARRANTY; without even the implied warranty of
138+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
139+ * General Public License for more details:*
140+ */
141+
142+#include <unistd.h>
143+#include <stdlib.h>
144+#include <string.h>
145+#include <stdio.h>
146+#include <getopt.h>
147+#include <errno.h>
148+#include <stdbool.h>
149+#include <sys/utsname.h>
150+#include <sys/stat.h>
151+
152+#include "udev.h"
153+
154+static bool set_loading(struct udev *udev, char *loadpath, const char *state) {
155+ FILE *ldfile;
156+
157+ ldfile = fopen(loadpath, "we");
158+ if (ldfile == NULL) {
159+ log_error("error: can not open '%s'", loadpath);
160+ return false;
161+ };
162+ fprintf(ldfile, "%s\n", state);
163+ fclose(ldfile);
164+ return true;
165+}
166+
167+static bool copy_firmware(struct udev *udev, const char *source, const char *target, size_t size) {
168+ char *buf;
169+ FILE *fsource = NULL, *ftarget = NULL;
170+ bool ret = false;
171+
172+ buf = malloc(size);
173+ if (buf == NULL) {
174+ log_error("No memory available to load firmware file");
175+ return false;
176+ }
177+
178+ log_debug("writing '%s' (%zi) to '%s'", source, size, target);
179+
180+ fsource = fopen(source, "re");
181+ if (fsource == NULL)
182+ goto exit;
183+ ftarget = fopen(target, "we");
184+ if (ftarget == NULL)
185+ goto exit;
186+ if (fread(buf, size, 1, fsource) != 1)
187+ goto exit;
188+ if (fwrite(buf, size, 1, ftarget) == 1)
189+ ret = true;
190+exit:
191+ if (ftarget != NULL)
192+ fclose(ftarget);
193+ if (fsource != NULL)
194+ fclose(fsource);
195+ free(buf);
196+ return ret;
197+}
198+
199+static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], bool test) {
200+ struct udev *udev = udev_device_get_udev(dev);
201+ static const char *searchpath[] = { FIRMWARE_PATH };
202+ char loadpath[UTIL_PATH_SIZE];
203+ char datapath[UTIL_PATH_SIZE];
204+ char fwpath[UTIL_PATH_SIZE];
205+ const char *firmware;
206+ FILE *fwfile = NULL;
207+ struct utsname kernel;
208+ struct stat statbuf;
209+ unsigned int i;
210+ int rc = EXIT_SUCCESS;
211+
212+ firmware = udev_device_get_property_value(dev, "FIRMWARE");
213+ if (firmware == NULL) {
214+ log_error("firmware parameter missing");
215+ rc = EXIT_FAILURE;
216+ goto exit;
217+ }
218+
219+ /* lookup firmware file */
220+ uname(&kernel);
221+ for (i = 0; i < ELEMENTSOF(searchpath); i++) {
222+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
223+ fwfile = fopen(fwpath, "re");
224+ if (fwfile != NULL)
225+ break;
226+
227+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
228+ fwfile = fopen(fwpath, "re");
229+ if (fwfile != NULL)
230+ break;
231+ }
232+
233+ strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
234+
235+ if (fwfile == NULL) {
236+ log_debug("did not find firmware file '%s'", firmware);
237+ rc = EXIT_FAILURE;
238+ /*
239+ * Do not cancel the request in the initrd, the real root might have
240+ * the firmware file and the 'coldplug' run in the real root will find
241+ * this pending request and fulfill or cancel it.
242+ * */
243+ if (!in_initrd())
244+ set_loading(udev, loadpath, "-1");
245+ goto exit;
246+ }
247+
248+ if (stat(fwpath, &statbuf) < 0 || statbuf.st_size == 0) {
249+ if (!in_initrd())
250+ set_loading(udev, loadpath, "-1");
251+ rc = EXIT_FAILURE;
252+ goto exit;
253+ }
254+
255+ if (!set_loading(udev, loadpath, "1"))
256+ goto exit;
257+
258+ strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL);
259+ if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {
260+ log_error("error sending firmware '%s' to device", firmware);
261+ set_loading(udev, loadpath, "-1");
262+ rc = EXIT_FAILURE;
263+ goto exit;
264+ };
265+
266+ set_loading(udev, loadpath, "0");
267+exit:
268+ if (fwfile)
269+ fclose(fwfile);
270+ return rc;
271+}
272+
273+const struct udev_builtin udev_builtin_firmware = {
274+ .name = "firmware",
275+ .cmd = builtin_firmware,
276+ .help = "kernel firmware loader",
277+ .run_once = true,
278+};
279diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c
280index e6b36f1..cd9947e 100644
281--- a/src/udev/udev-builtin.c
282+++ b/src/udev/udev-builtin.c
283@@ -31,6 +31,9 @@ static const struct udev_builtin *builtins[] = {
284 [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
285 #endif
286 [UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
287+#ifdef HAVE_FIRMWARE
288+ [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
289+#endif
290 [UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
291 [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
292 [UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
293diff --git a/src/udev/udev.h b/src/udev/udev.h
294index 8433e8d..d32366d 100644
295--- a/src/udev/udev.h
296+++ b/src/udev/udev.h
297@@ -148,6 +148,9 @@ enum udev_builtin_cmd {
298 UDEV_BUILTIN_BLKID,
299 #endif
300 UDEV_BUILTIN_BTRFS,
301+#ifdef HAVE_FIRMWARE
302+ UDEV_BUILTIN_FIRMWARE,
303+#endif
304 UDEV_BUILTIN_HWDB,
305 UDEV_BUILTIN_INPUT_ID,
306 UDEV_BUILTIN_KEYBOARD,
307@@ -176,6 +179,9 @@ struct udev_builtin {
308 extern const struct udev_builtin udev_builtin_blkid;
309 #endif
310 extern const struct udev_builtin udev_builtin_btrfs;
311+#ifdef HAVE_FIRMWARE
312+extern const struct udev_builtin udev_builtin_firmware;
313+#endif
314 extern const struct udev_builtin udev_builtin_hwdb;
315 extern const struct udev_builtin udev_builtin_input_id;
316 extern const struct udev_builtin udev_builtin_keyboard;
317diff --git a/src/udev/udevd.c b/src/udev/udevd.c
318index d336ee0..81e5dc5 100644
319--- a/src/udev/udevd.c
320+++ b/src/udev/udevd.c
321@@ -125,6 +125,9 @@ struct event {
322 bool is_block;
323 sd_event_source *timeout_warning;
324 sd_event_source *timeout;
325+#ifdef HAVE_FIRMWARE
326+ bool nodelay;
327+#endif
328 };
329
330 static inline struct event *node_to_event(struct udev_list_node *node) {
331@@ -613,6 +616,10 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
332 event->devnum = udev_device_get_devnum(dev);
333 event->is_block = streq("block", udev_device_get_subsystem(dev));
334 event->ifindex = udev_device_get_ifindex(dev);
335+#ifdef HAVE_FIRMWARE
336+ if (streq(udev_device_get_subsystem(dev), "firmware"))
337+ event->nodelay = true;
338+#endif
339
340 log_debug("seq %llu queued, '%s' '%s'", udev_device_get_seqnum(dev),
341 udev_device_get_action(dev), udev_device_get_subsystem(dev));
342@@ -698,6 +705,12 @@ static bool is_devpath_busy(Manager *manager, struct event *event) {
343 return true;
344 }
345
346+#ifdef HAVE_FIRMWARE
347+ /* allow to bypass the dependency tracking */
348+ if (event->nodelay)
349+ continue;
350+#endif
351+
352 /* parent device event found */
353 if (event->devpath[common] == '/') {
354 event->delaying_seqnum = loop_event->seqnum;
355--
3562.10.2
357