package/linux-headers: enable host build
PATCH 1/2 package/linux-headers: enable host build
This will be used for building tools that are included with the kernel, such as host-bpftool.
--- package/linux-headers/linux-headers.mk | 10 ++++++++++ 1 file changed, 10 insertions(+)
package/linux-headers/linux-headers.mk +10 -0
@@ -135,6 +135,15 @@ define LINUX_HEADERS_CONFIGURE_CMDS headers_install) endef +define HOST_LINUX_HEADERS_CONFIGURE_CMDS + (cd $(@D); \ + $(HOST_MAKE_ENV) $(MAKE) \ + HOSTCC="$(HOSTCC)" \ + HOSTCFLAGS="$(HOSTCFLAGS)" \ + HOSTCXX="$(HOSTCXX)" \ + defconfig) +endef + define LINUX_HEADERS_INSTALL_STAGING_CMDS (cd $(@D); \ $(TARGET_MAKE_ENV) $(MAKE) \
@@ -160,3 +169,4 @@ LINUX_HEADERS_POST_INSTALL_STAGING_HOOKS += LINUX_HEADERS_CHECK_VERSION endif $(eval $(generic-package)) +$(eval $(host-generic-package))
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] http://lists.busybox.net/mailman/listinfo/buildroot
PATCH 2/2 package/linux-tools: add host-bpftool support
This will be required for building systemd with bpf support.
--- package/Config.in.host | 1 + package/linux-tools/Config.in.host | 11 +++++++++++ package/linux-tools/linux-tool-bpftool.mk.in | 20 ++++++++++++++++++++ package/linux-tools/linux-tools.mk | 17 +++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 package/linux-tools/Config.in.host
package/Config.in.host +1 -0
@@ -45,6 +45,7 @@ menu "Host utilities" source "package/jsmin/Config.in.host" source "package/kmod/Config.in.host" source "package/libp11/Config.in.host" + source "package/linux-tools/Config.in.host" source "package/lld/Config.in.host" source "package/lpc3250loader/Config.in.host" source "package/lttng-babeltrace/Config.in.host"
package/linux-tools/Config.in.host new file +11 -0
@@ -0,0 +1,11 @@ +config BR2_PACKAGE_HOST_LINUX_TOOLS + bool + +config BR2_PACKAGE_HOST_LINUX_TOOLS_BPFTOOL + bool "host bpftool" + select BR2_PACKAGE_HOST_LINUX_TOOLS + help + bpftool is a tool for for inspection and simple manipulation + of eBPF programs and maps. + + These tools are available only from kernel version 4.15.
package/linux-tools/linux-tool-bpftool.mk.in +20 -0
@@ -5,6 +5,7 @@ ################################################################################ LINUX_TOOLS += bpftool +HOST_LINUX_TOOLS += host-bpftool BPFTOOL_DEPENDENCIES = binutils elfutils
@@ -17,6 +18,9 @@ BPFTOOL_DEPENDENCIES += zlib endif BPFTOOL_MAKE_OPTS = $(LINUX_MAKE_FLAGS) +HOST_BPFTOOL_MAKE_OPTS = $(HOST_MAKE_FLAGS) \ + CFLAGS="$(HOST_CFLAGS)" \ + LDFLAGS="$(HOST_LDFLAGS)" define BPFTOOL_BUILD_CMDS $(Q)if ! grep install $(LINUX_DIR)/tools/bpf/bpftool/Makefile >/dev/null 2>&1 ; then \
@@ -29,9 +33,25 @@ define BPFTOOL_BUILD_CMDS $(BPFTOOL_MAKE_OPTS) endef +define HOST_BPFTOOL_BUILD_CMDS + $(Q)if ! grep install $(HOST_LINUX_HEADERS_DIR)/tools/bpf/bpftool/Makefile >/dev/null 2>&1 ; then \ + echo "Your kernel version is too old and does not have install section in the bpf tools." ; \ + echo "At least kernel 4.15 must be used." ; \ + exit 1 ; \ + fi + + $(HOST_MAKE_ENV) $(MAKE1) -C $(HOST_LINUX_HEADERS_DIR) \ + $(HOST_BPFTOOL_MAKE_OPTS) \ + tools/bpf/bpftool +endef + define BPFTOOL_INSTALL_TARGET_CMDS $(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_DIR)/tools/bpf/bpftool \ $(BPFTOOL_MAKE_OPTS) \ DESTDIR=$(TARGET_DIR) \ install endef + +define HOST_BPFTOOL_INSTALL_CMDS + $(INSTALL) -m 0755 -D $(HOST_LINUX_HEADERS_DIR)/tools/bpf/bpftool/bpftool $(HOST_DIR)/usr/sbin/bpftool +endef
package/linux-tools/linux-tools.mk +17 -0
@@ -21,6 +21,7 @@ include $(sort $(wildcard package/linux-tools/*.mk.in)) # We only need the kernel to be extracted, not actually built LINUX_TOOLS_PATCH_DEPENDENCIES = linux +HOST_LINUX_TOOLS_DEPENDENCIES = host-linux-headers # Install Linux kernel tools in the staging directory since some tools # may install shared libraries and headers (e.g. cpupower).
@@ -34,6 +35,10 @@ LINUX_TOOLS_POST_BUILD_HOOKS += $(foreach tool,$(LINUX_TOOLS),\ $(if $(BR2_PACKAGE_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\ $(call UPPERCASE,$(tool))_BUILD_CMDS)) +HOST_LINUX_TOOLS_POST_BUILD_HOOKS += $(foreach tool,$(LINUX_TOOLS),\ + $(if $(BR2_PACKAGE_HOST_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\ + HOST_$(call UPPERCASE,$(tool))_BUILD_CMDS)) + LINUX_TOOLS_POST_INSTALL_STAGING_HOOKS += $(foreach tool,$(LINUX_TOOLS),\ $(if $(BR2_PACKAGE_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\ $(call UPPERCASE,$(tool))_INSTALL_STAGING_CMDS))
@@ -42,6 +47,10 @@ LINUX_TOOLS_POST_INSTALL_TARGET_HOOKS += $(foreach tool,$(LINUX_TOOLS),\ $(if $(BR2_PACKAGE_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\ $(call UPPERCASE,$(tool))_INSTALL_TARGET_CMDS)) +HOST_LINUX_TOOLS_POST_INSTALL_HOOKS += $(foreach tool,$(LINUX_TOOLS),\ + $(if $(BR2_PACKAGE_HOST_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\ + HOST_$(call UPPERCASE,$(tool))_INSTALL_CMDS)) + define LINUX_TOOLS_LINUX_CONFIG_FIXUPS $(foreach tool,$(LINUX_TOOLS),\ $(if $(BR2_PACKAGE_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\
@@ -49,6 +58,13 @@ define LINUX_TOOLS_LINUX_CONFIG_FIXUPS ) endef +define HOST_LINUX_TOOLS_LINUX_CONFIG_FIXUPS + $(foreach tool,$(LINUX_TOOLS),\ + $(if $(BR2_PACKAGE_HOST_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\ + $(HOST_$(call UPPERCASE,$(tool))_LINUX_CONFIG_FIXUPS)) + ) +endef + define LINUX_TOOLS_INSTALL_INIT_SYSTEMD $(foreach tool,$(LINUX_TOOLS),\ $(if $(BR2_PACKAGE_LINUX_TOOLS_$(call UPPERCASE,$(tool))),\
@@ -72,3 +88,4 @@ define LINUX_TOOLS_INSTALL_INIT_OPENRC endef $(eval $(generic-package)) +$(eval $(host-generic-package))
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] http://lists.busybox.net/mailman/listinfo/buildroot
Hello James,
Quoted 4 lines · On Tue, 10 Aug 2021 00:45:46 -0600 James Hilliard <[email protected]>…
This will be used for building tools that are included with the kernel, such as host-bpftool.
Signed-off-by James Hilliard <[email protected]>
I'm sorry, but I fail to see how this can make sense, for a number of reasons:
* For external toolchains, package/linux-headers/Config.in.host is not even included, which means that no version of kernel headers are defined.
* Even for internal toolchains, the kernel headers version selected for the target, which you re-use here for the host kernel headers, has no correlation with the actual kernel running on the build machine. If you are running an oldish 3.10 kernel on your build machine, install host-linux-headers 5.15, and build host-bpftool based on that, you'll run into issue.
So, perhaps the first thing is to figure out why the host variant of bpftool needs kernel headers. What are these tool doing on the host? What is the use case?
Then if we really want to build them for the host, I guess the only solution is to ask the user to install the kernel headers matching their build machine (so with some hidden option BR2_NEEDS_HOST_KERNEL_HEADERS, which is selected by your package, and then with logic in support/dependencies/ to check that).
Thanks!
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 18 lines · Thomas Petazzoni
Hello James,
Quoted 4 lines · On Tue, 10 Aug 2021 00:45:46 -0600 James Hilliard <[email protected]>…
This will be used for building tools that are included with the kernel, such as host-bpftool.
Signed-off-by James Hilliard <[email protected]>I'm sorry, but I fail to see how this can make sense, for a number of reasons:
* For external toolchains, package/linux-headers/Config.in.host is not even included, which means that no version of kernel headers are defined.
Quoted 6 lines
* Even for internal toolchains, the kernel headers version selected for the target, which you re-use here for the host kernel headers, has no correlation with the actual kernel running on the build machine. If you are running an oldish 3.10 kernel on your build machine, install host-linux-headers 5.15, and build host-bpftool based on that, you'll run into issue.
Yeah, I wasn't sure if this would work, previously this tool was only available integrated with the kernel, but it has now been separated like libbpf so we can use that version instead which shouldn't require building from the kernel tree anymore.
Quoted 4 lines
So, perhaps the first thing is to figure out why the host variant of bpftool needs kernel headers. What are these tool doing on the host? What is the use case?
This tool is needed to generate bpf skeleton files, systemd needs this for example to enable bpf-framework support.
Quoted 6 lines
Then if we really want to build them for the host, I guess the only solution is to ask the user to install the kernel headers matching their build machine (so with some hidden option
BR2_NEEDS_HOST_KERNEL_HEADERS, which is selected by your package, and then with logic in support/dependencies/ to check that).
I've made a patch to use the new stand-alone bpftool package instead:
https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/
Quoted 8 lines
Thanks!
Thomas
--
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot