From fb90bcce4ebf630e81f026a394206f2582ea622a Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 17 Mar 2020 13:55:56 +0900 Subject: [PATCH] interface: Choose interface after thor handshake To prevent that interface blocks other connection before host actually start transferring, connected interface is selected after handshake is done. Change-Id: I6b8587898b4dae83ffeb9e4330d379fa723e98d1 Signed-off-by: Dongwoo Lee --- src/interface.c | 14 ++++++++++++++ src/main.c | 6 ------ src/thor.c | 12 +----------- src/thor.h | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/interface.c b/src/interface.c index 69d2084..027a3fc 100644 --- a/src/interface.c +++ b/src/interface.c @@ -22,6 +22,7 @@ #include #include "interface.h" +#include "thor.h" struct tfm_interface_context { struct tfm_interface *connected; @@ -96,6 +97,19 @@ static void *connect_thread_main(void *ptr) return NULL; } + fprintf(stdout, "interface %s is ready.\n", intf->name); + + /* + * Each interface can handshake at the same time, but only one + * interface is used for flash to prevent data corruption. + */ + ret = thor_handshake(intf); + if (ret < 0) { + fprintf(stderr, "failed to handshake: %s\n", intf->name); + intf->ops->disconnect(intf); + return NULL; + } + pthread_mutex_lock(&ictx->mutex); if (ictx->connected) { pthread_mutex_unlock(&ictx->mutex); diff --git a/src/main.c b/src/main.c index 0281c30..7737e5e 100644 --- a/src/main.c +++ b/src/main.c @@ -100,12 +100,6 @@ int _main(int argc, char *argv[]) goto out_dfuexit; } - ret = thor_setup(intf); - if (ret < 0) { - ret = -1; - goto out_disconn; - } - ret = thor_process(intf, dfu); if (ret < 0) { ret = -1; diff --git a/src/thor.c b/src/thor.c index 6cb6984..ea8918e 100644 --- a/src/thor.c +++ b/src/thor.c @@ -319,7 +319,7 @@ static int thor_do_request(struct thor_context *tctx) return ret; } -static int thor_handshake(struct tfm_interface *intf) +int thor_handshake(struct tfm_interface *intf) { char buf[5]; ssize_t n; @@ -370,13 +370,3 @@ int thor_process(struct tfm_interface *intf, struct dfu_context *dfu) return 0; } - -int thor_setup(struct tfm_interface *intf) -{ - if (!intf) { - fprintf(stderr, "Invalid connection\n"); - return -EINVAL; - } - - return thor_handshake(intf); -} diff --git a/src/thor.h b/src/thor.h index 7a88006..c24fcc5 100644 --- a/src/thor.h +++ b/src/thor.h @@ -20,6 +20,6 @@ #include "dfu.h" #include "interface.h" -int thor_setup(struct tfm_interface *intf); +int thor_handshake(struct tfm_interface *intf); int thor_process(struct tfm_interface *intf, struct dfu_context *dfu); #endif -- 2.7.4