All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] package/linux-headers: enable host build
@ 2021-08-10  6:45 James Hilliard
  2021-08-10  6:45 ` [Buildroot] [PATCH 2/2] package/linux-tools: add host-bpftool support James Hilliard
  2021-12-28 22:33 ` [Buildroot] [PATCH 1/2] package/linux-headers: enable host build Thomas Petazzoni
  0 siblings, 2 replies; 4+ messages in thread
From: James Hilliard @ 2021-08-10  6:45 UTC (permalink / raw)
  To: buildroot; +Cc: James Hilliard, Yann E . MORIN, Thomas Petazzoni

This will be used for building tools that are included with the kernel,
such as host-bpftool.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 package/linux-headers/linux-headers.mk | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/package/linux-headers/linux-headers.mk b/package/linux-headers/linux-headers.mk
index a8d1c2ccaf..d171879bc9 100644
--- a/package/linux-headers/linux-headers.mk
+++ b/package/linux-headers/linux-headers.mk
@@ -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))
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH 2/2] package/linux-tools: add host-bpftool support
  2021-08-10  6:45 [Buildroot] [PATCH 1/2] package/linux-headers: enable host build James Hilliard
@ 2021-08-10  6:45 ` James Hilliard
  2021-12-28 22:33 ` [Buildroot] [PATCH 1/2] package/linux-headers: enable host build Thomas Petazzoni
  1 sibling, 0 replies; 4+ messages in thread
From: James Hilliard @ 2021-08-10  6:45 UTC (permalink / raw)
  To: buildroot; +Cc: James Hilliard, Yann E . MORIN, Thomas Petazzoni

This will be required for building systemd with bpf support.

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

_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Buildroot] [PATCH 1/2] package/linux-headers: enable host build
  2021-08-10  6:45 [Buildroot] [PATCH 1/2] package/linux-headers: enable host build James Hilliard
  2021-08-10  6:45 ` [Buildroot] [PATCH 2/2] package/linux-tools: add host-bpftool support James Hilliard
@ 2021-12-28 22:33 ` Thomas Petazzoni
  2022-01-31  2:22   ` James Hilliard
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2021-12-28 22:33 UTC (permalink / raw)
  To: James Hilliard; +Cc: Yann E . MORIN, buildroot

Hello James,

On Tue, 10 Aug 2021 00:45:46 -0600
James Hilliard <james.hilliard1@gmail.com> wrote:

> This will be used for building tools that are included with the kernel,
> such as host-bpftool.
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>

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
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Buildroot] [PATCH 1/2] package/linux-headers: enable host build
  2021-12-28 22:33 ` [Buildroot] [PATCH 1/2] package/linux-headers: enable host build Thomas Petazzoni
@ 2022-01-31  2:22   ` James Hilliard
  0 siblings, 0 replies; 4+ messages in thread
From: James Hilliard @ 2022-01-31  2:22 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: Yann E . MORIN, buildroot

On Tue, Dec 28, 2021 at 3:33 PM Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
>
> Hello James,
>
> On Tue, 10 Aug 2021 00:45:46 -0600
> James Hilliard <james.hilliard1@gmail.com> wrote:
>
> > This will be used for building tools that are included with the kernel,
> > such as host-bpftool.
> >
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>
> 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.

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.

>
> 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.

>
> 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/20220131021609.4117295-1-james.hilliard1@gmail.com/

>
> Thanks!
>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering and training
> https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-31  2:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10  6:45 [Buildroot] [PATCH 1/2] package/linux-headers: enable host build James Hilliard
2021-08-10  6:45 ` [Buildroot] [PATCH 2/2] package/linux-tools: add host-bpftool support James Hilliard
2021-12-28 22:33 ` [Buildroot] [PATCH 1/2] package/linux-headers: enable host build Thomas Petazzoni
2022-01-31  2:22   ` James Hilliard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.