summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0016-Revert-udev-remove-userspace-firmware-loading-suppor.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/systemd/systemd/0016-Revert-udev-remove-userspace-firmware-loading-suppor.patch')
-rw-r--r--meta/recipes-core/systemd/systemd/0016-Revert-udev-remove-userspace-firmware-loading-suppor.patch364
1 files changed, 364 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd/0016-Revert-udev-remove-userspace-firmware-loading-suppor.patch b/meta/recipes-core/systemd/systemd/0016-Revert-udev-remove-userspace-firmware-loading-suppor.patch
new file mode 100644
index 0000000000..03ab0d459e
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0016-Revert-udev-remove-userspace-firmware-loading-suppor.patch
@@ -0,0 +1,364 @@
1From d3661ec7fb4557c47f001986cbb8a684b8dbae4a Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 14 Dec 2015 05:33:32 +0000
4Subject: [PATCH 16/16] 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 | 25 +++++++
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, 217 insertions(+), 3 deletions(-)
24 create mode 100644 src/udev/udev-builtin-firmware.c
25
26diff --git a/Makefile.am b/Makefile.am
27index a511c3d..6181e55 100644
28--- a/Makefile.am
29+++ b/Makefile.am
30@@ -3650,6 +3650,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 bf67f8c..87b6f70 100644
51--- a/README
52+++ b/README
53@@ -51,14 +51,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 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 369805f..ce97674 100644
73--- a/TODO
74+++ b/TODO
75@@ -635,6 +635,7 @@ Features:
76 * rename "userspace" to "core-os"
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 a3e639d..00736f5 100644
85--- a/configure.ac
86+++ b/configure.ac
87@@ -1317,6 +1317,25 @@ AC_ARG_ENABLE(hwdb, [AC_HELP_STRING([--disable-hwdb], [disable hardware database
88 AM_CONDITIONAL(ENABLE_HWDB, [test x$enable_hwdb = xyes])
89
90 # ------------------------------------------------------------------------------
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 AC_ARG_ENABLE(manpages, AS_HELP_STRING([--disable-manpages], [disable manpages]))
112 AS_IF([test "x$enable_manpages" != xno], [
113@@ -1616,6 +1635,12 @@ AC_MSG_RESULT([
114 SysV init scripts: ${SYSTEM_SYSVINIT_PATH}
115 SysV rc?.d directories: ${SYSTEM_SYSVRCND_PATH}
116 Build Python: ${PYTHON}
117+<<<<<<< HEAD
118+=======
119+ Installation Python: ${PYTHON_BINARY}
120+ sphinx binary: ${SPHINX_BUILD}
121+ firmware path: ${FIRMWARE_PATH}
122+>>>>>>> parent of be2ea72... udev: remove userspace firmware loading support
123 PAM modules dir: ${with_pamlibdir}
124 PAM configuration dir: ${with_pamconfdir}
125 D-Bus policy dir: ${with_dbuspolicydir}
126diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c
127new file mode 100644
128index 0000000..bd8c2fb
129--- /dev/null
130+++ b/src/udev/udev-builtin-firmware.c
131@@ -0,0 +1,154 @@
132+/*
133+ * firmware - Kernel firmware loader
134+ *
135+ * Copyright (C) 2009 Piter Punk <piterpunk@slackware.com>
136+ * Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org>
137+ *
138+ * This program is free software; you can redistribute it and/or
139+ * modify it under the terms of the GNU General Public License as
140+ * published by the Free Software Foundation; either version 2 of the
141+ * License, or (at your option) any later version.
142+ *
143+ * This program is distributed in the hope that it will be useful, but
144+ * WITHOUT ANY WARRANTY; without even the implied warranty of
145+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
146+ * General Public License for more details:*
147+ */
148+
149+#include <unistd.h>
150+#include <stdlib.h>
151+#include <string.h>
152+#include <stdio.h>
153+#include <getopt.h>
154+#include <errno.h>
155+#include <stdbool.h>
156+#include <sys/utsname.h>
157+#include <sys/stat.h>
158+
159+#include "udev.h"
160+
161+static bool set_loading(struct udev *udev, char *loadpath, const char *state) {
162+ FILE *ldfile;
163+
164+ ldfile = fopen(loadpath, "we");
165+ if (ldfile == NULL) {
166+ log_error("error: can not open '%s'", loadpath);
167+ return false;
168+ };
169+ fprintf(ldfile, "%s\n", state);
170+ fclose(ldfile);
171+ return true;
172+}
173+
174+static bool copy_firmware(struct udev *udev, const char *source, const char *target, size_t size) {
175+ char *buf;
176+ FILE *fsource = NULL, *ftarget = NULL;
177+ bool ret = false;
178+
179+ buf = malloc(size);
180+ if (buf == NULL) {
181+ log_error("No memory available to load firmware file");
182+ return false;
183+ }
184+
185+ log_debug("writing '%s' (%zi) to '%s'", source, size, target);
186+
187+ fsource = fopen(source, "re");
188+ if (fsource == NULL)
189+ goto exit;
190+ ftarget = fopen(target, "we");
191+ if (ftarget == NULL)
192+ goto exit;
193+ if (fread(buf, size, 1, fsource) != 1)
194+ goto exit;
195+ if (fwrite(buf, size, 1, ftarget) == 1)
196+ ret = true;
197+exit:
198+ if (ftarget != NULL)
199+ fclose(ftarget);
200+ if (fsource != NULL)
201+ fclose(fsource);
202+ free(buf);
203+ return ret;
204+}
205+
206+static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], bool test) {
207+ struct udev *udev = udev_device_get_udev(dev);
208+ static const char *searchpath[] = { FIRMWARE_PATH };
209+ char loadpath[UTIL_PATH_SIZE];
210+ char datapath[UTIL_PATH_SIZE];
211+ char fwpath[UTIL_PATH_SIZE];
212+ const char *firmware;
213+ FILE *fwfile = NULL;
214+ struct utsname kernel;
215+ struct stat statbuf;
216+ unsigned int i;
217+ int rc = EXIT_SUCCESS;
218+
219+ firmware = udev_device_get_property_value(dev, "FIRMWARE");
220+ if (firmware == NULL) {
221+ log_error("firmware parameter missing");
222+ rc = EXIT_FAILURE;
223+ goto exit;
224+ }
225+
226+ /* lookup firmware file */
227+ uname(&kernel);
228+ for (i = 0; i < ELEMENTSOF(searchpath); i++) {
229+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
230+ fwfile = fopen(fwpath, "re");
231+ if (fwfile != NULL)
232+ break;
233+
234+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
235+ fwfile = fopen(fwpath, "re");
236+ if (fwfile != NULL)
237+ break;
238+ }
239+
240+ strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
241+
242+ if (fwfile == NULL) {
243+ log_debug("did not find firmware file '%s'", firmware);
244+ rc = EXIT_FAILURE;
245+ /*
246+ * Do not cancel the request in the initrd, the real root might have
247+ * the firmware file and the 'coldplug' run in the real root will find
248+ * this pending request and fulfill or cancel it.
249+ * */
250+ if (!in_initrd())
251+ set_loading(udev, loadpath, "-1");
252+ goto exit;
253+ }
254+
255+ if (stat(fwpath, &statbuf) < 0 || statbuf.st_size == 0) {
256+ if (!in_initrd())
257+ set_loading(udev, loadpath, "-1");
258+ rc = EXIT_FAILURE;
259+ goto exit;
260+ }
261+
262+ if (!set_loading(udev, loadpath, "1"))
263+ goto exit;
264+
265+ strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL);
266+ if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {
267+ log_error("error sending firmware '%s' to device", firmware);
268+ set_loading(udev, loadpath, "-1");
269+ rc = EXIT_FAILURE;
270+ goto exit;
271+ };
272+
273+ set_loading(udev, loadpath, "0");
274+exit:
275+ if (fwfile)
276+ fclose(fwfile);
277+ return rc;
278+}
279+
280+const struct udev_builtin udev_builtin_firmware = {
281+ .name = "firmware",
282+ .cmd = builtin_firmware,
283+ .help = "kernel firmware loader",
284+ .run_once = true,
285+};
286diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c
287index 18fb661..d0280bf 100644
288--- a/src/udev/udev-builtin.c
289+++ b/src/udev/udev-builtin.c
290@@ -33,6 +33,9 @@ static const struct udev_builtin *builtins[] = {
291 [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
292 #endif
293 [UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
294+#ifdef HAVE_FIRMWARE
295+ [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
296+#endif
297 [UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
298 [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
299 [UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
300diff --git a/src/udev/udev.h b/src/udev/udev.h
301index 4f40020..8f3560f 100644
302--- a/src/udev/udev.h
303+++ b/src/udev/udev.h
304@@ -149,6 +149,9 @@ enum udev_builtin_cmd {
305 UDEV_BUILTIN_BLKID,
306 #endif
307 UDEV_BUILTIN_BTRFS,
308+#ifdef HAVE_FIRMWARE
309+ UDEV_BUILTIN_FIRMWARE,
310+#endif
311 UDEV_BUILTIN_HWDB,
312 UDEV_BUILTIN_INPUT_ID,
313 UDEV_BUILTIN_KEYBOARD,
314@@ -177,6 +180,9 @@ struct udev_builtin {
315 extern const struct udev_builtin udev_builtin_blkid;
316 #endif
317 extern const struct udev_builtin udev_builtin_btrfs;
318+#ifdef HAVE_FIRMWARE
319+extern const struct udev_builtin udev_builtin_firmware;
320+#endif
321 extern const struct udev_builtin udev_builtin_hwdb;
322 extern const struct udev_builtin udev_builtin_input_id;
323 extern const struct udev_builtin udev_builtin_keyboard;
324diff --git a/src/udev/udevd.c b/src/udev/udevd.c
325index 366e7fb..7ca1b51 100644
326--- a/src/udev/udevd.c
327+++ b/src/udev/udevd.c
328@@ -127,6 +127,9 @@ struct event {
329 bool is_block;
330 sd_event_source *timeout_warning;
331 sd_event_source *timeout;
332+#ifdef HAVE_FIRMWARE
333+ bool nodelay;
334+#endif
335 };
336
337 static inline struct event *node_to_event(struct udev_list_node *node) {
338@@ -615,6 +618,10 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
339 event->devnum = udev_device_get_devnum(dev);
340 event->is_block = streq("block", udev_device_get_subsystem(dev));
341 event->ifindex = udev_device_get_ifindex(dev);
342+#ifdef HAVE_FIRMWARE
343+ if (streq(udev_device_get_subsystem(dev), "firmware"))
344+ event->nodelay = true;
345+#endif
346
347 log_debug("seq %llu queued, '%s' '%s'", udev_device_get_seqnum(dev),
348 udev_device_get_action(dev), udev_device_get_subsystem(dev));
349@@ -700,6 +707,12 @@ static bool is_devpath_busy(Manager *manager, struct event *event) {
350 return true;
351 }
352
353+#ifdef HAVE_FIRMWARE
354+ /* allow to bypass the dependency tracking */
355+ if (event->nodelay)
356+ continue;
357+#endif
358+
359 /* parent device event found */
360 if (event->devpath[common] == '/') {
361 event->delaying_seqnum = loop_event->seqnum;
362--
3632.6.4
364