usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
PATCH 1/1 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current dfu_flush() function writes filesystem only. This commit adds dfu_flush() to f_thor and now filesystem write is working.
This change was tested on Trats2 board.
--- drivers/usb/gadget/f_thor.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_thor.c +9 -4
@@ -204,14 +204,14 @@ static long long int download_head(unsigned long long total,static int download_tail (long long int left,int cnt) { +struct dfu_entity *dfu_entity =dfu_get_entity (alt_setting_num);void *transfer_buffer =dfu_get_buf ();int ret;debug ("%s: left: %llu cnt: %d\n" , __func__, left, cnt);if (left) { - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer, left, cnt++); + ret =dfu_write (dfu_entity, transfer_buffer, left, cnt++);if (ret) {error ("DFU write failed [%d]: left: %llu" , ret, left);return ret;
@@ -225,11 +225,16 @@ static int download_tail(long long int left, int cnt)* This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer,0 , cnt); + ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt);if (ret)error ("DFU write failed [%d] cnt: %d" , ret, cnt); + ret =dfu_flush (dfu_entity, transfer_buffer,0 , cnt); +if (ret) { +error ("DFU flush failed!" ); +return ret; + } +return ret; }
Signature · 1 line
1.8.3.2
PATCH 1/1 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Quoted 40 lines · Przemyslaw Marczak
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current
dfu_flush()function writes filesystem only. This commit addsdfu_flush()tof_thorand now filesystem write is working.This change was tested on Trats2 board.
Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>--- drivers/usb/gadget/f_thor.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/usb/gadget/f_thor.c +2
-2@@ -204,14 +204,14 @@ static long long int download_head(unsigned long long total, static int download_tail(long long int left, int cnt) { +struct dfu_entity *dfu_entity =dfu_get_entity (alt_setting_num);void *transfer_buffer =dfu_get_buf ();int ret;debug ("%s: left: %llu cnt: %d\n" , __func__, left, cnt);if (left) { - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer, left, cnt++); + ret =dfu_write (dfu_entity, transfer_buffer, left, cnt++);if (ret) {error ("DFU write failed [%d]: left: %llu" , ret, left);drivers/usb/gadget/f_thor.c +0
-0return ret;
drivers/usb/gadget/f_thor.c static int download_tail(long long int left, int cnt) · line 230
Quoted 8 lines
drivers/usb/gadget/f_thor.c +1
-2@@ -225,11 +225,16 @@ static int download_tail(long long int left, int cnt)* This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer,0 , cnt); + ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt);if (ret)error ("DFU write failed [%d] cnt: %d" , ret, cnt);
Please split this into two patches, one which does cleanup (that's the part above) and one which fixes the functionality (that's the part below).
drivers/usb/gadget/f_thor.c static int download_tail(long long int left, int cnt) · line 239
Quoted 8 lines
drivers/usb/gadget/f_thor.c +6
-0+ ret =dfu_flush (dfu_entity, transfer_buffer,0 , cnt); +if (ret) { +error ("DFU flush failed!" ); +return ret; + } +return ret; }
Best regards,
Marek Vasut
PATCH v2 1/2 usb:gadget:f_thor: code cleanup in function download_tail()
In reply to Przemyslaw MarczakIn thor's download_tail() function, dfu_get_entity() is called before each dfu_write() call and the returned entity pointers are the same. So dfu_get_entity() can be called just once and this patch changes this.
---
Changes v2:
- separate fix and cleanup into two commits
drivers/usb/gadget/f_thor.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_thor.c +3 -4
@@ -204,14 +204,14 @@ static long long int download_head(unsigned long long total,static int download_tail (long long int left,int cnt) { +struct dfu_entity *dfu_entity =dfu_get_entity (alt_setting_num);void *transfer_buffer =dfu_get_buf ();int ret;debug ("%s: left: %llu cnt: %d\n" , __func__, left, cnt);if (left) { - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer, left, cnt++); + ret =dfu_write (dfu_entity, transfer_buffer, left, cnt++);if (ret) {error ("DFU write failed [%d]: left: %llu" , ret, left);return ret;
@@ -225,8 +225,7 @@ static int download_tail(long long int left, int cnt)* This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer,0 , cnt); + ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt);if (ret)error ("DFU write failed [%d] cnt: %d" , ret, cnt);
Signature · 1 line
1.9.1
PATCH v2 2/2 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current dfu_flush() function writes filesystem only. This commit adds dfu_flush() to f_thor and now filesystem write is working.
This change was tested on Trats2 board.
---
Changes v2:
- separate fix and cleanup into two commits
drivers/usb/gadget/f_thor.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/gadget/f_thor.c +6 -0
@@ -229,6 +229,12 @@ static int download_tail(long long int left, int cnt)if (ret)error ("DFU write failed [%d] cnt: %d" , ret, cnt); + ret =dfu_flush (dfu_entity, transfer_buffer,0 , cnt); +if (ret) { +error ("DFU flush failed!" ); +return ret; + } +return ret; }
Signature · 1 line
1.9.1
PATCH v2 2/2 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Quoted 6 lines · Przemyslaw Marczak
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current
dfu_flush()function writes filesystem only. This commit addsdfu_flush()tof_thorand now filesystem write is working.
Quoted 7 lines
This change was tested on Trats2 board.
Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>
Best regards,
Marek Vasut
PATCH v2 1/2 usb:gadget:f_thor: code cleanup in function download_tail()
In reply to Przemyslaw MarczakQuoted 10 lines · Przemyslaw Marczak
In thor's
download_tail()function,dfu_get_entity()is called before eachdfu_write()call and the returned entity pointers are the same. Sodfu_get_entity()can be called just once and this patch changes this.Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>
Best regards,
Marek Vasut
PATCH v3 1/2 usb:gadget:f_thor: code cleanup in function download_tail()
In reply to Przemyslaw MarczakIn thor's download_tail() function, dfu_get_entity() is called before each dfu_write() call and the returned entity pointers are the same. So dfu_get_entity() can be called just once and this patch changes this.
---
Changes v2:
- separate fix and cleanup into two commits
Changes v3:
- download_tail(): add exit label
--- drivers/usb/gadget/f_thor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/gadget/f_thor.c +5 -5
@@ -204,17 +204,17 @@ static long long int download_head(unsigned long long total,static int download_tail (long long int left,int cnt) { +struct dfu_entity *dfu_entity =dfu_get_entity (alt_setting_num);void *transfer_buffer =dfu_get_buf ();int ret;debug ("%s: left: %llu cnt: %d\n" , __func__, left, cnt);if (left) { - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer, left, cnt++); + ret =dfu_write (dfu_entity, transfer_buffer, left, cnt++);if (ret) {error ("DFU write failed [%d]: left: %llu" , ret, left); -return ret; + goto exit; } }
@@ -225,11 +225,11 @@ static int download_tail(long long int left, int cnt)* This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer,0 , cnt); + ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt);if (ret)error ("DFU write failed [%d] cnt: %d" , ret, cnt); +exit:return ret; }
Signature · 1 line
1.9.1
PATCH v3 2/2 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current dfu_flush() function writes filesystem only. This commit adds dfu_flush() to f_thor and now filesystem write is working.
This change was tested on Trats2 board.
---
Changes v2:
- separate fix and cleanup into two commits
Changes v3:
- none
--- drivers/usb/gadget/f_thor.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/usb/gadget/f_thor.c +7 -1
@@ -226,8 +226,14 @@ static int download_tail(long long int left, int cnt)* need fo call dfu_free_buf() is needed. */ ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt); -if (ret) +if (ret) {error ("DFU write failed [%d] cnt: %d" , ret, cnt); + goto exit; + } + + ret =dfu_flush (dfu_entity, transfer_buffer,0 , cnt); +if (ret) +error ("DFU flush failed!" ); exit:return ret;
Signature · 1 line
1.9.1
PATCH v3 2/2 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Hi Przemyslaw,
Quoted 30 lines
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current
dfu_flush()function writes filesystem only. This commit addsdfu_flush()tof_thorand now filesystem write is working.This change was tested on Trats2 board.
Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>---
Changes v2:
- separate fix and cleanup into two commitsChanges v3:
- none--- drivers/usb/gadget/f_thor.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/usb/gadget/f_thor.c +0
-0
drivers/usb/gadget/f_thor.c static int download_tail(long long int left, int · line 229
Quoted 4 lines
drivers/usb/gadget/f_thor.c +0
-0@@ -226,8 +226,14 @@ static int download_tail(long long int left, intcnt) * need fo call dfu_free_buf() is needed. */ ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt);
I think this dfu_write() call can be now removed, since what we expect now is to call the dfu_flush() here.
After this change please accordingly update the above comment.
Quoted 12 lines
drivers/usb/gadget/f_thor.c +7
-1-if (ret) +if (ret) {error ("DFU write failed [%d] cnt: %d" , ret, cnt); + goto exit; + } + + ret =dfu_flush (dfu_entity, transfer_buffer,0 , cnt); +if (ret) +error ("DFU flush failed!" ); exit:return ret;
Signature · 5 lines
Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
PATCH v3 2/2 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
Quoted 15 lines · Lukasz Majewski
Hi Przemyslaw,
Quoted 13 lines
Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current
dfu_flush()function writes filesystem only. This commit addsdfu_flush()tof_thorand now filesystem write is working.This change was tested on Trats2 board.
Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>
Please submit new patches on top of u-boot-usb/master , thanks.
Best regards,
Marek Vasut
PATCH v4 1/3 usb:gadget:f_thor: code cleanup in function download_tail()
In reply to Przemyslaw MarczakIn thor's download_tail() function, dfu_get_entity() is called before each dfu_write() call and the returned entity pointers are the same. So dfu_get_entity() can be called just once and this patch changes this.
---
Changes v2:
- separate fix and cleanup into two commits
Changes v3:
- download_tail(): add exit label
Changes v4:
- none
--- drivers/usb/gadget/f_thor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/gadget/f_thor.c +5 -5
@@ -204,17 +204,17 @@ static long long int download_head(unsigned long long total,static int download_tail (long long int left,int cnt) { +struct dfu_entity *dfu_entity =dfu_get_entity (alt_setting_num);void *transfer_buffer =dfu_get_buf ();int ret;debug ("%s: left: %llu cnt: %d\n" , __func__, left, cnt);if (left) { - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer, left, cnt++); + ret =dfu_write (dfu_entity, transfer_buffer, left, cnt++);if (ret) {error ("DFU write failed [%d]: left: %llu" , ret, left); -return ret; + goto exit; } }
@@ -225,11 +225,11 @@ static int download_tail(long long int left, int cnt)* This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret =dfu_write (dfu_get_entity (alt_setting_num), - transfer_buffer,0 , cnt); + ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt);if (ret)error ("DFU write failed [%d] cnt: %d" , ret, cnt); +exit:return ret; }
Signature · 1 line
1.9.1
PATCH v4 1/3 usb:gadget:f_thor: code cleanup in function download_tail()
Hello Heiko,
Quoted 15 lines · Przemyslaw Marczak
In thor's
download_tail()function,dfu_get_entity()is called before eachdfu_write()call and the returned entity pointers are the same. Sodfu_get_entity()can be called just once and this patch changes this.Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>---
Changes v2:
- separate fix and cleanup into two commits
Quoted 6 lines
Changes v3:
-download_tail(): add exit labelChanges v4:
- none
---
Could you look at those changes, please?
Thank you
Signature · 4 lines
Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com
PATCH v4 1/3 usb:gadget:f_thor: code cleanup in function download_tail()
In reply to Przemyslaw MarczakHello Marek,
Quoted 15 lines · Przemyslaw Marczak
In thor's
download_tail()function,dfu_get_entity()is called before eachdfu_write()call and the returned entity pointers are the same. Sodfu_get_entity()can be called just once and this patch changes this.Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>---
Changes v2:
- separate fix and cleanup into two commits
Quoted 5 lines
Changes v3:
-download_tail(): add exit labelChanges v4:
- none
I've checked the u-boot-usb/master tree and I found that one commit of this patch set is missed, because it is v3 (there was only two commits). Could you please apply the patch set version 4?
Thank you,
Signature · 4 lines
Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com
PATCH v4 1/3 usb:gadget:f_thor: code cleanup in function download_tail()
Hi Przemyslaw, Marek,
Quoted 21 lines
Hello Marek,
Quoted 18 lines · Przemyslaw Marczak
In thor's
download_tail()function,dfu_get_entity()is called before eachdfu_write()call and the returned entity pointers are the same. Sodfu_get_entity()can be called just once and this patch changes this.Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>---
Changes v2:
- separate fix and cleanup into two commitsChanges v3:
-download_tail(): add exit label
Quoted 6 lines
Quoted 2 lines
Changes v4:
- noneI've checked the u-boot-usb/master tree and I found that one commit of this patch set is missed, because it is v3 (there was only two commits). Could you please apply the patch set version 4?
I've discussed this issue with Przemek, and we agreed that Przemek will prepare diff patch between version 3, which is already in mainline and version 4.
Then, after ML review, I will pull them to u-boot-dfu branch.
Marek, does it work for you?
Quoted 2 lines
Thank you,
Signature · 5 lines
Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
PATCH v4 1/3 usb:gadget:f_thor: code cleanup in function download_tail()
Quoted 30 lines · Lukasz Majewski
Hi Przemyslaw, Marek,
Quoted 21 lines
Hello Marek,
Quoted 18 lines · Przemyslaw Marczak
In thor's
download_tail()function,dfu_get_entity()is called before eachdfu_write()call and the returned entity pointers are the same. Sodfu_get_entity()can be called just once and this patch changes this.Signed-off-by Przemyslaw Marczak <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>---
Changes v2:
- separate fix and cleanup into two commitsChanges v3:
-download_tail(): add exit labelQuoted 6 lines
Quoted 2 lines
Changes v4:
- noneI've checked the u-boot-usb/master tree and I found that one commit of this patch set is missed, because it is v3 (there was only two commits). Could you please apply the patch set version 4?
Quoted 7 lines
I've discussed this issue with Przemek, and we agreed that Przemek will prepare diff patch between version 3, which is already in mainline and version 4.
Then, after ML review, I will pull them to u-boot-dfu branch.
Marek, does it work for you?
Yes, thanks.
Best regards,
Marek Vasut
PATCH v4 2/3 usb:gadget:f_thor: fix write to filesystem by add dfu_flush()
In reply to Przemyslaw MarczakSince dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current dfu_flush() function writes filesystem only. This commit adds dfu_flush() to f_thor and now filesystem write is working.
This change was tested on Trats2 board.
---
Changes v2:
- separate fix and cleanup into two commits
Changes v3:
- none
Changes v4:
- download_tail(): remove dfu_write with 0 size
--- drivers/usb/gadget/f_thor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_thor.c +4 -4
@@ -219,15 +219,15 @@ static int download_tail(long long int left, int cnt) }/* -* To store last "packet" DFU storage backend requires dfu_write with -* size parameter equal to 0 +* To store last "packet" or write file from buffer to filesystem +* DFU storage backend requires dfu_flush * * This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret =dfu_write (dfu_entity, transfer_buffer,0 , cnt); + ret =dfu_flush (dfu_entity, transfer_buffer,0 , cnt);if (ret) -error ("DFU write failed [%d] cnt: %d" , ret, cnt); +error ("DFU flush failed!" ); exit:return ret;
Signature · 1 line
1.9.1
PATCH v4 3/3 drivers:dfu: dfu_flush(): add raw data flush to complete
In reply to Przemyslaw MarczakBefore dfu write and flush operations separation, dfu write data was flushed by host download request with len of zero size.
Since above change manually calling dfu write with zero size has non sense (e.g. in THOR). This should be done by flush operation.
So now dfu_write_buffer_drain() is called in dfu_flush(). If there is any raw data to flush (like it can be in thor) then it will be physically written to medium.
---
Changes v4:
- new commit
--- drivers/dfu/dfu.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/dfu/dfu.c +4 -0
@@ -131,6 +131,10 @@ int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) {int ret =0 ; + ret =dfu_write_buffer_drain (dfu); +if (ret) +return ret; +if (dfu->flush_medium) ret = dfu->flush_medium (dfu);
Signature · 1 line
1.9.1