Skip to content

Conversation

jfischer-no
Copy link
Contributor

usb: do not add ZLP if lenght to be transmitted is just zero

It is possible that the actual data stage length of
the control transfer is zero, in that case we do not
need an additional ZLP packet.

This fixes a problem with USB DFU, where after an upload
the device is no longer responsive if upload size is
multiple of control endpoint MPS.


usb: dfu: disable USB DFU uploading by default

Firmware uploading to the host may not always be desired,
disable it by default.

Enable it for existing USB DFU sample to keep
the usual behavior, add note about new option to README.rst.

It is possible that the actual data stage length of
the control transfer is zero, in that case we do not
need an additional ZLP packet.

This fixes a problem with USB DFU, where after an upload
the device is no longer responsive if upload size is
multiple of control endpoint MPS.

Signed-off-by: Johann Fischer <[email protected]>
Rename confusing UPLOAD_FLASH_AREA_ID to DOWNLOAD_FLASH_AREA_ID
as it is area where firmware image is downloaded.

Signed-off-by: Johann Fischer <[email protected]>
@jfischer-no jfischer-no added bug The issue is a bug, or the PR is fixing a bug area: USB Universal Serial Bus area: DFU Device Firmware Upgrade labels Feb 2, 2022
@jfischer-no jfischer-no added this to the v3.0.0 milestone Feb 2, 2022
@jfischer-no jfischer-no requested a review from nashif as a code owner February 2, 2022 19:05
@jfischer-no jfischer-no force-pushed the pr-usb-dfu-fixes-for-300 branch from d9d35a5 to af2f936 Compare February 2, 2022 19:08

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this description is not very clear

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling this option allows to download the image by the host. Be aware that the primary image (executable one) is always plain-text despite the image encryption is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do the Security Risk: Enabling this option ... to make it more clear

Copy link
Contributor Author

@jfischer-no jfischer-no Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is upload / uploading, device uploads the firmware to the host, downloading is from host to device. Clearly described according to the USB DFU spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfischer-no Yes, let use upload word:
Security Risk: Enabling this option allows to upload the image to the host. Be aware that the primary image (executable one) is always plain-text despite the image encryption is enabled.

Copy link
Contributor Author

@jfischer-no jfischer-no Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decrypted firmware is correct term in this case, not plain-text.

What about single slot?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single slot update works with mcuboot serial recovery and allows decryption in place on serial upload. This means that allowing download is risk in application running from single slot if it has been uploaded as encrypted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we do not, yet, have a method to get information from on mcuboot configuration to resolve this at application runtime. Application also does not know whether it has been uploaded encrypted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decrypted firmware is correct term in this case, not plain-text.

OK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated description

@gmarull gmarull removed their request for review February 3, 2022 12:41
Copy link
Contributor

@nvlsianpu nvlsianpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch looks as I expected.

Copy link
Contributor

@hackwerken hackwerken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thing this is being fixed :)

Note that the device can let the host know it is not capable of uploading. See https://github.com/zephyrproject-rtos/zephyr/blob/af2f936d8d0000e143faa32e5cf997160082554c/subsys/usb/class/dfu/usb_dfu.c#L104

And USB DFU Specification page 13

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to not even compile in the upload code. Then an upload is impossible even if someone manages to bypass this check. Altho the compiler will probably optimize away the unused code, that does require those optimizations to be enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, my wish would be that underlying flash API simply has no access to this area if not enabled.

@jfischer-no
Copy link
Contributor Author

Good thing this is being fixed :)

Note that the device can let the host know it is not capable of uploading. See

https://github.com/zephyrproject-rtos/zephyr/blob/af2f936d8d0000e143faa32e5cf997160082554c/subsys/usb/class/dfu/usb_dfu.c#L104

And USB DFU Specification page 13

Thanks for the hint, totally forgot about DFU attributes.

Firmware uploading to the host may not always be desired,
disable it by default.

Enable it for existing USB DFU sample to keep
the usual behavior, add note about new option to README.rst.

Signed-off-by: Johann Fischer <[email protected]>
@jfischer-no jfischer-no force-pushed the pr-usb-dfu-fixes-for-300 branch from af2f936 to d6e20de Compare February 8, 2022 17:57
@jfischer-no jfischer-no requested review from nvlsianpu and removed request for utzig and mbolivar-nordic February 8, 2022 17:58
Copy link
Contributor

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK.
Tested on nrf52840dk_nrf52840 with the upload enabled and disabled and works OK.

@carlescufi
Copy link
Member

@nvlsianpu can you please take a look?

@dkalowsk dkalowsk merged commit 3b7807c into zephyrproject-rtos:main Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DFU Device Firmware Upgrade area: Documentation area: Samples Samples area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants