From 68bb8ad1ab0d3e3f832bc48d600a6eefab717b7b Mon Sep 17 00:00:00 2001 From: Mark Pryor Date: Mon, 28 Apr 2025 11:51:57 -0700 Subject: [PATCH] introduce xen_mkimage --- grub.macros | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++ grub.patches | 1 + grub2.spec | 41 +++++++++++ 3 files changed, 229 insertions(+) diff --git a/grub.macros b/grub.macros index 5038650..72b6327 100644 --- a/grub.macros +++ b/grub.macros @@ -50,6 +50,8 @@ -e 's/-mcpu=power[[:alnum:]]\\+/-mcpu=power6/g' \\\ )} %global efi_host_cflags %{expand:%%(echo %{host_cflags})} +%global xen_host_cflags %{expand:%%(echo %{host_cflags})} +%global xen_pvh_host_cflags %{expand:%%(echo %{host_cflags})} %global target_cflags %{expand:%%(echo %{build_cflags} | %{cflags_sed})} %global legacy_target_cflags \\\ @@ -59,6 +61,8 @@ -e 's/-mcpu=power[[:alnum:]]\\+/-mcpu=power6/g' \\\ )} %global efi_target_cflags %{expand:%%(echo %{target_cflags})} +%global xen_target_cflags %{expand:%%(echo %{target_cflags})} +%global xen_pvh_target_cflags %{expand:%%(echo %{target_cflags})} %global ldflags_sed \\\ sed \\\ @@ -72,6 +76,8 @@ %{ldflags_sed} \\\ )} %global efi_host_ldflags %{expand:%%(echo %{host_ldflags})} +%global xen_host_ldflags %{expand:%%(echo %{host_ldflags})} +%global xen_pvh_host_ldflags %{expand:%%(echo %{host_ldflags})} %global target_ldflags %{expand:%%(echo %{build_ldflags} -Wl,--no-warn-rwx-segments -static | %{ldflags_sed})} %global legacy_target_ldflags \\\ @@ -79,15 +85,21 @@ %{ldflags_sed} \\\ )} %global efi_target_ldflags %{expand:%%(echo %{target_ldflags})} +%global xen_target_ldflags %{expand:%%(echo %{target_ldflags})} +%global xen_pvh_target_ldflags %{expand:%%(echo %{target_ldflags})} %global with_efi_arch 0 %global with_alt_efi_arch 0 %global with_legacy_arch 0 %global with_emu_arch 1 +%global with_xen_arch 0 +%global with_xen_pvh_arch 0 %global emuarch %{_arch} %global grubefiarch %{nil} %global grublegacyarch %{nil} %global grubelfname %{nil} +%global xen_package_arch %{nil} +%global xen_pvh_package_arch %{nil} # sparc is always compiled 64 bit %ifarch %{sparc} @@ -131,6 +143,24 @@ %global efi_modules " efi_netfs efifwsetup efinet lsefi lsefimmap connectefi " %endif +%global xen_arch x86_64 +%ifarch %{xen_arch} +%global with_xen_arch 1 +%else +%global with_xen_arch 0 +%endif +%{!?with_xen_arch:%global without_xen_arch 0} +%{?with_xen_arch:%global without_xen_arch 1} + +%global xen_pvh_arch x86_64 +%ifarch %{xen_pvh_arch} +%global with_xen_pvh_arch 1 +%else +%global with_xen_pvh_arch 0 +%endif +%{!?with_xen_pvh_arch:%global without_xen_pvh_arch 0} +%{?with_xen_pvh_arch:%global without_xen_pvh_arch 1} + %ifarch %{x86_64} %{ix86} %global platform_modules " backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug keylayouts at_keyboard " %endif @@ -163,11 +193,18 @@ %global target_cpu_name %{_arch} %global grub_target_name %{_arch}-efi %global package_arch efi-x64 +%global xen_package_arch xen-x64 +%global xen_pvh_package_arch xen_pvh-i386 %global legacy_target_cpu_name i386 %global legacy_package_arch pc %global platform pc +%global xen_grub_target_name %{_arch}-xen +%global xen_pvh_grub_target_name i386-xen_pvh +%global grubxenarch %{xen_grub_target_name} +%global grubxenpvharch %{xen_pvh_grub_target_name} + %global alt_efi_arch ia32 %global alt_target_cpu_name i386 %global alt_grub_target_name i386-efi @@ -333,6 +370,32 @@ Provides: grub2-efi-cdboot = %{evr} \ This subpackage provides optional components of grub used with removeable media on %{1} systems.\ %{nil} +%define define_xen_variant(o) \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%{1}-%{tarversion}}}\ +%{expand:%%package %{1}-modules} \ +Summary: Modules used to build custom grub-%{xen_grub_target_name}.bin images \ +BuildArch: noarch \ +Requires: grub2-tools = %{evr} \ +Provides: grub2-xen-modules = %{evr} \ +Obsoletes: grub2-xen-modules < %{evr} \ +%{expand:%%description %{1}-modules} \ +%{desc} \ +This subpackage provides support for rebuilding your own grub-%{xen_grub_target_name}.bin. \ +%{nil} + +%define define_xen_pvh_variant(o) \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%{1}-%{tarversion}}}\ +%{expand:%%package %{1}-modules} \ +Summary: Modules used to build custom grub-%{xen_pvh_grub_target_name}.bin images \ +BuildArch: noarch \ +Requires: grub2-tools = %{evr} \ +Provides: grub2-xen_pvh-modules = %{evr} \ +Obsoletes: grub2-xen_pvh-modules < %{evr} \ +%{expand:%%description %{1}-modules} \ +%{desc} \ +This subpackage provides support for rebuilding your own grub-%{xen_pvh_grub_target_name}.bin. \ +%{nil} + %global do_common_setup() \ %setup -q -n grub-%{tarversion} \ rm -fv docs/*.info \ @@ -378,6 +441,46 @@ git add . \ git commit -m "After efi configure" \ %{nil} +%define do_xen_configure() \ +%configure \\\ + %{cc_equals} \\\ + HOST_CFLAGS="%{3}" \\\ + HOST_CPPFLAGS="-I$(pwd)" \\\ + HOST_LDFLAGS="%{xen_host_ldflags}" \\\ + TARGET_CFLAGS="%{2}" \\\ + TARGET_CPPFLAGS="-I$(pwd)" \\\ + TARGET_LDFLAGS="%{xen_target_ldflags}" \\\ + --with-rpm-version=%{version}-%{release} \\\ + --with-platform=xen \\\ + --with-utils=host \\\ + --target=%{1} \\\ + --with-grubdir=grub2 \\\ + --program-transform-name=s,grub,grub2, \\\ + --disable-werror || ( cat config.log ; exit 1 ) \ +git add . \ +git commit -m "After xen configure" \ +%{nil} + +%define do_xen_pvh_configure() \ +%configure \\\ + %{cc_equals} \\\ + HOST_CFLAGS="%{3}" \\\ + HOST_CPPFLAGS="-I$(pwd)" \\\ + HOST_LDFLAGS="%{xen_pvh_host_ldflags}" \\\ + TARGET_CFLAGS="%{2}" \\\ + TARGET_CPPFLAGS="-I$(pwd)" \\\ + TARGET_LDFLAGS="%{xen_pvh_target_ldflags}" \\\ + --with-rpm-version=%{version}-%{release} \\\ + --with-platform=xen_pvh \\\ + --with-utils=host \\\ + --target=%{1} \\\ + --with-grubdir=grub2 \\\ + --program-transform-name=s,grub,grub2, \\\ + --disable-werror || ( cat config.log ; exit 1 ) \ +git add . \ +git commit -m "After xen_pvh configure" \ +%{nil} + %define do_efi_build_modules() \ make %{?_smp_mflags} ascii.h widthspec.h \ make %{?_smp_mflags} -C grub-core \ @@ -393,6 +496,16 @@ for x in grub-mkimage ; do \\\ done \ %{nil} +%define do_xen_build_modules() \ +make %{?_smp_mflags} ascii.h widthspec.h \ +make %{?_smp_mflags} -C grub-core \ +%{nil} + +%define do_xen_pvh_build_modules() \ +make %{?_smp_mflags} ascii.h widthspec.h \ +make %{?_smp_mflags} -C grub-core \ +%{nil} + %define do_install_protected_file() \ touch %{1}.conf \ echo %{1} > %{1}.conf \ @@ -560,6 +673,20 @@ make %{?_smp_mflags} -C grub-core \ cd .. \ %{nil} +%define do_xen_build() \ +cd grub-%{1}-%{tarversion} \ +%{expand:%%do_xen_configure %%{2} %%{3} %%{4}} \ +%do_xen_build_modules \ +cd .. \ +%{nil} + +%define do_xen_pvh_build() \ +cd grub-%{1}-%{tarversion} \ +%{expand:%%do_xen_pvh_configure %%{2} %%{3} %%{4}} \ +%do_xen_pvh_build_modules \ +cd .. \ +%{nil} + %define do_alt_efi_install() \ cd grub-%{1}-%{tarversion} \ install -d -m 755 $RPM_BUILD_ROOT/usr/lib/grub/%{grubaltefiarch}/ \ @@ -657,6 +784,48 @@ fi \ cd .. \ %{nil} +%define do_xen_install() \ +cd grub-%{1}-%{tarversion} \ +make DESTDIR=$RPM_BUILD_ROOT install \ +%{expand:%%{xen_mkimage %{1} %{SOURCE16}}} \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub.info \ +fi \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ +fi \ +find $RPM_BUILD_ROOT -iname "*.module" -exec chmod a-x {} '\;' \ +cd .. \ +%{nil} + +%define xen_mkimage() \ +target=%{1} \ +cfgfile=%{2} \ +pvfile=grub2-%{1}.bin \ + ./grub-mkstandalone -v --compress=xz --locale-dir=%{buildroot}/usr/share/locale --locales=en\@quot --fonts="unicode" \\\ + --modules="linux normal" --themes="" -d grub-core \\\ + -O %{1} -o $pvfile boot/grub/grub.cfg=${cfgfile} \ +pvdir=%{buildroot}/usr/share/pvgrub2/%{1} \ +if [ ! -d $pvdir ]; then \\\ +install -m 755 -d $pvdir \ +fi \ +install -m 755 $pvfile $pvdir/$pvfile \ +%{nil} + +%define do_xen_pvh_install() \ +cd grub-%{1}-%{tarversion} \ +make DESTDIR=$RPM_BUILD_ROOT install \ +%{expand:%%{xen_mkimage %{1} %{SOURCE16}}} \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub.info \ +fi \ +if [ -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info ]; then \ + rm -f $RPM_BUILD_ROOT%{_infodir}/grub-dev.info \ +fi \ +find $RPM_BUILD_ROOT -iname "*.module" -exec chmod a-x {} '\;' \ +cd .. \ +%{nil} + %define do_common_install() \ install -d -m 0755 \\\ $RPM_BUILD_ROOT%{_datarootdir}/locale/en\@quot \\\ @@ -743,3 +912,21 @@ ln -s ../boot/grub2/grub.cfg \\\ %attr(0700,root,root) %verify(not mtime) %{efi_esp_dir}/%{3} \ %attr(0700,root,root)/boot/grub2/fonts \ %{nil} + +%define define_xen_variant_files() \ +%{expand:%%files %{1}-modules} \ +%defattr(-,root,root,-) \ +%dir %{_libdir}/grub/%{2}/ \ +%{_libdir}/grub/%{2}/* \ +%exclude %{_libdir}/grub/%{2}/*.module \ +%{_datadir}/pvgrub2/%{2}/*%{2}* \ +%{nil} + +%define define_xen_pvh_variant_files() \ +%{expand:%%files %{1}-modules} \ +%defattr(-,root,root,-) \ +%dir %{_libdir}/grub/%{2}/ \ +%{_libdir}/grub/%{2}/* \ +%exclude %{_libdir}/grub/%{2}/*.module \ +%{_datadir}/pvgrub2/%{2}/*%{2}* \ +%{nil} diff --git a/grub.patches b/grub.patches index 2ca6a9b..58ff6ea 100644 --- a/grub.patches +++ b/grub.patches @@ -358,3 +358,4 @@ Patch0358: 0358-loader-i386-linux-Cast-left-shift-to-grub_uint32_t.patch Patch0359: 0359-loader-i386-bsd-Use-safe-math-to-avoid-underflow.patch Patch0360: 0360-fs-ext2-Rework-out-of-bounds-read-for-inline-and-ext.patch Patch0361: 0361-powerpc-increase-MIN-RMA-size-for-CAS-negotiation.patch +Patch0601: 0601-Enable-building-blscfg-module-on-xen-and-xen_pvh.patch diff --git a/grub2.spec b/grub2.spec index 3f0d001..c744bc5 100644 --- a/grub2.spec +++ b/grub2.spec @@ -35,6 +35,7 @@ Source9: strtoull_test.c Source10: 20-grub.install Source11: grub.patches Source12: sbat.csv.in +Source16: grub_grub.cfg %include %{SOURCE1} @@ -170,6 +171,12 @@ This subpackage provides tools for support of all platforms. %if 0%{with_legacy_arch} %{expand:%define_legacy_variant %%{legacy_package_arch}} %endif +%if 0%{with_xen_arch} +%{expand:%define_xen_variant %%{xen_package_arch} -o} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%define_xen_pvh_variant %%{xen_pvh_package_arch} -o} +%endif %if 0%{with_emu_arch} %package emu @@ -217,6 +224,22 @@ grep -A100000 '# stuff "make" creates' .gitignore > grub-emu-%{tarversion}/.giti cp %{SOURCE4} grub-emu-%{tarversion}/unifont.pcf.gz git add grub-emu-%{tarversion} %endif +%if 0%{with_xen_arch} +mkdir grub-%{grubxenarch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grubxenarch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grubxenarch}-%{tarversion}/unifont.pcf.gz +sed -e "s,@@VERSION@@,%{version},g" -e "s,@@VERSION_RELEASE@@,%{version}-%{release},g" \ + %{SOURCE12} > grub-%{grubxenarch}-%{tarversion}/sbat.csv +git add grub-%{grubxenarch}-%{tarversion} +%endif +%if 0%{with_xen_pvh_arch} +mkdir grub-%{grubxenpvharch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grubxenpvharch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grubxenpvharch}-%{tarversion}/unifont.pcf.gz +sed -e "s,@@VERSION@@,%{version},g" -e "s,@@VERSION_RELEASE@@,%{version}-%{release},g" \ + %{SOURCE12} > grub-%{grubxenpvharch}-%{tarversion}/sbat.csv +git add grub-%{grubxenpvharch}-%{tarversion} +%endif git commit -m "After making subdirs" %build @@ -232,6 +255,12 @@ git commit -m "After making subdirs" %if 0%{with_emu_arch} %{expand:%do_emu_build} %endif +%if 0%{with_xen_arch} +%{expand:%do_xen_build %%{grubxenarch} %%{_target_platform} %%{xen_target_cflags} %%{xen_host_cflags}} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%do_xen_pvh_build %%{grubxenpvharch} %%{_target_platform} %%{xen_pvh_target_cflags} %%{xen_pvh_host_cflags}} +%endif %ifarch ppc64le %{expand:%do_ieee1275_build_images %%{grublegacyarch} %{grubelfname} %{sb_cer} %{sb_key}} %endif @@ -261,6 +290,12 @@ rm -fr $RPM_BUILD_ROOT %if 0%{with_emu_arch} %{expand:%do_emu_install %%{package_arch}} %endif +%if 0%{with_xen_arch} +%{expand:%do_xen_install %%{grubxenarch}} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%do_xen_pvh_install %%{grubxenpvharch}} +%endif rm -f $RPM_BUILD_ROOT%{_infodir}/dir ln -s grub2-set-password ${RPM_BUILD_ROOT}/%{_sbindir}/grub2-setpassword echo '.so man8/grub2-set-password.8' > ${RPM_BUILD_ROOT}/%{_datadir}/man/man8/grub2-setpassword.8 @@ -562,6 +597,12 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %if 0%{with_legacy_arch} %{expand:%define_legacy_variant_files %%{legacy_package_arch} %%{grublegacyarch}} %endif +%if 0%{with_xen_arch} +%{expand:%define_xen_variant_files %%{xen_package_arch} %%{xen_grub_target_name}} +%endif +%if 0%{with_xen_pvh_arch} +%{expand:%define_xen_pvh_variant_files %%{xen_pvh_package_arch} %%{xen_pvh_grub_target_name}} +%endif %if 0%{with_emu_arch} %files emu -- 2.47.1