1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-05-12 19:06:29 +02:00
parent 9ce14a75e7
commit 776fabbc8b
5 changed files with 39 additions and 4 deletions

View File

@ -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')

View File

@ -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

8
src/fundamental/sbat.h Normal file
View File

@ -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

View File

@ -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')],

23
src/test/test-sbat.c Normal file
View File

@ -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);