summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/boot/efi/boot.c12
-rw-r--r--src/boot/efi/cpio.c2
-rw-r--r--src/boot/efi/devicetree.c2
-rw-r--r--src/boot/efi/drivers.c2
-rw-r--r--src/boot/efi/efi-string.h26
-rw-r--r--src/boot/efi/random-seed.c2
-rw-r--r--src/boot/efi/util.c18
-rw-r--r--src/boot/efi/util.h5
-rw-r--r--src/fundamental/efivars-fundamental.h6
-rw-r--r--src/fundamental/macro-fundamental.h3
-rw-r--r--src/fundamental/string-util-fundamental.c2
-rw-r--r--src/fundamental/string-util-fundamental.h2
12 files changed, 47 insertions, 35 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index 79cb36c717..ea19dd82d2 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -1,7 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include <inttypes.h>
-
#include "bcd.h"
#include "bootspec-fundamental.h"
#include "console.h"
@@ -1375,7 +1373,7 @@ static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
if (err != EFI_SUCCESS)
return;
- err = get_file_info_harder(handle, &file_info, &file_info_size);
+ err = get_file_info(handle, &file_info, &file_info_size);
if (err != EFI_SUCCESS)
return;
@@ -1648,7 +1646,7 @@ static void config_load_entries(
for (;;) {
_cleanup_free_ char *content = NULL;
- err = readdir_harder(entries_dir, &f, &f_size);
+ err = readdir(entries_dir, &f, &f_size);
if (err != EFI_SUCCESS || !f)
break;
@@ -2117,7 +2115,7 @@ static void config_entry_add_unified(
size_t offs[_SECTION_MAX] = {}, szs[_SECTION_MAX] = {}, pos = 0;
char *line, *key, *value;
- err = readdir_harder(linux_dir, &f, &f_size);
+ err = readdir(linux_dir, &f, &f_size);
if (err != EFI_SUCCESS || !f)
break;
@@ -2300,7 +2298,7 @@ static EFI_STATUS initrd_prepare(
return err;
_cleanup_free_ EFI_FILE_INFO *info = NULL;
- err = get_file_info_harder(handle, &info, NULL);
+ err = get_file_info(handle, &info, NULL);
if (err != EFI_SUCCESS)
return err;
@@ -2493,7 +2491,7 @@ static EFI_STATUS secure_boot_discover_keys(Config *config, EFI_FILE *root_dir)
size_t dirent_size = 0;
ConfigEntry *entry = NULL;
- err = readdir_harder(keys_basedir, &dirent, &dirent_size);
+ err = readdir(keys_basedir, &dirent, &dirent_size);
if (err != EFI_SUCCESS || !dirent)
return err;
diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c
index bcd5e975ea..2e971a9167 100644
--- a/src/boot/efi/cpio.c
+++ b/src/boot/efi/cpio.c
@@ -373,7 +373,7 @@ EFI_STATUS pack_cpio(
for (;;) {
_cleanup_free_ char16_t *d = NULL;
- err = readdir_harder(extra_dir, &dirent, &dirent_size);
+ err = readdir(extra_dir, &dirent, &dirent_size);
if (err != EFI_SUCCESS)
return log_error_status(err, "Failed to read extra directory of loaded image: %m");
if (!dirent) /* End of directory */
diff --git a/src/boot/efi/devicetree.c b/src/boot/efi/devicetree.c
index 2304daa23b..3916bca946 100644
--- a/src/boot/efi/devicetree.c
+++ b/src/boot/efi/devicetree.c
@@ -79,7 +79,7 @@ EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir
if (err != EFI_SUCCESS)
return err;
- err = get_file_info_harder(handle, &info, NULL);
+ err = get_file_info(handle, &info, NULL);
if (err != EFI_SUCCESS)
return err;
if (info->FileSize < FDT_V1_SIZE || info->FileSize > 32 * 1024 * 1024)
diff --git a/src/boot/efi/drivers.c b/src/boot/efi/drivers.c
index e38e3e3b8c..25bf694723 100644
--- a/src/boot/efi/drivers.c
+++ b/src/boot/efi/drivers.c
@@ -87,7 +87,7 @@ EFI_STATUS load_drivers(
return log_error_status(err, "Failed to open \\EFI\\systemd\\drivers: %m");
for (;;) {
- err = readdir_harder(drivers_dir, &dirent, &dirent_size);
+ err = readdir(drivers_dir, &dirent, &dirent_size);
if (err != EFI_SUCCESS)
return log_error_status(err, "Failed to read extra directory of loaded image: %m");
if (!dirent) /* End of directory */
diff --git a/src/boot/efi/efi-string.h b/src/boot/efi/efi-string.h
index ea9493bcbb..6b6b0d57b4 100644
--- a/src/boot/efi/efi-string.h
+++ b/src/boot/efi/efi-string.h
@@ -121,6 +121,32 @@ _gnu_printf_(2, 0) _warn_unused_result_ char16_t *xvasprintf_status(EFI_STATUS s
# define printf(...) printf_status(EFI_SUCCESS, __VA_ARGS__)
# define xasprintf(...) xasprintf_status(EFI_SUCCESS, __VA_ARGS__)
+/* inttypes.h is provided by libc instead of the compiler and is not supposed to be used in freestanding
+ * environments. We could use clang __*_FMT*__ constants for this, bug gcc does not have them. :( */
+
+# if defined(__ILP32__)
+# define PRI64_PREFIX "ll"
+# elif defined(__LP64__)
+# define PRI64_PREFIX "l"
+# elif defined(__LLP64__) || (__SIZEOF_LONG__ == 4 && __SIZEOF_POINTER__ == 8)
+# define PRI64_PREFIX "ll"
+# else
+# error Unknown 64-bit data model
+# endif
+
+# define PRIi32 "i"
+# define PRIu32 "u"
+# define PRIx32 "x"
+# define PRIX32 "X"
+# define PRIiPTR "zi"
+# define PRIuPTR "zu"
+# define PRIxPTR "zx"
+# define PRIXPTR "zX"
+# define PRIi64 PRI64_PREFIX "i"
+# define PRIu64 PRI64_PREFIX "u"
+# define PRIx64 PRI64_PREFIX "x"
+# define PRIX64 PRI64_PREFIX "X"
+
/* The compiler normally has knowledge about standard functions such as memcmp, but this is not the case when
* compiling with -ffreestanding. By referring to builtins, the compiler can check arguments and do
* optimizations again. Note that we still need to provide implementations as the compiler is free to not
diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c
index daf0a4c0a9..8147e545e4 100644
--- a/src/boot/efi/random-seed.c
+++ b/src/boot/efi/random-seed.c
@@ -200,7 +200,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir) {
return err;
}
- err = get_file_info_harder(handle, &info, NULL);
+ err = get_file_info(handle, &info, NULL);
if (err != EFI_SUCCESS)
return log_error_status(err, "Failed to get file info for random seed: %m");
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
index 48b30a8f5a..96c62e6bfa 100644
--- a/src/boot/efi/util.c
+++ b/src/boot/efi/util.c
@@ -1,7 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include <inttypes.h>
-
#include "proto/device-path.h"
#include "proto/simple-text-io.h"
#include "ticks.h"
@@ -300,7 +298,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, size_t off, size_t siz
if (size == 0) {
_cleanup_free_ EFI_FILE_INFO *info = NULL;
- err = get_file_info_harder(handle, &info, NULL);
+ err = get_file_info(handle, &info, NULL);
if (err != EFI_SUCCESS)
return err;
@@ -372,11 +370,7 @@ void sort_pointer_array(
}
}
-EFI_STATUS get_file_info_harder(
- EFI_FILE *handle,
- EFI_FILE_INFO **ret,
- size_t *ret_size) {
-
+EFI_STATUS get_file_info(EFI_FILE *handle, EFI_FILE_INFO **ret, size_t *ret_size) {
size_t size = offsetof(EFI_FILE_INFO, FileName) + 256;
_cleanup_free_ EFI_FILE_INFO *fi = NULL;
EFI_STATUS err;
@@ -384,8 +378,6 @@ EFI_STATUS get_file_info_harder(
assert(handle);
assert(ret);
- /* A lot like LibFileInfo() but with useful error propagation */
-
fi = xmalloc(size);
err = handle->GetInfo(handle, MAKE_GUID_PTR(EFI_FILE_INFO), &size, fi);
if (err == EFI_BUFFER_TOO_SMALL) {
@@ -405,7 +397,7 @@ EFI_STATUS get_file_info_harder(
return EFI_SUCCESS;
}
-EFI_STATUS readdir_harder(
+EFI_STATUS readdir(
EFI_FILE *handle,
EFI_FILE_INFO **buffer,
size_t *buffer_size) {
@@ -425,7 +417,7 @@ EFI_STATUS readdir_harder(
* position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when
* the buffer was too small. Therefore, start with a buffer that should handle FAT32 max
* file name length.
- * As a side effect, most readdir_harder() calls will now be slightly faster. */
+ * As a side effect, most readdir() calls will now be slightly faster. */
sz = sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t);
*buffer = xmalloc(sz);
*buffer_size = sz;
@@ -491,7 +483,7 @@ EFI_STATUS open_directory(
if (err != EFI_SUCCESS)
return err;
- err = get_file_info_harder(dir, &file_info, NULL);
+ err = get_file_info(dir, &file_info, NULL);
if (err != EFI_SUCCESS)
return err;
if (!FLAGS_SET(file_info->Attribute, EFI_FILE_DIRECTORY))
diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h
index ab15e2bf23..614d83fb71 100644
--- a/src/boot/efi/util.h
+++ b/src/boot/efi/util.h
@@ -125,9 +125,8 @@ void clear_screen(size_t attr);
typedef int (*compare_pointer_func_t)(const void *a, const void *b);
void sort_pointer_array(void **array, size_t n_members, compare_pointer_func_t compare);
-EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, size_t *ret_size);
-
-EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, size_t *buffer_size);
+EFI_STATUS get_file_info(EFI_FILE *handle, EFI_FILE_INFO **ret, size_t *ret_size);
+EFI_STATUS readdir(EFI_FILE *handle, EFI_FILE_INFO **buffer, size_t *buffer_size);
bool is_ascii(const char16_t *f);
diff --git a/src/fundamental/efivars-fundamental.h b/src/fundamental/efivars-fundamental.h
index cf785f8b7d..3bad79b036 100644
--- a/src/fundamental/efivars-fundamental.h
+++ b/src/fundamental/efivars-fundamental.h
@@ -1,7 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include <errno.h>
+#ifdef SD_BOOT
+# define EINVAL 22
+#else
+# include <errno.h>
+#endif
#include "string-util-fundamental.h"
/* Features of the loader, i.e. systemd-boot */
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
index c4ad957588..fa5b5d221a 100644
--- a/src/fundamental/macro-fundamental.h
+++ b/src/fundamental/macro-fundamental.h
@@ -339,11 +339,8 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
#define ALIGN2_PTR(p) ((void*) ALIGN2((uintptr_t) p))
#define ALIGN4_PTR(p) ((void*) ALIGN4((uintptr_t) p))
#define ALIGN8_PTR(p) ((void*) ALIGN8((uintptr_t) p))
-#if !SD_BOOT
-/* libefi also provides ALIGN, and we do not use them in sd-boot explicitly. */
#define ALIGN(l) ALIGN_TO(l, sizeof(void*))
#define ALIGN_PTR(p) ((void*) ALIGN((uintptr_t) (p)))
-#endif
/* Checks if the specified pointer is aligned as appropriate for the specific type */
#define IS_ALIGNED16(p) (((uintptr_t) p) % __alignof__(uint16_t) == 0)
diff --git a/src/fundamental/string-util-fundamental.c b/src/fundamental/string-util-fundamental.c
index 484131d72a..a5bafc63f4 100644
--- a/src/fundamental/string-util-fundamental.c
+++ b/src/fundamental/string-util-fundamental.c
@@ -20,7 +20,6 @@ sd_char *startswith(const sd_char *s, const sd_char *prefix) {
return (sd_char*) s + l;
}
-#if !SD_BOOT
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
size_t l;
@@ -33,7 +32,6 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
return (sd_char*) s + l;
}
-#endif
sd_char* endswith(const sd_char *s, const sd_char *postfix) {
size_t sl, pl;
diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h
index f55dcbf56a..9019542b16 100644
--- a/src/fundamental/string-util-fundamental.h
+++ b/src/fundamental/string-util-fundamental.h
@@ -58,9 +58,7 @@ static inline size_t strlen_ptr(const sd_char *s) {
}
sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
-#if !SD_BOOT
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
-#endif
sd_char *endswith(const sd_char *s, const sd_char *postfix) _pure_;
sd_char *endswith_no_case(const sd_char *s, const sd_char *postfix) _pure_;