From a9a67ae0d784cf6b0fc187926d98288874e0071f Mon Sep 17 00:00:00 2001 From: foopub <45460217+foopub@users.noreply.github.com> Date: Tue, 28 Jun 2022 23:40:02 +0000 Subject: [PATCH 1/2] Provide openocd_cmd and add some documentation (#492) * Provide openocd_cmd * Add openocd instructions for dongle --- deploy.py | 10 +++++++- docs/boards/nrf52840_dongle.md | 42 ++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/deploy.py b/deploy.py index dfb8b87..10022f0 100755 --- a/deploy.py +++ b/deploy.py @@ -270,7 +270,7 @@ class OpenSKInstaller: jlink_speed=1200, openocd=self.args.programmer == "openocd", openocd_board=board.openocd_board, - openocd_cmd="openocd", + openocd_cmd=self.args.openocd_cmd, openocd_commands=copy.copy(board.openocd_commands), openocd_options=copy.copy(board.openocd_options), jtag=False, @@ -1005,6 +1005,14 @@ if __name__ == "__main__": help=("Sets the method to be used to flash Tock OS or the application " "on the target board."), ) + main_parser.add_argument( + "--openocd_cmd", + dest="openocd_cmd", + metavar="CMD", + default="openocd", + help=("Specifies a custom command to use when calling openocd. Can be " + "used to pass arguments i.e. 'openocd -s /tmp/openocd_scripts'."), + ) main_parser.add_argument( "--no-tockos", diff --git a/docs/boards/nrf52840_dongle.md b/docs/boards/nrf52840_dongle.md index 38b9796..737e081 100644 --- a/docs/boards/nrf52840_dongle.md +++ b/docs/boards/nrf52840_dongle.md @@ -59,14 +59,48 @@ Follow these steps: ![Nordic dongle retainer clip](../img/dongle_clip.jpg) -1. Depending on the programmer you're using, you may have to adapt the next - command line. Run our script for compiling/flashing Tock OS on your device: +#### JLink +Run our script for compiling/flashing Tock OS on your device: + +```shell +$ ./deploy.py --board=nrf52840_dongle --programmer=jlink +``` + +#### OpenOCD + +1. Create your openocd config, named `nordic_nrf52840_dongle.cfg` in the + appropriate location: ```shell - $ ./deploy.py --board=nrf52840_dongle_opensk --programmer=jlink + mkdir -p ${HOME}/.openocd/board + touch ${HOME}/.openocd/board/nordic_nrf52840_dongle.cfg + ``` + + Paste the following st-link example and edit the specific setup to your needs: + ``` + # Specific setup + source [find interface/stlink-dap.cfg] + transport select dapdirect_swd + + # The rest should be kept the same + set CHIPNAME nrf52840 + source [find target/nrf52.cfg] ``` -1. Remove the programming cable and the USB-A extension cable. +1. Test your config: + + ```shell + openocd -f board/nordic_nrf52840_dongle.cfg + ``` + +1. Run the deploy script with the appropriate options, i.e.: + + ```shell + ./deploy.py --board=nrf52840_dongle --opensk --programmer=openocd + ``` + + +Finally, remove the programming cable and the USB-A extension cable. ### Buttons and LEDs From 8549e2e436fe2b516969032ea210f1673e486dbd Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Thu, 30 Jun 2022 16:56:05 +0200 Subject: [PATCH 2/2] Configure the flash as read-only at boot --- patches/tock/01-persistent-storage.patch | 5 +++-- patches/tock/09-add-vendor-hid-usb-interface.patch | 2 +- patches/tock/10-avoid-app-reentry.patch | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/patches/tock/01-persistent-storage.patch b/patches/tock/01-persistent-storage.patch index aed7581..105ee46 100644 --- a/patches/tock/01-persistent-storage.patch +++ b/patches/tock/01-persistent-storage.patch @@ -1,5 +1,5 @@ diff --git a/chips/nrf52/src/nvmc.rs b/chips/nrf52/src/nvmc.rs -index adbc2a2b5..7594ec867 100644 +index adbc2a2b5..4092cf346 100644 --- a/chips/nrf52/src/nvmc.rs +++ b/chips/nrf52/src/nvmc.rs @@ -3,15 +3,19 @@ @@ -68,7 +68,7 @@ index adbc2a2b5..7594ec867 100644 let word: u32 = (data[i + 0] as u32) << 0 | (data[i + 1] as u32) << 8 | (data[i + 2] as u32) << 16 -@@ -387,3 +399,236 @@ impl hil::flash::Flash for Nvmc { +@@ -387,3 +399,237 @@ impl hil::flash::Flash for Nvmc { self.erase_page(page_number) } } @@ -139,6 +139,7 @@ index adbc2a2b5..7594ec867 100644 + apps: Grant, + deferred_caller: &'static DynamicDeferredCall, + ) -> SyscallDriver { ++ nvmc.configure_readonly(); + SyscallDriver { + nvmc, + apps, diff --git a/patches/tock/09-add-vendor-hid-usb-interface.patch b/patches/tock/09-add-vendor-hid-usb-interface.patch index 40c1d38..bee6552 100644 --- a/patches/tock/09-add-vendor-hid-usb-interface.patch +++ b/patches/tock/09-add-vendor-hid-usb-interface.patch @@ -156,7 +156,7 @@ index f7899d8c5..6956523c6 100644 hil::usb::CtrlSetupResult::ErrGeneric } diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs -index 642039120..41d69752c 100644 +index 642039120..adb7fde14 100644 --- a/capsules/src/usb/usbc_ctap_hid.rs +++ b/capsules/src/usb/usbc_ctap_hid.rs @@ -44,21 +44,59 @@ static CTAP_REPORT_DESCRIPTOR: &'static [u8] = &[ diff --git a/patches/tock/10-avoid-app-reentry.patch b/patches/tock/10-avoid-app-reentry.patch index cfc9939..c8b5136 100644 --- a/patches/tock/10-avoid-app-reentry.patch +++ b/patches/tock/10-avoid-app-reentry.patch @@ -1,6 +1,6 @@ diff --git a/capsules/src/usb/app.rs b/capsules/src/usb/app.rs new file mode 100644 -index 000000000..28dff3575 +index 000000000..c2f434f12 --- /dev/null +++ b/capsules/src/usb/app.rs @@ -0,0 +1,65 @@ @@ -79,7 +79,7 @@ index 3f3a4f646..cb5e0af97 100644 pub mod descriptors; pub mod usb_ctap; diff --git a/capsules/src/usb/usb_ctap.rs b/capsules/src/usb/usb_ctap.rs -index da3d16d85..3a709aab5 100644 +index da3d16d85..e8f1a87a4 100644 --- a/capsules/src/usb/usb_ctap.rs +++ b/capsules/src/usb/usb_ctap.rs @@ -1,7 +1,7 @@ @@ -262,7 +262,7 @@ index da3d16d85..3a709aab5 100644 if !app.waiting { // The call to receive_packet() collected a pending packet. diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs -index 41d69752c..cf17d7942 100644 +index adb7fde14..f6762b4b9 100644 --- a/capsules/src/usb/usbc_ctap_hid.rs +++ b/capsules/src/usb/usbc_ctap_hid.rs @@ -11,6 +11,7 @@ use super::descriptors::HIDSubordinateDescriptor;