Attention is currently required from: lynxis lazus.
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42174?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Verified-1 by Jenkins Builder
Change subject: dfu: rewrite firmware downloading
......................................................................
dfu: rewrite firmware downloading
Improve handling of dfu_state by moving more state changing towards the
IRQ handler. Having both the main loop and IRQ changes dfu_state within
the same state could lead to races.
The main loop is now only a simple worker which reports back via dfu_flash_done &
dfu_flash_status.
Change-Id: I345d5948455b25cd8a2efb1abfd9d0986ebd8cef
---
M usb/class/dfu/device/dfudf.c
M usb/class/dfu/device/dfudf.h
M usb_start.c
3 files changed, 79 insertions(+), 34 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/74/42174/2
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42174?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I345d5948455b25cd8a2efb1abfd9d0986ebd8cef
Gerrit-Change-Number: 42174
Gerrit-PatchSet: 2
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu>
Attention is currently required from: lynxis lazus.
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Verified-1 by Jenkins Builder
Change subject: dfu: mainloop: work on a local copy of dfu_state
......................................................................
dfu: mainloop: work on a local copy of dfu_state
Prevent race conditions between main loop and irq.
Copy at the start of the loop the dfu state and work on it.
Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944
---
M usb_start.c
1 file changed, 6 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/70/42170/2
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944
Gerrit-Change-Number: 42170
Gerrit-PatchSet: 2
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu>
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder
Change subject: dfu: usb_dfu() convert if() intos switch/case
......................................................................
dfu: usb_dfu() convert if() intos switch/case
Improves the overview of the handled states.
No functional change.
Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
---
M usb_start.c
1 file changed, 10 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/73/42173/2
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
Gerrit-Change-Number: 42173
Gerrit-PatchSet: 2
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42177?usp=email )
Change subject: dfu: MANIFEST: mainloop: wait 5 ms before handling the state
......................................................................
dfu: MANIFEST: mainloop: wait 5 ms before handling the state
Gives the USB stack some time to deliver the last USB message before
going through the state machine which might end in a too quick system reset.
Change-Id: If9178120eed46f75089abf1898db3176cce93df2
---
M usb_start.c
1 file changed, 3 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/77/42177/1
diff --git a/usb_start.c b/usb_start.c
index 7b164a0..185cd28 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -199,6 +199,9 @@
case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data
// in practice most downloaded files are just the raw binary with DFU suffix
+ /* give the previous GET STATUS packet some time to arrive, because otherwise
+ the board might go into reset to fast through MANIFEST_WAIT_RESET */
+ delay_ms(5);
CRITICAL_SECTION_ENTER();
dfu_manifestation_complete = true; // we completed flashing and all checks
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42177?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: If9178120eed46f75089abf1898db3176cce93df2
Gerrit-Change-Number: 42177
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42174?usp=email )
Change subject: dfu: rewrite firmware downloading
......................................................................
dfu: rewrite firmware downloading
Improve handling of dfu_state by moving more state changing towards the
IRQ handler. Having both the main loop and IRQ changes dfu_state within
the same state could lead to races.
The main loop is now only a simple worker which reports back via dfu_flash_done &
dfu_flash_status.
Change-Id: I345d5948455b25cd8a2efb1abfd9d0986ebd8cef
---
M usb/class/dfu/device/dfudf.c
M usb/class/dfu/device/dfudf.h
M usb_start.c
3 files changed, 78 insertions(+), 34 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/74/42174/1
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
index c66454b..0f5ec0e 100644
--- a/usb/class/dfu/device/dfudf.c
+++ b/usb/class/dfu/device/dfudf.c
@@ -42,9 +42,15 @@
volatile enum usb_dfu_state dfu_state = USB_DFU_STATE_DFU_IDLE;
volatile enum usb_dfu_status dfu_status = USB_DFU_STATUS_OK;
+/* flashed the last given block */
uint8_t dfu_download_data[512];
-uint16_t dfu_download_length = 0;
-size_t dfu_download_offset = 0;
+volatile uint16_t dfu_download_length = 0;
+volatile size_t dfu_download_offset = 0;
+
+/* only when flash done is true, flash rc is valid */
+volatile bool dfu_flash_done = false;
+volatile enum usb_dfu_status dfu_flash_status = USB_DFU_STATUS_ERR_UNKNOWN;
+
bool dfu_manifestation_complete = false;
/**
@@ -159,10 +165,20 @@
dfu_state = USB_DFU_STATE_DFU_ERROR; // unsupported class request
to_return = ERR_UNSUPPORTED_OP; // stall control pipe (don't reply to the request)
break;
- case USB_DFU_GETSTATUS: // get status
+ case USB_DFU_GETSTATUS:
switch (dfu_state) {
- case USB_DFU_STATE_DFU_DNLOAD_SYNC: // download has not completed
- dfu_state = USB_DFU_STATE_DFU_DNBUSY; // switch to busy state
+ case USB_DFU_STATE_DFU_DNLOAD_SYNC:
+ case USB_DFU_STATE_DFU_DNBUSY:
+ if (!dfu_flash_done) {
+ dfu_state = USB_DFU_STATE_DFU_DNBUSY;
+ break;
+ }
+
+ dfu_status = dfu_flash_status;
+ if (dfu_status == USB_DFU_STATUS_OK)
+ dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE;
+ else
+ dfu_state = USB_DFU_STATE_DFU_ERROR;
break;
case USB_DFU_STATE_DFU_MANIFEST_SYNC:
if (!dfu_manifestation_complete) {
@@ -230,36 +246,49 @@
if (!(usb_dfu_func_desc->bmAttributes & USB_REQ_DFU_DNLOAD)) { // download is not enabled
dfu_state = USB_DFU_STATE_DFU_ERROR; // unsupported class request
to_return = ERR_UNSUPPORTED_OP; // stall control pipe (don't reply to the request)
+ break;
} else if (USB_DFU_STATE_DFU_IDLE != dfu_state && USB_DFU_STATE_DFU_DNLOAD_IDLE != dfu_state) { // wrong state to request download
// warn about programming error
dfu_status = USB_DFU_STATUS_ERR_PROG;
dfu_state = USB_DFU_STATE_DFU_ERROR;
to_return = ERR_INVALID_ARG; // stall control pipe to indicate error
+ break;
} else if (USB_DFU_STATE_DFU_IDLE == dfu_state && (0 == req->wLength)) { // download request should not start empty
// warn about programming error
dfu_status = USB_DFU_STATUS_ERR_PROG;
dfu_state = USB_DFU_STATE_DFU_ERROR;
to_return = ERR_INVALID_ARG; // stall control pipe to indicate error
+ break;
} else if (USB_DFU_STATE_DFU_DNLOAD_IDLE == dfu_state && (0 == req->wLength)) { // download completed
dfu_manifestation_complete = false; // clear manifestation status
+ to_return = usbdc_xfer(ep, NULL, 0, false); // send ack to the setup request to get the data
dfu_state = USB_DFU_STATE_DFU_MANIFEST_SYNC; // prepare for manifestation phase
- to_return = usbdc_xfer(ep, NULL, 0, false); // send ACK
+ break;
} else if (req->wLength > sizeof(dfu_download_data)) { // there is more data to be flash then our buffer (the USB control buffer size should be less or equal)
// warn about programming error
dfu_status = USB_DFU_STATUS_ERR_PROG;
dfu_state = USB_DFU_STATE_DFU_ERROR;
to_return = ERR_INVALID_ARG; // stall control pipe to indicate error
- } else { // there is data to be flash
- if (USB_SETUP_STAGE == stage) { // there will be data to be flash
- to_return = usbdc_xfer(ep, dfu_download_data, req->wLength, false); // send ack to the setup request to get the data
- } else { // now there is data to be flashed
- dfu_download_offset = req->wValue * sizeof(dfu_download_data); // remember which block to flash
- dfu_download_length = req->wLength; // remember the data size to be flash
- dfu_state = USB_DFU_STATE_DFU_DNLOAD_SYNC; // go to sync state
- to_return = usbdc_xfer(ep, NULL, 0, false); // ACK the data
- // we let the main application flash the data because this can be long and would stall the USB ISR
- }
+ break;
}
+
+ /* The error cases are handled */
+ if (USB_SETUP_STAGE == stage) { // there will be data to be flash
+ to_return = usbdc_xfer(ep, dfu_download_data, req->wLength, false); // send ack to the setup request to get the data
+ break;
+ }
+
+ // now there is data to be flashed
+ if (USB_DFU_STATE_DFU_IDLE == dfu_state) {
+ /* first packet */
+ dfu_download_offset = 0;
+ }
+
+ /* main loop will increment offset after flashing */
+ dfu_download_length = req->wLength;
+ dfu_state = USB_DFU_STATE_DFU_DNLOAD_SYNC;
+ to_return = usbdc_xfer(ep, NULL, 0, false);
+ dfu_flash_done = false;
break;
default: // all other DFU class OUT request
dfu_state = USB_DFU_STATE_DFU_ERROR; // unknown class request
diff --git a/usb/class/dfu/device/dfudf.h b/usb/class/dfu/device/dfudf.h
index 818252d..b9db46f 100644
--- a/usb/class/dfu/device/dfudf.h
+++ b/usb/class/dfu/device/dfudf.h
@@ -48,9 +48,14 @@
*/
extern uint8_t dfu_download_data[512];
/** Length of downloaded data in bytes */
-extern uint16_t dfu_download_length;
+extern volatile uint16_t dfu_download_length;
/** Offset of where the downloaded data should be flashed in bytes */
-extern size_t dfu_download_offset;
+extern volatile size_t dfu_download_offset;
+
+/** when flash done is true, flash status is valid */
+extern volatile bool dfu_flash_done;
+/** Result of the last blocked flashed. */
+extern volatile enum usb_dfu_status dfu_flash_status;
/** If manifestation (firmware flash and check) is complete */
extern bool dfu_manifestation_complete;
diff --git a/usb_start.c b/usb_start.c
index 78711f1..bf06596 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -164,25 +164,35 @@
// run the second part of the USB DFU state machine handling non-USB aspects
switch (last_dfu_state) {
case USB_DFU_STATE_DFU_DNLOAD_SYNC:
- case USB_DFU_STATE_DFU_DNBUSY: // there is some data to be flashed
+ case USB_DFU_STATE_DFU_DNBUSY:
+ if (dfu_flash_done)
+ break;
+
+ /* FIXME: check if dfu_download_offset / length are valid */
+
LED_SYSTEM_off(); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed
- int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
- if (ERR_NONE == rc) {
- dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing this block has been completed
- } else { // there has been a programming error
- dfu_state = USB_DFU_STATE_DFU_ERROR;
- if (ERR_BAD_ADDRESS == rc) {
- dfu_status = USB_DFU_STATUS_ERR_ADDRESS;
- } else if (ERR_DENIED == rc) {
- dfu_status = USB_DFU_STATUS_ERR_WRITE;
- } else {
- dfu_status = USB_DFU_STATUS_ERR_PROG;
- }
+ int32_t rc = flash_write(&FLASH_0,
+ application_start_address + dfu_download_offset,
+ dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
+ CRITICAL_SECTION_ENTER();
+ switch (rc) {
+ case ERR_NONE:
+ dfu_flash_status = USB_DFU_STATUS_OK;
+ dfu_download_offset += dfu_download_length;
+ break;
+ case ERR_BAD_ADDRESS:
+ dfu_flash_status = USB_DFU_STATUS_ERR_ADDRESS;
+ break;
+ case ERR_DENIED:
+ dfu_flash_status = USB_DFU_STATUS_ERR_WRITE;
+ break;
+ default:
+ dfu_flash_status = USB_DFU_STATUS_ERR_PROG;
+ break;
}
- } else { // there was no data to flash
- // this case should not happen, but it's not a critical error
- dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue
+ dfu_flash_done = true;
+ CRITICAL_SECTION_LEAVE();
}
LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
break;
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42174?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I345d5948455b25cd8a2efb1abfd9d0986ebd8cef
Gerrit-Change-Number: 42174
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42176?usp=email )
Change subject: dfu: protect USB_DFU_STATE_DFU_MANIFEST by a critical section
......................................................................
dfu: protect USB_DFU_STATE_DFU_MANIFEST by a critical section
In the MANIFEST state, the IRQ won't move the state, but
to prevent incosistency between dfu_manifestation_complete &
dfu_state, use a critical section.
Change-Id: Idf5fb7d55b4051ba7e235dfa409a4de18a8f208c
---
M usb_start.c
1 file changed, 2 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/76/42176/1
diff --git a/usb_start.c b/usb_start.c
index bf06596..7b164a0 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -199,12 +199,14 @@
case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data
// in practice most downloaded files are just the raw binary with DFU suffix
+ CRITICAL_SECTION_ENTER();
dfu_manifestation_complete = true; // we completed flashing and all checks
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
dfu_state = USB_DFU_STATE_DFU_MANIFEST_SYNC;
} else {
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET;
}
+ CRITICAL_SECTION_LEAVE();
break;
case USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET:
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) {
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42176?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Idf5fb7d55b4051ba7e235dfa409a4de18a8f208c
Gerrit-Change-Number: 42176
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42175?usp=email )
Change subject: dfu: MANIFEST_SYNC: stay in MANIFEST_SYNC when manifestationIntolerant & completed
......................................................................
dfu: MANIFEST_SYNC: stay in MANIFEST_SYNC when manifestationIntolerant & completed
In theory a device which is manifestintolerant and completed the manifestation should
not reach MANIFEST_SYNC again.
Remove the state transistion to WAIT-RESET and stay in the current state and
wait for the main loop to change the state is safer.
Change-Id: I8c34a18e2336731126a8c01070d86e2547578e3d
---
M usb/class/dfu/device/dfudf.c
1 file changed, 6 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/75/42175/1
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
index 0f5ec0e..7b13cc3 100644
--- a/usb/class/dfu/device/dfudf.c
+++ b/usb/class/dfu/device/dfudf.c
@@ -183,10 +183,12 @@
case USB_DFU_STATE_DFU_MANIFEST_SYNC:
if (!dfu_manifestation_complete) {
dfu_state = USB_DFU_STATE_DFU_MANIFEST; // go to manifest mode
- } else if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
- dfu_state = USB_DFU_STATE_DFU_IDLE; // go back to idle mode
- } else { // this should not happen (after manifestation the state should be dfuMANIFEST-WAIT-RESET if we are not manifest tolerant)
- dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET; // wait for reset
+ } else {
+ /* manifestation complete */
+ if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
+ dfu_state = USB_DFU_STATE_DFU_IDLE; // go back to idle mode
+ }
+ /* otherwise stay in MANIFEST_SYNC */
}
break;
default:
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42175?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I8c34a18e2336731126a8c01070d86e2547578e3d
Gerrit-Change-Number: 42175
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email )
Change subject: dfu: usb_dfu() convert if() intos switch/case
......................................................................
dfu: usb_dfu() convert if() intos switch/case
Improves the overview of the handled states.
No functional change.
Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
---
M usb_start.c
1 file changed, 10 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/73/42173/1
diff --git a/usb_start.c b/usb_start.c
index c80703e..78711f1 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -162,7 +162,9 @@
enum usb_dfu_state last_dfu_state = dfu_state;
// run the second part of the USB DFU state machine handling non-USB aspects
- if (USB_DFU_STATE_DFU_DNLOAD_SYNC == last_dfu_state || USB_DFU_STATE_DFU_DNBUSY == last_dfu_state) { // there is some data to be flashed
+ switch (last_dfu_state) {
+ case USB_DFU_STATE_DFU_DNLOAD_SYNC:
+ case USB_DFU_STATE_DFU_DNBUSY: // there is some data to be flashed
LED_SYSTEM_off(); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed
int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
@@ -183,8 +185,8 @@
dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue
}
LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
- }
- if (USB_DFU_STATE_DFU_MANIFEST == last_dfu_state) { // we can start manifestation (finish flashing)
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data
// in practice most downloaded files are just the raw binary with DFU suffix
dfu_manifestation_complete = true; // we completed flashing and all checks
@@ -193,13 +195,16 @@
} else {
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET;
}
- }
- if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == last_dfu_state) {
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET:
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) {
usb_dfu_reset(USB_EV_RESET, 0); // immediately reset
} else { // wait for USB reset
usb_d_register_callback(USB_D_CB_EVENT, (FUNC_PTR)usb_dfu_reset); // register new USB reset event handler
}
+ break;
+ default:
+ break;
}
}
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
Gerrit-Change-Number: 42173
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42172?usp=email )
Change subject: dfu: irq: GET_STATUS: set state before sending it
......................................................................
dfu: irq: GET_STATUS: set state before sending it
The DFU spec, v1.1: "6.1.2 DFU_GETSTATUS Request" states the
GET_STATUS should contain the state,
to which the device transistions to after processing this message.
Change-Id: I6d28404d6936f7ea79fcee90f0c8191f0f623ad8
---
M usb/class/dfu/device/dfudf.c
1 file changed, 9 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/72/42172/1
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
index 882cad8..c66454b 100644
--- a/usb/class/dfu/device/dfudf.c
+++ b/usb/class/dfu/device/dfudf.c
@@ -160,14 +160,6 @@
to_return = ERR_UNSUPPORTED_OP; // stall control pipe (don't reply to the request)
break;
case USB_DFU_GETSTATUS: // get status
- response[0] = dfu_status; // set status
- response[1] = 10; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
- response[2] = 0; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
- response[3] = 0; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
- response[4] = dfu_state; // set state
- response[5] = 0; // string not used
- to_return = usbdc_xfer(ep, response, 6, false); // send back status
-
switch (dfu_state) {
case USB_DFU_STATE_DFU_DNLOAD_SYNC: // download has not completed
dfu_state = USB_DFU_STATE_DFU_DNBUSY; // switch to busy state
@@ -184,6 +176,15 @@
default:
break;
}
+
+ response[0] = dfu_status; // set status
+ response[1] = 10; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
+ response[2] = 0; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
+ response[3] = 0; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
+ response[4] = dfu_state; // set state
+ response[5] = 0; // string not used
+ to_return = usbdc_xfer(ep, response, 6, false); // send back status
+
break;
case USB_DFU_GETSTATE: // get state
response[0] = dfu_state; // return state
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42172?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I6d28404d6936f7ea79fcee90f0c8191f0f623ad8
Gerrit-Change-Number: 42172
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42171?usp=email )
Change subject: dfu: irq: replace if(states) with a switch case
......................................................................
dfu: irq: replace if(states) with a switch case
Improves the overview. No functional change.
Change-Id: Ic32fe16dff4b7bb933ec62e36a9c7c7829aece1b
---
M usb/class/dfu/device/dfudf.c
1 file changed, 8 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/71/42171/1
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
index 5bdb64a..882cad8 100644
--- a/usb/class/dfu/device/dfudf.c
+++ b/usb/class/dfu/device/dfudf.c
@@ -167,9 +167,12 @@
response[4] = dfu_state; // set state
response[5] = 0; // string not used
to_return = usbdc_xfer(ep, response, 6, false); // send back status
- if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state) { // download has not completed
+
+ switch (dfu_state) {
+ case USB_DFU_STATE_DFU_DNLOAD_SYNC: // download has not completed
dfu_state = USB_DFU_STATE_DFU_DNBUSY; // switch to busy state
- } else if (USB_DFU_STATE_DFU_MANIFEST_SYNC == dfu_state) {
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST_SYNC:
if (!dfu_manifestation_complete) {
dfu_state = USB_DFU_STATE_DFU_MANIFEST; // go to manifest mode
} else if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
@@ -177,6 +180,9 @@
} else { // this should not happen (after manifestation the state should be dfuMANIFEST-WAIT-RESET if we are not manifest tolerant)
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET; // wait for reset
}
+ break;
+ default:
+ break;
}
break;
case USB_DFU_GETSTATE: // get state
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42171?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ic32fe16dff4b7bb933ec62e36a9c7c7829aece1b
Gerrit-Change-Number: 42171
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>