From: Zbigniew Jędrzejewski-Szmek Date: Thu, 12 May 2022 17:06:29 +0000 (+0200) Subject: Add a "test" that prints the SBAT table X-Git-Tag: v251~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=776fabbc8bcd25f809c89ac571b9709343c538b8;p=thirdparty%2Fsystemd.git Add a "test" that prints the SBAT table The SBAT section was included in a special section in the EFI code, but the contents weren't directly visible in any way. Let's add a "test" that prints them for visual inspection. If there's some external linter for this format, we could hook it up in the future. --- diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index d7dae94ef2d..e0edbf18a22 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -3,6 +3,8 @@ conf.set10('ENABLE_EFI', get_option('efi')) conf.set10('HAVE_GNU_EFI', false) +efi_config_h_dir = meson.current_build_dir() + if not get_option('efi') or get_option('gnu-efi') == 'false' if get_option('gnu-efi') == 'true' error('gnu-efi support requested, but general efi support is disabled') diff --git a/src/boot/efi/secure-boot.c b/src/boot/efi/secure-boot.c index ab2d256031a..23505d5ae80 100644 --- a/src/boot/efi/secure-boot.c +++ b/src/boot/efi/secure-boot.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sbat.h" #include "secure-boot.h" #include "util.h" @@ -30,8 +31,5 @@ SecureBootMode secure_boot_mode(void) { } #ifdef SBAT_DISTRO -static const char sbat[] _used_ _section_(".sbat") = - "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md\n" - SBAT_PROJECT ",1,The systemd Developers," SBAT_PROJECT "," PROJECT_VERSION "," PROJECT_URL "\n" - SBAT_PROJECT "." SBAT_DISTRO "," STRINGIFY(SBAT_DISTRO_GENERATION) "," SBAT_DISTRO_SUMMARY "," SBAT_DISTRO_PKGNAME "," SBAT_DISTRO_VERSION "," SBAT_DISTRO_URL "\n"; +static const char sbat[] _used_ _section_(".sbat") = SBAT_SECTION_TEXT; #endif diff --git a/src/fundamental/sbat.h b/src/fundamental/sbat.h new file mode 100644 index 00000000000..b3c09dcb4c3 --- /dev/null +++ b/src/fundamental/sbat.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#ifdef SBAT_DISTRO +# define SBAT_SECTION_TEXT \ + "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md\n" \ + SBAT_PROJECT ",1,The systemd Developers," SBAT_PROJECT "," PROJECT_VERSION "," PROJECT_URL "\n" \ + SBAT_PROJECT "." SBAT_DISTRO "," STRINGIFY(SBAT_DISTRO_GENERATION) "," SBAT_DISTRO_SUMMARY "," SBAT_DISTRO_PKGNAME "," SBAT_DISTRO_VERSION "," SBAT_DISTRO_URL "\n" +#endif diff --git a/src/test/meson.build b/src/test/meson.build index eb24988bea2..74da544a46e 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -478,6 +478,10 @@ tests += [ [files('test-date.c')], + [files('test-sbat.c'), + [], [], [], 'HAVE_GNU_EFI', '', + ['-I@0@'.format(efi_config_h_dir)]], + [files('test-sleep.c')], [files('test-tpm2.c')], diff --git a/src/test/test-sbat.c b/src/test/test-sbat.c new file mode 100644 index 00000000000..1a905418d1d --- /dev/null +++ b/src/test/test-sbat.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +/* We include efi_config.h after undefining PROJECT_VERSION which is also defined in config.h. */ +#undef PROJECT_VERSION +#include "efi_config.h" + +#include "build.h" +#include "sbat.h" +#include "tests.h" + +TEST(sbat_section_text) { + log_info("---SBAT-----------&<----------------------------------------\n" + "%s" + "------------------>&-----------------------------------------", +#ifdef SBAT_DISTRO + SBAT_SECTION_TEXT +#else + "(not defined)" +#endif + ); +} + +DEFINE_TEST_MAIN(LOG_INFO);