Skip to contentSkip to conversation

eudev: generate hwdb.bin at system startup

PATCH Superseded Carlos Santos 2 participants 3 messages Oct 16, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 eudev: generate hwdb.bin at system startup

From: Carlos Santos <[email protected]>

Programs that use libudev (e.g. lsusb, from usbutils) need the hwdb.bin file to work properly.

If BR2_PACKAGE_EUDEV_ENABLE_HWDB is selected then the eudev installation populates /etc/udev/hwdb.d/ but does not genarete /etc/udev/hwdb.bin. It must be created running "udevadm hwdb --update" on the target device but this does not work with a read-only /etc, so we need these changes:

- Add the BR2_PACKAGE_EUDEV_HWDB_BIN_PATH config, allowing the user to set the location of hwdb.bin.
- Patch the configuration script, allowing to set the hwdb.bin path by means of an environment variable (udevhwdbbinpath).
- Pass the value set in BR2_PACKAGE_EUDEV_HWDB_BIN_PATH to the configure script by means of the udevhwdbbinpath variable.
- Make the S10udev init script run "udevadm hwdb --update" to recreate hwdb.bin or print an error message if the operation fails (e.g. no write permission on the filesystem).

---
Changes v1->v2
- Incorporate fixes and improvements provided by Matt Weber

Note: there was a discussion via email and on IRC, with suggetsions to prebuild hwdb.bin at build time and to add a /etc/defaults/udev cfg file instead patching S10udev (like in the recent S01logging suggested updates). I like both suggestions but I'd prefer to implement them in subsequent patches rather, since they woud require additional changes (e.g. adding eudev as a host tool).

---
 package/eudev/Config.in |  9 +++++++++
 package/eudev/S10udev   |  8 +++++++-
 package/eudev/eudev.mk  | 13 ++++++++++++-
 3 files changed, 28 insertions(+), 2 deletions(-)
package/eudev/Config.in +9 -0
index 2220265a55..a589a14af3 100644
@@ -32,6 +32,15 @@ config BR2_PACKAGE_EUDEV_ENABLE_HWDB
 	help
 	  Enables hardware database installation to /etc/udev/hwdb.d
 
+config BR2_PACKAGE_EUDEV_HWDB_BIN_PATH
+	string "hwdb.bin path"
+	default "/etc/udev/hwdb.bin"
+	help
+	  Location of the hwdb.bin file, which is re-generated at system
+	  startup. The default is /etc/udev/hwdb.bin but you may want to
+	  move it elsewhere (e.g. /var/run/udev/hwdb.bin) if /etc is in
+	  a read-only filesystem.
+
 endif
 
 comment "eudev needs eudev /dev management"
package/eudev/S10udev +7 -1
index 4e799d6507..08aca82dd9 100755
@@ -21,14 +21,20 @@ UDEV_CONFIG=/etc/udev/udev.conf
 test -r $UDEV_CONFIG || exit 6
 . $UDEV_CONFIG
 
+UDEV_HWDB_BIN=%%UDEV_HWDB_BIN%%
+
 case "$1" in
     start)
         printf "Populating %s using udev: " "${udev_root:-/dev}"
         [ -e /proc/sys/kernel/hotplug ] && printf '\000\000\000\000' > /proc/sys/kernel/hotplug
         /sbin/udevd -d || { echo "FAIL"; exit 1; }
+        echo "done"
         udevadm trigger --type=subsystems --action=add
         udevadm trigger --type=devices --action=add
-        udevadm settle --timeout=30 || echo "udevadm settle failed"
+        udevadm settle --timeout=30 || { echo "udevadm settle failed" && exit 1; }
+        echo "done"
+        printf "Compiling hardware database information $UDEV_HWDB_BIN: "
+        udevadm hwdb --update || { echo "FAIL" && exit 1; }
         echo "done"
         ;;
     stop)
package/eudev/eudev.mk +12 -1
index 11dc93762b..0a9c9d5a67 100644
@@ -44,8 +44,19 @@ else
 EUDEV_CONF_OPTS += --disable-selinux
 endif
 
+define EUDEV_POST_PATCH
+	$(SED) 's,$${udevconfdir}/hwdb.bin,$${udevhwdbbinpath:-$${udevconfdir}/hwdb.bin},' \
+		$(@D)/configure
+endef
+EUDEV_POST_PATCH_HOOKS += EUDEV_POST_PATCH
+
+EUDEV_CONF_ENV += udevhwdbbinpath=$(BR2_PACKAGE_EUDEV_HWDB_BIN_PATH)
+
 define EUDEV_INSTALL_INIT_SYSV
-	$(INSTALL) -D -m 0755 package/eudev/S10udev $(TARGET_DIR)/etc/init.d/S10udev
+	$(INSTALL) -D -m 0755 package/eudev/S10udev \
+		$(TARGET_DIR)/etc/init.d/S10udev
+	$(SED) 's,%%UDEV_HWDB_BIN%%,$(BR2_PACKAGE_EUDEV_HWDB_BIN_PATH),' \
+		$(TARGET_DIR)/etc/init.d/S10udev
 endef
 
 # Required by default rules for input devices
Signature · 1 line
2.14.4
#1 lore raw

PATCH v2 1/1 eudev: generate hwdb.bin at system startup

Carlos,

Quoted 5 lines · Carlos Santos

From: Carlos Santos <[email protected]>

Programs that use libudev (e.g. lsusb, from usbutils) need the hwdb.bin file to work properly.

Sounds like a great runtime test? I had wondered other then testing that the .bin generates, what's the example with those tools to show the bin is working?

Quoted 22 lines

If BR2_PACKAGE_EUDEV_ENABLE_HWDB is selected then the eudev installation populates /etc/udev/hwdb.d/ but does not genarete /etc/udev/hwdb.bin. It must be created running "udevadm hwdb --update" on the target device but this does not work with a read-only /etc, so we need these changes:

- Add the BR2_PACKAGE_EUDEV_HWDB_BIN_PATH config, allowing the user to set the location of hwdb.bin.
- Patch the configuration script, allowing to set the hwdb.bin path by means of an environment variable (udevhwdbbinpath).
- Pass the value set in BR2_PACKAGE_EUDEV_HWDB_BIN_PATH to the configure script by means of the udevhwdbbinpath variable.
- Make the S10udev init script run "udevadm hwdb --update" to recreate hwdb.bin or print an error message if the operation fails (e.g. no write permission on the filesystem).

---
Changes v1->v2
- Incorporate fixes and improvements provided by Matt Weber

Quoted 6 lines

Note: there was a discussion via email and on IRC, with suggetsions to prebuild hwdb.bin at build time and to add a /etc/defaults/udev cfg file instead patching S10udev (like in the recent S01logging suggested updates). I like both suggestions but I'd prefer to implement them in subsequent patches rather, since they woud require additional changes (e.g. adding eudev as a host tool).

Guessing the use of SED setting that value maybe a sticking point where there would be a push to use the default cfg approach. Wouldn't need to be an offline build in this patchset.

Quoted 11 lines
---
 package/eudev/Config.in |  9 +++++++++
 package/eudev/S10udev   |  8 +++++++-
 package/eudev/eudev.mk  | 13 ++++++++++++-
 3 files changed, 28 insertions(+), 2 deletions(-)
package/eudev/Config.in +0 -0
index 2220265a55..a589a14af3 100644

package/eudev/Config.in config BR2_PACKAGE_EUDEV_ENABLE_HWDB · line 35

Quoted 4 lines
package/eudev/Config.in +1 -0
@@ -32,6 +32,15 @@ config BR2_PACKAGE_EUDEV_ENABLE_HWDB
        help
          Enables hardware database installation to /etc/udev/hwdb.d
 
+config BR2_PACKAGE_EUDEV_HWDB_BIN_PATH

I believe the dependency needs reflected here on BR2_PACKAGE_EUDEV_ENABLE_HWDB? Wouldn't that be the case?

Quoted 65 lines
package/eudev/Config.in +8 -0
+       string "hwdb.bin path"
+       default "/etc/udev/hwdb.bin"
+       help
+         Location of the hwdb.bin file, which is re-generated at system
+         startup. The default is /etc/udev/hwdb.bin but you may want to
+         move it elsewhere (e.g. /var/run/udev/hwdb.bin) if /etc is in
+         a read-only filesystem.
+
 endif
 
 comment "eudev needs eudev /dev management"
package/eudev/S10udev +7 -1
index 4e799d6507..08aca82dd9 100755
@@ -21,14 +21,20 @@ UDEV_CONFIG=/etc/udev/udev.conf
 test -r $UDEV_CONFIG || exit 6
 . $UDEV_CONFIG
 
+UDEV_HWDB_BIN=%%UDEV_HWDB_BIN%%
+
 case "$1" in
     start)
         printf "Populating %s using udev: " "${udev_root:-/dev}"
         [ -e /proc/sys/kernel/hotplug ] && printf '\000\000\000\000' > /proc/sys/kernel/hotplug
         /sbin/udevd -d || { echo "FAIL"; exit 1; }
+        echo "done"
         udevadm trigger --type=subsystems --action=add
         udevadm trigger --type=devices --action=add
-        udevadm settle --timeout=30 || echo "udevadm settle failed"
+        udevadm settle --timeout=30 || { echo "udevadm settle failed" && exit 1; }
+        echo "done"
+        printf "Compiling hardware database information $UDEV_HWDB_BIN: "
+        udevadm hwdb --update || { echo "FAIL" && exit 1; }
         echo "done"
         ;;
     stop)
package/eudev/eudev.mk +12 -2
index 11dc93762b..0a9c9d5a67 100644
@@ -44,8 +44,19 @@ else
 EUDEV_CONF_OPTS += --disable-selinux
 endif
 
+define EUDEV_POST_PATCH
+       $(SED) 's,$${udevconfdir}/hwdb.bin,$${udevhwdbbinpath:-$${udevconfdir}/hwdb.bin},' \
+               $(@D)/configure
+endef
+EUDEV_POST_PATCH_HOOKS += EUDEV_POST_PATCH
+
+EUDEV_CONF_ENV += udevhwdbbinpath=$(BR2_PACKAGE_EUDEV_HWDB_BIN_PATH)
+
 define EUDEV_INSTALL_INIT_SYSV
-       $(INSTALL) -D -m 0755 package/eudev/S10udev $(TARGET_DIR)/etc/init.d/S10udev
+       $(INSTALL) -D -m 0755 package/eudev/S10udev \
+               $(TARGET_DIR)/etc/init.d/S10udev
+       $(SED) 's,%%UDEV_HWDB_BIN%%,$(BR2_PACKAGE_EUDEV_HWDB_BIN_PATH),' \
+               $(TARGET_DIR)/etc/init.d/S10udev
 endef
 
 # Required by default rules for input devices
--

2.14.4

Signature · 8 lines
Matthew L Weber / Pr Software Engineer
Airborne Information Systems / RC Linux Secure Platforms
MS 131-100, C Ave NE, Cedar Rapids, IA, 52498, USA
www.rockwellcollins.com

Note: Any Export License Required Information and License Restricted
Third Party Intellectual Property (TPIP) content must be encrypted and
sent to matthew.weber at corp.rockwellcollins.com.
#2 lore raw

PATCH v2 1/1 eudev: generate hwdb.bin at system startup

Quoted 11 lines

From: "Matthew Weber" <[email protected]>
To: "DATACOM" <[email protected]>
Cc: "buildroot" <[email protected]>, "Bernd Kuhls" <[email protected]>, "Eric Le Bihan" <[email protected]>, "Yann Morin" <[email protected]>, "Carlos Santos" <[email protected]>
Sent: Tuesday, October 16, 2018 12:21:41 PM
Subject: Re: [PATCH v2] eudev: generate hwdb.bin at system startup

Carlos,

Quoted 1 line · Carlos Santos
Quoted 8 lines
Quoted 4 lines

From: Carlos Santos <[email protected]>

Programs that use libudev (e.g. lsusb, from usbutils) need the hwdb.bin file to work properly.

Sounds like a great runtime test? I had wondered other then testing that the .bin generates, what's the example with those tools to show the bin is working?

# lsusb -V
lsusb (usbutils) 010
# lsusb 
Bus 002 Device 002: ID 0951:16a3 Kingston Technology 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
dm8620# mv /etc/udev/hwdb.bin /etc/udev/hwdb.bin~
# lsusb 
Bus 002 Device 002: ID 0951:16a3  
Bus 002 Device 001: ID 1d6b:0003  
Bus 001 Device 001: ID 1d6b:0002  
Quoted 28 lines
Quoted 21 lines

If BR2_PACKAGE_EUDEV_ENABLE_HWDB is selected then the eudev installation populates /etc/udev/hwdb.d/ but does not genarete /etc/udev/hwdb.bin. It must be created running "udevadm hwdb --update" on the target device but this does not work with a read-only /etc, so we need these changes:

- Add the BR2_PACKAGE_EUDEV_HWDB_BIN_PATH config, allowing the user to set the location of hwdb.bin.
- Patch the configuration script, allowing to set the hwdb.bin path by means of an environment variable (udevhwdbbinpath).
- Pass the value set in BR2_PACKAGE_EUDEV_HWDB_BIN_PATH to the configure script by means of the udevhwdbbinpath variable.
- Make the S10udev init script run "udevadm hwdb --update" to recreate hwdb.bin or print an error message if the operation fails (e.g. no write permission on the filesystem).

---
Changes v1->v2
- Incorporate fixes and improvements provided by Matt Weber

Quoted 6 lines

Note: there was a discussion via email and on IRC, with suggetsions to prebuild hwdb.bin at build time and to add a /etc/defaults/udev cfg file instead patching S10udev (like in the recent S01logging suggested updates). I like both suggestions but I'd prefer to implement them in subsequent patches rather, since they woud require additional changes (e.g. adding eudev as a host tool).

Quoted 3 lines

Guessing the use of SED setting that value maybe a sticking point where there would be a push to use the default cfg approach. Wouldn't need to be an offline build in this patchset.

The problem here is that we must set a default path at build time, since the /etc/default/<foo> files are optional. Moreover, S10udev requires an extreme overhauling due to several bugs:

- the inclusion of /etc/udev/udev.conf does not make sense;
- poor error handling and report;
- there is no "restart" nor "reload";
- it should use start-stop-daemon to start/stop udevd.

Quoted 14 lines
Quoted 14 lines
---
 package/eudev/Config.in |  9 +++++++++
 package/eudev/S10udev   |  8 +++++++-
 package/eudev/eudev.mk  | 13 ++++++++++++-
 3 files changed, 28 insertions(+), 2 deletions(-)
package/eudev/Config.in +0 -0
index 2220265a55..a589a14af3 100644
@@ -32,6 +32,15 @@ config BR2_PACKAGE_EUDEV_ENABLE_HWDB
        help
          Enables hardware database installation to /etc/udev/hwdb.d
 
Quoted 4 lines

package/eudev/Config.in config BR2_PACKAGE_EUDEV_ENABLE_HWDB · line 35

Quoted 1 line
package/eudev/Config.in +1 -0
+config BR2_PACKAGE_EUDEV_HWDB_BIN_PATH

I believe the dependency needs reflected here on BR2_PACKAGE_EUDEV_ENABLE_HWDB? Wouldn't that be the case?

Yes, I forgot this one. Sorry.

[...]

Signature · 3 lines
Carlos Santos (Casantos) - DATACOM, P&D
?Marched towards the enemy, spear upright, armed with the certainty
that only the ignorant can have.? ? Epitaph of a volunteer