Skip to contentSkip to conversation

udev providers: compile the hwdb at build time (branch yem/host-eudev)

PATCH Superseded Yann E. MORIN 3 participants 9 messages Oct 28, 2019 – Oct 29, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover udev providers: compile the hwdb at build time (branch yem/host-eudev)

Hello All!

The *.hwdb files installed by eudev or systemd are "source" files; they need to be compiled into a binary form to be useful.

This needs udevadm to be available, so we introduce a eudev host variant to provide it, and use that from both eudev and systemd to compile the database during target-finalize.

Regards,
Yann E. MORIN.

The following changes since commit 658388138ceba022c0db7ddb30a453140911f994

package/libsigrok: fix libftdi support (2019-10-28 23:37:58 +0100)

are available in the git repository at:

git://git.buildroot.org/~ymorin/git/buildroot.git

for you to fetch changes up to 371d42c6636c11fe7ad280c28ca67aa9e2d9f3ba

package/systemd: generate hwdb.bin (2019-10-28 23:54:09 +0100)

----------------------------------------------------------------
Yann E. MORIN (3):
package/eudev: introduce a host variant
package/eudev: generate hwdb.bin
package/systemd: generate hwdb.bin

 package/Config.in.host       |  1 +
 package/eudev/Config.in      |  3 ++-
 package/eudev/Config.in.host |  3 +++
 package/eudev/eudev.mk       | 36 ++++++++++++++++++++++++++++++++++++
 package/systemd/Config.in    |  1 +
 package/systemd/systemd.mk   | 23 +++++++++++++++++++++++
 6 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 package/eudev/Config.in.host
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH 1/3 package/eudev: introduce a host variant

eudev and systemd provide a hardware database (hwdb) as a set of multiple files. Various other utilities may also use that database.

Those files have to be "compiled" into a binary to be useful; libudev (and thus all utilities based on it) only use the compiled hwdb.

Compiling the hwdb is done with udevadm, using the hwdb sub-command:

    udevadm hwdb --update

Provide a simple host-variant of eudev, so that we can call udevadm at build time.

This host udevadm will read files from $(HOST_DIR)/etc/udev/hwdb.d/*.hwdb and write the compiled hwdb to $(HOST_DIR)/etc/udev/hwdb.bin.

Cc Peter Korsgaard <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Carlos Santos <[email protected]>
---
 package/Config.in.host       |  1 +
 package/eudev/Config.in.host |  3 +++
 package/eudev/eudev.mk       | 14 ++++++++++++++
 3 files changed, 18 insertions(+)
 create mode 100644 package/eudev/Config.in.host
package/Config.in.host +1 -0
index 914491e210..c0ac4fbbcc 100644
@@ -17,6 +17,7 @@ menu "Host utilities"
 	source "package/dtc/Config.in.host"
 	source "package/e2fsprogs/Config.in.host"
 	source "package/e2tools/Config.in.host"
+	source "package/eudev/Config.in.host"
 	source "package/f2fs-tools/Config.in.host"
 	source "package/faketime/Config.in.host"
 	source "package/fatcat/Config.in.host"
package/eudev/Config.in.host new file +3 -0
new file mode 100644
index 0000000000..87dfc43912
@@ -0,0 +1,3 @@
+# Select this if you need host eudev tools (e.g. udevadm)
+config BR2_PACKAGE_HOST_EUDEV
+	bool
package/eudev/eudev.mk +14 -0
index 2a3adb849c..12568a6645 100644
@@ -55,4 +55,18 @@ define EUDEV_USERS
 	- - kvm -1 * - - - kvm nodes
 endef
 
+HOST_EUDEV_DEPENDENCIES = host-gperf host-pkgconf
+HOST_EUDEV_CONF_OPTS = \
+	--disable-manpages \
+	--sbindir=$(HOST_DIR)/sbin \
+	--libexecdir=$(HOST_DIR)/lib \
+	--with-rootlibdir=$(HOST_DIR)/lib \
+	--disable-introspection \
+	--disable-kmod \
+	--disable-blkid \
+	--disable-rule-generator \
+	--enable-hwdb \
+	--disable-selinux
+
 $(eval $(autotools-package))
+$(eval $(host-autotools-package))
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/3 package/eudev: introduce a host variant

Quoted 58 lines · Yann E. MORIN

eudev and systemd provide a hardware database (hwdb) as a set of multiple files. Various other utilities may also use that database.

Those files have to be "compiled" into a binary to be useful; libudev (and thus all utilities based on it) only use the compiled hwdb.

Compiling the hwdb is done with udevadm, using the hwdb sub-command:

    udevadm hwdb --update

Provide a simple host-variant of eudev, so that we can call udevadm at build time.

This host udevadm will read files from $(HOST_DIR)/etc/udev/hwdb.d/*.hwdb and write the compiled hwdb to $(HOST_DIR)/etc/udev/hwdb.bin.

Cc Peter Korsgaard <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Carlos Santos <[email protected]>
---
 package/Config.in.host       |  1 +
 package/eudev/Config.in.host |  3 +++
 package/eudev/eudev.mk       | 14 ++++++++++++++
 3 files changed, 18 insertions(+)
 create mode 100644 package/eudev/Config.in.host
package/Config.in.host +1 -0
index 914491e210..c0ac4fbbcc 100644
@@ -17,6 +17,7 @@ menu "Host utilities"
        source "package/dtc/Config.in.host"
        source "package/e2fsprogs/Config.in.host"
        source "package/e2tools/Config.in.host"
+       source "package/eudev/Config.in.host"
        source "package/f2fs-tools/Config.in.host"
        source "package/faketime/Config.in.host"
        source "package/fatcat/Config.in.host"
package/eudev/Config.in.host new file +3 -0
new file mode 100644
index 0000000000..87dfc43912
@@ -0,0 +1,3 @@
+# Select this if you need host eudev tools (e.g. udevadm)
+config BR2_PACKAGE_HOST_EUDEV
+       bool
package/eudev/eudev.mk +2 -0
index 2a3adb849c..12568a6645 100644
@@ -55,4 +55,18 @@ define EUDEV_USERS
        - - kvm -1 * - - - kvm nodes
 endef
 
+HOST_EUDEV_DEPENDENCIES = host-gperf host-pkgconf
+HOST_EUDEV_CONF_OPTS = \

package/eudev/eudev.mk define EUDEV_USERS · line 69

Quoted 10 lines
package/eudev/eudev.mk +10 -0
+       --disable-manpages \
+       --sbindir=$(HOST_DIR)/sbin \
+       --libexecdir=$(HOST_DIR)/lib \
+       --with-rootlibdir=$(HOST_DIR)/lib \
+       --disable-introspection \
+       --disable-kmod \
+       --disable-blkid \
+       --disable-rule-generator \
+       --enable-hwdb \
+       --disable-selinux

This uses the default --prefix=$(HOST_DIR), which ruins the --rut argument of udevadm and is r=teh reason why the file copies are required in the following patches. Use this, instead:

# Use custom configuration commands because the default --prefix="$(HOST_DIR)"

# argument ruins the "udevadm hwdb --update --root <path>" command, making the
# root be $(HOST_DIR)/<path>. We also customize sysconfdir to create hwdb.bin
# at /usr/lib/udev if systemd is selected.
define HOST_EUDEV_CONFIGURE_CMDS
    (cd $(@D); rm -rf config.cache; \
    $(HOST_CONFIGURE_OPTS) \
    ./configure \
        --enable-shared --disable-static \
        --disable-manpages \
        --sysconfdir=$(if $(BR2_PACKAGE_SYSTEMD),/usr/lib,/etc) \
        --sbindir=/sbin \
        --libexecdir=/lib \
        --with-rootlibdir=/lib \
        --disable-introspection \
        --disable-kmod \
        --disable-blkid \
        --disable-rule-generator \
        --enable-hwdb \
        --disable-selinux \
    )
endef

# We just want udevadm
define HOST_EUDEV_INSTALL_CMDS

    $(INSTALL) -D -m 0755 $(@D)/src/udev/udevadm \
        $(HOST_DIR)/bin/udevadm

endef

Quoted 5 lines
package/eudev/eudev.mk +1 -1
 $(eval $(autotools-package))
+$(eval $(host-autotools-package))
--

2.20.1

Signature · 1 line
Carlos Santos <[email protected]>
#3 lore raw

PATCH 1/3 package/eudev: introduce a host variant

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Carlos" == Carlos Santos <[email protected]> writes:

Hi,

Quoted 40 lines

package/eudev/eudev.mk define EUDEV_USERS · line 69

Quoted 12 lines
package/eudev/eudev.mk +12 -0
+HOST_EUDEV_DEPENDENCIES = host-gperf host-pkgconf
+HOST_EUDEV_CONF_OPTS = \
+       --disable-manpages \
+       --sbindir=$(HOST_DIR)/sbin \
+       --libexecdir=$(HOST_DIR)/lib \
+       --with-rootlibdir=$(HOST_DIR)/lib \
+       --disable-introspection \
+       --disable-kmod \
+       --disable-blkid \
+       --disable-rule-generator \
+       --enable-hwdb \
+       --disable-selinux

This uses the default --prefix=$(HOST_DIR), which ruins the --rut argument of udevadm and is r=teh reason why the file copies are required in the following patches. Use this, instead:

# Use custom configuration commands because the default --prefix="$(HOST_DIR)"

# argument ruins the "udevadm hwdb --update --root <path>" command, making the
# root be $(HOST_DIR)/<path>. We also customize sysconfdir to create hwdb.bin
# at /usr/lib/udev if systemd is selected.
define HOST_EUDEV_CONFIGURE_CMDS
    (cd $(@D); rm -rf config.cache; \
    $(HOST_CONFIGURE_OPTS) \
    ./configure \
        --enable-shared --disable-static \
        --disable-manpages \
        --sysconfdir=$(if $(BR2_PACKAGE_SYSTEMD),/usr/lib,/etc) \
        --sbindir=/sbin \
        --libexecdir=/lib \
        --with-rootlibdir=/lib \
        --disable-introspection \
        --disable-kmod \
        --disable-blkid \
        --disable-rule-generator \
        --enable-hwdb \
        --disable-selinux \
    )
endef
Quoted 5 lines

# We just want udevadm
define HOST_EUDEV_INSTALL_CMDS

    $(INSTALL) -D -m 0755 $(@D)/src/udev/udevadm \
        $(HOST_DIR)/bin/udevadm

endef

As long as this is the only reason for having host-eudev, this is indeed simpler and means that we can have a single TARGET_FINALIZE hook.

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH 1/3 package/eudev: introduce a host variant

Quoted 51 lines · Peter Korsgaard
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Carlos" == Carlos Santos <[email protected]> writes:

Hi,

Quoted 40 lines

package/eudev/eudev.mk define EUDEV_USERS · line 69

Quoted 12 lines
package/eudev/eudev.mk +12 -0
+HOST_EUDEV_DEPENDENCIES = host-gperf host-pkgconf
+HOST_EUDEV_CONF_OPTS = \
+       --disable-manpages \
+       --sbindir=$(HOST_DIR)/sbin \
+       --libexecdir=$(HOST_DIR)/lib \
+       --with-rootlibdir=$(HOST_DIR)/lib \
+       --disable-introspection \
+       --disable-kmod \
+       --disable-blkid \
+       --disable-rule-generator \
+       --enable-hwdb \
+       --disable-selinux

This uses the default --prefix=$(HOST_DIR), which ruins the --rut argument of udevadm and is r=teh reason why the file copies are required in the following patches. Use this, instead:

# Use custom configuration commands because the default --prefix="$(HOST_DIR)"

# argument ruins the "udevadm hwdb --update --root <path>" command, making the
# root be $(HOST_DIR)/<path>. We also customize sysconfdir to create hwdb.bin
# at /usr/lib/udev if systemd is selected.
define HOST_EUDEV_CONFIGURE_CMDS
    (cd $(@D); rm -rf config.cache; \
    $(HOST_CONFIGURE_OPTS) \
    ./configure \
        --enable-shared --disable-static \
        --disable-manpages \
        --sysconfdir=$(if $(BR2_PACKAGE_SYSTEMD),/usr/lib,/etc) \
        --sbindir=/sbin \
        --libexecdir=/lib \
        --with-rootlibdir=/lib \
        --disable-introspection \
        --disable-kmod \
        --disable-blkid \
        --disable-rule-generator \
        --enable-hwdb \
        --disable-selinux \
    )
endef
Quoted 5 lines

# We just want udevadm
define HOST_EUDEV_INSTALL_CMDS

    $(INSTALL) -D -m 0755 $(@D)/src/udev/udevadm \
        $(HOST_DIR)/bin/udevadm

endef

Quoted 5 lines

As long as this is the only reason for having host-eudev, this is indeed simpler and means that we can have a single TARGET_FINALIZE hook.

--
Bye, Peter Korsgaard

I just noticed that eudev by default looks for .hwdb files in /usr/lib/udev/hwdb.d/ and /etc/udev/hwdb.d/ an that systemd looks for hwdb.bin at /etc/udev/ too.

So we could simplify the the patches by omitting the --sysconfdir argument and removing both hwdb.d directories in the rootfs-pre-cmd hooks.

We could also make the removal optional (default yes) for the cases in which the user wants to rebuild the database at run-time (e.g. after adding .hwdb files). I'm not a fan of feature provisioning but it would be much harder to do this otherwise.

Finally, the hooks could be moved to a single location instead of repeated in package/eudev.mk and package/systemd.mk. package/udev.mk would be the ideal location but virtual packages can't have hooks.

Anyway, these are just optional improvements that can be made later.

Signature · 1 line
Carlos Santos <[email protected]>
#5 lore raw

PATCH 2/3 package/eudev: generate hwdb.bin

In reply to Yann E. MORIN

For the hwdb installed by eudev to be useful, it has to be compiled into a binary form.

This is a bit tricky:
- the .hwdb files (the source) are installed in TARGET_DIR,
- HOST_DIR/bin/udevadm only looks in HOST_DIR

So, we copy the .hwdb files for the target from TARGET_DIR and into HOST_DIR, run udevadm, and copy the generated hwdb.bin back to TARGET_DIR.

Various packages may install their .hwdb files, so we can only generate hwdb.bin after all packages have been installed, that is as a target-finalize hook.

Finally, the .hwdb files take as much space as the generated hwdb.bin (in the order of 8MiB currently), so we remove them for target.

However, to still support iterative builds (e.g. make foo-reinstall), we still want to have the .hwdb in target/. So we remove them as a pre-rootfs hook.

Cc Peter Korsgaard <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Carlos Santos <[email protected]>
---
 package/eudev/Config.in |  3 ++-
 package/eudev/eudev.mk  | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
package/eudev/Config.in +2 -1
index 2220265a55..b1d2f37a72 100644
@@ -29,8 +29,9 @@ config BR2_PACKAGE_EUDEV_RULES_GEN
 config BR2_PACKAGE_EUDEV_ENABLE_HWDB
 	bool "enable hwdb installation"
 	default y
+	select BR2_PACKAGE_HOST_EUDEV # for udevadm, during target-finalize
 	help
-	  Enables hardware database installation to /etc/udev/hwdb.d
+	  Enables hardware database installation to /etc/udev/hwdb.bin
 
 endif
 
package/eudev/eudev.mk +22 -0
index 12568a6645..9bb96714f0 100644
@@ -33,6 +33,28 @@ endif
 
 ifeq ($(BR2_PACKAGE_EUDEV_ENABLE_HWDB),y)
 EUDEV_CONF_OPTS += --enable-hwdb
+
+# "udevadm hwdb" was configured with its prefix set to HOST_DIR (it is
+# from a host package), so it can only look in there to find .hwdb files.
+# Remove existing .hwdb files (they are from the host variant or a
+# previous run), and replace them with those from target.
+define EUDEV_BUILD_HWDB
+	rm -rf $(HOST_DIR)/etc/udev/hwdb.d
+	cp -a $(TARGET_DIR)/etc/udev/hwdb.d $(HOST_DIR)/etc/udev/hwdb.d
+	$(HOST_DIR)/bin/udevadm hwdb --update
+	$(INSTALL) -D -m 0644 $(HOST_DIR)/etc/udev/hwdb.bin \
+		$(TARGET_DIR)/etc/udev/hwdb.bin
+endef
+EUDEV_TARGET_FINALIZE_HOOKS += EUDEV_BUILD_HWDB
+
+# Note: this will run in the filesystem context, so will use a copy
+# of tharget/, not the real one, so the files are still available on
+# re-builds (foo-rebuild, etc...)
+define EUDEV_RM_HWDB_SRC
+	rm -rf $(TARGET_DIR)/etc/udev/hwdb.d/
+endef
+EUDEV_ROOTFS_PRE_CMD_HOOKS += EUDEV_RM_HWDB_SRC
+
 else
 EUDEV_CONF_OPTS += --disable-hwdb
 endif
Signature · 1 line
2.20.1
#6 lore raw

PATCH 2/3 package/eudev: generate hwdb.bin

Quoted 56 lines · Yann E. MORIN

For the hwdb installed by eudev to be useful, it has to be compiled into a binary form.

This is a bit tricky:
- the .hwdb files (the source) are installed in TARGET_DIR,
- HOST_DIR/bin/udevadm only looks in HOST_DIR

So, we copy the .hwdb files for the target from TARGET_DIR and into HOST_DIR, run udevadm, and copy the generated hwdb.bin back to TARGET_DIR.

Various packages may install their .hwdb files, so we can only generate hwdb.bin after all packages have been installed, that is as a target-finalize hook.

Finally, the .hwdb files take as much space as the generated hwdb.bin (in the order of 8MiB currently), so we remove them for target.

However, to still support iterative builds (e.g. make foo-reinstall), we still want to have the .hwdb in target/. So we remove them as a pre-rootfs hook.

Cc Peter Korsgaard <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Carlos Santos <[email protected]>
---
 package/eudev/Config.in |  3 ++-
 package/eudev/eudev.mk  | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
package/eudev/Config.in +2 -1
index 2220265a55..b1d2f37a72 100644
@@ -29,8 +29,9 @@ config BR2_PACKAGE_EUDEV_RULES_GEN
 config BR2_PACKAGE_EUDEV_ENABLE_HWDB
        bool "enable hwdb installation"
        default y
+       select BR2_PACKAGE_HOST_EUDEV # for udevadm, during target-finalize
        help
-         Enables hardware database installation to /etc/udev/hwdb.d
+         Enables hardware database installation to /etc/udev/hwdb.bin
 
 endif
 
package/eudev/eudev.mk +1 -0
index 12568a6645..9bb96714f0 100644
@@ -33,6 +33,28 @@ endif
 
 ifeq ($(BR2_PACKAGE_EUDEV_ENABLE_HWDB),y)
 EUDEV_CONF_OPTS += --enable-hwdb
+

package/eudev/eudev.mk endif · line 46

Quoted 10 lines
package/eudev/eudev.mk +10 -0
+# "udevadm hwdb" was configured with its prefix set to HOST_DIR (it is
+# from a host package), so it can only look in there to find .hwdb files.
+# Remove existing .hwdb files (they are from the host variant or a
+# previous run), and replace them with those from target.
+define EUDEV_BUILD_HWDB
+       rm -rf $(HOST_DIR)/etc/udev/hwdb.d
+       cp -a $(TARGET_DIR)/etc/udev/hwdb.d $(HOST_DIR)/etc/udev/hwdb.d
+       $(HOST_DIR)/bin/udevadm hwdb --update
+       $(INSTALL) -D -m 0644 $(HOST_DIR)/etc/udev/hwdb.bin \
+               $(TARGET_DIR)/etc/udev/hwdb.bin

Use

    $(HOST_DIR)/bin/udevadm hwdb --update --root $(TARGET_DIR)
Quoted 17 lines
package/eudev/eudev.mk +11 -1
+endef
+EUDEV_TARGET_FINALIZE_HOOKS += EUDEV_BUILD_HWDB
+
+# Note: this will run in the filesystem context, so will use a copy
+# of tharget/, not the real one, so the files are still available on
+# re-builds (foo-rebuild, etc...)
+define EUDEV_RM_HWDB_SRC
+       rm -rf $(TARGET_DIR)/etc/udev/hwdb.d/
+endef
+EUDEV_ROOTFS_PRE_CMD_HOOKS += EUDEV_RM_HWDB_SRC
+
 else
 EUDEV_CONF_OPTS += --disable-hwdb
 endif
--

2.20.1

Signature · 1 line
Carlos Santos <[email protected]>
#7 lore raw

PATCH 3/3 package/systemd: generate hwdb.bin

In reply to Yann E. MORIN

For the hwdb installed by systemd to be useful, it has to be compiled into a binary form.

This is a bit tricky:
- the .hwdb files (the source) are installed in TARGET_DIR,
- HOST_DIR/bin/udevadm only looks in HOST_DIR

So, we copy the .hwdb files for the target from TARGET_DIR and into HOST_DIR, run udevadm, and copy the generated hwdb.bin back to TARGET_DIR.

Various packages may install their .hwdb files, so we can only generate hwdb.bin after all packages have been installed, that is as a target-finalize hook.

Finally, the .hwdb files take as much space as the generated hwdb.bin (in the order of 8MiB currently), so we remove them for target.

However, to still support iterative builds (e.g. make foo-reinstall), we still want to have the .hwdb in target/. So we remove them as a pre-rootfs hook.

Cc Peter Korsgaard <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Carlos Santos <[email protected]>
---
 package/systemd/Config.in  |  1 +
 package/systemd/systemd.mk | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
package/systemd/Config.in +1 -0
index 601398bf96..aef39abe27 100644
@@ -199,6 +199,7 @@ config BR2_PACKAGE_SYSTEMD_HOSTNAMED
 config BR2_PACKAGE_SYSTEMD_HWDB
 	bool "enable hwdb installation"
 	default y
+	select BR2_PACKAGE_HOST_EUDEV # for udevadm, during target-finalize
 	help
 	  Enables hardware database installation to /usr/lib/udev/hwdb.d
 
package/systemd/systemd.mk +23 -0
index df40961fee..4e8db8fd31 100644
@@ -203,6 +203,29 @@ endif
 
 ifeq ($(BR2_PACKAGE_SYSTEMD_HWDB),y)
 SYSTEMD_CONF_OPTS += -Dhwdb=true
+
+# "udevadm hwdb" was configured with its prefix set to HOST_DIR (it is
+# from a host package), so it can only look in there to find .hwdb files.
+# Remove existing .hwdb files (they are from the host variant or a
+# previous run), and replace them with those from target.
+# Note that systemd and eudev put their files in diffeernt locations.
+define SYSTEMD_BUILD_HWDB
+	rm -rf $(HOST_DIR)/etc/udev/hwdb.d
+	cp -a $(TARGET_DIR)/usr/lib/udev/hwdb.d $(HOST_DIR)/etc/udev/hwdb.d
+	$(HOST_DIR)/bin/udevadm hwdb --update
+	$(INSTALL) -D -m 0644 $(HOST_DIR)/etc/udev/hwdb.bin \
+		$(TARGET_DIR)/usr/lib/udev/hwdb.bin
+endef
+SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_BUILD_HWDB
+
+# Note: this will run in the filesystem context, so will use a copy
+# of tharget/, not the real one, so the files are still available on
+# re-builds (foo-rebuild, etc...)
+define SYSTEMD_RM_HWDB_SRC
+	rm -rf $(TARGET_DIR)/usr/lib/udev/hwdb.d/
+endef
+SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SYSTEMD_RM_HWDB_SRC
+
 else
 SYSTEMD_CONF_OPTS += -Dhwdb=false
 endif
Signature · 1 line
2.20.1
#8 lore raw

PATCH 3/3 package/systemd: generate hwdb.bin

Quoted 54 lines · Yann E. MORIN

For the hwdb installed by systemd to be useful, it has to be compiled into a binary form.

This is a bit tricky:
- the .hwdb files (the source) are installed in TARGET_DIR,
- HOST_DIR/bin/udevadm only looks in HOST_DIR

So, we copy the .hwdb files for the target from TARGET_DIR and into HOST_DIR, run udevadm, and copy the generated hwdb.bin back to TARGET_DIR.

Various packages may install their .hwdb files, so we can only generate hwdb.bin after all packages have been installed, that is as a target-finalize hook.

Finally, the .hwdb files take as much space as the generated hwdb.bin (in the order of 8MiB currently), so we remove them for target.

However, to still support iterative builds (e.g. make foo-reinstall), we still want to have the .hwdb in target/. So we remove them as a pre-rootfs hook.

Cc Peter Korsgaard <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Carlos Santos <[email protected]>
---
 package/systemd/Config.in  |  1 +
 package/systemd/systemd.mk | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
package/systemd/Config.in +1 -0
index 601398bf96..aef39abe27 100644
@@ -199,6 +199,7 @@ config BR2_PACKAGE_SYSTEMD_HOSTNAMED
 config BR2_PACKAGE_SYSTEMD_HWDB
        bool "enable hwdb installation"
        default y
+       select BR2_PACKAGE_HOST_EUDEV # for udevadm, during target-finalize
        help
          Enables hardware database installation to /usr/lib/udev/hwdb.d
 
package/systemd/systemd.mk +2 -0
index df40961fee..4e8db8fd31 100644
@@ -203,6 +203,29 @@ endif
 
 ifeq ($(BR2_PACKAGE_SYSTEMD_HWDB),y)
 SYSTEMD_CONF_OPTS += -Dhwdb=true
+
+# "udevadm hwdb" was configured with its prefix set to HOST_DIR (it is

package/systemd/systemd.mk endif · line 217

Quoted 10 lines
package/systemd/systemd.mk +10 -0
+# from a host package), so it can only look in there to find .hwdb files.
+# Remove existing .hwdb files (they are from the host variant or a
+# previous run), and replace them with those from target.
+# Note that systemd and eudev put their files in diffeernt locations.
+define SYSTEMD_BUILD_HWDB
+       rm -rf $(HOST_DIR)/etc/udev/hwdb.d
+       cp -a $(TARGET_DIR)/usr/lib/udev/hwdb.d $(HOST_DIR)/etc/udev/hwdb.d
+       $(HOST_DIR)/bin/udevadm hwdb --update
+       $(INSTALL) -D -m 0644 $(HOST_DIR)/etc/udev/hwdb.bin \
+               $(TARGET_DIR)/usr/lib/udev/hwdb.bin

Use

        $(HOST_DIR)/bin/udevadm hwdb --update --root $(TARGET_DIR)
Quoted 17 lines
package/systemd/systemd.mk +11 -1
+endef
+SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_BUILD_HWDB
+
+# Note: this will run in the filesystem context, so will use a copy
+# of tharget/, not the real one, so the files are still available on
+# re-builds (foo-rebuild, etc...)
+define SYSTEMD_RM_HWDB_SRC
+       rm -rf $(TARGET_DIR)/usr/lib/udev/hwdb.d/
+endef
+SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SYSTEMD_RM_HWDB_SRC
+
 else
 SYSTEMD_CONF_OPTS += -Dhwdb=false
 endif
--

2.20.1

Signature · 1 line
Carlos Santos <[email protected]>