From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: David Dgien <dgienda125@gmail.com>, Claude <noreply@claude.ai>,
Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 07/12] kbuild: add support for installing and stripping modules
Date: Thu, 15 Jan 2026 12:54:33 +0100 [thread overview]
Message-ID: <20260115115924.3428886-8-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260115115924.3428886-1-a.fatoum@barebox.org>
We have a defunct modules_install target, which fails when called.
Fix it, so it actually installs stripped modules.
This is important, because we don't want barebox to attempt relocation
the .debug sections as it doesn't support all relocations that can occur
there.
Note that unlike Linux, we always strip. Linux on the other hand has a
check that skips relocation of non-alloc segments and we may want to add
that too in future, but only after switching to barebox proper being
linked in PBL as proper ELF.
Co-developed-by: Claude <noreply@claude.ai>
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
Makefile | 15 ++-------
scripts/Makefile.modinst | 67 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 12 deletions(-)
create mode 100644 scripts/Makefile.modinst
diff --git a/Makefile b/Makefile
index 1a5f21b66ebb..b6023dc4ff2c 100644
--- a/Makefile
+++ b/Makefile
@@ -448,7 +448,6 @@ LEX = flex
YACC = bison
AWK = awk
GENKSYMS = scripts/genksyms/genksyms
-DEPMOD = /sbin/depmod
KALLSYMS = scripts/kallsyms
SCONFIGPOST = scripts/sconfig/sconfigpost
PERL = perl
@@ -1317,18 +1316,13 @@ modules_prepare: prepare scripts
# Target to install modules
PHONY += modules_install
-modules_install: _modinst_ _modinst_post
+modules_install: _modinst_
PHONY += _modinst_
_modinst_:
- @if [ -z "`$(DEPMOD) -V 2>/dev/null | grep module-init-tools`" ]; then \
- echo "Warning: you may need to install module-init-tools"; \
- echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
- sleep 1; \
- fi
- @rm -rf $(MODLIB)/kernel
+ @rm -rf $(MODLIB)/barebox
@rm -f $(MODLIB)/source
- @mkdir -p $(MODLIB)/kernel
+ @mkdir -p $(MODLIB)/barebox
@ln -s $(srctree) $(MODLIB)/source
@if [ ! $(objtree) -ef $(MODLIB)/build ]; then \
rm -f $(MODLIB)/build ; \
@@ -1346,9 +1340,6 @@ depmod_opts :=
else
depmod_opts := -b $(INSTALL_MOD_PATH) -r
endif
-PHONY += _modinst_post
-_modinst_post: _modinst_
- if [ -r System.map -a -x $(DEPMOD) ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
else # CONFIG_MODULES
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
new file mode 100644
index 000000000000..6cb9b6ccaa1e
--- /dev/null
+++ b/scripts/Makefile.modinst
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Installing modules
+# ==========================================================================
+
+PHONY := __modinst
+__modinst:
+
+include $(objtree)/include/config/auto.conf
+include $(srctree)/scripts/Kbuild.include
+
+install-y :=
+
+# remove the old directory
+$(shell rm -fr $(MODLIB)/barebox)
+
+dst := $(MODLIB)/barebox
+
+# Find all .ko files in the build tree
+modules := $(shell find $(objtree) -name '*.ko' -not -path '$(MODLIB)/*' 2>/dev/null)
+modules-dst := $(addprefix $(dst)/, $(patsubst $(objtree)/%,%,$(modules)))
+
+install-$(CONFIG_MODULES) += $(modules-dst)
+
+__modinst: $(install-y)
+ @:
+
+#
+# Installation
+#
+quiet_cmd_install = INSTALL $@
+ cmd_install = mkdir -p $(dir $@) && cp $< $@
+
+INSTALL_MOD_STRIP ?= 1
+
+# Strip
+#
+# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
+# are installed. If INSTALL_MOD_STRIP is '1', then the default option
+# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
+# as the options to the strip command.
+ifdef INSTALL_MOD_STRIP
+
+ifeq ($(INSTALL_MOD_STRIP),1)
+strip-option := --strip-debug
+else
+strip-option := $(INSTALL_MOD_STRIP)
+endif
+
+quiet_cmd_strip = STRIP $@
+ cmd_strip = $(STRIP) $(strip-option) $@
+
+else
+
+quiet_cmd_strip =
+ cmd_strip = :
+
+endif
+
+$(dst)/%.ko: $(objtree)/%.ko FORCE
+ $(call cmd,install)
+ $(call cmd,strip)
+
+PHONY += FORCE
+FORCE:
+
+.PHONY: $(PHONY)
--
2.47.3
next prev parent reply other threads:[~2026-01-15 12:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 11:54 [PATCH 00/12] ARM32: modules: fix bitrot and add test Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 01/12] boards: qemu-virt: reserve BIOS device tree Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 02/12] ARM: qemu-virt: add image for use as -bios Ahmad Fatoum
2026-01-16 8:33 ` Sascha Hauer
2026-01-16 10:21 ` Ahmad Fatoum
2026-01-16 12:52 ` Ahmad Fatoum
2026-01-16 15:16 ` Sascha Hauer
2026-01-15 11:54 ` [PATCH 03/12] kbuild: build *.mod.c with -std=gnu11 Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 04/12] ARM32: mark modules as incompatible with ARM_MMU_PERMISSIONS Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 05/12] treewide: fix some missing EXPORT_SYMBOL Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 06/12] pci: ecam: enable build as module Ahmad Fatoum
2026-01-15 11:54 ` Ahmad Fatoum [this message]
2026-01-15 11:54 ` [PATCH 08/12] ARM32: module: handle more relocations Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 09/12] commands: pm_domain: make command tristate Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 10/12] test: conftest: add support for describing FW_CFG environment in YAML Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 11/12] defaultenv: add barebox_modules_env target Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 12/12] test: arm: add simple driver/command module test Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260115115924.3428886-8-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=dgienda125@gmail.com \
--cc=noreply@claude.ai \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox