summaryrefslogtreecommitdiff
path: root/src/boot
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-02-04 03:21:08 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-09 14:22:54 +0900
commite5bc5f1f5ac3595bfbe77d4896d6b7b22a0310a8 (patch)
treeebf3a88d73ad0a49008c9a441a58ad387702e900 /src/boot
parent5f33b2300b1ce7749a686dd1699ea0818b45857c (diff)
downloadsystemd-e5bc5f1f5ac3595bfbe77d4896d6b7b22a0310a8.tar.gz
fundamental: move several macros and functions into src/fundamental/
sd-boot has a copy of a subset of codes from libbasic. This makes sd-boot share the code with libbasic, and dedup the code. Note, startswith_no_case() is dropped from sd-boot, as - it is not used, - the previous implementation is not correct, - gnu-efi does not have StrniCmp() or so.
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/efi/boot.c2
-rw-r--r--src/boot/efi/loader-features.h14
-rw-r--r--src/boot/efi/meson.build14
-rw-r--r--src/boot/efi/util.c56
-rw-r--r--src/boot/efi/util.h21
5 files changed, 11 insertions, 96 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index 3ba326586b..5f2e8f4b7c 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -7,9 +7,9 @@
#include "console.h"
#include "crc32.h"
#include "disk.h"
+#include "efi-loader-features.h"
#include "graphics.h"
#include "linux.h"
-#include "loader-features.h"
#include "measure.h"
#include "pe.h"
#include "random-seed.h"
diff --git a/src/boot/efi/loader-features.h b/src/boot/efi/loader-features.h
deleted file mode 100644
index f07dacb859..0000000000
--- a/src/boot/efi/loader-features.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-#ifndef UINT64_C
-# define UINT64_C(c) (c ## ULL)
-#endif
-
-#define EFI_LOADER_FEATURE_CONFIG_TIMEOUT (UINT64_C(1) << 0)
-#define EFI_LOADER_FEATURE_CONFIG_TIMEOUT_ONE_SHOT (UINT64_C(1) << 1)
-#define EFI_LOADER_FEATURE_ENTRY_DEFAULT (UINT64_C(1) << 2)
-#define EFI_LOADER_FEATURE_ENTRY_ONESHOT (UINT64_C(1) << 3)
-#define EFI_LOADER_FEATURE_BOOT_COUNTING (UINT64_C(1) << 4)
-#define EFI_LOADER_FEATURE_XBOOTLDR (UINT64_C(1) << 5)
-#define EFI_LOADER_FEATURE_RANDOM_SEED (UINT64_C(1) << 6)
diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build
index 177957e76a..fdbbed6f83 100644
--- a/src/boot/efi/meson.build
+++ b/src/boot/efi/meson.build
@@ -145,6 +145,8 @@ if have_gnu_efi
'-Wno-missing-field-initializers',
'-isystem', efi_incdir,
'-isystem', join_paths(efi_incdir, gnu_efi_path_arch),
+ '-I', fundamental_path,
+ '-DSD_BOOT',
'-include', efi_config_h,
'-include', version_h]
if efi_arch == 'x86_64'
@@ -194,17 +196,17 @@ if have_gnu_efi
systemd_boot_objects = []
stub_objects = []
- foreach file : common_sources + systemd_boot_sources + stub_sources
- o_file = custom_target(file + '.o',
+ foreach file : fundamental_source_paths + common_sources + systemd_boot_sources + stub_sources
+ o_file = custom_target(file.split('/')[-1] + '.o',
input : file,
- output : file + '.o',
+ output : file.split('/')[-1] + '.o',
command : efi_cc + ['-c', '@INPUT@', '-o', '@OUTPUT@']
+ compile_args,
- depend_files : efi_headers)
- if (common_sources + systemd_boot_sources).contains(file)
+ depend_files : efi_headers + fundamental_headers)
+ if (fundamental_source_paths + common_sources + systemd_boot_sources).contains(file)
systemd_boot_objects += o_file
endif
- if (common_sources + stub_sources).contains(file)
+ if (fundamental_source_paths + common_sources + stub_sources).contains(file)
stub_objects += o_file
endif
endforeach
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
index 74dc8de9c8..06fbd500e5 100644
--- a/src/boot/efi/util.c
+++ b/src/boot/efi/util.c
@@ -369,62 +369,6 @@ CHAR8 *strchra(CHAR8 *s, CHAR8 c) {
return NULL;
}
-const CHAR16 *startswith(const CHAR16 *s, const CHAR16 *prefix) {
- UINTN l;
-
- l = StrLen(prefix);
- if (StrnCmp(s, prefix, l) == 0)
- return s + l;
-
- return NULL;
-}
-
-const CHAR16 *endswith(const CHAR16 *s, const CHAR16 *postfix) {
- UINTN sl, pl;
-
- sl = StrLen(s);
- pl = StrLen(postfix);
-
- if (pl == 0)
- return s + sl;
-
- if (sl < pl)
- return NULL;
-
- if (StrnCmp(s + sl - pl, postfix, pl) != 0)
- return NULL;
-
- return s + sl - pl;
-}
-
-const CHAR16 *startswith_no_case(const CHAR16 *s, const CHAR16 *prefix) {
- UINTN l;
-
- l = StrLen(prefix);
- if (StriCmp(s, prefix) == 0)
- return s + l;
-
- return NULL;
-}
-
-const CHAR16 *endswith_no_case(const CHAR16 *s, const CHAR16 *postfix) {
- UINTN sl, pl;
-
- sl = StrLen(s);
- pl = StrLen(postfix);
-
- if (pl == 0)
- return s + sl;
-
- if (sl < pl)
- return NULL;
-
- if (StriCmp(s + sl - pl, postfix) != 0)
- return NULL;
-
- return s + sl - pl;
-}
-
EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
_cleanup_(FileHandleClosep) EFI_FILE_HANDLE handle = NULL;
_cleanup_freepool_ CHAR8 *buf = NULL;
diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h
index a21e84ecdc..6fe61ac457 100644
--- a/src/boot/efi/util.h
+++ b/src/boot/efi/util.h
@@ -4,17 +4,14 @@
#include <efi.h>
#include <efilib.h>
-#define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
+#include "string-util-fundamental.h"
+
#define OFFSETOF(x,y) __builtin_offsetof(x,y)
static inline UINTN ALIGN_TO(UINTN l, UINTN ali) {
return ((l + ali - 1) & ~(ali - 1));
}
-static inline const CHAR16 *yes_no(BOOLEAN b) {
- return b ? L"yes" : L"no";
-}
-
EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b);
UINT64 ticks_read(void);
@@ -39,12 +36,6 @@ CHAR8 *strchra(CHAR8 *s, CHAR8 c);
CHAR16 *stra_to_path(CHAR8 *stra);
CHAR16 *stra_to_str(CHAR8 *stra);
-const CHAR16 *startswith(const CHAR16 *s, const CHAR16 *prefix);
-const CHAR16 *endswith(const CHAR16 *s, const CHAR16 *postfix);
-
-const CHAR16 *startswith_no_case(const CHAR16 *s, const CHAR16 *prefix);
-const CHAR16 *endswith_no_case(const CHAR16 *s, const CHAR16 *postfix);
-
EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
static inline void FreePoolp(void *p) {
@@ -56,7 +47,6 @@ static inline void FreePoolp(void *p) {
FreePool(q);
}
-#define _cleanup_(x) __attribute__((__cleanup__(x)))
#define _cleanup_freepool_ _cleanup_(FreePoolp)
static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) {
@@ -78,11 +68,4 @@ static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) {
#define UINTN_MAX (~(UINTN)0)
#define INTN_MAX ((INTN)(UINTN_MAX>>1))
-#define TAKE_PTR(ptr) \
- ({ \
- typeof(ptr) _ptr_ = (ptr); \
- (ptr) = NULL; \
- _ptr_; \
- })
-
EFI_STATUS log_oom(void);