Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
uses: jidicula/[email protected]
with:
clang-format-version: '13'
check-path: 'src'
check-path: 'transport'
fallback-style: 'Google' # optional
67 changes: 4 additions & 63 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "libhoth",
srcs = ["libhoth.c"],
hdrs = ["libhoth.h"],
)

cc_library(
name = "git_version",
hdrs = [":gen_version_header"],
Expand All @@ -20,63 +14,10 @@ genrule(
)

cc_library(
name = "libhoth_ec",
hdrs = ["libhoth_ec.h"],
)

cc_library(
name = "libhoth_mtd",
srcs = ["libhoth_mtd.c"],
hdrs = ["libhoth_mtd.h"],
deps = [
":libhoth",
":libhoth_ec",
],
)

cc_library(
name = "libhoth_spi",
srcs = ["libhoth_spi.c"],
hdrs = ["libhoth_spi.h"],
deps = [
":libhoth",
":libhoth_ec",
],
)

cc_library(
name = "libhoth_usb",
srcs = ["libhoth_usb.c"],
hdrs = ["libhoth_usb.h"],
deps = [
":libhoth",
":libhoth_usb_device",
"@libusb//:libusb",
],
)

cc_library(
name = "libhoth_dbus",
srcs = ["libhoth_dbus.c"],
hdrs = ["libhoth_dbus.h"],
linkopts = ["-lsystemd"],
defines = ["DBUS_BACKEND"],
deps = [
":libhoth",
],
)


cc_library(
name = "libhoth_usb_device",
srcs = [
"libhoth_usb_fifo.c",
"libhoth_usb_mailbox.c",
],
hdrs = ["libhoth_usb_device.h"],
name = "libhoth",
srcs = ["libhoth.c"],
hdrs = ["libhoth.h"],
deps = [
":libhoth",
":libhoth_ec",
"@libusb//:libusb",
"//transports:libhoth_device",
],
)
11 changes: 6 additions & 5 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ cc_binary(
":srtm",
"//:git_version",
"//:libhoth",
"//:libhoth_mtd",
"//:libhoth_spi",
"//:libhoth_usb",
"//transports:libhoth_device",
"//transports:libhoth_mtd",
"//transports:libhoth_spi",
"//transports:libhoth_usb",
"@libusb//:libusb",
] + select({
":dbus_backend" : ["//:libhoth_dbus"],
":dbus_backend": ["//transports:libhoth_dbus"],
"//conditions:default": [],
})
}),
)
1 change: 1 addition & 0 deletions examples/htool.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <unistd.h>

#include "../libhoth.h"
#include "../transports/libhoth_device.h"
#include "authorization_record.h"
#include "ec_util.h"
#include "host_commands.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <termios.h>
#include <unistd.h>

#include "../libhoth.h"
#include "../transports/libhoth_device.h"
#include "ec_util.h"
#include "host_commands.h"
#include "htool.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdlib.h>
#include <string.h>

#include "../libhoth_mtd.h"
#include "../transports/libhoth_mtd.h"
#include "ec_util.h"
#include "host_commands.h"
#include "htool.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_raw_host_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stdlib.h>
#include <unistd.h>

#include "../libhoth.h"
#include "../transports/libhoth_device.h"
#include "ec_util.h"
#include "host_commands.h"
#include "htool.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdlib.h>
#include <string.h>

#include "../libhoth_spi.h"
#include "../transports/libhoth_spi.h"
#include "ec_util.h"
#include "host_commands.h"
#include "htool.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_spi_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// for MIN()
#include <sys/param.h>

#include "../libhoth.h"
#include "../transports/libhoth_device.h"
#include "host_commands.h"
#include "htool.h"
#include "htool_progress.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <string.h>
#include <unistd.h>

#include "../libhoth_usb.h"
#include "../transports/libhoth_usb.h"
#include "ec_util.h"
#include "host_commands.h"
#include "htool_cmd.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git_version_h = vcs_tag(
replace_string: '@GIT_COMMIT@',
)

link_with = [libhoth]
link_with = [libhoth, libhoth_transport]
c_args = []

if get_option('dbus_backend')
Expand Down
6 changes: 3 additions & 3 deletions libhoth.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "libhoth.h"

#include <stdlib.h>

#include "transports/libhoth_device.h"

int libhoth_send_request(struct libhoth_device* dev, const void* request,
size_t request_size) {
if (dev == NULL) {
Expand All @@ -42,4 +42,4 @@ int libhoth_device_close(struct libhoth_device* dev) {
int status = dev->close(dev);
free(dev);
return status;
}
}
29 changes: 1 addition & 28 deletions libhoth.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,7 @@
extern "C" {
#endif

#define LIBHOTH_MAILBOX_SIZE 1024

typedef enum {
LIBHOTH_OK = 0,
LIBHOTH_ERR_UNKNOWN_VENDOR = 1,
LIBHOTH_ERR_INTERFACE_NOT_FOUND = 2,
LIBHOTH_ERR_MALLOC_FAILED = 3,
LIBHOTH_ERR_TIMEOUT = 4,
LIBHOTH_ERR_OUT_UNDERFLOW = 5,
LIBHOTH_ERR_IN_OVERFLOW = 6,
LIBHOTH_ERR_UNSUPPORTED_VERSION = 7,
LIBHOTH_ERR_INVALID_PARAMETER = 8,
LIBHOTH_ERR_FAIL = 9,
LIBHOTH_ERR_RESPONSE_BUFFER_OVERFLOW = 10,
LIBHOTH_ERR_INTERFACE_BUSY = 11,
} libhoth_status;

struct libhoth_device {
int (*send)(struct libhoth_device *dev, const void *request,
size_t request_size);
int (*receive)(struct libhoth_device *dev, void *response,
size_t max_response_size, size_t *actual_size, int timeout_ms);
int (*close)(struct libhoth_device *dev);
int (*claim)(struct libhoth_device *dev);
int (*release)(struct libhoth_device *dev);

void *user_ctx;
};
#include "transports/libhoth_device.h"

// Request is a buffer containing the EC request header and trailing payload.
// This function is not thread-safe. In multi-threaded contexts, callers must
Expand Down
25 changes: 7 additions & 18 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
project('libhoth', 'c', 'cpp', license: 'Apache-2.0', version: '0.0.0')

libhoth_srcs = [
'libhoth.c',
'libhoth_mtd.c',
'libhoth_usb.c',
'libhoth_spi.c',
'libhoth_usb_fifo.c',
'libhoth_usb_mailbox.c',
]
subdir('transports')

libsystemd = dependency('libsystemd')
libhoth_dbus = static_library('hoth_dbus', 'libhoth_dbus.c', dependencies: [libsystemd])

libusb = dependency('libusb-1.0')
install_headers('transports/libhoth_device.h')
install_headers('transports/libhoth_usb.h')
install_headers('transports/libhoth_usb_device.h')
install_headers('libhoth.h')

libhoth = library('hoth', libhoth_srcs, dependencies: [libusb], install: true, \
libhoth = library('hoth', ['libhoth.c'], link_with: [libhoth_transport], dependencies: [libusb], \
version: meson.project_version())

install_headers('libhoth.h')
install_headers('libhoth_usb.h')
install_headers('libhoth_usb_device.h')

pkg = import('pkgconfig')
pkg.generate(libhoth, name: 'libhoth', description: 'Hoth interface library')
pkg.generate([libhoth], name: 'libhoth', description: 'Hoth interface library')

subdir('examples')
67 changes: 67 additions & 0 deletions transports/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "libhoth_device",
hdrs = ["libhoth_device.h"],
)

cc_library(
name = "libhoth_ec",
hdrs = ["libhoth_ec.h"],
)

cc_library(
name = "libhoth_mtd",
srcs = ["libhoth_mtd.c"],
hdrs = ["libhoth_mtd.h"],
deps = [
":libhoth_device",
":libhoth_ec",
],
)

cc_library(
name = "libhoth_spi",
srcs = ["libhoth_spi.c"],
hdrs = ["libhoth_spi.h"],
deps = [
":libhoth_device",
":libhoth_ec",
],
)

cc_library(
name = "libhoth_usb",
srcs = ["libhoth_usb.c"],
hdrs = ["libhoth_usb.h"],
deps = [
":libhoth_device",
":libhoth_usb_device",
"@libusb//:libusb",
],
)

cc_library(
name = "libhoth_dbus",
srcs = ["libhoth_dbus.c"],
hdrs = ["libhoth_dbus.h"],
linkopts = ["-lsystemd"],
defines = ["DBUS_BACKEND"],
deps = [
":libhoth_device",
],
)

cc_library(
name = "libhoth_usb_device",
srcs = [
"libhoth_usb_fifo.c",
"libhoth_usb_mailbox.c",
],
hdrs = ["libhoth_usb_device.h"],
deps = [
":libhoth_device",
":libhoth_ec",
"@libusb//:libusb",
],
)
2 changes: 1 addition & 1 deletion libhoth_dbus.c → transports/libhoth_dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string.h>
#include <systemd/sd-bus.h>

#include "libhoth.h"
#include "libhoth_device.h"

#define HOTHD_SERVICE "xyz.openbmc_project.Control.Hoth"
#define HOTHD_OBJECT "/xyz/openbmc_project/Control/Hoth"
Expand Down
File renamed without changes.
Loading