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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
014f42d
zephyr: Replace DT_FLASH_DEV_NAME with DT_CHOSEN_ZEPHYR_FLASH_CONTROL…
galak Apr 8, 2020
8cd5dc5
zephyr: convert DT_JEDEC_SPI_NOR_0_LABEL to new dt macros
galak Apr 8, 2020
39d1aef
Revert "zephyr: convert DT_JEDEC_SPI_NOR_0_LABEL to new dt macros"
nvlsianpu May 7, 2020
48b8ef0
Revert "Revert "zephyr: convert DT_JEDEC_SPI_NOR_0_LABEL to new dt ma…
nvlsianpu May 7, 2020
5657d00
mergeup: merge up to upstream 82c5f7c
nvlsianpu May 7, 2020
b7254d1
zephyr: Change DT_FLASH_AREA_ macros to FLASH_AREA_
galak May 8, 2020
322b11a
zephyr: Change DT_FLASH_AREA_ macros to FLASH_AREA for multimage
nvlsianpu May 11, 2020
1f181dd
sim: Fixup devicetree.h for changes to mcuboot
galak May 11, 2020
e88113b
scripts/assemble: Rework to use EDT library to get devicetree data
galak May 11, 2020
f625267
kconfig: Update to CONFIG_FLOAT to CONFIG_FPU rename in zephyr
joerchan May 19, 2020
4bb0f95
cmake: use find_package to locate Zephyr
tejlmand May 28, 2020
ba7748d
Convert from Zephyr to C99 types
galak May 27, 2020
60cc568
Revert "zephyr: Change DT_FLASH_AREA_ macros to FLASH_AREA_"
nvlsianpu Jun 8, 2020
032eb72
mergeup: merge up to upstream 9b48d08
nvlsianpu Jun 8, 2020
d52aff5
mergeup: merge up to upstream 33fbef5
nvlsianpu Jun 19, 2020
9920005
zephyr: serial: Align with new callback signature
carlescufi Jul 20, 2020
813d29c
mergeup: merge up to upstream 1cb076c
nvlsianpu Aug 3, 2020
0f2c585
mergeup: merge up to upstream 5a6e181
nvlsianpu Aug 14, 2020
3ab5ab3
sample: inclusive language: whitelist -> allow
nashif Aug 26, 2020
f78d1d0
imgtool: fix package's author email
utzig Aug 17, 2020
4804219
zephyr: struct device const-ification
utzig Sep 2, 2020
a5d79cf
boot: zephyr: Fix build issue for multiple conf files
MarekPieta Aug 12, 2020
e8bfc03
zephyr: Fix serial recovery compilation warnings
de-nordic Sep 11, 2020
e312fa2
synch with upstream 296949e
nvlsianpu Oct 7, 2020
7718705
[nrf noup] ci: add Jenkins-based CI for NCS
thst-nordic Nov 23, 2018
228e886
[nrf toup] zephyr: add support for Thingy:91
bjda Sep 20, 2019
45f0833
[nrf noup] zephyr: Remove duplication from Kconfig and cmake
sigvartmh Mar 26, 2019
68f2bcc
[nrf noup] boot: bootutil: Add shared crypto functions for ECDSA
sigvartmh Feb 14, 2019
e6e6850
[nrf noup] boot: zephyr: Call fw_info_ext_api_provide() before booting
oyvindronningstad Feb 12, 2020
04514d6
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
59e02e2
[nrf noup] zephyr: lock mcuboot using fprotect before jumping
hakonfam Jan 6, 2020
f35f763
[nrf noup] boot: zephyr: nrf53 network core bootloader implementation
sigvartmh Aug 27, 2020
1788ad7
[nrf noup] kconfig: use cc310 for ecdsa by default
hakonfam Oct 8, 2020
4d1b74b
[nrf noup] kconfig: enable external crypto config
hakonfam Oct 8, 2020
74e2e0f
[nrf fromtree] zephyr: Fix serial recovery compilation warnings
de-nordic Sep 11, 2020
54238ad
[nrf fromtree] boot: zephyr: reset SPLIM registers before boot
hakonfam Oct 1, 2020
45a94cb
[nrf fromtree] boot: zephyr: Disable HW stack protection
mniestroj Oct 5, 2020
d0634dd
[nrf fromtree] doc: fix link to external page in PORTING
utzig Oct 1, 2020
80eb854
[nrf fromtree] kconfig: zephyr: provide logic ...
hakonfam Sep 28, 2020
3264059
[nrf fromtree] bootutil: fix swap-move brick with padded image0
utzig Oct 6, 2020
931d96b
[nrf fromtree] bootutil: fix boostrapping in swap-move
utzig Oct 4, 2020
02833fa
[nrf fromlist] zephyr: update name of nrf5340 dk
hakonfam Jun 3, 2020
b03e43f
[nrf fromlist] zephyr: enable progressive erase on all nRF boards
bjda Sep 20, 2019
a821395
[nrf fromlist] doc: clean up multi-image documentation
mbolivar-nordic Aug 8, 2019
8564559
[nrf fromlist] bootutil: copy image size with fast overwrite
utzig Oct 4, 2020
e9d64d4
[nrf temphack] Kconfig: add accessor for flash write block size
mbolivar-nordic Apr 24, 2020
a8cc987
[nrf temphack] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
4c5ff85
[nrf temphack] boot: bootutil: Word align read buffer in loader
sigvartmh May 27, 2020
ac05235
[nrf temphack] Kconfig: select 8-bits flash access for recovery mode
nvlsianpu Oct 16, 2020
e64c5f0
synch with upstream c625da4
nvlsianpu Oct 21, 2020
710ce7f
synch with upstream c74c551
nvlsianpu Oct 29, 2020
c71d218
Merge: Synchronized up to JuulLabs-OSS@c74c551
nvlsianpu Oct 29, 2020
b54f9ac
synch with upstream d2122bc
nvlsianpu Nov 18, 2020
9680f01
Revert "[nrf fromlist] bootutil: copy image size with fast overwrite"
ioannisg Nov 20, 2020
f5f3439
Revert "[nrf fromlist] doc: clean up multi-image documentation"
ioannisg Nov 20, 2020
d9a0c0f
Revert "[nrf fromlist] zephyr: enable progressive erase on all nRF bo…
ioannisg Nov 20, 2020
8c4b1d5
Revert "[nrf fromlist] zephyr: update name of nrf5340 dk"
ioannisg Nov 20, 2020
3cadeb9
Revert "[nrf fromtree] bootutil: fix boostrapping in swap-move"
ioannisg Nov 20, 2020
9912d21
Revert "[nrf fromtree] bootutil: fix swap-move brick with padded image0"
ioannisg Nov 20, 2020
ddcc4e1
Revert "[nrf fromtree] doc: fix link to external page in PORTING"
ioannisg Nov 20, 2020
4fb56e7
Revert "[nrf fromtree] boot: zephyr: Disable HW stack protection"
ioannisg Nov 20, 2020
9851136
Revert "[nrf fromtree] boot: zephyr: reset SPLIM registers before boot"
ioannisg Nov 20, 2020
8d0f628
Revert "[nrf fromtree] zephyr: Fix serial recovery compilation warnings"
ioannisg Nov 20, 2020
aada128
Revert "[nrf fromtree] kconfig: zephyr: provide logic ..."
ioannisg Nov 20, 2020
6e3825f
Merge: Synchronized up to mcu-tools@d2122bc
nvlsianpu Nov 23, 2020
ec663cc
Revert "[nrf temphack] Kconfig: select 8-bits flash access for recove…
ioannisg Nov 23, 2020
389b7f2
Revert "[nrf temphack] boot: bootutil: Word align read buffer in loader"
ioannisg Nov 23, 2020
a85b621
Revert "[nrf temphack] do_boot: clean peripherals state before boot"
ioannisg Nov 23, 2020
9bbc222
Revert "[nrf noup] kconfig: enable external crypto config"
ioannisg Nov 23, 2020
e991409
Revert "[nrf noup] kconfig: use cc310 for ecdsa by default"
ioannisg Nov 23, 2020
fb00c70
Revert "[nrf noup] boot: zephyr: nrf53 network core bootloader implem…
ioannisg Nov 23, 2020
7aa2990
Revert "[nrf temphack] Kconfig: add accessor for flash write block size"
ioannisg Nov 23, 2020
d544535
Revert "[nrf noup] zephyr: lock mcuboot using fprotect before jumping"
ioannisg Nov 23, 2020
449c296
Revert "[nrf noup] treewide: add NCS partition manager support"
ioannisg Nov 23, 2020
f8d1c84
Revert "[nrf noup] boot: bootutil: Add shared crypto functions for EC…
ioannisg Nov 23, 2020
c7ee647
Revert "[nrf noup] zephyr: Remove duplication from Kconfig and cmake"
ioannisg Nov 23, 2020
f5fdc5c
[nrf mergeup]: Synchronize mcuboot with zephyrproject-rtos/mcuboot
ioannisg Nov 23, 2020
3fddc54
[nrf noup] zephyr: Remove duplication from Kconfig and cmake
sigvartmh Mar 26, 2019
fd12a3d
[nrf noup] boot: bootutil: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
ecbaa04
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
01c58f5
[nrf noup] zephyr: lock mcuboot using fprotect before jumping
hakonfam Jan 6, 2020
ee8ab63
[nrf temphack] Kconfig: add accessor for flash write block size
mbolivar-nordic Apr 24, 2020
df05bff
[nrf noup] boot: zephyr: nrf53 network core bootloader implementation
sigvartmh Aug 27, 2020
ee5338f
[nrf noup] kconfig: use cc310 for ecdsa by default
hakonfam Oct 8, 2020
fbd3e7a
[nrf noup] kconfig: enable external crypto config
hakonfam Oct 8, 2020
bd4d82f
[nrf temphack] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
794fbcf
[nrf noup] PM: adapted PM related code to CONFIG_SINGLE_APPLICATION_SLOT
nvlsianpu Nov 26, 2020
534a4ec
[nrf fromlist] zephyr: use minimal CBPRINTF implementation
nvlsianpu Nov 27, 2020
853e112
[nrf temphack]: remove CONFIG_DEBUG=y in Zephyr prj.conf
tejlmand Nov 27, 2020
b95e493
[nrf fromtree] zephyr/Kconfig: Added default pin for serial ...
osaether Nov 25, 2020
ef39423
[nrf noup] pm: clarify the purpose of the mcuboot_pad partition
vidarbe Nov 30, 2020
cb5a7b3
Merge: Synchronized up to mcu-tools/mcuboot@e512181
henrikbrixandersen Jan 13, 2021
c986a90
Merge: Synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu Jan 14, 2021
915a281
synch with upstream be64e6a
nvlsianpu Jan 14, 2021
6f48e0a
Merge: synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu Jan 14, 2021
52ff566
synch with upstream ce50334
nvlsianpu Jan 15, 2021
3f49b5a
Merge: synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu Jan 20, 2021
9f8ccb9
[nrf noup] ci: use zephyr/scripts/ci/check_compliance.py
thst-nordic Jan 20, 2021
8834daf
[nrf noup] ci: replace jenkins pipeline in jenkinsfile with a stub
thst-nordic Jan 21, 2021
eda03c6
Revert "[nrf noup] ci: replace jenkins pipeline in jenkinsfile with a…
jfischer-no Jan 22, 2021
8faa32b
Revert "[nrf noup] ci: use zephyr/scripts/ci/check_compliance.py"
jfischer-no Jan 22, 2021
62f5e99
Revert "[nrf noup] pm: clarify the purpose of the mcuboot_pad partition"
jfischer-no Jan 22, 2021
d180288
Revert "[nrf fromtree] zephyr/Kconfig: Added default pin for serial ..."
jfischer-no Jan 22, 2021
3397b9a
Revert "[nrf temphack]: remove CONFIG_DEBUG=y in Zephyr prj.conf"
jfischer-no Jan 22, 2021
6109ca6
Revert "[nrf fromlist] zephyr: use minimal CBPRINTF implementation"
jfischer-no Jan 22, 2021
c86f393
Revert "[nrf noup] PM: adapted PM related code to CONFIG_SINGLE_APPLI…
jfischer-no Jan 22, 2021
6f10738
Revert "[nrf temphack] do_boot: clean peripherals state before boot"
jfischer-no Jan 22, 2021
154f9c0
Revert "[nrf noup] kconfig: enable external crypto config"
jfischer-no Jan 22, 2021
78a55d2
Revert "[nrf noup] kconfig: use cc310 for ecdsa by default"
jfischer-no Jan 22, 2021
8ea00df
Revert "[nrf noup] boot: zephyr: nrf53 network core bootloader implem…
jfischer-no Jan 22, 2021
12c6bf9
Revert "[nrf temphack] Kconfig: add accessor for flash write block size"
jfischer-no Jan 25, 2021
c7de60b
Revert "[nrf noup] zephyr: lock mcuboot using fprotect before jumping"
jfischer-no Jan 25, 2021
3b2a790
Revert "[nrf noup] treewide: add NCS partition manager support"
jfischer-no Jan 25, 2021
7958a42
[nrf mergeup]: Synchronize mcuboot with zephyrproject-rtos/mcuboot
jfischer-no Jan 25, 2021
84cc24d
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
0bb3e66
[nrf noup] zephyr: lock mcuboot using fprotect before jumping
hakonfam Jan 6, 2020
6841a6b
[nrf noup] boot: zephyr: nrf53 network core bootloader implementation
sigvartmh Aug 27, 2020
d80776b
[nrf noup] kconfig: use cc310 for ecdsa by default
hakonfam Oct 8, 2020
ca4d049
[nrf noup] kconfig: enable external crypto config
hakonfam Oct 8, 2020
18a0a8a
[nrf temphack] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
a79c7ec
[nrf noup] PM: adapted PM related code to CONFIG_SINGLE_APPLICATION_SLOT
nvlsianpu Nov 26, 2020
798c351
[nrf temphack]: remove CONFIG_DEBUG=y in Zephyr prj.conf
tejlmand Nov 27, 2020
cab5843
[nrf noup] pm: clarify the purpose of the mcuboot_pad partition
vidarbe Nov 30, 2020
0e60baf
[nrf noup] ci: use zephyr/scripts/ci/check_compliance.py
thst-nordic Jan 20, 2021
78fc1d6
[nrf noup] ci: replace jenkins pipeline in jenkinsfile with a stub
thst-nordic Jan 21, 2021
770fe67
synch with upstream a513b8e
nvlsianpu Jan 27, 2021
30e0c5a
Merge: synchronized up to mcu-tools@a513b8e
nvlsianpu Jan 27, 2021
2c0608f
synch with upstream 360763d
nvlsianpu Feb 5, 2021
4620e27
[nrf noup] pm: Don't create second image partition in single slot build
sebastiandraus Feb 4, 2021
3fc5941
Merge: Synchronized up to https://github.com/zephyrproject-rtos/mcubo…
nvlsianpu Feb 5, 2021
3384cd3
Revert "[nrf noup] boot: zephyr: nrf53 network core bootloader implem…
nvlsianpu Feb 8, 2021
ef3af33
[nrf mergeup]: Synchronize MCUboot with zephyrproject-rtos/mcuboot
nvlsianpu Feb 8, 2021
b767052
[nrf noup] boot: zephyr: nrf53 network core bootloader implementation
sigvartmh Aug 27, 2020
858dd03
[nrf temphack] prj.conf: don't use CONFIG_LOG_MODE_MINIMAL yet
nvlsianpu Feb 8, 2021
3ea42d2
Revert "[nrf temphack] prj.conf: don't use CONFIG_LOG_MODE_MINIMAL yet"
anangl Mar 5, 2021
769d5a3
Made boot_serial_start yield to allow the usb connection to be establ…
CapnOdin Apr 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Backport
on:
pull_request:
types:
- closed
- labeled

jobs:
backport:
runs-on: ubuntu-18.04
name: Backport
steps:
- name: Backport Bot
uses: Gaurav0/[email protected]
with:
bot_username: NordicBuilder
bot_token: 151a9b45052f9ee8be5a59963d31ad7b92c3ecb5
bot_token_key: 67bb1f1f998d546859786a4088917c65415c0ebd
github_token: ${{ secrets.GITHUB_TOKEN }}
57 changes: 57 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# All these sections are optional, edit this file as you like.
[general]
ignore=title-trailing-punctuation, T3, title-max-length, T1, body-hard-tab, B3, B1
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
verbosity = 3
# By default gitlint will ignore merge commits. Set to 'false' to disable.
ignore-merge-commits=true
# Enable debug mode (prints more output). Disabled by default
debug = false

# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
extra-path=../../zephyr/scripts/gitlint

[title-max-length-no-revert]
line-length=72

[body-min-line-count]
min-line-count=1

[body-max-line-count]
max-line-count=200

[title-starts-with-subsystem]
regex = ^(?!subsys:)(([^:]+):)(\s([^:]+):)*\s(.+)$

[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
# will not cause a violation, but "WIP: my title" will.
words=wip

[title-match-regex]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit-msg title must be matched to.
# Note that the regex can contradict with other rules if not used correctly
# (e.g. title-must-not-contain-word).
#regex=^US[0-9]*

[max-line-length-with-exceptions]
# B1 = body-max-line-length
line-length=72

[body-min-length]
min-length=3

[body-is-missing]
# Whether to ignore this rule on merge commits (which typically only have a title)
# default = True
ignore-merge-commits=false

[body-changed-file-mention]
# List of files that need to be explicitly mentioned in the body when they are changed
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
#files=gitlint/rules.py,README.md
6 changes: 6 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library("CI_LIB") _

def pipeline = new ncs.sdk_mcuboot.Main()

pipeline.run(JOB_NAME)

1 change: 1 addition & 0 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

continue;
}
off += rc;
Expand Down
27 changes: 27 additions & 0 deletions boot/bootutil/include/bootutil/crypto/ecdsa_p256.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#if (defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_CC310) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_MBED_TLS)) != 1
#error "One crypto backend must be defined: either CC310 or TINYCRYPT"
#endif
Expand All @@ -29,6 +30,11 @@
#define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8)
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#include <bl_crypto.h>
#define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8)
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -76,6 +82,27 @@ static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx, u
}
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
typedef uintptr_t bootutil_ecdsa_p256_context;

static inline void bootutil_ecdsa_p256_init(bootutil_ecdsa_p256_context *ctx)
{
(void)ctx;
}

static inline void bootutil_ecdsa_p256_drop(bootutil_ecdsa_p256_context *ctx)
{
(void)ctx;
}

static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx, uint8_t *pk, uint8_t *hash, uint8_t *sig)
{
(void)ctx;
return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE,
pk, sig);
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
32 changes: 32 additions & 0 deletions boot/bootutil/include/bootutil/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#if (defined(MCUBOOT_USE_MBED_TLS) + \
defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_CC310)) != 1
#error "One crypto backend must be defined: either CC310, MBED_TLS or TINYCRYPT"
#endif
Expand Down Expand Up @@ -134,6 +135,37 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
}
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)

#include <bl_crypto.h>

typedef bl_sha256_ctx_t bootutil_sha256_context;

static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
{
bl_sha256_init(ctx);
}

static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)
{
(void)ctx;
}

static inline int bootutil_sha256_update(bootutil_sha256_context *ctx,
const void *data,
uint32_t data_len)
{
return bl_sha256_update(ctx, data, data_len);
}

static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
uint8_t *output)
{
bl_sha256_finalize(ctx, output);
return 0;
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 5 additions & 1 deletion boot/bootutil/src/image_ec256.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
#ifdef MCUBOOT_USE_CC310
#define NUM_ECC_BYTES (256 / 8)
#endif
#if defined (MCUBOOT_USE_TINYCRYPT) || defined (MCUBOOT_USE_CC310)
#ifdef MCUBOOT_USE_NRF_EXTERNAL_CRYPTO
#define NUM_ECC_BYTES (256 / 8)
#endif
#if defined (MCUBOOT_USE_TINYCRYPT) || defined (MCUBOOT_USE_CC310) \
|| defined (MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#include "bootutil/sign_key.h"

#include "mbedtls/oid.h"
Expand Down
99 changes: 95 additions & 4 deletions boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#include "bootutil/boot_record.h"
#include "bootutil/fault_injection_hardening.h"

#ifdef CONFIG_SOC_NRF5340_CPUAPP
#include <dfu/pcd.h>
#endif

#ifdef MCUBOOT_ENC_IMAGES
#include "bootutil/enc_key.h"
#endif
Expand Down Expand Up @@ -90,6 +94,15 @@ boot_read_image_headers(struct boot_loader_state *state, bool require_all,
*
* Failure to read any headers is a fatal error.
*/
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. The primary slot of the second image
* (image 1) will not contain a valid image header until an upgrade
* of mcuboot has happened (filling S1 with the new version).
*/
if (BOOT_CURR_IMG(state) == 1 && i == 0) {
continue;
}
#endif /* PM_S1_ADDRESS */
if (i > 0 && !require_all) {
return 0;
} else {
Expand Down Expand Up @@ -715,6 +728,47 @@ boot_validated_swap_type(struct boot_loader_state *state,
{
int swap_type;
fih_int fih_rc = FIH_FAILURE;
bool upgrade_valid = false;

#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
const struct flash_area *secondary_fa =
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
uint32_t vtable_addr = 0;
uint32_t *vtable = 0;
uint32_t reset_addr = 0;
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
* B1 slot S0 or S1) share the same secondary slot, we need to check
* whether the update candidate in the secondary slot is intended for
* image 0 or image 1 primary by looking at the address of the reset
* vector. Note that there are good reasons for not using img_num from
* the swap info.
*/

if (hdr->ih_magic == IMAGE_MAGIC) {
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
vtable = (uint32_t *)(vtable_addr);
reset_addr = vtable[1];
#ifdef PM_S1_ADDRESS
const struct flash_area *primary_fa;
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
BOOT_CURR_IMG(state),
BOOT_PRIMARY_SLOT),
&primary_fa);

if (rc != 0) {
return BOOT_SWAP_TYPE_FAIL;
}
/* Get start and end of primary slot for current image */
if (reset_addr < primary_fa->fa_off ||
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
/* The image in the secondary slot is not intended for this image
*/
return BOOT_SWAP_TYPE_NONE;
}
#endif /* PM_S1_ADDRESS */
}
#endif /* PM_S1_ADDRESS || CONFIG_SOC_NRF5340_CPUAPP */

swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
if (BOOT_IS_UPGRADE(swap_type)) {
Expand All @@ -728,7 +782,31 @@ boot_validated_swap_type(struct boot_loader_state *state,
} else {
swap_type = BOOT_SWAP_TYPE_FAIL;
}
} else {
upgrade_valid = true;
}

#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
/* If the update is valid, and it targets the network core: perform the
* update and indicate to the caller of this function that no update is
* available
*/
if (upgrade_valid && reset_addr > PM_CPUNET_B0N_ADDRESS) {
uint32_t fw_size = hdr->ih_img_size;

BOOT_LOG_INF("Starting network core update");
int rc = pcd_network_core_update(vtable, fw_size);

if (rc != 0) {
swap_type = BOOT_SWAP_TYPE_FAIL;
} else {
BOOT_LOG_INF("Done updating network core");
rc = swap_erase_trailer_sectors(state,
secondary_fa);
swap_type = BOOT_SWAP_TYPE_NONE;
}
}
#endif /* CONFIG_SOC_NRF5340_CPUAPP */
}

return swap_type;
Expand Down Expand Up @@ -1839,10 +1917,23 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
}

#ifdef MCUBOOT_VALIDATE_PRIMARY_SLOT
FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_PRIMARY_SLOT, NULL);
if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
goto out;
}
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. If secure boot is enabled, then mcuboot
* will be stored in either partition S0 or S1. Image 1 primary
* will point to the 'other' Sx partition. Hence, image 1 primary
* does not contain a valid image until mcuboot has been upgraded.
* Note that B0 will perform validation of the active mcuboot image,
* so there is no security lost by skipping this check for image 1
* primary.
*/
if (BOOT_CURR_IMG(state) == 0)
#endif
{
FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_PRIMARY_SLOT, NULL);
if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
goto out;
}
}
#else
/* Even if we're not re-validating the primary slot, we could be booting
* onto an empty flash chip. At least do a basic sanity check that
Expand Down
13 changes: 13 additions & 0 deletions boot/bootutil/src/swap_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
int
boot_slots_compatible(struct boot_loader_state *state)
{
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. In this case, image 1 primary points to the other
* B1 slot (ie S0 or S1), and image 0 primary points to the app.
* With this configuration, image 0 and image 1 share the secondary slot.
* Hence, the primary slot of image 1 will be *smaller* than image 1's
* secondary slot. This is not allowed in upstream mcuboot, so we need
* this patch to allow it. Also, all of these checks are redundant when
* partition manager is in use, and since we have the same sector size
* in all of our flash.
*/
return 1;
#else
size_t num_sectors_pri;
size_t num_sectors_sec;
size_t sector_sz_pri = 0;
Expand Down Expand Up @@ -247,6 +259,7 @@ boot_slots_compatible(struct boot_loader_state *state)
}

return 1;
#endif /* PM_S1_ADDRESS */
}

#define BOOT_LOG_SWAP_STATE(area, state) \
Expand Down
13 changes: 13 additions & 0 deletions boot/bootutil/src/swap_scratch.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
int
boot_slots_compatible(struct boot_loader_state *state)
{
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. In this case, image 1 primary points to the other
* B1 slot (ie S0 or S1), and image 0 primary points to the app.
* With this configuration, image 0 and image 1 share the secondary slot.
* Hence, the primary slot of image 1 will be *smaller* than image 1's
* secondary slot. This is not allowed in upstream mcuboot, so we need
* this patch to allow it. Also, all of these checks are redundant when
* partition manager is in use, and since we have the same sector size
* in all of our flash.
*/
return 1;
#else
size_t num_sectors_primary;
size_t num_sectors_secondary;
size_t sz0, sz1;
Expand Down Expand Up @@ -260,6 +272,7 @@ boot_slots_compatible(struct boot_loader_state *state)
}

return 1;
#endif /* PM_S1_ADDRESS */
}

#define BOOT_LOG_SWAP_STATE(area, state) \
Expand Down
Loading