Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions include/libpldm/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
extern "C" {
#endif

#include <libpldm/byteorder.h>
#include <libpldm/compiler.h>
#include <libpldm/pldm_types.h>

#include <asm/byteorder.h>
#include <stdalign.h>
#include <stdbool.h>
#include <stddef.h>
Expand Down Expand Up @@ -203,12 +203,6 @@ struct pldm_msg_hdr {
uint8_t command; //!< PLDM command code
} __attribute__((packed));

// Macros for byte-swapping variables in-place
#define HTOLE32(X) ((X) = htole32(X))
#define HTOLE16(X) ((X) = htole16(X))
#define LE32TOH(X) ((X) = le32toh(X))
#define LE16TOH(X) ((X) = le16toh(X))

/** @struct pldm_msg
*
* Structure representing PLDM message
Expand Down
37 changes: 37 additions & 0 deletions include/libpldm/byteorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
#ifndef BYTEORDER_H
#define BYTEORDER_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __ZEPHYR__
#include <zephyr/sys/byteorder.h>

#define HTOLE32(X) ((X) = sys_cpu_to_le32(X))
#define HTOLE16(X) ((X) = sys_cpu_to_le16(X))
#define LE32TOH(X) ((X) = sys_le32_to_cpu(X))
#define LE16TOH(X) ((X) = sys_le16_to_cpu(X))

#ifdef CONFIG_LITTLE_ENDIAN
#define __LITTLE_ENDIAN_BITFIELD
#elif defined(CONFIG_BIG_ENDIAN)
#define __BIG_ENDIAN_BITFIELD
#endif

#else
#include <asm/byteorder.h>

#define HTOLE32(X) ((X) = htole32(X))
#define HTOLE16(X) ((X) = htole16(X))
#define LE32TOH(X) ((X) = le32toh(X))
#define LE16TOH(X) ((X) = le16toh(X))

#endif

#ifdef __cplusplus
}
#endif

#endif
6 changes: 6 additions & 0 deletions include/libpldm/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
#define LIBPLDM_CC_NONNULL
#endif

#ifdef __ZEPHYR__

#define EUCLEAN 117

#endif

#endif
1 change: 0 additions & 1 deletion include/libpldm/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern "C" {

#include <libpldm/pldm_types.h>

#include <asm/byteorder.h>
#include <stddef.h>
#include <stdint.h>

Expand Down
1 change: 0 additions & 1 deletion include/libpldm/fru.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern "C" {

#include <libpldm/base.h>

#include <asm/byteorder.h>
#include <stddef.h>
#include <stdint.h>

Expand Down
15 changes: 15 additions & 0 deletions src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@

#include <assert.h>

#ifdef __ZEPHYR__
#include <zephyr/toolchain.h>

#if !defined(__cplusplus) || __cplusplus < 201103L

#ifndef static_assert
#define static_assert BUILD_ASSERT
#endif /* static_assert */

#endif /* !defined(__cplusplus) || __cplusplus < 201103L */

#define SSIZE_MAX INT_MAX

#endif /* __ZEPHYR__ */

static struct {
static_assert(__has_attribute(always_inline),
"`always_inline` attribute is required");
Expand Down
2 changes: 2 additions & 0 deletions src/dsp/bios_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <stdlib.h>
#include <string.h>

#include "compiler.h"

#define POINTER_CHECK(pointer) \
do { \
if ((pointer) == NULL) \
Expand Down
56 changes: 56 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2026 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_PLDM)
set(PLDM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)

zephyr_interface_library_named(pldm)
zephyr_include_directories(${PLDM_ROOT}/include)
zephyr_include_directories(${PLDM_ROOT}/src)

zephyr_library_named(modules_pldm)
zephyr_library_link_libraries(pldm)


# While we follow what is done in the meson.build and mark all symbols as hidden
# by default, that is somewhat useless for Zephyr, as everything is compiled together.
# Do this anyway so visibility attributes are properly set. One could enforce
# them on Zephyr during post-build.
set_target_properties(modules_pldm PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(modules_pldm PROPERTIES CXX_VISIBILITY_PRESET hidden)

target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_STABLE=__attribute__\(\(visibility\("default"\)\)\) _GNU_SOURCE)

if (CONFIG_PLDM_ABI_TESTING)
target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_TESTING=__attribute__\(\(visibility\("default"\)\)\))
else()
target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_TESTING= )
endif()

if (CONFIG_PLDM_ABI_DEPRECATED)
target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_DEPRECATED=__attribute__\(\(visibility\("default"\)\)\))
else()
target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_DEPRECATED= )
endif()

if (CONFIG_PLDM_ABI_DEPRECATED_UNSAFE)
target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_DEPRECATED_UNSAFE=__attribute__\(\(visibility\("default"\)\)\))
else()
target_compile_definitions(modules_pldm PUBLIC LIBPLDM_ABI_DEPRECATED_UNSAFE= )
endif()

zephyr_library_sources(
${PLDM_ROOT}/src/utils.c
${PLDM_ROOT}/src/responder.c

${PLDM_ROOT}/src/dsp/base.c
${PLDM_ROOT}/src/dsp/bios.c
${PLDM_ROOT}/src/dsp/bios_table.c
${PLDM_ROOT}/src/dsp/firmware_update.c
${PLDM_ROOT}/src/dsp/fru.c
${PLDM_ROOT}/src/dsp/pdr.c
${PLDM_ROOT}/src/dsp/platform.c
)

endif()
27 changes: 27 additions & 0 deletions zephyr/Kconfig.pldm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2026 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

config PLDM
bool "PLDM library"
help
Enable PLDM support

if PLDM

config PLDM_ABI_TESTING
bool "PLDM ABI testing"
help
Enable PLDM testing features ABI

config PLDM_ABI_DEPRECATED
bool "PLDM ABI deprecated"
help
Enable PLDM deprecated features ABI

config PLDM_ABI_DEPRECATED_UNSAFE
bool "PLDM ABI deprecated unsafe"
help
Enable PLDM deprecated unsafe features ABI

endif
4 changes: 4 additions & 0 deletions zephyr/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: libpldm
build:
cmake: zephyr/
kconfig: zephyr/Kconfig.pldm