Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed serial dfu using usb #148

Open
wants to merge 136 commits into
base: main
Choose a base branch
from
Open

Conversation

CapnOdin
Copy link

It is not possible to use BOOT_SERIAL_CDC_ACM at the moment as the USB handling is not given an opportunity to run after entering serial recovery mode.

I don't know if this is a good solution, but since I could not open an issue I thought I would share how I got it working, if for no other reason than to inform you of the issue.

Signed-off-by: Albert Juhl [email protected]

galak and others added 30 commits April 30, 2020 10:59
…LER_LABEL

As upstream zephyr is phasing out DT_FLASH defines for non-partition
usage replace DT_FLASH_DEV_NAME with
DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL.

Signed-off-by: Kumar Gala <[email protected]>
As the DT define DT_JEDEC_SPI_NOR_0_LABEL is intended to be deprecated
move to the new macro style to determine for DT_JEDEC_SPI_NOR_0_LABEL

Signed-off-by: Kumar Gala <[email protected]>
…cros""

This reverts commit 39d1aef.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synchronize up to

mcu-tools/mcuboot@82c5f7
which is same as v1.6.0-rc2 tag.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
As we replace the legacy DT_FLASH_ support use the new FLASH_AREA_
macros.

Signed-off-by: Kumar Gala <[email protected]>
Use the new FLASH_AREA_ macros.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Fixup how we fake out devicetree.h, which is now really the flash map
API for what mcuboot is using.

Signed-off-by: Kumar Gala <[email protected]>
Update CONFIG_FLOAT to CONFIG_FPU which has been renamed in zephyr.

Signed-off-by: Joakim Andersson <[email protected]>
Using find_package to locate Zephyr.

Old behavior was to use $ENV{ZEPHYR_BASE} for inclusion of boiler plate
code.

Whenever an automatic run of CMake happend by the build system / IDE
then it was required that ZEPHYR_BASE was defined.
Using ZEPHYR_BASE only to locate the Zephyr package allows CMake to
cache the base variable and thus allowing subsequent invocation even
if ZEPHYR_BASE is not set in the environment.

It also removes the risk of strange build results if a user switchs
between different Zephyr based project folders and forgetting to reset
ZEPHYR_BASE before running ninja / make.

Signed-off-by: Torsten Rasmussen <[email protected]>
Convert to use C99 types as we intend to deprecate the zephyr
specific integer types.

Signed-off-by: Kumar Gala <[email protected]>
This reverts commit b7254d1.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synchronize up to:
mcu-tools/mcuboot@9b48d08

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synchronize up to:
mcu-tools/mcuboot@33fbef5

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Align the code to the new UART callback signature, see:

zephyrproject-rtos/zephyr#26426

Signed-off-by: Carles Cufi <[email protected]>
Synchronize up to:
mcu-tools/mcuboot@1cb076c

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synchronize up to:
mcu-tools/mcuboot@5a6e181

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Change whitelist->allow to be compatible with sanitycheck in zephyr.

Signed-off-by: Anas Nashif <[email protected]>
Fix author email after move to new mailing list.

Signed-off-by: Fabio Utzig <[email protected]>
Follows up the change added to Zephyr with:

zephyrproject-rtos/zephyr#24873

Signed-off-by: Fabio Utzig <[email protected]>
Change fixes build issue that occurs if CONF_FILE contains multiple
file paths instead of single file path.

Signed-off-by: Marek Pieta <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
Missing const on pointers to device structures caused compilation
warnings when compiling bootloader with serial recovery enabled.

Signed-off-by: Dominik Ermel <[email protected]>
Synchronized up to:
https://github.com/JuulLabs-OSS/mcuboot/commit/@296949e

Improvements:
- hardening against hardware level fault injection and timing attacks
- Abstract crypto primitives to simplify porting.
- boot: Add ram-load upgrade mode
- renamed single-image mode to single-slot mode

- kconfig: provide logic for setting key file, simplify prj.conf

- imgtool: Print image digest during verify
- imgtool: Add possibility to set confirm flag for hex files as well
- imgtool: --confirm implies --pad

- Added single-slot Zephyr-RTOS test build

fixes:
- bootutil: fix boostrapping in swap-move
- bootutil: fix swap-move brick with padded image_0
- Disable HW stack protection (temporary hack)
- reset SPLIM registers before boot
- fixes build issue that occurs if CONF_FILE contains multiple file paths instead of single file path.
- imgtool: Fix 'custom_tlvs' argument handling
- Turn off cache for Cortex M7 before chain-loading.- hardening against hardware level fault injection and timing attacks

Conflicts:
- took upsteram boot/zephyr/sample.yaml

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Add Jenkinsfile and .gitlint files.

Signed-off-by: Thomas Stilwell <[email protected]>
Signed-off-by: Ulrich Myhre <[email protected]>
Signed-off-by: Chris Bittner <[email protected]>
Signed-off-by: Martí Bolívar <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
(cherry picked from commit 1a8bd29)
Adds project configurations for the two systems on the Thingy:91
(PCA-20035) board.

This was the "nrf9160_pca20035" board name in NCS v1.2. It has been
renamed "thingy91_nrf9160" for NCS v1.3.

Signed-off-by: Bernt Johan Damslora <[email protected]>
Signed-off-by: Sigvart Hovland <[email protected]>
Signed-off-by: Jon Helge Nistad <[email protected]>
(cherry picked from commit 96e698c)
Removes `NRFXLIB_CRYPTO`, `NRF_CC310_BL` and the `add_subdirectory`
of nrfxlib it will still check that the nrfxlib is located outside
the mcuboot directory.

Signed-off-by: Sigvart Hovland <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
Signed-off-by: Martí Bolívar <[email protected]>
Signed-off-by: Emil Obalski <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
(cherry picked from commit 4dacbdc)
* Add functions for ecdsa_verify_secp256r1 and sha256 to use the shared
crypto API
* Add Kconfig and CMake variables for selecting shared crypto when using
ecdsa
* Add custom section to project for placing the API section in the
correct location in flash

Signed-off-by: Sigvart Hovland <[email protected]>
Signed-off-by: Martí Bolívar <[email protected]>
Signed-off-by: Emil Obalski <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
(cherry picked from commit ef8f826)
If EXT_API_PROVIDE EXT_API is enabled. This is relevant only when
the immutable bootloader has booted mcuboot.

Signed-off-by: Øyvind Rønningstad <[email protected]>
Signed-off-by: Emil Obalski <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
(cherry picked from commit c876abb)
Partition Manager is an nRF Connect SDK component which uses yaml
files to resolve flash partition placement with a holistic view of the
device.

This component's MCUboot portions began life as upstream mcuboot
PR#430. This added support for being built as a sub image from the
downstream Nordic patch set for a zephyr multi image build
system (mcuboot 430 was combined with effor submitted to upstream
zephyr as PR#13672, which was ultimately reworked after being rejected
for mainline at the ELCE 2019 conference in Lyon).

It has since evolved over time. This is the version that will go into
NCS v1.3. It features:

- page size aligned partitions for all partitions used by mcuboot.
- image swaps without scratch partitions

Add support for configurations where there exists two primary slots
but only one secondary slot, which is shared. These two primary slots
are the regular application and B1. B1 can be either S0 or S1
depending on the state of the device.

Decide where an upgrade should be stored by looking at the vector
table.

Provide update candidates for both s0 and s1. These candidates must be
signed with mcuboot after being signed by b0.

Additional notes:

- we make update.hex without trailer data

  This is needed for serial recovery to work using hex files.
  Prior to this the update.hex got TLV data at the end of the
  partition, which caused many blank pages to be included,
  which made it hard to use in a serial recovery scheme.

  Instead, make update.hex without TLV data at the end,
  and provide a new file test_update.hex which contains
  the TLV data, and can be directly flashed to test the
  upgrade procedure.

- we use a function for signing the application as future-proofing
  for when other components must be signed as well

- this includes an update to single image applications that enables
  support for partition manager; when single image DFU is used, a
  scratch partition is not needed.

- In NCS, image 1 primary slot is the upgrade bank for mcuboot (IE S0 or
  S1 depending on the active slot). It is not required that this slot
  contains any valid data.

- The nRF boards all have a single flash page size, and partition
  manager deals with the size of the update partitions and so on, so we
  must skip a boot_slots_compatible() check to avoid getting an error.

- There is no need to verify the target when using partition manager.

Signed-off-by: Håkon Øye Amundsen <[email protected]>
Signed-off-by: Øyvind Rønningstad <[email protected]>
Signed-off-by: Sebastian Bøe <[email protected]>
Signed-off-by: Sigvart Hovland <[email protected]>
Signed-off-by: Martí Bolívar <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
Signed-off-by: Andrzej Głąbek <[email protected]>
Signed-off-by: Robert Lubos <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
Signed-off-by: Dominik Ermel <[email protected]>
Signed-off-by: Emil Obalski <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
Signed-off-by: Pawel Dunaj <[email protected]>
(cherry picked from commit e632ea6)
(cherry picked from commit e66f032)
(cherry picked from commit fcbc47f)
(cherry picked from commit 5409c45)
(cherry picked from commit 50155fd)
(cherry picked from commit d7373a0)
nvlsianpu and others added 11 commits January 27, 2021 14:43
    Synchronized up to:
    mcu-tools/mcuboot@a513b8e

    - fix build issue caused by that CONFIG_LOG_MINIMAL was replaced by CONFIG_LOG_MODE_MINIMAL
    - imgtool: fix validation with protected TLVs

    Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synch up to:
mcu-tools/mcuboot@a513b8e

merged by GitHub GUI nrfconnect#44

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synchronized up to:
mcu-tools/mcuboot@360763d

- fixed corupted build when the image encryption feature is enabled.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
This commit prevents creating secondary image partition
if CONFIG_SINGLE_APPLICATION_SLOT=y.

Signed-off-by: Draus, Sebastian <[email protected]>
…entation"

This reverts commit 6841a6b.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Synchronize MCUboot up to upstream commit
3fc5941

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Enables network core updates of nrf53 using MCUBoot by identifying
images through their start addresses. Also implements the control and
transfer using the PCD module.

Signed-off-by: Sigvart Hovland <[email protected]>
Signed-off-by: Håkon Øye Amundsen <[email protected]>

(cherry picked from commit a401d3a)
(cherry picked from commit f35f763)
(cherry picked from commit 3373578)
Signed-off-by: Ioannis Glaropoulos <[email protected]>
(cherry picked from commit df05bff)
Signed-off-by: Johann Fischer <[email protected]>
(cherry picked from commit 6841a6b)
Signed-off-by: Andrzej Puzdrowski <[email protected]>
MCUboot was updated to newer version which uses refactored
LOG Kconfig keyword not available in sdk-zephyr yet.

Revert this commit on the next upmerge.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
@hakonfam hakonfam requested a review from nvlsianpu April 14, 2021 18:40
@hakonfam
Copy link
Contributor

Thanks for your contribution, we will look into it :)

@@ -626,6 +626,7 @@ boot_serial_start(const struct boot_uart_funcs *f)
while (1) {
rc = f->read(in_buf + off, sizeof(in_buf) - off, &full_line);
if (rc <= 0 && !full_line) {
k_yield();
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 Is it possible that USB processing is at to low priority?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is not enough info about the surroundings, is there a problem with enumeration during startup?
The competitor(s) (driver/usb_transfer/CDC ACM) priority is system workqueue priority or CONFIG_USB_WORKQUEUE_PRIORITY.

main(void)
⬇️

  • boot_console_init(void)
  • ⬇️
  • boot_uart_fifo_init(void) <- here, it would make sense to add wait-for-dtr
    ⬇️

boot_serial_start(&boot_funcs)

Copy link
Author

Choose a reason for hiding this comment

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

@jfischer-no Is there any specific info you want me to provide?

Copy link
Contributor

@jfischer-no jfischer-no Apr 16, 2021

Choose a reason for hiding this comment

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

How does the problem manifest itself on the host side? Is the device enumerated/configured successfully or are there timeouts during the transfer? What is host OS?

Copy link
Author

Choose a reason for hiding this comment

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

I have tried it on Windows 10 and Manjaro Arm (Raspberry Pi 4) without yielding no device appears in device manager nor in /dev/. The OS seems to act the same way it would if no USB had been connected.

Copy link
Author

@CapnOdin CapnOdin Apr 19, 2021

Choose a reason for hiding this comment

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

It works on my custom nrf52840 print and on my evk-nina-b3. But not on my nrf5340dk. To be clear it won't compile when targeting nrf5340dk_nrf5340_cpuapp.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect it fails because of:

/home/user/zephyr-project/nrf/include/dfu/pcd.h:35:10: fatal error: pm_config.h: No such file or directory
   35 | #include <pm_config.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

I cannot help with that, but you can comment this include out for testing. Apart from faults after image reading, when the Button 1 is pressed the bootloader goes into recovery mode and USB initialized fine:

west build -b nrf5340dk_nrf5340_cpuapp ./ -- -DCONF_FILE="./usb_cdc_acm_log_recovery.conf" -DCONFIG_FLASH=y

*** Booting Zephyr OS build v2.4.99-ncs2  ***
[00:00:00.257,202] <inf> mcuboot: Starting bootloader
[00:00:00.257,690] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, i3
[00:00:00.257,751] <inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3,3
[00:00:00.257,751] <inf> mcuboot: Boot source: none
[00:00:00.257,751] <wrn> mcuboot: Failed reading image headers; Image=0
[00:00:00.257,843] <err> os: ***** USAGE FAULT *****
[00:00:00.257,843] <err> os:   Stack overflow (context area not valid)
[00:00:00.257,843] <err> os: r0/a1:  0x20005e90  r1/a2:  0x2000439b  r2/a3:  0x00000100
[00:00:00.257,843] <err> os: r3/a4:  0x20005e98 r12/ip:  0x000070b5 r14/lr:  0x0000ec2d
[00:00:00.257,843] <err> os:  xpsr:  0x29000200
[00:00:00.257,843] <err> os: Faulting instruction address (r15/pc): 0x00009094
[00:00:00.257,873] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
[00:00:00.257,873] <err> os: Current thread: 0x20000620 (unknown)
*** Booting Zephyr OS build v2.4.99-ncs2  ***ng system
[00:00:00.257,354] <inf> mcuboot: Starting bootloader
[00:00:00.257,537] <inf> mcuboot: Enter the serial recovery mode
[00:00:00.261,749] <inf> usb_cdc_acm: Device suspended
[00:00:00.363,983] <inf> usb_cdc_acm: Device resumed
[00:00:00.363,983] <inf> usb_cdc_acm: from suspend
[00:00:00.641,998] <inf> usb_cdc_acm: Device configured
[180542.153707] usb 3-1: new full-speed USB device number 23 using xhci_hcd
[180542.303463] usb 3-1: New USB device found, idVendor=2fe3, idProduct=0100, bcdDevice= 2.04
[180542.303467] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[180542.303468] usb 3-1: Product: MCUBOOT
[180542.303469] usb 3-1: Manufacturer: ZEPHYR
[180542.303470] usb 3-1: SerialNumber: BB423ADEE1289E02
[180542.304794] cdc_acm 3-1:1.0: ttyACM3: USB ACM device

Copy link
Contributor

Choose a reason for hiding this comment

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

@CapnOdin could you retest with nRF Connect SDK 1.5.1 now that it's released?

Copy link
Contributor

Choose a reason for hiding this comment

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

@CapnOdin also, which revision of the nRF53 DK do you have?

Copy link
Author

Choose a reason for hiding this comment

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

It says the following on the box:
nRF6835
0.11.0
2020.50

From the box my earlier nrf5340-PDK came in I can tell that the second value is the revision but I have no idea why it says nRF6835 on the sticker.

Yes I will test it in 1.5.1 on Monday.

@mbolivar-nordic
Copy link
Contributor

Please rebase onto the new history in main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.