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
14 changes: 7 additions & 7 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ genrule(
cc_library(
name = "libhoth_transports_headers",
hdrs = [
"//transports:headers",
"//transports:headers",
],
include_prefix = "libhoth/transports",
strip_include_prefix = "transports",
Expand All @@ -32,23 +32,23 @@ cc_library(
cc_library(
name = "libhoth_transports_headers_legacy",
hdrs = [
"//transports:headers",
"//transports:headers",
],
include_prefix = "transports",
strip_include_prefix = "transports",
)

cc_library(
name = "libhoth",
visibility = ["//visibility:public"],
deps = [
"//transports:libhoth_device",
"//transports:libhoth_usb",
"//transports:libhoth_spi",
"//transports:libhoth_mtd",
":libhoth_transports_headers",
":libhoth_transports_headers_legacy",
"//transports:libhoth_device",
"//transports:libhoth_mtd",
"//transports:libhoth_spi",
"//transports:libhoth_usb",
],
visibility = ["//visibility:public"],
)

alias(
Expand Down
8 changes: 4 additions & 4 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ cc_binary(
"htool_jtag.h",
"htool_key_rotation.c",
"htool_key_rotation.h",
"htool_macros.h",
"htool_mauv.c",
"htool_mauv.h",
"htool_macros.h",
"htool_mtd.c",
"htool_panic.c",
"htool_panic.h",
Expand Down Expand Up @@ -231,10 +231,10 @@ cc_binary(
"htool_spi.c",
"htool_statistics.c",
"htool_statistics.h",
"htool_tpm.c",
"htool_tpm.h",
"htool_target_control.c",
"htool_target_control.h",
"htool_tpm.c",
"htool_tpm.h",
"htool_update_failure_reasons.h",
"htool_usb.c",
"htool_usb.h",
Expand All @@ -247,11 +247,11 @@ cc_binary(
"//protocol:authz_record",
"//protocol:chipinfo",
"//protocol:console",
"//protocol:gpio_drive_strength",
"//protocol:controlled_storage",
"//protocol:dfu_check",
"//protocol:dfu_hostcmd",
"//protocol:firmware_update",
"//protocol:gpio_drive_strength",
"//protocol:hello",
"//protocol:host_cmd",
"//protocol:i2c",
Expand Down
85 changes: 85 additions & 0 deletions examples/htool.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -893,6 +894,59 @@ static int command_set_gpio_drive_strength(const struct htool_invocation* inv) {
return 0;
}

static int command_get_gpio_drive_strength(const struct htool_invocation* inv) {
struct libhoth_device* dev = htool_libhoth_device();
if (!dev) {
return -1;
}

bool has_dio = htool_has_param(inv, "dio");
bool has_mio = htool_has_param(inv, "mio");

if (!has_dio && !has_mio) {
fprintf(stderr, "Must specify either --dio or --mio.\n");
return -1;
}

if (has_dio && has_mio) {
fprintf(stderr, "Cannot specify both --dio and --mio.\n");
return -1;
}

uint32_t pad;
uint8_t dio_index = 0;
uint8_t mio_index = 0;
if (has_dio) {
uint32_t dio;
if (htool_get_param_u32(inv, "dio", &dio)) {
return -1;
}
dio_index = (uint8_t)dio;
pad = dio + LIBHOTH_GPIO_DIO_PAD_OFFSET;
} else {
uint32_t mio;
if (htool_get_param_u32(inv, "mio", &mio)) {
return -1;
}
mio_index = (uint8_t)mio;
pad = mio;
}

uint8_t strength = 0;
libhoth_error err =
libhoth_get_gpio_drive_strength(dev, (uint8_t)pad, &strength);
if (err != HOTH_SUCCESS) {
htool_report_error("get_gpio_drive_strength", err);
return -1;
}
if (has_dio) {
printf("DIO %" PRIu8 " drive strength: %" PRIu8 "\n", dio_index, strength);
} else {
printf("MIO %" PRIu8 " drive strength: %" PRIu8 "\n", mio_index, strength);
}
return 0;
}

static int command_hello(const struct htool_invocation* inv) {
struct libhoth_device* dev = htool_libhoth_device();
if (!dev) {
Expand Down Expand Up @@ -1750,6 +1804,37 @@ static const struct htool_cmd CMDS[] = {
{}},
.func = command_set_gpio_drive_strength,
},
{
.verbs = (const char*[]){"gpio", "get_drive_strength", NULL},
.desc = "Get GPIO drive strength",
.params =
(const struct htool_param[]){
{.type = HTOOL_FLAG_VALUE,
.ch = 'd',
.name = "dio",
.default_value = NULL,
.desc = "The DIO pad with the given index. Values are:\n"
" 0 => USB_DP\n"
" 1 => USB_DN\n"
" 2-5 => SPI_HOST0_D0-3\n"
" 6-9 => SPI_DEV_D0-3\n"
" 12 => SPI_DEV_CLK\n"
" 13 => SPI_DEV_CSB\n"
" 14 => SPI_HOST0_CLK\n"
" 15 => SPI_HOST0_CSB"},
{.type = HTOOL_FLAG_VALUE,
.ch = 'm',
.name = "mio",
.default_value = NULL,
.desc = "The MIO pad with the given index. Values are:\n"
" 0-8 => IOA0-8\n"
" 9-21 => IOB0-12\n"
" 22-34 => IOC0-12\n"
" 35-41 => IOR0-7\n"
" 42-46 => IOR10-13"},
{}},
.func = command_get_gpio_drive_strength,
},
{
.verbs = (const char*[]){"hello", NULL},
.desc = "A test function to send and receive an integer",
Expand Down
2 changes: 1 addition & 1 deletion examples/htool_security_certificates_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "examples/htool_security_certificates.h"
#include "htool_security_certificates.h"

#include <errno.h>
#include <gmock/gmock.h>
Expand Down
6 changes: 3 additions & 3 deletions examples/test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include "examples/host_commands.h"
#include "examples/htool.h"
#include "examples/htool_cmd.h"
#include "examples/htool_security_v2.h"
#include "examples/htool_security_version.h"
#include "htool_cmd.h"
#include "htool_security_v2.h"
#include "htool_security_version.h"
#include "protocol/host_cmd.h"
#include "protocol/test/libhoth_device_mock.h"
#include "transports/libhoth_device.h"
Expand Down
10 changes: 4 additions & 6 deletions protocol/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ cc_library(
srcs = ["status.c"],
hdrs = ["status.h"],
defines = ["LIBHOTH_SUPPORT_LIBUSB"],
visibility = ["//visibility:public"],
deps = [
"@libusb//:libusb",
"@libusb",
],
visibility = ["//visibility:public"],
)

cc_test(
Expand Down Expand Up @@ -125,10 +125,10 @@ cc_library(
deps = [
":command_version",
":host_cmd",
":libhoth_status",
":payload_info",
":progress",
":util",
":libhoth_status",
"//transports:libhoth_device",
],
)
Expand Down Expand Up @@ -583,8 +583,8 @@ cc_test(
"//protocol/test:test_data",
],
deps = [
":host_cmd",
":dfu_check",
":host_cmd",
":opentitan_version",
"//protocol/test:libhoth_device_mock",
"//transports:libhoth_device",
Expand All @@ -593,7 +593,6 @@ cc_test(
],
)


cc_library(
name = "util",
srcs = ["util.c"],
Expand Down Expand Up @@ -621,4 +620,3 @@ cc_test(
"@googletest//:gtest_main",
],
)

22 changes: 22 additions & 0 deletions protocol/gpio_drive_strength.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,25 @@ libhoth_error libhoth_set_gpio_drive_strength(struct libhoth_device* const dev,
/*version=*/0, &request, sizeof(request),
/*response=*/NULL, /*response_size=*/0, NULL);
}

libhoth_error libhoth_get_gpio_drive_strength(struct libhoth_device* const dev,
const uint8_t pad,
uint8_t* const strength) {
if (strength == NULL) {
return LIBHOTH_ERR_CONSTRUCT(HOTH_CTX_CMD_EXEC, HOTH_HOST_SPACE_LIBHOTH,
LIBHOTH_ERR_INVALID_PARAMETER);
}

const struct hoth_request_get_gpio_drive_strength request = {
.pad = pad,
};
struct hoth_response_get_gpio_drive_strength response;
const libhoth_error err = libhoth_hostcmd_exec_v2(
dev, HOTH_CMD_GET_GPIO_DRIVE_STRENGTH, /*version=*/0, &request,
sizeof(request), &response, sizeof(response), /*out_resp_size=*/NULL);
if (err != HOTH_SUCCESS) {
return err;
}
*strength = response.strength;
return HOTH_SUCCESS;
}
12 changes: 12 additions & 0 deletions protocol/gpio_drive_strength.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {
#endif

#define HOTH_CMD_SET_GPIO_DRIVE_STRENGTH 0x3E56
#define HOTH_CMD_GET_GPIO_DRIVE_STRENGTH 0x3E59
#define MAX_GPIO_DRIVE_STRENGTH 0xF
#define LIBHOTH_GPIO_DIO_PAD_OFFSET 128

Expand All @@ -33,9 +34,20 @@ struct hoth_request_set_gpio_drive_strength {
uint8_t strength;
} __hoth_align1;

struct hoth_request_get_gpio_drive_strength {
uint8_t pad;
} __hoth_align1;

struct hoth_response_get_gpio_drive_strength {
uint8_t strength;
} __hoth_align1;

libhoth_error libhoth_set_gpio_drive_strength(struct libhoth_device* dev,
uint8_t pad, uint8_t strength);

libhoth_error libhoth_get_gpio_drive_strength(struct libhoth_device* dev,
uint8_t pad, uint8_t* strength);

#ifdef __cplusplus
}
#endif
Expand Down
24 changes: 24 additions & 0 deletions protocol/gpio_drive_strength_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,27 @@ TEST_F(LibHothTest, set_gpio_drive_strength_invalid_param) {
EXPECT_EQ(LIBHOTH_ERR_GET_SPACE(err), HOTH_HOST_SPACE_LIBHOTH);
EXPECT_EQ(LIBHOTH_ERR_GET_CODE(err), LIBHOTH_ERR_INVALID_PARAMETER);
}

TEST_F(LibHothTest, get_gpio_drive_strength_success) {
EXPECT_CALL(mock_, send(_, UsesCommand(HOTH_CMD_GET_GPIO_DRIVE_STRENGTH), _))
.WillOnce(Return(LIBHOTH_OK));

struct hoth_response_get_gpio_drive_strength resp = {
.strength = 7,
};
EXPECT_CALL(mock_, receive)
.WillOnce(DoAll(CopyResp(&resp, sizeof(resp)), Return(LIBHOTH_OK)));

uint8_t strength = 0;
EXPECT_EQ(libhoth_get_gpio_drive_strength(&hoth_dev_, 10, &strength),
HOTH_SUCCESS);
EXPECT_EQ(strength, 7);
}

TEST_F(LibHothTest, get_gpio_drive_strength_null_param) {
libhoth_error err = libhoth_get_gpio_drive_strength(&hoth_dev_, 10, nullptr);
EXPECT_NE(err, HOTH_SUCCESS);
EXPECT_EQ(LIBHOTH_ERR_GET_CTX(err), HOTH_CTX_CMD_EXEC);
EXPECT_EQ(LIBHOTH_ERR_GET_SPACE(err), HOTH_HOST_SPACE_LIBHOTH);
EXPECT_EQ(LIBHOTH_ERR_GET_CODE(err), LIBHOTH_ERR_INVALID_PARAMETER);
}
4 changes: 2 additions & 2 deletions transports/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ cc_library(
)

filegroup(
name = "headers",
srcs = glob(["*.h"])
name = "headers",
srcs = glob(["*.h"]),
)
Loading