f_thor: allow to download 4GB images
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Tue, 10 Nov 2015 11:29:18 +0000 (12:29 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 28 Oct 2024 11:27:50 +0000 (20:27 +0900)
This commit fixes 2GB file size limit for thor downloader.

The application on host side sends the downloaded file size as 32-bit
unsigned value. But the thor implementation on U-Boot side interpreted
this as signed value. This caused an error for files with size greater
than 2GB.

This commit fixes the data types in code, which allows to send file
of size 4GB.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
drivers/usb/gadget/f_thor.c

index 637612a69e7ccaf7230031ffc2f4a459a15809c3..a842972f08f3c7920230597ebb08be1db37b6355 100644 (file)
@@ -157,10 +157,10 @@ static int process_rqt_cmd(struct udevice *udc, const struct rqt_box *rqt)
 static long long int download_head(struct udevice *udc,
                                   unsigned long long total,
                                   unsigned int packet_size,
-                                  long long int *left,
+                                  size_t *left,
                                   int *cnt)
 {
-       long long int rcv_cnt = 0, left_to_rcv, ret_rcv;
+       size_t rcv_cnt = 0, left_to_rcv, ret_rcv;
        struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num);
        void *transfer_buffer = dfu_get_buf(dfu_entity);
        void *buf = transfer_buffer;
@@ -180,7 +180,7 @@ static long long int download_head(struct udevice *udc,
                if (ret_rcv < 0)
                        return ret_rcv;
                rcv_cnt += ret_rcv;
-               debug("%d: RCV data count: %llu cnt: %d\n", usb_pkt_cnt,
+               debug("%d: RCV data count: %u cnt: %d\n", usb_pkt_cnt,
                      rcv_cnt, *cnt);
 
                if ((rcv_cnt % THOR_STORE_UNIT_SIZE) == 0) {
@@ -205,7 +205,7 @@ static long long int download_head(struct udevice *udc,
         * on the medium (they are smaller than THOR_STORE_UNIT_SIZE)
         */
        *left = left_to_rcv + buf - transfer_buffer;
-       debug("%s: left: %llu left_to_rcv: %llu buf: 0x%p\n", __func__,
+       debug("%s: left: %u left_to_rcv: %u buf: 0x%p\n", __func__,
              *left, left_to_rcv, buf);
 
        if (left_to_rcv) {
@@ -217,9 +217,9 @@ static long long int download_head(struct udevice *udc,
                send_data_rsp(udc, 0, ++usb_pkt_cnt);
        }
 
-       debug("%s: %llu total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
+       debug("%s: %u total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
 
-       return rcv_cnt;
+       return 0;
 }
 
 static int download_tail(long long int left, int cnt)
@@ -267,8 +267,8 @@ static int download_tail(long long int left, int cnt)
 static long long int process_rqt_download(struct udevice *udc, const struct rqt_box *rqt)
 {
        ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
-       static long long int left, ret_head;
-       int file_type, ret = 0;
+       int ret_head, file_type, ret = 0;
+       static size_t left;
        static int cnt;
 
        memset(rsp, 0, sizeof(struct rsp_box));
@@ -284,7 +284,7 @@ static long long int process_rqt_download(struct udevice *udc, const struct rqt_
                total_file_size = thor_file_size;
                downloaded_file_size = 0;
 #endif
-               debug("INIT: total %d bytes\n", rqt->int_data[0]);
+               debug("INIT: total %u bytes\n", (size_t)rqt->int_data[0]);
                break;
        case RQT_DL_FILE_INFO:
                file_type = rqt->int_data[0];
@@ -553,7 +553,8 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
 static int thor_rx_data(struct udevice *udc)
 {
        struct thor_dev *dev = thor_func->dev;
-       int data_to_rx, tmp, status;
+       size_t data_to_rx, tmp;
+       int status;
 
        data_to_rx = dev->out_req->length;
        tmp = data_to_rx;
@@ -719,7 +720,7 @@ int thor_init(struct udevice *udc)
 #endif
        /* Wait for a device enumeration and configuration settings */
        debug("THOR enumeration/configuration setting....\n");
-       while (!dev->configuration_done)
+       while (!dev->configuration_done) {
                dm_usb_gadget_handle_interrupts(udc);