From: Seung-Woo Kim Date: Wed, 2 May 2018 06:02:12 +0000 (+0900) Subject: Fix to check protocol version before refusing large file X-Git-Tag: accepted/tizen/devbase/tools/20190927.061831~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4e3640c13b47b602c31f68cb12583392abcb474;p=tools%2Flthor.git Fix to check protocol version before refusing large file From protocol version 5.0, it will be supported large file size with 64bit value. Fix to check protocol version before resuing large file. Change-Id: Ie2b76d5e857c143289332e543bb65254ac522081 Signed-off-by: Seung-Woo Kim --- diff --git a/libthor/thor.c b/libthor/thor.c index cfd2302..6dc37e4 100644 --- a/libthor/thor.c +++ b/libthor/thor.c @@ -157,6 +157,19 @@ static int t_thor_exec_cmd(thor_device_handle *th, request_type req_id, NULL, 0, NULL); } +int thor_get_proto_ver(thor_device_handle *th) +{ + int ret; + struct res_pkt resp; + + ret = t_thor_exec_cmd_full(th, RQT_INFO, RQT_INFO_VER_PROTOCOL, + NULL, 0, NULL, 0, &resp); + if (!ret) + ret = (resp.int_data[0] << 8) | resp.int_data[1]; + + return ret; +} + int thor_start_session(thor_device_handle *th, off_t total) { int ret; diff --git a/libthor/thor.h b/libthor/thor.h index 7f13ff5..c9a432d 100644 --- a/libthor/thor.h +++ b/libthor/thor.h @@ -81,6 +81,9 @@ int thor_open(struct thor_device_id *dev_id, int wait, /* Close the device */ void thor_close(thor_device_handle *th); +/* Get protocol version of the device */ +int thor_get_proto_ver(thor_device_handle *th); + /* Start thor "session" */ int thor_start_session(thor_device_handle *th, off_t total); diff --git a/lthor.c b/lthor.c index bb33436..d1554dc 100644 --- a/lthor.c +++ b/lthor.c @@ -311,21 +311,33 @@ static int process_download(struct thor_device_id *dev_id, const char *pitfile, printf("\t" TERM_YELLOW "total" TERM_NORMAL" :\t%.2fMB\n\n", (double)total_size/MB); - if (total_size > (4*GB - 1*KB)) { - fprintf(stderr, - TERM_RED - "[ERROR] Images over 4GB are not supported by thor protocol.\n" - TERM_NORMAL); - ret = -EOVERFLOW; - goto release_data_srcs; - } + /* Check protocol version */ + if (thor_get_proto_ver(th) < 0x500) { + /* + * Until THOR protocol 4.0, total file size is in 32bit + * unsigned int[1] to show progress, so files less than 4GB + * are allowed. + */ + if (total_size > (4*GB - 1*KB)) { + fprintf(stderr, + TERM_RED + "[ERROR] Images over 4GB are not supported by thor protocol.\n" + TERM_NORMAL); + ret = -EOVERFLOW; + goto release_data_srcs; + } - if (total_size > (2*GB - 1*KB)) { - fprintf(stderr, - TERM_RED - "[WARNING] Not all bootloaders support images over 2GB.\n" - " If your download will fail this may be a reason.\n" - TERM_NORMAL); + /* + * Early THOR protocol 4.0 bootloader set 32bit signed int[1], + * so only files less than 2GB are allowed. + */ + if (total_size > (2*GB - 1*KB)) { + fprintf(stderr, + TERM_RED + "[WARNING] Not all bootloaders support images over 2GB.\n" + " If your download will fail this may be a reason.\n" + TERM_NORMAL); + } } ret = do_download(th, data_parts, entries, total_size);