[Buildroot] [PATCH 2/2] package/linux-tools: add host-bpftool support

James Hilliard james.hilliard1 at gmail.com
Tue Aug 10 06:45:47 UTC 2021


This will be required for building systemd with bpf support.

Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
---
 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

diff --git a/package/Config.in.host b/package/Config.in.host
index 8d443ea255..98cc67b238 100644
--- a/package/Config.in.host
+++ b/package/Config.in.host
@@ -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"
diff --git a/package/linux-tools/Config.in.host b/package/linux-tools/Config.in.host
new file mode 100644
index 0000000000..b228f9b02d
--- /dev/null
+++ b/package/linux-tools/Config.in.host
@@ -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.
diff --git a/package/linux-tools/linux-tool-bpftool.mk.in b/package/linux-tools/linux-tool-bpftool.mk.in
index 0c4d3693a3..c5e6fb97db 100644
--- a/package/linux-tools/linux-tool-bpftool.mk.in
+++ b/package/linux-tools/linux-tool-bpftool.mk.in
@@ -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
diff --git a/package/linux-tools/linux-tools.mk b/package/linux-tools/linux-tools.mk
index 81b1fbc176..0375883d95 100644
--- a/package/linux-tools/linux-tools.mk
+++ b/package/linux-tools/linux-tools.mk
@@ -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))
-- 
2.25.1



More information about the buildroot mailing list