2022-07-14 05:11:28

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 1/4] kbuild: rpm-pkg: fix build error when _arch is undefined

Cross-building (bin)rpm-pkg fails on several architectures.

For example, 'make ARCH=arm binrpm-pkg' fails like follows:

sh ./scripts/package/mkspec prebuilt > ./binkernel.spec
rpmbuild --define "_builddir ." --target \
arm -bb ./binkernel.spec
Building target platforms: arm
Building for target arm
warning: line 19: It's not recommended to have unversioned Obsoletes: Obsoletes: kernel-headers
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.0S8t2F
+ umask 022
+ cd .
+ mkdir -p /home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch}/boot
+ make -f ./Makefile image_name
+ cp arch/arm/boot/zImage /home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch}/boot/vmlinuz-5.19.0-rc6
+ make -f ./Makefile INSTALL_MOD_PATH=/home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch} modules_install
make[3]: *** No rule to make target '/home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.arch/arm/crypto/aes-arm-bs.ko{_arch}/lib/modules/5.19.0-rc6/kernel/%', needed by '__modinst'. Stop.
make[2]: *** [Makefile:1768: modules_install] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.0S8t2F (%install)

By default, 'buildroot' contains %{_arch} (see /usr/lib/rpm/macros).

_arch is generally defined in /usr/lib/rpm/platforms/*/macros, where
the platform sub-directory is specified by --target= option for cross
builds.

If the given arch does not exist, %{_arch} is not expanded.
In the example above, --target=arm is passed to rpmbuild, but
/usr/lib/rpm/platforms/arm-linux/ does not exist.

The '%' character in the path confuses GNU make and rpmbuild.

The same occurs for such architectures as csky, microblaze, nios2, etc.

Define _arch if it has not been defined.

Reported-by: Jason Self <[email protected]>
Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 3 +++
1 file changed, 3 insertions(+)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 7c477ca7dc98..8fa7c5b8a1a1 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -49,6 +49,9 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
URL: https://www.kernel.org
$S Source: kernel-$__KERNELRELEASE.tar.gz
Provides: $PROVIDES
+ # $UTS_MACHINE as a fallback of _arch in case
+ # /usr/lib/rpm/platform/*/macros was not included.
+ %define _arch %{?_arch:$UTS_MACHINE}
%define __spec_install_post /usr/lib/rpm/brp-compress || :
%define debug_package %{nil}

--
2.34.1


2022-07-14 05:24:08

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 4/4] kbuild: error out if $(INSTALL_MOD_PATH) contains % or :

If the directory pass given to INSTALL_MOD_PATH contains % or :,
the module_install fails.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.modinst | 3 +++
1 file changed, 3 insertions(+)

diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
index 16a02e9237d3..a4c987c23750 100644
--- a/scripts/Makefile.modinst
+++ b/scripts/Makefile.modinst
@@ -18,6 +18,9 @@ INSTALL_MOD_DIR ?= extra
dst := $(MODLIB)/$(INSTALL_MOD_DIR)
endif

+$(foreach x, % :, $(if $(findstring $x, $(dst)), \
+ $(error module installation path cannot contain '$x')))
+
suffix-y :=
suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
--
2.34.1

2022-07-14 05:41:45

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 2/4] kbuild: rpm-pkg: pass 'linux' to --target option of rpmbuild

Presumably, _target_os is defined even if the --target flag does not
specify it, but it is better to make it explicit.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.package | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index 77b612183c08..5017f6b2da80 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -56,7 +56,7 @@ rpm-pkg:
$(MAKE) clean
$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
$(call cmd,src_tar,$(KERNELPATH),kernel.spec)
- +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \
+ +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \
--define='_smp_mflags %{nil}'

# binrpm-pkg
@@ -66,7 +66,7 @@ binrpm-pkg:
$(MAKE) -f $(srctree)/Makefile
$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
- $(UTS_MACHINE) -bb $(objtree)/binkernel.spec
+ $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec

PHONY += deb-pkg
deb-pkg:
--
2.34.1

2022-07-15 09:45:56

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 4/4] kbuild: error out if $(INSTALL_MOD_PATH) contains % or :

On Thu, Jul 14, 2022 at 02:02:43PM +0900, Masahiro Yamada wrote:
> If the directory pass given to INSTALL_MOD_PATH contains % or :,
> the module_install fails.
>
> % is used in pattern rules, and : as the separator of dependencies.
>
> Bail out with a clearer error message.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---

Reviewed-by: Nicolas Schier <[email protected]>

2022-07-16 16:06:09

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 4/4] kbuild: error out if $(INSTALL_MOD_PATH) contains % or :

On Thu, Jul 14, 2022 at 2:03 PM Masahiro Yamada <[email protected]> wrote:
>
> If the directory pass given to INSTALL_MOD_PATH contains % or :,

A typo.

directory pass -> directory path





> the module_install fails.
>
> % is used in pattern rules, and : as the separator of dependencies.
>
> Bail out with a clearer error message.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> scripts/Makefile.modinst | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
> index 16a02e9237d3..a4c987c23750 100644
> --- a/scripts/Makefile.modinst
> +++ b/scripts/Makefile.modinst
> @@ -18,6 +18,9 @@ INSTALL_MOD_DIR ?= extra
> dst := $(MODLIB)/$(INSTALL_MOD_DIR)
> endif
>
> +$(foreach x, % :, $(if $(findstring $x, $(dst)), \
> + $(error module installation path cannot contain '$x')))
> +
> suffix-y :=
> suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
> suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
> --
> 2.34.1
>


--
Best Regards
Masahiro Yamada