All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Cc: nathan@kernel.org, nicolas@fjasle.eu,
	linux-kbuild@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kbuild: rpm-pkg: add dtb files in kernel rpm
Date: Sat, 9 Mar 2024 23:24:29 +0900	[thread overview]
Message-ID: <CAK7LNAQ6_kr0Q1RB0dELiGUObFJ4HEEu3XTErGf6FaNntKMnTg@mail.gmail.com> (raw)
In-Reply-To: <20240305110915.184868-1-jtornosm@redhat.com>

On Tue, Mar 5, 2024 at 8:09 PM Jose Ignacio Tornos Martinez
<jtornosm@redhat.com> wrote:
>
> Some architectures, like aarch64 ones, need a dtb file to configure the
> hardware. The default dtb file can be preloaded from u-boot, but the final
> and/or more complete dtb file needs to be able to be loaded later from
> rootfs.
>
> Add the possible dtb files to the kernel rpm and mimic Fedora shipping
> process, storing the dtb files in the module directory. These dtb files
> will be copied to /boot directory by the install scripts, but add fallback
> just in case, checking if the content in /boot directory is correct.
>
> Mark the files installed to /boot as %ghost to make sure they will be
> removed when the package is uninstalled.
>
> Tested with Fedora Rawhide (x86_64 and aarch64) with dnf and rpm tools.
> In addition, fallback was also tested after modifying the install scripts.
>
> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
> ---
>  scripts/package/kernel.spec | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
> index c256b73cca3e..5c4c1ffcba6c 100644
> --- a/scripts/package/kernel.spec
> +++ b/scripts/package/kernel.spec
> @@ -61,6 +61,9 @@ cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEAS
>  %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
>  cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE}
>  cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config
> +if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ];then



${srctree} and ${SRCARCH} are not always defined in kernel.spec.


They are not defined if you directly run 'rpmbuild -rb <SRPM>'.


The following will correctly check the presence of
${srctree}/arch/${SRCARCH}/boot/dts.


if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d
${srctree}/arch/${SRCARCH}/boot/dts'; then








> +       %{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install
> +fi
>  ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
>  %if %{with_devel}
>  %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
> @@ -81,6 +84,14 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA
>                 echo "%ghost /boot/${x}-%{KERNELRELEASE}"
>         done
>
> +       if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then
> +               echo "/lib/modules/%{KERNELRELEASE}/dtb"
> +               for x in $(find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -name "*" \
> +                               -exec realpath --relative-to "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" {} \;); do
> +                       echo "%ghost /boot/dtb-%{KERNELRELEASE}/${x}"
> +               done


Instead of the for-loop, you can write it in one command:


  find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf
"%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n"


Is the escaping % complex?













> +       fi
> +
>         echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
>  } > %{buildroot}/kernel.list
>
> @@ -96,6 +107,12 @@ for file in vmlinuz System.map config; do
>                 cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"
>         fi
>  done
> +if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ]; then
> +       if ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" &>/dev/null; then


I do not recommend the bash'ism "&>/dev/null".

The scriptlet is executed by /bin/sh, which
may not be bash, although on most RPM-based
distro, it is a symlink to bash.


You can squash the nested if-conditionals:


if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \
   ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb"
"/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then
        ...
fi





> +               rm -rf "/boot/dtb-%{KERNELRELEASE}"
> +               cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}"
> +       fi
> +fi
>  if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then
>         /usr/sbin/depmod %{KERNELRELEASE}
>  fi
> --
> 2.43.2
>
>


--
Best Regards



Masahiro Yamada

  reply	other threads:[~2024-03-09 14:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 11:09 [PATCH] kbuild: rpm-pkg: add dtb files in kernel rpm Jose Ignacio Tornos Martinez
2024-03-09 14:24 ` Masahiro Yamada [this message]
2024-03-11 16:18   ` Jose Ignacio Tornos Martinez
2024-03-11 16:22   ` [PATCH V2] " Jose Ignacio Tornos Martinez
2024-03-15 19:00     ` Nathan Chancellor
2024-03-18 17:33     ` Masahiro Yamada

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=CAK7LNAQ6_kr0Q1RB0dELiGUObFJ4HEEu3XTErGf6FaNntKMnTg@mail.gmail.com \
    --to=masahiroy@kernel.org \
    --cc=jtornosm@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas@fjasle.eu \
    /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 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.