1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

Merge pull request #34730 from yuwata/boot-efi-follow-ups

boot/efi: several follow-ups for recent change
This commit is contained in:
Lennart Poettering 2024-10-14 09:56:47 +02:00 committed by GitHub
commit ab826c4647
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 42 deletions

View File

@ -52,15 +52,6 @@ EFI_STATUS log_internal(EFI_STATUS status, uint8_t text_color, const char *forma
return status;
}
#ifdef EFI_DEBUG
void log_hexdump(const char16_t *prefix, const void *data, size_t size) {
/* Debugging helper — please keep this around, even if not used */
_cleanup_free_ char16_t *hex = hexdump(data, size);
log_internal(EFI_SUCCESS, EFI_LIGHTRED, "%ls[%zu]: %ls", prefix, size, hex);
}
#endif
void log_wait(void) {
if (log_count == 0)
return;

View File

@ -23,13 +23,17 @@ __attribute__((no_stack_protector, noinline)) void __stack_chk_guard_init(void);
_noreturn_ void freeze(void);
void log_wait(void);
_gnu_printf_(3, 4) EFI_STATUS log_internal(EFI_STATUS status, uint8_t text_color, const char *format, ...);
#define log_debug(...) log_internal(EFI_SUCCESS, EFI_LIGHTGRAY, __VA_ARGS__)
#define log_info(...) log_internal(EFI_SUCCESS, EFI_WHITE, __VA_ARGS__)
#define log_error_status(status, ...) log_internal(status, EFI_LIGHTRED, __VA_ARGS__)
#define log_error(...) log_internal(EFI_INVALID_PARAMETER, EFI_LIGHTRED, __VA_ARGS__)
#define log_oom() log_internal(EFI_OUT_OF_RESOURCES, EFI_LIGHTRED, "Out of memory.")
#define log_trace() log_internal(EFI_SUCCESS, EFI_LIGHTRED, "%s:%i@%s", __FILE__, __LINE__, __func__)
#define log_full(status, text_color, format, ...) \
log_internal(status, text_color, "%s:%i@%s: " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#define log_debug(...) log_full(EFI_SUCCESS, EFI_LIGHTGRAY, __VA_ARGS__)
#define log_info(...) log_full(EFI_SUCCESS, EFI_WHITE, __VA_ARGS__)
#define log_error_status(status, ...) log_full(status, EFI_LIGHTRED, __VA_ARGS__)
#define log_error(...) log_full(EFI_INVALID_PARAMETER, EFI_LIGHTRED, __VA_ARGS__)
#define log_oom() log_full(EFI_OUT_OF_RESOURCES, EFI_LIGHTRED, "Out of memory.")
#ifdef EFI_DEBUG
void log_hexdump(const char16_t *prefix, const void *data, size_t size);
#endif
/* Debugging helper — please keep this around, even if not used */
#define log_hexdump(prefix, data, size) \
({ \
_cleanup_free_ char16_t *hex = hexdump(data, size); \
log_debug("%ls[%zu]: %ls", prefix, size, hex); \
})

View File

@ -85,7 +85,7 @@ typedef struct {
char contents[];
} _packed_ SmbiosTableType11;
static const void *find_smbios_configuration_table(uint64_t *ret_size) {
static const void* find_smbios_configuration_table(uint64_t *ret_size) {
assert(ret_size);
const Smbios3EntryPoint *entry3 = find_configuration_table(MAKE_GUID_PTR(SMBIOS3_TABLE));
@ -102,32 +102,33 @@ static const void *find_smbios_configuration_table(uint64_t *ret_size) {
return PHYSICAL_ADDRESS_TO_POINTER(entry->table_address);
}
*ret_size = 0;
return NULL;
}
static const SmbiosHeader *get_smbios_table(uint8_t type, size_t min_size, uint64_t *ret_size_left) {
uint64_t size = 0;
static const SmbiosHeader* get_smbios_table(uint8_t type, size_t min_size, uint64_t *ret_size_left) {
uint64_t size;
const uint8_t *p = find_smbios_configuration_table(&size);
if (!p)
return NULL;
goto not_found;
for (;;) {
if (size < sizeof(SmbiosHeader))
return NULL;
goto not_found;
const SmbiosHeader *header = (const SmbiosHeader *) p;
/* End of table. */
if (header->type == 127)
return NULL;
goto not_found;
if (size < header->length)
return NULL;
goto not_found;
if (header->type == type) {
/* Table is smaller than the minimum expected size? Refuse */
if (header->length < min_size)
return NULL;
goto not_found;
if (ret_size_left)
*ret_size_left = size;
@ -150,7 +151,7 @@ static const SmbiosHeader *get_smbios_table(uint8_t type, size_t min_size, uint6
for (;;) {
const uint8_t *e = memchr(p, 0, size);
if (!e)
return NULL;
goto not_found;
if (!first && e == p) {/* Double NUL byte means we've reached the end of the string table. */
p++;
@ -164,6 +165,10 @@ static const SmbiosHeader *get_smbios_table(uint8_t type, size_t min_size, uint6
}
}
not_found:
if (ret_size_left)
*ret_size_left = 0;
return NULL;
}
@ -186,13 +191,10 @@ const char* smbios_find_oem_string(const char *name) {
if (!type11)
return NULL;
const char *s = type11->contents;
assert(left >= type11->header.length); /* get_smbios_table() already validated this */
left -= type11->header.length;
const char *limit = s + left;
for (const char *p = s; p < limit; ) {
for (const char *p = type11->contents, *limit = type11->contents + left; p < limit; ) {
const char *e = memchr(p, 0, limit - p);
if (!e || e == p) /* Double NUL byte means we've reached the end of the OEM strings. */
break;
@ -208,8 +210,7 @@ const char* smbios_find_oem_string(const char *name) {
}
static const char* smbios_get_string(const SmbiosHeader *header, size_t nr, uint64_t left) {
assert(header);
const char *s = (const char *) header;
const char *s = (const char *) ASSERT_PTR(header);
/* We assume that get_smbios_table() already validated the header size making some superficial sense */
assert(left >= header->length);
@ -227,24 +228,34 @@ static const char* smbios_get_string(const SmbiosHeader *header, size_t nr, uint
p = e + 1;
}
return NULL;
}
void smbios_raw_info_populate(RawSmbiosInfo *ret_info) {
assert(ret_info);
uint64_t left;
assert(ret_info);
const SmbiosTableType1 *type1 = (const SmbiosTableType1 *) get_smbios_table(1, sizeof(SmbiosTableType1), &left);
if (type1) {
ret_info->manufacturer = smbios_get_string(&type1->header, type1->manufacturer, left);
ret_info->product_name = smbios_get_string(&type1->header, type1->product_name, left);
ret_info->product_sku = smbios_get_string(&type1->header, type1->sku_number, left);
ret_info->family = smbios_get_string(&type1->header, type1->family, left);
} else {
ret_info->manufacturer = NULL;
ret_info->product_name = NULL;
ret_info->product_sku = NULL;
ret_info->family = NULL;
}
const SmbiosTableType2 *type2 = (const SmbiosTableType2 *) get_smbios_table(2, sizeof(SmbiosTableType2), &left);
if (type2) {
ret_info->baseboard_manufacturer = smbios_get_string(&type2->header, type2->manufacturer, left);
ret_info->baseboard_product = smbios_get_string(&type2->header, type2->product_name, left);
} else {
ret_info->baseboard_manufacturer = NULL;
ret_info->baseboard_product = NULL;
}
}

View File

@ -4,8 +4,8 @@
#include "efi.h"
#include "efi-string.h"
#include "log.h"
#include "proto/file-io.h"
#include "memory-util-fundamental.h"
#include "proto/file-io.h"
#include "string-util-fundamental.h"
/* This is provided by the linker. */

View File

@ -21,14 +21,8 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <stdbool.h>
#if SD_BOOT
# include "efi-string.h"
#else
# include <string.h>
#endif
#include "macro-fundamental.h"
#include "memory-util-fundamental.h"
#include "sha256-fundamental.h"
#include "unaligned-fundamental.h"