systemd: add firmware loading support
Userspace firmware loading support is required for the Linux imx-sdma driver. The patches that accomplish this were originally in poky, but were removed in the thud upgrade. Re-work the patches so they apply over systemd v239. https://jira.digi.com/browse/DEL-6932 Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
This commit is contained in:
parent
3a674e3526
commit
0765189c93
|
|
@ -0,0 +1,374 @@
|
|||
From 6c0e15dd6c65b64ca773ce756a8f0356ea5229e9 Mon Sep 17 00:00:00 2001
|
||||
From: Chen Qi <Qi.Chen@windriver.com>
|
||||
Date: Wed, 28 Feb 2018 21:05:39 -0800
|
||||
Subject: [PATCH] Revert "udev: remove userspace firmware loading support"
|
||||
|
||||
This reverts commit be2ea723b1d023b3d385d3b791ee4607cbfb20ca.
|
||||
Userspace firmware loading support is needed for Linux < 3.7.
|
||||
|
||||
Upstream-Status: Inappropriate [OE specific]
|
||||
|
||||
Signed-off-by: Jonathan Liu <net147@gmail.com>
|
||||
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
|
||||
---
|
||||
README | 4 +-
|
||||
TODO | 1 +
|
||||
meson.build | 7 ++
|
||||
meson_options.txt | 2 +
|
||||
rules/meson.build | 4 +
|
||||
src/udev/meson.build | 4 +
|
||||
src/udev/udev-builtin-firmware.c | 154 +++++++++++++++++++++++++++++++++++++++
|
||||
src/udev/udev-builtin.c | 3 +
|
||||
src/udev/udev.h | 6 ++
|
||||
src/udev/udevd.c | 12 +++
|
||||
10 files changed, 195 insertions(+), 2 deletions(-)
|
||||
create mode 100644 src/udev/udev-builtin-firmware.c
|
||||
|
||||
diff --git a/README b/README
|
||||
index 2cde08c..c8cc573 100644
|
||||
--- a/README
|
||||
+++ b/README
|
||||
@@ -58,8 +58,8 @@ REQUIREMENTS:
|
||||
Legacy hotplug slows down the system and confuses udev:
|
||||
CONFIG_UEVENT_HELPER_PATH=""
|
||||
|
||||
- Userspace firmware loading is not supported and should
|
||||
- be disabled in the kernel:
|
||||
+ Userspace firmware loading is deprecated, will go away, and
|
||||
+ sometimes causes problems:
|
||||
CONFIG_FW_LOADER_USER_HELPER=n
|
||||
|
||||
Some udev rules and virtualization detection relies on it:
|
||||
diff --git a/TODO b/TODO
|
||||
index ff1008a..7949333 100644
|
||||
--- a/TODO
|
||||
+++ b/TODO
|
||||
@@ -844,6 +844,7 @@ Features:
|
||||
* initialize the hostname from the fs label of /, if /etc/hostname does not exist?
|
||||
|
||||
* udev:
|
||||
+ - remove src/udev/udev-builtin-firmware.c (CONFIG_FW_LOADER_USER_HELPER=n)
|
||||
- move to LGPL
|
||||
- kill scsi_id
|
||||
- add trigger --subsystem-match=usb/usb_device device
|
||||
diff --git a/meson.build b/meson.build
|
||||
index b283d1e..39dee74 100644
|
||||
--- a/meson.build
|
||||
+++ b/meson.build
|
||||
@@ -66,6 +66,10 @@ sysvrcnd_path = get_option('sysvrcnd-path')
|
||||
conf.set10('HAVE_SYSV_COMPAT', sysvinit_path != '' and sysvrcnd_path != '',
|
||||
description : 'SysV init scripts and rcN.d links are supported')
|
||||
|
||||
+firmware_path = get_option('firmware-path')
|
||||
+conf.set10('HAVE_FIRMWARE', firmware_path != '',
|
||||
+ description : 'Userspace firmware loading is supported')
|
||||
+
|
||||
# join_paths ignore the preceding arguments if an absolute component is
|
||||
# encountered, so this should canonicalize various paths when they are
|
||||
# absolute or relative.
|
||||
@@ -180,6 +184,7 @@ conf.set_quoted('SYSTEM_CONFIG_UNIT_PATH', join_paths(pkgsysc
|
||||
conf.set_quoted('SYSTEM_DATA_UNIT_PATH', systemunitdir)
|
||||
conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path)
|
||||
conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path)
|
||||
+conf.set_quoted('FIRMWARE_PATH', firmware_path)
|
||||
conf.set_quoted('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-local'))
|
||||
conf.set_quoted('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-local'))
|
||||
|
||||
@@ -267,6 +272,7 @@ substs.set('SYSTEMCTL', join_paths(rootbin
|
||||
substs.set('RANDOM_SEED', join_paths(randomseeddir, 'random-seed'))
|
||||
substs.set('SYSTEM_SYSVINIT_PATH', sysvinit_path)
|
||||
substs.set('SYSTEM_SYSVRCND_PATH', sysvrcnd_path)
|
||||
+substs.set('FIRMWARE_PATH', firmware_path)
|
||||
substs.set('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-local'))
|
||||
substs.set('RC_LOCAL_SCRIPT_PATH_STOP', get_option('halt-local'))
|
||||
substs.set('MEMORY_ACCOUNTING_DEFAULT', memory_accounting_default ? 'yes' : 'no')
|
||||
@@ -2820,6 +2826,7 @@ status = [
|
||||
'rootlib directory: @0@'.format(rootlibdir),
|
||||
'SysV init scripts: @0@'.format(sysvinit_path),
|
||||
'SysV rc?.d directories: @0@'.format(sysvrcnd_path),
|
||||
+ 'firmware path: @0@'.format(firmware_path),
|
||||
'PAM modules directory: @0@'.format(pamlibdir),
|
||||
'PAM configuration directory: @0@'.format(pamconfdir),
|
||||
'RPM macros directory: @0@'.format(rpmmacrosdir),
|
||||
diff --git a/meson_options.txt b/meson_options.txt
|
||||
index a396ce3..9f7f1b1 100644
|
||||
--- a/meson_options.txt
|
||||
+++ b/meson_options.txt
|
||||
@@ -109,6 +109,8 @@ option('tmpfiles', type : 'boolean',
|
||||
description : 'support for tmpfiles.d')
|
||||
option('importd', type : 'combo', choices : ['auto', 'true', 'false'],
|
||||
description : 'install the systemd-importd daemon')
|
||||
+option('firmware-path', type : 'string', value : '',
|
||||
+ description : 'Firmware search path')
|
||||
option('hwdb', type : 'boolean',
|
||||
description : 'support for the hardware database')
|
||||
option('rfkill', type : 'boolean',
|
||||
diff --git a/rules/meson.build b/rules/meson.build
|
||||
index b6a32ba..d3f3214 100644
|
||||
--- a/rules/meson.build
|
||||
+++ b/rules/meson.build
|
||||
@@ -26,6 +26,10 @@ rules = files('''
|
||||
install_data(rules,
|
||||
install_dir : udevrulesdir)
|
||||
|
||||
+if conf.get('HAVE_FIRMWARE') == 1
|
||||
+ install_data('50-firmware.rules', install_dir : udevrulesdir)
|
||||
+endif
|
||||
+
|
||||
all_rules = rules
|
||||
|
||||
rules_in = '''
|
||||
diff --git a/src/udev/meson.build b/src/udev/meson.build
|
||||
index 3bcd2bd..0dd4022 100644
|
||||
--- a/src/udev/meson.build
|
||||
+++ b/src/udev/meson.build
|
||||
@@ -52,6 +52,10 @@ if conf.get('HAVE_ACL') == 1
|
||||
sd_login_c]
|
||||
endif
|
||||
|
||||
+if conf.get('HAVE_FIRMWARE') == 1
|
||||
+ libudev_core_sources += ['udev-builtin-firmware.c']
|
||||
+endif
|
||||
+
|
||||
############################################################
|
||||
|
||||
generate_keyboard_keys_list = find_program('generate-keyboard-keys-list.sh')
|
||||
diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c
|
||||
new file mode 100644
|
||||
index 0000000..bd8c2fb
|
||||
--- /dev/null
|
||||
+++ b/src/udev/udev-builtin-firmware.c
|
||||
@@ -0,0 +1,154 @@
|
||||
+/*
|
||||
+ * firmware - Kernel firmware loader
|
||||
+ *
|
||||
+ * Copyright (C) 2009 Piter Punk <piterpunk@slackware.com>
|
||||
+ * Copyright (C) 2009-2011 Kay Sievers <kay@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 "udev.h"
|
||||
+
|
||||
+static bool set_loading(struct udev *udev, char *loadpath, const char *state) {
|
||||
+ FILE *ldfile;
|
||||
+
|
||||
+ ldfile = fopen(loadpath, "we");
|
||||
+ if (ldfile == NULL) {
|
||||
+ log_error("error: can not open '%s'", 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) {
|
||||
+ log_error("No memory available to load firmware file");
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ log_debug("writing '%s' (%zi) to '%s'", source, size, target);
|
||||
+
|
||||
+ fsource = fopen(source, "re");
|
||||
+ if (fsource == NULL)
|
||||
+ goto exit;
|
||||
+ ftarget = fopen(target, "we");
|
||||
+ 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;
|
||||
+}
|
||||
+
|
||||
+static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], bool test) {
|
||||
+ struct udev *udev = udev_device_get_udev(dev);
|
||||
+ static const char *searchpath[] = { FIRMWARE_PATH };
|
||||
+ char loadpath[UTIL_PATH_SIZE];
|
||||
+ char datapath[UTIL_PATH_SIZE];
|
||||
+ char fwpath[UTIL_PATH_SIZE];
|
||||
+ const char *firmware;
|
||||
+ FILE *fwfile = NULL;
|
||||
+ struct utsname kernel;
|
||||
+ struct stat statbuf;
|
||||
+ unsigned int i;
|
||||
+ int rc = EXIT_SUCCESS;
|
||||
+
|
||||
+ firmware = udev_device_get_property_value(dev, "FIRMWARE");
|
||||
+ if (firmware == NULL) {
|
||||
+ log_error("firmware parameter missing");
|
||||
+ rc = EXIT_FAILURE;
|
||||
+ goto exit;
|
||||
+ }
|
||||
+
|
||||
+ /* lookup firmware file */
|
||||
+ uname(&kernel);
|
||||
+ for (i = 0; i < ELEMENTSOF(searchpath); i++) {
|
||||
+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
|
||||
+ fwfile = fopen(fwpath, "re");
|
||||
+ if (fwfile != NULL)
|
||||
+ break;
|
||||
+
|
||||
+ strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
|
||||
+ fwfile = fopen(fwpath, "re");
|
||||
+ if (fwfile != NULL)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
|
||||
+
|
||||
+ if (fwfile == NULL) {
|
||||
+ log_debug("did not find firmware file '%s'", firmware);
|
||||
+ rc = EXIT_FAILURE;
|
||||
+ /*
|
||||
+ * Do not cancel the request in the initrd, the real root might have
|
||||
+ * the firmware file and the 'coldplug' run in the real root will find
|
||||
+ * this pending request and fulfill or cancel it.
|
||||
+ * */
|
||||
+ if (!in_initrd())
|
||||
+ set_loading(udev, loadpath, "-1");
|
||||
+ goto exit;
|
||||
+ }
|
||||
+
|
||||
+ if (stat(fwpath, &statbuf) < 0 || statbuf.st_size == 0) {
|
||||
+ if (!in_initrd())
|
||||
+ set_loading(udev, loadpath, "-1");
|
||||
+ rc = EXIT_FAILURE;
|
||||
+ goto exit;
|
||||
+ }
|
||||
+
|
||||
+ if (!set_loading(udev, loadpath, "1"))
|
||||
+ goto exit;
|
||||
+
|
||||
+ strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL);
|
||||
+ if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {
|
||||
+ log_error("error sending firmware '%s' to device", firmware);
|
||||
+ set_loading(udev, loadpath, "-1");
|
||||
+ rc = EXIT_FAILURE;
|
||||
+ goto exit;
|
||||
+ };
|
||||
+
|
||||
+ set_loading(udev, loadpath, "0");
|
||||
+exit:
|
||||
+ if (fwfile)
|
||||
+ fclose(fwfile);
|
||||
+ return rc;
|
||||
+}
|
||||
+
|
||||
+const struct udev_builtin udev_builtin_firmware = {
|
||||
+ .name = "firmware",
|
||||
+ .cmd = builtin_firmware,
|
||||
+ .help = "kernel firmware loader",
|
||||
+ .run_once = true,
|
||||
+};
|
||||
diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c
|
||||
index 576d83d..e58f772 100644
|
||||
--- a/src/udev/udev-builtin.c
|
||||
+++ b/src/udev/udev-builtin.c
|
||||
@@ -14,6 +14,9 @@ static const struct udev_builtin *builtins[] = {
|
||||
[UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
|
||||
#endif
|
||||
[UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
|
||||
+#if HAVE_FIRMWARE
|
||||
+ [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
|
||||
+#endif
|
||||
[UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
|
||||
[UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
|
||||
[UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
|
||||
diff --git a/src/udev/udev.h b/src/udev/udev.h
|
||||
index 4596d0e..c800ef5 100644
|
||||
--- a/src/udev/udev.h
|
||||
+++ b/src/udev/udev.h
|
||||
@@ -138,6 +138,9 @@ enum udev_builtin_cmd {
|
||||
UDEV_BUILTIN_BLKID,
|
||||
#endif
|
||||
UDEV_BUILTIN_BTRFS,
|
||||
+#if HAVE_FIRMWARE
|
||||
+ UDEV_BUILTIN_FIRMWARE,
|
||||
+#endif
|
||||
UDEV_BUILTIN_HWDB,
|
||||
UDEV_BUILTIN_INPUT_ID,
|
||||
UDEV_BUILTIN_KEYBOARD,
|
||||
@@ -166,6 +169,9 @@ struct udev_builtin {
|
||||
extern const struct udev_builtin udev_builtin_blkid;
|
||||
#endif
|
||||
extern const struct udev_builtin udev_builtin_btrfs;
|
||||
+#if HAVE_FIRMWARE
|
||||
+extern const struct udev_builtin udev_builtin_firmware;
|
||||
+#endif
|
||||
extern const struct udev_builtin udev_builtin_hwdb;
|
||||
extern const struct udev_builtin udev_builtin_input_id;
|
||||
extern const struct udev_builtin udev_builtin_keyboard;
|
||||
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
|
||||
index 34f6a95..b132db7 100644
|
||||
--- a/src/udev/udevd.c
|
||||
+++ b/src/udev/udevd.c
|
||||
@@ -114,6 +114,9 @@ struct event {
|
||||
bool is_block;
|
||||
sd_event_source *timeout_warning;
|
||||
sd_event_source *timeout;
|
||||
+#if HAVE_FIRMWARE
|
||||
+ bool nodelay;
|
||||
+#endif
|
||||
};
|
||||
|
||||
static void event_queue_cleanup(Manager *manager, enum event_state type);
|
||||
@@ -604,6 +607,10 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
|
||||
event->devnum = udev_device_get_devnum(dev);
|
||||
event->is_block = streq("block", udev_device_get_subsystem(dev));
|
||||
event->ifindex = udev_device_get_ifindex(dev);
|
||||
+#if HAVE_FIRMWARE
|
||||
+ if (streq(udev_device_get_subsystem(dev), "firmware"))
|
||||
+ event->nodelay = true;
|
||||
+#endif
|
||||
|
||||
log_debug("seq %llu queued, '%s' '%s'", udev_device_get_seqnum(dev),
|
||||
udev_device_get_action(dev), udev_device_get_subsystem(dev));
|
||||
@@ -687,6 +694,11 @@ static bool is_devpath_busy(Manager *manager, struct event *event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+#if HAVE_FIRMWARE
|
||||
+ /* allow to bypass the dependency tracking */
|
||||
+ if (event->nodelay)
|
||||
+ continue;
|
||||
+#endif
|
||||
/* parent device event found */
|
||||
if (event->devpath[common] == '/') {
|
||||
event->delaying_seqnum = loop_event->seqnum;
|
||||
--
|
||||
2.7.4
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
From 35d6d384e83ac38077603611bb791969ef95fe68 Mon Sep 17 00:00:00 2001
|
||||
From: Jonathan Liu <net147@gmail.com>
|
||||
Date: Thu, 19 Mar 2015 15:01:29 +1100
|
||||
Subject: [PATCH 07/31] Revert "rules: remove firmware loading rules"
|
||||
|
||||
This reverts commit 70e7d754ddb356fb1a2942b262f8cee9650e2a19.
|
||||
Userspace firmware loading support is needed for Linux < 3.7.
|
||||
|
||||
Upstream-Status: Inappropriate [OE specific]
|
||||
|
||||
Signed-off-by: Jonathan Liu <net147@gmail.com>
|
||||
---
|
||||
rules/50-firmware.rules | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
create mode 100644 rules/50-firmware.rules
|
||||
|
||||
diff --git a/rules/50-firmware.rules b/rules/50-firmware.rules
|
||||
new file mode 100644
|
||||
index 000000000..f0ae68451
|
||||
--- /dev/null
|
||||
+++ b/rules/50-firmware.rules
|
||||
@@ -0,0 +1,3 @@
|
||||
+# do not edit this file, it will be overwritten on update
|
||||
+
|
||||
+SUBSYSTEM=="firmware", ACTION=="add", RUN{builtin}="firmware"
|
||||
--
|
||||
2.13.0
|
||||
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
|
||||
|
||||
SRC_URI += " \
|
||||
file://0001-Revert-udev-remove-userspace-firmware-loading-suppor.patch \
|
||||
file://0001-udev-use-the-usual-set-of-load-paths-for-udev-rules.patch \
|
||||
file://0002-sd-resolve-forcefully-cancel-worker-threads-during-r.patch \
|
||||
file://0007-Revert-rules-remove-firmware-loading-rules.patch \
|
||||
"
|
||||
|
||||
#FIX-it: Workaround as missing ending slash in FIRMWARE_PATH [YOCIMX-2831]
|
||||
EXTRA_OEMESON_remove = "-Dfirmware-path=${nonarch_base_libdir}/firmware "
|
||||
EXTRA_OEMESON += "-Dfirmware-path=${nonarch_base_libdir}/firmware/ "
|
||||
|
||||
# Remove systemd-networkd from our images, since we already use NetworkManager
|
||||
|
|
|
|||
Loading…
Reference in New Issue