summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0008-Revert-udev-remove-userspace-firmware-loading-suppor.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/systemd/systemd/0008-Revert-udev-remove-userspace-firmware-loading-suppor.patch')
-rw-r--r--meta/recipes-core/systemd/systemd/0008-Revert-udev-remove-userspace-firmware-loading-suppor.patch377
1 files changed, 0 insertions, 377 deletions
diff --git a/meta/recipes-core/systemd/systemd/0008-Revert-udev-remove-userspace-firmware-loading-suppor.patch b/meta/recipes-core/systemd/systemd/0008-Revert-udev-remove-userspace-firmware-loading-suppor.patch
deleted file mode 100644
index 15d7e0290a..0000000000
--- a/meta/recipes-core/systemd/systemd/0008-Revert-udev-remove-userspace-firmware-loading-suppor.patch
+++ /dev/null
@@ -1,377 +0,0 @@
1From 5cce7626f33e92f624ac06b613125813fb47d445 Mon Sep 17 00:00:00 2001
2From: Chen Qi <Qi.Chen@windriver.com>
3Date: Wed, 28 Feb 2018 21:05:39 -0800
4Subject: [PATCH 08/31] 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>
14Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
15---
16 README | 4 +-
17 TODO | 1 +
18 meson.build | 9 +++
19 meson_options.txt | 2 +
20 rules/meson.build | 4 +
21 src/udev/meson.build | 4 +
22 src/udev/udev-builtin-firmware.c | 154 +++++++++++++++++++++++++++++++++++++++
23 src/udev/udev-builtin.c | 3 +
24 src/udev/udev.h | 6 ++
25 src/udev/udevd.c | 12 +++
26 10 files changed, 197 insertions(+), 2 deletions(-)
27 create mode 100644 src/udev/udev-builtin-firmware.c
28
29diff --git a/README b/README
30index 8807e5cfe..bfd7a35de 100644
31--- a/README
32+++ b/README
33@@ -58,8 +58,8 @@ REQUIREMENTS:
34 Legacy hotplug slows down the system and confuses udev:
35 CONFIG_UEVENT_HELPER_PATH=""
36
37- Userspace firmware loading is not supported and should
38- be disabled in the kernel:
39+ Userspace firmware loading is deprecated, will go away, and
40+ sometimes causes problems:
41 CONFIG_FW_LOADER_USER_HELPER=n
42
43 Some udev rules and virtualization detection relies on it:
44diff --git a/TODO b/TODO
45index a77028c7b..39e72d7ec 100644
46--- a/TODO
47+++ b/TODO
48@@ -783,6 +783,7 @@ Features:
49 * initialize the hostname from the fs label of /, if /etc/hostname does not exist?
50
51 * udev:
52+ - remove src/udev/udev-builtin-firmware.c (CONFIG_FW_LOADER_USER_HELPER=n)
53 - move to LGPL
54 - kill scsi_id
55 - add trigger --subsystem-match=usb/usb_device device
56diff --git a/meson.build b/meson.build
57index 918101d6b..9c25022a4 100644
58--- a/meson.build
59+++ b/meson.build
60@@ -72,6 +72,12 @@ conf.set10('HAVE_SYSV_COMPAT', have,
61 description : 'SysV init scripts and rcN.d links are supported')
62 m4_defines += have ? ['-DHAVE_SYSV_COMPAT'] : []
63
64+firmware_path = get_option('firmware-path')
65+have = firmware_path != ''
66+conf.set10('HAVE_FIRMWARE', have,
67+ description : 'Userspace firmware loading is supported')
68+m4_defines += have ? ['-DHAVE_FIRMWARE'] : []
69+
70 # join_paths ignore the preceding arguments if an absolute component is
71 # encountered, so this should canonicalize various paths when they are
72 # absolute or relative.
73@@ -178,6 +184,7 @@ conf.set_quoted('SYSTEM_CONFIG_UNIT_PATH', join_paths(pkgsysc
74 conf.set_quoted('SYSTEM_DATA_UNIT_PATH', systemunitdir)
75 conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path)
76 conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path)
77+conf.set_quoted('FIRMWARE_PATH', firmware_path)
78 conf.set_quoted('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-local'))
79 conf.set_quoted('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-local'))
80 conf.set_quoted('USER_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'user'))
81@@ -258,6 +265,7 @@ substs.set('SYSTEMCTL', join_paths(rootbin
82 substs.set('RANDOM_SEED', join_paths(randomseeddir, 'random-seed'))
83 substs.set('SYSTEM_SYSVINIT_PATH', sysvinit_path)
84 substs.set('SYSTEM_SYSVRCND_PATH', sysvrcnd_path)
85+substs.set('FIRMWARE_PATH', firmware_path)
86 substs.set('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-local'))
87 substs.set('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-local'))
88
89@@ -2715,6 +2723,7 @@ status = [
90 'roothome directory: @0@'.format(roothomedir),
91 'SysV init scripts: @0@'.format(sysvinit_path),
92 'SysV rc?.d directories: @0@'.format(sysvrcnd_path),
93+ 'firmware path: @0@'.format(firmware_path),
94 'PAM modules directory: @0@'.format(pamlibdir),
95 'PAM configuration directory: @0@'.format(pamconfdir),
96 'RPM macros directory: @0@'.format(rpmmacrosdir),
97diff --git a/meson_options.txt b/meson_options.txt
98index 0b24f0e0f..92d25fa35 100644
99--- a/meson_options.txt
100+++ b/meson_options.txt
101@@ -108,6 +108,8 @@ option('tmpfiles', type : 'boolean',
102 description : 'support for tmpfiles.d')
103 option('importd', type : 'combo', choices : ['auto', 'true', 'false'],
104 description : 'install the systemd-importd daemon')
105+option('firmware-path', type : 'string', value : '',
106+ description : 'Firmware search path')
107 option('hwdb', type : 'boolean',
108 description : 'support for the hardware database')
109 option('rfkill', type : 'boolean',
110diff --git a/rules/meson.build b/rules/meson.build
111index e253b9f59..5eee5fbca 100644
112--- a/rules/meson.build
113+++ b/rules/meson.build
114@@ -41,6 +41,10 @@ rules = files('''
115 install_data(rules,
116 install_dir : udevrulesdir)
117
118+if conf.get('HAVE_FIRMWARE') == 1
119+ install_data('50-firmware.rules', install_dir : udevrulesdir)
120+endif
121+
122 all_rules = rules
123
124 rules_in = '''
125diff --git a/src/udev/meson.build b/src/udev/meson.build
126index de2fd2d9c..b6b0ca006 100644
127--- a/src/udev/meson.build
128+++ b/src/udev/meson.build
129@@ -67,6 +67,10 @@ if conf.get('HAVE_ACL') == 1
130 sd_login_c]
131 endif
132
133+if conf.get('HAVE_FIRMWARE') == 1
134+ libudev_core_sources += ['udev-builtin-firmware.c']
135+endif
136+
137 ############################################################
138
139 generate_keyboard_keys_list = find_program('generate-keyboard-keys-list.sh')
140diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c
141new file mode 100644
142index 000000000..bd8c2fb96
143--- /dev/null
144+++ b/src/udev/udev-builtin-firmware.c
145@@ -0,0 +1,154 @@
146+/*
147+ * firmware - Kernel firmware loader
148+ *
149+ * Copyright (C) 2009 Piter Punk <piterpunk@slackware.com>
150+ * Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org>
151+ *
152+ * This program is free software; you can redistribute it and/or
153+ * modify it under the terms of the GNU General Public License as
154+ * published by the Free Software Foundation; either version 2 of the
155+ * License, or (at your option) any later version.
156+ *
157+ * This program is distributed in the hope that it will be useful, but
158+ * WITHOUT ANY WARRANTY; without even the implied warranty of
159+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
160+ * General Public License for more details:*
161+ */
162+
163+#include <unistd.h>
164+#include <stdlib.h>
165+#include <string.h>
166+#include <stdio.h>
167+#include <getopt.h>
168+#include <errno.h>
169+#include <stdbool.h>
170+#include <sys/utsname.h>
171+#include <sys/stat.h>
172+
173+#include "udev.h"
174+
175+static bool set_loading(struct udev *udev, char *loadpath, const char *state) {
176+ FILE *ldfile;
177+
178+ ldfile = fopen(loadpath, "we");
179+ if (ldfile == NULL) {
180+ log_error("error: can not open '%s'", loadpath);
181+ return false;
182+ };
183+ fprintf(ldfile, "%s\n", state);
184+ fclose(ldfile);
185+ return true;
186+}
187+
188+static bool copy_firmware(struct udev *udev, const char *source, const char *target, size_t size) {
189+ char *buf;
190+ FILE *fsource = NULL, *ftarget = NULL;
191+ bool ret = false;
192+
193+ buf = malloc(size);
194+ if (buf == NULL) {
195+ log_error("No memory available to load firmware file");
196+ return false;
197+ }
198+
199+ log_debug("writing '%s' (%zi) to '%s'", source, size, target);
200+
201+ fsource = fopen(source, "re");
202+ if (fsource == NULL)
203+ goto exit;
204+ ftarget = fopen(target, "we");
205+ if (ftarget == NULL)
206+ goto exit;
207+ if (fread(buf, size, 1, fsource) != 1)
208+ goto exit;
209+ if (fwrite(buf, size, 1, ftarget) == 1)
210+ ret = true;
211+exit:
212+ if (ftarget != NULL)
213+ fclose(ftarget);
214+ if (fsource != NULL)
215+ fclose(fsource);
216+ free(buf);
217+ return ret;
218+}
219+
220+static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], bool test) {
221+ struct udev *udev = udev_device_get_udev(dev);
222+ static const char *searchpath[] = { FIRMWARE_PATH };
223+ char loadpath[UTIL_PATH_SIZE];
224+ char datapath[UTIL_PATH_SIZE];
225+ char fwpath[UTIL_PATH_SIZE];
226+ const char *firmware;
227+ FILE *fwfile = NULL;
228+ struct utsname kernel;
229+ struct stat statbuf;
230+ unsigned int i;
231+ int rc = EXIT_SUCCESS;
232+
233+ firmware = udev_device_get_property_value(dev, "FIRMWARE");
234+ if (firmware == NULL) {
235+ log_error("firmware parameter missing");
236+ rc = EXIT_FAILURE;
237+ goto exit;
238+ }
239+
240+ /* lookup firmware file */
241+ uname(&kernel);
242+ for (i = 0; i < ELEMENTSOF(searchpath); i++) {
243+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
244+ fwfile = fopen(fwpath, "re");
245+ if (fwfile != NULL)
246+ break;
247+
248+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
249+ fwfile = fopen(fwpath, "re");
250+ if (fwfile != NULL)
251+ break;
252+ }
253+
254+ strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
255+
256+ if (fwfile == NULL) {
257+ log_debug("did not find firmware file '%s'", firmware);
258+ rc = EXIT_FAILURE;
259+ /*
260+ * Do not cancel the request in the initrd, the real root might have
261+ * the firmware file and the 'coldplug' run in the real root will find
262+ * this pending request and fulfill or cancel it.
263+ * */
264+ if (!in_initrd())
265+ set_loading(udev, loadpath, "-1");
266+ goto exit;
267+ }
268+
269+ if (stat(fwpath, &statbuf) < 0 || statbuf.st_size == 0) {
270+ if (!in_initrd())
271+ set_loading(udev, loadpath, "-1");
272+ rc = EXIT_FAILURE;
273+ goto exit;
274+ }
275+
276+ if (!set_loading(udev, loadpath, "1"))
277+ goto exit;
278+
279+ strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL);
280+ if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {
281+ log_error("error sending firmware '%s' to device", firmware);
282+ set_loading(udev, loadpath, "-1");
283+ rc = EXIT_FAILURE;
284+ goto exit;
285+ };
286+
287+ set_loading(udev, loadpath, "0");
288+exit:
289+ if (fwfile)
290+ fclose(fwfile);
291+ return rc;
292+}
293+
294+const struct udev_builtin udev_builtin_firmware = {
295+ .name = "firmware",
296+ .cmd = builtin_firmware,
297+ .help = "kernel firmware loader",
298+ .run_once = true,
299+};
300diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c
301index db2b6874f..ccd88638c 100644
302--- a/src/udev/udev-builtin.c
303+++ b/src/udev/udev-builtin.c
304@@ -32,6 +32,9 @@ static const struct udev_builtin *builtins[] = {
305 [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
306 #endif
307 [UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
308+#if HAVE_FIRMWARE
309+ [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
310+#endif
311 [UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
312 [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
313 [UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
314diff --git a/src/udev/udev.h b/src/udev/udev.h
315index ea11c2d29..c47dd3d88 100644
316--- a/src/udev/udev.h
317+++ b/src/udev/udev.h
318@@ -151,6 +151,9 @@ enum udev_builtin_cmd {
319 UDEV_BUILTIN_BLKID,
320 #endif
321 UDEV_BUILTIN_BTRFS,
322+#if HAVE_FIRMWARE
323+ UDEV_BUILTIN_FIRMWARE,
324+#endif
325 UDEV_BUILTIN_HWDB,
326 UDEV_BUILTIN_INPUT_ID,
327 UDEV_BUILTIN_KEYBOARD,
328@@ -179,6 +182,9 @@ struct udev_builtin {
329 extern const struct udev_builtin udev_builtin_blkid;
330 #endif
331 extern const struct udev_builtin udev_builtin_btrfs;
332+#if HAVE_FIRMWARE
333+extern const struct udev_builtin udev_builtin_firmware;
334+#endif
335 extern const struct udev_builtin udev_builtin_hwdb;
336 extern const struct udev_builtin udev_builtin_input_id;
337 extern const struct udev_builtin udev_builtin_keyboard;
338diff --git a/src/udev/udevd.c b/src/udev/udevd.c
339index 5c757d513..2f3313007 100644
340--- a/src/udev/udevd.c
341+++ b/src/udev/udevd.c
342@@ -127,6 +127,9 @@ struct event {
343 bool is_block;
344 sd_event_source *timeout_warning;
345 sd_event_source *timeout;
346+#if HAVE_FIRMWARE
347+ bool nodelay;
348+#endif
349 };
350
351 static void event_queue_cleanup(Manager *manager, enum event_state type);
352@@ -609,6 +612,10 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
353 event->devnum = udev_device_get_devnum(dev);
354 event->is_block = streq("block", udev_device_get_subsystem(dev));
355 event->ifindex = udev_device_get_ifindex(dev);
356+#if HAVE_FIRMWARE
357+ if (streq(udev_device_get_subsystem(dev), "firmware"))
358+ event->nodelay = true;
359+#endif
360
361 log_debug("seq %llu queued, '%s' '%s'", udev_device_get_seqnum(dev),
362 udev_device_get_action(dev), udev_device_get_subsystem(dev));
363@@ -692,6 +699,11 @@ static bool is_devpath_busy(Manager *manager, struct event *event) {
364 return true;
365 }
366
367+#if HAVE_FIRMWARE
368+ /* allow to bypass the dependency tracking */
369+ if (event->nodelay)
370+ continue;
371+#endif
372 /* parent device event found */
373 if (event->devpath[common] == '/') {
374 event->delaying_seqnum = loop_event->seqnum;
375--
3762.13.0
377