aboutsummaryrefslogtreecommitdiff
path: root/eim/sw/hash_eim.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2015-04-08 16:01:31 -0400
committerPaul Selkirk <paul@psgd.org>2015-04-08 16:03:15 -0400
commitaeaf94f4e83826fe56f38fc670973a60a5010ef1 (patch)
tree6f3d3ba5d0caf5be29f2a4f873a97b8070d6adc9 /eim/sw/hash_eim.c
parent891a24d969181f02762c031b9cfe0fd96c116634 (diff)
Unify and refactor eim and i2c software.
Unify memory maps. Move tc_init, tc_next, tc_wait_* into tc_[eim|i2c].c. Move eim_setup into tc_eim.c, move i2c_open into tc_i2c.c.
Diffstat (limited to 'eim/sw/hash_eim.c')
-rw-r--r--eim/sw/hash_eim.c55
1 files changed, 10 insertions, 45 deletions
diff --git a/eim/sw/hash_eim.c b/eim/sw/hash_eim.c
index 8ea761b..e698129 100644
--- a/eim/sw/hash_eim.c
+++ b/eim/sw/hash_eim.c
@@ -101,55 +101,25 @@ struct ctrl *find_algo(char *algo)
return NULL;
}
-/* ---------------- test-case low-level code ---------------- */
-
-int tc_init(off_t offset, int mode)
-{
- uint8_t buf[4] = { 0, 0, 0, CTRL_INIT_CMD + mode };
-
- return tc_write(offset, buf, 4);
-}
-
-int tc_next(off_t offset, int mode)
-{
- uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT_CMD + mode };
-
- return tc_write(offset, buf, 4);
-}
-
-int tc_wait_ready(off_t offset)
-{
- return tc_wait(offset, STATUS_READY_BIT, NULL);
-}
-
-int tc_wait_valid(off_t offset)
-{
- return tc_wait(offset, STATUS_VALID_BIT, NULL);
-}
-
/* ---------------- hash ---------------- */
-int transmit(off_t offset, uint8_t *block, int blen, int mode, int first)
+static int transmit(off_t offset, uint8_t *block, int blen, int mode, int first)
{
- off_t base = offset & ~(0xff);
+ off_t base = offset & ~(0x1ff);
+ uint8_t ctrl_cmd[4] = { 0 };
if (tc_write(offset, block, blen) != 0)
return 1;
- if (first) {
- if (tc_init(base + ADDR_CTRL, mode) != 0)
- return 1;
- }
- else {
- if (tc_next(base + ADDR_CTRL, mode) != 0)
- return 1;
- }
+ ctrl_cmd[3] = (first ? CTRL_INIT_CMD : CTRL_NEXT_CMD) | mode;
- return tc_wait_ready(base + ADDR_STATUS);
+ return
+ tc_write(base + ADDR_CTRL, ctrl_cmd, 4) ||
+ tc_wait_ready(base + ADDR_STATUS);
}
-int pad_transmit(off_t offset, uint8_t *block, uint8_t flen, uint8_t blen,
- uint8_t mode, long long tlen, int first)
+static int pad_transmit(off_t offset, uint8_t *block, uint8_t flen, uint8_t blen,
+ uint8_t mode, long long tlen, int first)
{
assert(flen < blen);
@@ -173,7 +143,7 @@ int pad_transmit(off_t offset, uint8_t *block, uint8_t flen, uint8_t blen,
}
/* return number of digest bytes read */
-int hash(char *algo, char *file, uint8_t *digest)
+static int hash(char *algo, char *file, uint8_t *digest)
{
uint8_t block[SHA512_BLOCK_LEN];
struct ctrl *ctrl;
@@ -305,11 +275,6 @@ int main(int argc, char *argv[])
printf("reading from stdin\n");
}
- if (eim_setup() != 0) {
- fprintf(stderr, "EIM setup failed\n");
- return EXIT_FAILURE;
- }
-
dlen = hash(algo, file, digest);
if (dlen < 0)
return EXIT_FAILURE;