summaryrefslogtreecommitdiff
path: root/board/host/board.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-10-03 18:28:57 -0700
committerCommit Bot <commit-bot@chromium.org>2020-08-07 21:16:39 +0000
commitb29d0808e22d30c3e9ce85dd31457ab8ff28dd2c (patch)
treeed5984d796061918350904ba20568944bc4f16ca /board/host/board.c
parent1c62421d797d31f2cbc05a5cfe6b9f1219f5484a (diff)
downloadchrome-ec-b29d0808e22d30c3e9ce85dd31457ab8ff28dd2c.tar.gz
CBI: Add unit test
This patch adds unit tests for Cros Board Info APIs. BUG=b:163038871 BRANCH=none TEST=buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I7b2fdb2c4f13da12f8c0dc2ab526332cbd46d849 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2339393
Diffstat (limited to 'board/host/board.c')
-rw-r--r--board/host/board.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/board/host/board.c b/board/host/board.c
index 307ccac991..25abd9a0ad 100644
--- a/board/host/board.c
+++ b/board/host/board.c
@@ -6,6 +6,7 @@
#include "battery.h"
#include "button.h"
+#include "cros_board_info.h"
#include "extpower.h"
#include "gpio.h"
#include "host_command.h"
@@ -17,6 +18,7 @@
#include "power_button.h"
#include "spi.h"
#include "temp_sensor.h"
+#include "test_util.h"
#include "timer.h"
#include "util.h"
@@ -65,6 +67,8 @@ const struct i2c_port_t i2c_ports[] = {
{"lightbar", I2C_PORT_LIGHTBAR, 100, 0, 0},
#elif defined I2C_PORT_HOST_TCPC
{"tcpc", I2C_PORT_HOST_TCPC, 100, 0, 0},
+#elif defined I2C_PORT_EEPROM
+ {"eeprom", I2C_PORT_EEPROM, 100, 0, 0},
#endif
};
@@ -97,3 +101,32 @@ int board_get_entropy(void *buffer, int len)
return 1;
}
#endif
+
+static uint8_t eeprom[CBI_EEPROM_SIZE];
+
+int eeprom_i2c_xfer(int port, uint16_t addr_flags,
+ const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
+{
+ static int offset;
+
+ if (port != I2C_PORT_EEPROM || addr_flags != I2C_ADDR_EEPROM_FLAGS)
+ return EC_ERROR_INVAL;
+
+ if (out_size == 1 && (flags & I2C_XFER_START)) {
+ offset = *out;
+ } else {
+ if (offset + out_size > sizeof(eeprom))
+ return EC_ERROR_OVERFLOW;
+ memcpy(&eeprom[offset], out, out_size);
+ }
+
+ if (in) {
+ if (offset + in_size > sizeof(eeprom))
+ return EC_ERROR_OVERFLOW;
+ memcpy(in, &eeprom[offset], in_size);
+ }
+
+ return EC_SUCCESS;
+}
+DECLARE_TEST_I2C_XFER(eeprom_i2c_xfer);