Fix to check protocol version before refusing large file 04/177604/3
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 2 May 2018 06:02:12 +0000 (15:02 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 18 May 2018 03:51:36 +0000 (12:51 +0900)
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 <sw0312.kim@samsung.com>
libthor/thor.c
libthor/thor.h
lthor.c

index cfd2302..6dc37e4 100644 (file)
@@ -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;
index 7f13ff5..c9a432d 100644 (file)
@@ -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 (file)
--- 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);