Skip to content

Commit 82010fc

Browse files
authored
Merge pull request #947 from robjwells/picotool
Remove elf2uf2-rs in favour of picotool
2 parents 01cdf55 + 75da203 commit 82010fc

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ rustup update stable
6767
rustup target add thumbv6m-none-eabi
6868
```
6969

70-
You may also want to install these helpful tools:
70+
You may also want to install probe-rs, to flash your device over the SWD pins
71+
with a debug probe:
7172

7273
```sh
73-
# Useful to creating UF2 images for the RP2040 USB Bootloader
74-
cargo install elf2uf2-rs --locked
75-
# Useful for flashing over the SWD pins using a supported JTAG probe
7674
cargo install --locked probe-rs-tools
7775
```
7876

77+
And also [picotool], if you are not using a debug probe or wish to create UF2
78+
images for the USB bootloader. You can download a [pre-built picotool
79+
binary][picotool-releases] for your system.
80+
81+
[picotool]: https://github.com/raspberrypi/picotool
82+
[picotool-releases]: https://github.com/raspberrypi/pico-sdk-tools/releases
83+
7984
## Packages
8085

8186
There is a _Hardware Abstraction Layer_ (or HAL) crate for the RP2040 chip,
@@ -125,11 +130,8 @@ a [separate repository][BSPs].
125130
Rust generates standard Arm ELF files, which you can load onto your Raspberry Pi
126131
Silicon device with your favourite Arm flashing/debugging tool. In addition, the
127132
RP2040 contains a ROM bootloader which appears as a Mass Storage Device over USB
128-
that accepts UF2 format images. You can use the `elf2uf2-rs` package to convert
129-
the Arm ELF file to a UF2 format image.
130-
131-
For boards with USB Device support like the Raspberry Pi Pico, we recommend you
132-
use the UF2 process.
133+
that accepts UF2 format images. You can use picotool to flash your device over
134+
USB, or convert the Arm ELF file to a UF2 format image.
133135

134136
The RP2040 contains two Cortex-M0+ processors, which execute Thumb-2 encoded
135137
ARMv6-M instructions. There are no operating-specific features in the binaries
@@ -156,20 +158,16 @@ More detailed information on how the linker flags work can be found in
156158
In most cases, it should be sufficient to use the example files from the
157159
[Project Template].
158160

159-
### Loading a UF2 over USB
160-
161-
*Step 1* - Install [`elf2uf2-rs`](https://github.com/JoNil/elf2uf2-rs):
161+
### Loading over USB with picotool
162162

163-
```console
164-
$ cargo install elf2uf2-rs --locked
165-
```
163+
*Step 1* - Install a [picotool binary][picotool-releases] for your system.
166164

167165
*Step 2* - Make sure your .cargo/config contains the following (it should by
168166
default if you are working in this repository):
169167

170168
```toml
171169
[target.thumbv6m-none-eabi]
172-
runner = "elf2uf2-rs -d"
170+
runner = "picotool load --update --verify --execute -t elf"
173171
```
174172

175173
The `thumbv6m-none-eabi` target may be replaced by the all-Arm wildcard
@@ -180,8 +178,8 @@ whilst holding some kind of "Boot Select" button. On Linux, you will also need
180178
to 'mount' the device, like you would a USB Thumb Drive.
181179

182180
*Step 4* - Use `cargo run`, which will compile the code and started the
183-
specified 'runner'. As the 'runner' is the elf2uf2-rs tool, it will build a UF2
184-
file and copy it to your RP2040.
181+
specified 'runner'. As the 'runner' is picotool, it will flash your compiled
182+
binary over USB.
185183

186184
```console
187185
$ cargo run --release --features "critical-section-impl,rt,defmt" --example pwm_blink
@@ -190,6 +188,22 @@ $ cargo run --release --features "critical-section-impl,rt,defmt" --example pwm_
190188
(The `pwm_blink` example doesn't need all these feature flags. They are listed here
191189
so you can use the same command for all examples.)
192190

191+
If you want to create a UF2 file, which is loaded by copying it over to the
192+
RPI-RP2 mass storage device, use the `picotool uf2 convert` command on your
193+
compiled program with the `-t elf` argument.
194+
195+
```console
196+
$ picotool uf2 convert -t elf target/thumbv6m-none-eabi/release/pwm_blink
197+
pwm_blink.uf2
198+
```
199+
200+
Picotool can also read "Binary Info" from a device with `picotool info`. To
201+
enable this in your firmware, see the [rp-binary-info] crate and the
202+
corresponding [binary info example].
203+
204+
[rp-binary-info]: https://github.com/rp-rs/rp-hal/tree/main/rp-binary-info
205+
[binary info example]: https://github.com/rp-rs/rp-hal/blob/main/rp2040-hal-examples/src/bin/binary_info_demo.rs
206+
193207
### Loading with probe-rs
194208
[probe-rs](https://github.com/probe-rs/probe-rs) is a library and a
195209
command-line tool which can flash a wide variety of microcontrollers
@@ -234,20 +248,6 @@ connected to the RP2040.
234248
$ cargo run --release --example pwm_blink
235249
```
236250

237-
### Loading with picotool
238-
239-
As ELF files produced by compiling Rust code are completely compatible with ELF
240-
files produced by compiling C or C++ code, you can also use the Raspberry Pi
241-
tool [picotool](https://github.com/raspberrypi/picotool). The only thing to be
242-
aware of is that picotool expects your ELF files to have a `.elf` extension, and
243-
by default Rust does not give the ELF files any extension. You can fix this by
244-
simply renaming the file.
245-
246-
Also of note is that the special
247-
[pico-sdk](https://github.com/raspberrypi/pico-sdk) macros which hide
248-
information in the ELF file in a way that `picotool info` can read it out, are
249-
not supported in Rust. An alternative is TBC.
250-
251251
[Project Template]: https://github.com/rp-rs/rp2040-project-template
252252

253253
<!-- ROADMAP -->

on-target-tests/.cargo/config.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ target = "thumbv6m-none-eabi"
1818
# * linker argument -Tlink.x tells the linker to use link.x as the linker
1919
# script. This is usually provided by the cortex-m-rt crate, and by default
2020
# the version in that crate will include a file called `memory.x` which
21-
# describes the particular memory layout for your specific chip.
21+
# describes the particular memory layout for your specific chip.
2222
# * no-vectorize-loops turns off the loop vectorizer (seeing as the M0+ doesn't
2323
# have SIMD)
2424
rustflags = [
@@ -28,9 +28,8 @@ rustflags = [
2828
"-C", "no-vectorize-loops",
2929
]
3030

31-
# This runner will make a UF2 file and then copy it to a mounted RP2040 in USB
32-
# Bootloader mode:
33-
runner = "elf2uf2-rs -d"
31+
# This runner will flash a mounted RP2040 in USB Bootloader mode:
32+
runner = "picotool load --update --verify --execute -t elf"
3433

3534
# This runner will find a supported SWD debug probe and flash your RP2040 over
3635
# SWD:

rp2040-hal-examples/.cargo/config.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ target = "thumbv6m-none-eabi"
1818
# * linker argument -Tlink.x tells the linker to use link.x as the linker
1919
# script. This is usually provided by the cortex-m-rt crate, and by default
2020
# the version in that crate will include a file called `memory.x` which
21-
# describes the particular memory layout for your specific chip.
21+
# describes the particular memory layout for your specific chip.
2222
# * no-vectorize-loops turns off the loop vectorizer (seeing as the M0+ doesn't
2323
# have SIMD)
2424
rustflags = [
@@ -28,9 +28,8 @@ rustflags = [
2828
"-C", "no-vectorize-loops",
2929
]
3030

31-
# This runner will make a UF2 file and then copy it to a mounted RP2040 in USB
32-
# Bootloader mode:
33-
runner = "elf2uf2-rs -d"
31+
# This runner will flash a mounted RP2040 in USB Bootloader mode:
32+
runner = "picotool load --update --verify --execute -t elf"
3433

3534
# This runner will find a supported SWD debug probe and flash your RP2040 over
3635
# SWD:

rp2040-hal-examples/README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,30 @@ $ cargo build
7878
$ cargo build --bin dormant_sleep
7979
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
8080
$ file ./target/thumbv6m-none-eabi/debug/dormant_sleep
81-
./target/thumbv6m-none-eabi/debug/dormant_sleep: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
81+
./target/thumbv6m-none-eabi/debug/dormant_sleep: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, with debug_info, not stripped
8282
```
8383

84-
You can also 'run' an example, which will invoke [`elf2uf2-rs`] to copy it to an
85-
RP2040's virtual USB Mass Storage Device (which it puts over the USB port when
86-
in its ROM bootloader). You should install that if you don't have it already:
84+
You can also 'run' an example, which will invoke [picotool] to flash the RP2040
85+
over USB. You should install that if you don't have it already; [pre-built
86+
binaries][picotool-releases] are available for Windows, Linux, and macOS.
8787

8888
```console
89-
$ cargo install elf2uf2-rs --locked
9089
$ cd rp2040-hal-examples
9190
$ cargo run --bin dormant_sleep
92-
Compiling rp2040-hal v0.10.0 (/home/user/rp-hal/rp2040-hal)
91+
Compiling rp2040-hal v0.11.0 (/home/user/rp-hal/rp2040-hal)
9392
Compiling rp2040-hal-examples v0.1.0 (/home/user/rp-hal/rp2040-hal-examples)
94-
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.62s
95-
Running `elf2uf2-rs -d target/thumbv6m-none-eabi/debug/dormant_sleep`
96-
Found pico uf2 disk /media/user/RP2040
97-
Transfering program to pico
98-
88.50 KB / 88.50 KB [=====================================] 100.00 % 430.77 KB/s
93+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.47s
94+
Running `picotool load --update --verify --execute -t elf target/thumbv6m-none-eabi/debug/dormant_sleep`
95+
Loading into Flash: [==============================] 100%
96+
Verifying Flash: [==============================] 100%
97+
OK
98+
99+
The device was rebooted to start the application.
99100
$
100101
```
101102

102-
[`elf2uf2-rs`]: https://github.com/JoNil/elf2uf2-rs
103+
[picotool]: https://github.com/raspberrypi/picotool
104+
[picotool-releases]: https://github.com/raspberrypi/pico-sdk-tools/releases
103105

104106
<!-- ROADMAP -->
105107
## Roadmap

0 commit comments

Comments
 (0)