Anda perlu menyetel PICO_SDK_PATH di lingkungan, atau meneruskannya ke cmake dengan -DPICO_SDK_PATH=/path/to/pico-sdk
. Untuk menggunakan fitur seperti penandatanganan atau hashing, Anda perlu memastikan submodul mbedtls di SDK sudah dicentang - ini dapat dilakukan dengan menjalankannya dari direktori SDK Anda.
git submodule update --init lib/mbedtls
Anda juga perlu menginstal libusb-1.0
.
Gunakan alat paket favorit Anda untuk menginstal dependensi. Misalnya, di Ubuntu:
sudo apt install build-essential pkg-config libusb-1.0-0-dev cmake
Kemudian cukup buat seperti proyek CMake biasa:
mkdir build
cd build
cmake ..
make
Di Linux Anda dapat menambahkan aturan udev untuk menjalankan picotool tanpa sudo:
sudo cp udev/99-picotool.rules /etc/udev/rules.d/
Unduh libUSB dari sini https://libusb.info/
atur variabel lingkungan LIBUSB_ROOT ke direktori instalasi.
mkdir build
cd build
cmake -G "NMake Makefiles" ..
nmake
Unduh libUSB dari sini https://libusb.info/
atur variabel lingkungan LIBUSB_ROOT ke direktori instalasi.
mkdir build
cd build
cmake ..
make
Tidak perlu mengunduh libusb secara terpisah atau mengatur LIBUSB_ROOT
.
pacman -S $MINGW_PACKAGE_PREFIX-{toolchain,cmake,libusb}
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX
cmake --build .
Raspberry Pi Pico SDK (pico-sdk) versi 2.0.0 ke atas menggunakan picotool
untuk melakukan konversi ELF-ke-UF2 yang sebelumnya ditangani oleh alat elf2uf2
di SDK. SDK juga menggunakan picotool
untuk melakukan hash dan menandatangani binari.
Meskipun SDK dapat mengunduh picotool sendiri per proyek, jika Anda memiliki beberapa proyek atau konfigurasi build, lebih baik menginstal satu salinan picotool
secara lokal. Hal ini dapat dilakukan paling sederhana dengan make install
atau cmake --install .
; SDK akan menggunakan versi terinstal ini secara default.
Alternatifnya, Anda dapat menginstal ke jalur khusus melalui:
cmake -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR -DPICOTOOL_FLAT_INSTALL=1 ..
Agar SDK dapat menemukan picotool
di jalur khusus ini, Anda perlu menyetel variabel picotool_DIR
di proyek Anda, baik dengan menyetel variabel lingkungan picotool_DIR
, dengan meneruskan -Dpicotool_DIR=$MY_INSTALL_DIR/picotool
ke perintah cmake
Anda, atau dengan menambahkan set(picotool_DIR $MY_INSTALL_DIR/picotool)
ke file CMakeLists.txt Anda.
picotool
adalah alat untuk bekerja dengan biner RP2040/RP2350, dan berinteraksi dengan perangkat RP2040/RP2350 saat berada dalam mode BOOTSEL. (Pada picotool
versi 1.1, dimungkinkan juga untuk berinteraksi dengan perangkat yang tidak berada dalam mode BOOTSEL, tetapi menggunakan dukungan USB stdio dari Raspberry Pi Pico SDK dengan menggunakan argumen -f
dari picotool
).
Catatan untuk dokumentasi tambahan lihat https://rptl.io/pico-get-started
$ picotool help
PICOTOOL:
Tool for interacting with RP2040/RP2350 device(s) in BOOTSEL mode, or with an RP2040/RP2350 binary
SYNOPSIS:
picotool info [-b] [-p] [-d] [--debug] [-l] [-a] [device-selection]
picotool info [-b] [-p] [-d] [--debug] [-l] [-a] [-t ]
picotool config [-s ] [-g ] [device-selection]
picotool config [-s ] [-g ] [-t ]
picotool load [-p] [-n] [-N] [-u] [-v] [-x] [-t ] [-o ] [device-selection]
picotool encrypt [--quiet] [--verbose] [--hash] [--sign] [-t ] [-o ] [-t ] [-t ] [] [-t ]
picotool seal [--quiet] [--verbose] [--hash] [--sign] [--clear] [-t ] [-o ] [-t ] [] [-t ] [] [-t ] [--major ] [--minor ] [--rollback [..]]
picotool link [--quiet] [--verbose] [-t ] [-t ] [-t ] [] [-t ] [-p]
picotool save [-p] [device-selection]
picotool save -a [device-selection]
picotool save -r [device-selection]
picotool verify [device-selection]
picotool reboot [-a] [-u] [-g ] [-c ] [device-selection]
picotool otp list|get|set|load|dump|permissions|white-label
picotool partition info|create
picotool uf2 info|convert
picotool version [-s] []
picotool coprodis [--quiet] [--verbose] [-t ] [-t ]
picotool help []
COMMANDS:
info Display information from the target device(s) or file.
Without any arguments, this will display basic information for all connected RP2040 devices in BOOTSEL mode
config Display or change program configuration settings from the target device(s) or file.
load Load the program / memory range stored in a file onto the device.
encrypt Encrypt the program.
seal Add final metadata to a binary, optionally including a hash and/or signature.
link Link multiple binaries into one block loop.
save Save the program / memory stored in flash on the device to a file.
verify Check that the device contents match those in the file.
reboot Reboot the device
otp Commands related to the RP2350 OTP (One-Time-Programmable) Memory
partition Commands related to RP2350 Partition Tables
uf2 Commands related to UF2 creation and status
version Display picotool version
coprodis Post-process coprocessor instructions in dissassembly files.
help Show general help or help for a specific command
Use "picotool help " for more info
Catatan perintah yang tidak berfungsi pada file memerlukan perangkat dalam mode BOOTSEL untuk terhubung.
Ini adalah dukungan Informasi Biner di SDK yang memungkinkan penyimpanan informasi ringkas yang dapat ditemukan picotool
dengan mudah (Lihat bagian Info Biner di bawah). Perintah info untuk membaca informasi ini.
Informasi dapat dibaca dari satu atau lebih perangkat yang terhubung dalam mode BOOTSEL, atau dari file. File ini dapat berupa file ELF, UF2 atau BIN.
$ picotool help info
INFO:
Display information from the target device(s) or file.
Without any arguments, this will display basic information for all connected RP2040 devices in BOOTSEL mode
SYNOPSIS:
picotool info [-b] [-p] [-d] [--debug] [-l] [-a] [device-selection]
picotool info [-b] [-p] [-d] [--debug] [-l] [-a] [-t ]
OPTIONS:
Information to display
-b, --basic
Include basic information. This is the default
-p, --pins
Include pin information
-d, --device
Include device information
--debug
Include device debug information
-l, --build
Include build attributes
-a, --all
Include all information
TARGET SELECTION:
To target one or more connected RP2040 device(s) in BOOTSEL mode (the default)
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
To target a file
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
Perhatikan argumen -f sedikit berbeda untuk platform Windows vs macOS/Unix.
misalnya
$ picotool info Nama Informasi Program: hello_world fitur: stdout ke UART
$ picotool info -a
Program Information
name: hello_world
features: stdout to UART
binary start: 0x10000000
binary end: 0x1000606c
Fixed Pin Information
20: UART1 TX
21: UART1 RX
Build Information
build date: Dec 31 2020
build attributes: Debug build
Device Information
flash size: 2048K
ROM version: 2
$ picotool info -bp Nama Informasi Program: hello_world fitur: stdout ke UART
Informasi Pin Tetap 20: UART1 TX 21: UART1 RX
$ picotool info -a lcd_1602_i2c.uf2
File lcd_1602_i2c.uf2:
Program Information
name: lcd_1602_i2c
web site: https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/lcd_1602_i2c
binary start: 0x10000000
binary end: 0x10003c1c
Fixed Pin Information
4: I2C0 SDA
5: I2C0 SCL
Build Information
build date: Dec 31 2020
Config memungkinkan Anda mengonfigurasi info biner pada perangkat, jika dapat dikonfigurasi. Secara khusus, Anda dapat mengonfigurasi bi_ptr_int32
dan bi_ptr_string
.
$ picotool help config
CONFIG:
Display or change program configuration settings from the target device(s) or file.
SYNOPSIS:
picotool config [-s ] [-g ] [device-selection]
picotool config [-s ] [-g ] [-t ]
OPTIONS:
Variable name
New value
-g
Filter by feature group
TARGET SELECTION:
To target one or more connected RP2040 device(s) in BOOTSEL mode (the default)
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
To target a file
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
$ picotool config
n = 5
name = "Billy"
nonconst_pins:
default_pin = 3
default_name = "My First Pin"
$ picotool config -g nonconst_pins
nonconst_pins:
default_pin = 3
default_name = "My First Pin"
$ picotool config -s name Jane
name = "Billy"
setting name -> "Jane"
$ picotool config
n = 5
name = "Jane"
nonconst_pins:
default_pin = 3
default_name = "My First Pin"
load
memungkinkan Anda menulis data dari file ke perangkat (baik menulis ke flash, atau ke RAM)
$ picotool help load
LOAD:
Load the program / memory range stored in a file onto the device.
SYNOPSIS:
picotool load [--ignore-partitions] [--family ] [-p ] [-n] [-N] [-u] [-v] [-x] [-t ] [-o
] [device-selection]
OPTIONS:
Post load actions
--ignore-partitions
When writing flash data, ignore the partition table and write to absolute space
--family
Specify the family ID of the file to load
family id to use for load
-p, --partition
Specify the partition to load into
partition to load into
-n, --no-overwrite
When writing flash data, do not overwrite an existing program in flash. If picotool cannot determine the size/presence of the
program in flash, the command fails
-N, --no-overwrite-unsafe
When writing flash data, do not overwrite an existing program in flash. If picotool cannot determine the size/presence of the
program in flash, the load continues anyway
-u, --update
Skip writing flash sectors that already contain identical data
-v, --verify
Verify the data was written correctly
-x, --execute
Attempt to execute the downloaded file as a program after the load
File to load from
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
BIN file options
-o, --offset
Specify the load address for a BIN file
Load offset (memory address; default 0x10000000)
Target device selection
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
misalnya
$ picotool load blink.uf2
Loading into Flash: [==============================] 100%
save
memungkinkan Anda menyimpan rentang RAM, program dalam flash, atau rentang flash eksplisit dari perangkat ke file BIN atau file UF2.
$ picotool help save
SAVE:
Save the program / memory stored in flash on the device to a file.
SYNOPSIS:
picotool save [-p] [device-selection]
picotool save -a [device-selection]
picotool save -r [device-selection]
OPTIONS:
Selection of data to save
-p, --program
Save the installed program only. This is the default
-a, --all
Save all of flash memory
-r, --range
Save a range of memory. Note that UF2s always store complete 256 byte-aligned blocks of 256 bytes, and the range is expanded
accordingly
The lower address bound in hex
The upper address bound in hex
Source device selection
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
File to save to
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
misal lihat dulu apa yang ada di perangkat...
$ picotool info
Program Information
name: lcd_1602_i2c
web site: https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/lcd_1602_i2c
... menyimpannya ke file ...
$ picotool save spoon.uf2
Saving file: [==============================] 100%
Wrote 51200 bytes to spoon.uf2
... dan melihat file tersebut:
$ picotool info spoon.uf2
File spoon.uf2:
Program Information
name: lcd_1602_i2c
web site: https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/lcd_1602_i2c
seal
memungkinkan Anda menandatangani dan/atau meng-hash biner untuk dijalankan pada RP2350.
Secara default, ini hanya akan menandatangani biner, tetapi ini dapat dikonfigurasi dengan argumen --hash
dan --no-sign
.
Kunci penandatanganan Anda harus untuk kurva secp256k1 , dalam format PEM. Anda dapat membuat file .PEM dengan:
openssl ecparam -name secp256k1 -genkey -out private.pem
$ picotool help seal
SEAL:
Add final metadata to a binary, optionally including a hash and/or signature.
SYNOPSIS:
picotool seal [--quiet] [--verbose] [--hash] [--sign] [--clear] [-t ] [-o ] [-t ] [] [-t
] [] [-t ] [--major ] [--minor ] [--rollback [..]]
OPTIONS:
--quiet
Don't print any output
--verbose
Print verbose output
--major
Add Major Version
--minor
Add Minor Version
--rollback [..]
Add Rollback Version
Configuration
--hash
Hash the file
--sign
Sign the file
--clear
Clear all of SRAM on load
File to load from
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
BIN file options
-o, --offset
Specify the load address for a BIN file
Load offset (memory address; default 0x10000000)
File to save to
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
Key file
The file name
-t
Specify file type (pem) explicitly, ignoring file extension
File to save OTP to (will edit existing file if it exists)
The file name
-t
Specify file type (json) explicitly, ignoring file extension
encrypt
memungkinkan Anda mengenkripsi dan menandatangani biner untuk digunakan pada RP2350. Secara default, ini akan menandatangani biner terenkripsi, tetapi dapat dikonfigurasi mirip dengan picotool sign
.
Biner terenkripsi akan memiliki struktur berikut:
Kunci AES harus disediakan sebagai file .bin dari kunci AES 256 bit yang akan digunakan untuk enkripsi.
$ picotool help encrypt
ENCRYPT:
Encrypt the program.
SYNOPSIS:
picotool encrypt [--quiet] [--verbose] [--hash] [--sign] [-t ] [-o ] [-t ] [-t ]
[] [-t ]
OPTIONS:
--quiet
Don't print any output
--verbose
Print verbose output
Signing Configuration
--hash
Hash the encrypted file
--sign
Sign the encrypted file
File to load from
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
BIN file options
-o, --offset
Specify the load address for a BIN file
Load offset (memory address; default 0x10000000)
File to save to
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
AES Key
The file name
-t
Specify file type (bin) explicitly, ignoring file extension
Signing Key file
The file name
-t
Specify file type (pem) explicitly, ignoring file extension
Perintah partition
memungkinkan Anda berinteraksi dengan tabel partisi pada perangkat RP2350, dan juga membuatnya.
$ picotool help partition info
PARTITION INFO:
Print the device's partition table.
SYNOPSIS:
picotool partition info -m [device-selection]
OPTIONS:
-m [device-selection]
$ picotool partition info
un-partitioned_space : S(rw) NSBOOT(rw) NS(rw), uf2 { absolute }
partitions:
0(A) 00002000->00201000 S(rw) NSBOOT(rw) NS(rw), id=0000000000000000, "A", uf2 { rp2350-arm-s, rp2350-riscv }, arm_boot 1, riscv_boot 1
1(B w/ 0) 00201000->00400000 S(rw) NSBOOT(rw) NS(rw), id=0000000000000001, "B", uf2 { rp2350-arm-s, rp2350-riscv }, arm_boot 1, riscv_boot 1
$ picotool partition info -m rp2350-arm-s
un-partitioned_space : S(rw) NSBOOT(rw) NS(rw), uf2 { absolute }
partitions:
0(A) 00002000->00201000 S(rw) NSBOOT(rw) NS(rw), id=0000000000000000, "A", uf2 { rp2350-arm-s, rp2350-riscv }, arm_boot 1, riscv_boot 1
1(B w/ 0) 00201000->00400000 S(rw) NSBOOT(rw) NS(rw), id=0000000000000001, "B", uf2 { rp2350-arm-s, rp2350-riscv }, arm_boot 1, riscv_boot 1
Family id 'rp2350-arm-s' can be downloaded in partition 0:
00002000->00201000
Perintah ini memungkinkan Anda membuat tabel partisi, dan juga menyematkannya ke dalam loop blok jika file ELF (misalnya, untuk bootloader). Secara default, semua tabel partisi di-hash, dan Anda juga dapat menandatanganinya.
$ picotool help partition create
PARTITION CREATE:
Create a partition table from json
SYNOPSIS:
picotool partition create [--quiet] [--verbose] [-t ] [-t ] [[-o ] [--family ]]
[] [-t ] [[--sign ] [-t ] [--no-hash] [--singleton]] [[--abs-block] []]
OPTIONS:
--quiet
Don't print any output
--verbose
Print verbose output
partition table JSON
The file name
-t
Specify file type (json) explicitly, ignoring file extension
output file
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
UF2 output options
-o, --offset
Specify the load address for UF2 file output
Load offset (memory address; default 0x10000000)
--family
Specify the family if for UF2 file output
family id for UF2 (default absolute)
embed partition table into bootloader ELF
The file name
-t
Specify file type (elf) explicitly, ignoring file extension
Partition Table Options
--sign
The file name
-t
Specify file type (pem) explicitly, ignoring file extension
--no-hash
Don't hash the partition table
--singleton
Singleton partition table
Errata RP2350-E9 Fix
--abs-block
Enforce support for an absolute block
absolute block location (default to 0x10ffff00)
Perintah uf2
memungkinkan pembuatan UF2, dan cam memberikan informasi jika pengunduhan UF2 gagal.
Perintah ini menggantikan fungsionalitas elf2uf2 yang sebelumnya ada di Raspberry Pi Pico SDK. Ini akan mencoba mendeteksi ID keluarga secara otomatis, tetapi jika gagal, Anda dapat menentukannya secara manual dengan argumen --family
.
picotool help uf2 convert
UF2 CONVERT:
Convert ELF/BIN to UF2.
SYNOPSIS:
picotool uf2 convert [--quiet] [--verbose] [-t ] [-t ] [-o ] [--family ]
[[--abs-block] []]
OPTIONS:
--quiet
Don't print any output
--verbose
Print verbose output
File to load from
The file name
-t
Specify file type (uf2 | elf | bin) explicitly, ignoring file extension
File to save UF2 to
The file name
-t
Specify file type (uf2) explicitly, ignoring file extension
Packaging Options
-o, --offset
Specify the load address
Load offset (memory address; default 0x10000000 for BIN file)
UF2 Family options
family id for UF2
Errata RP2350-E9 Fix
--abs-block
Add an absolute block
absolute block location (default to 0x10ffff00)
Perintah ini membaca informasi pada perangkat tentang mengapa pengunduhan UF2 gagal. Ini hanya akan memberikan informasi jika unduhan terbaru gagal.
$ picotool help uf2 info
UF2 INFO:
Print info about UF2 download.
SYNOPSIS:
picotool uf2 info [device-selection]
OPTIONS:
Target device selection
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
Perintah otp
adalah untuk berinteraksi dengan Memori OTP RP2350. Mereka tidak tersedia di perangkat RP2040, karena RP2040 tidak memiliki OTP.
Perlu diperhatikan bahwa Memori OTP bersifat One-Time-Programmable, yang berarti bahwa sekali bit diubah dari 0 ke 1, bit tersebut tidak dapat diubah kembali. Oleh karena itu, berhati-hatilah saat menggunakan perintah ini, karena berisiko merusak perangkat RP2350 Anda. Misalnya, jika Anda menyetel SECURE_BOOT_ENABLE namun tidak menyetel kunci boot, dan menonaktifkan antarmuka PICOBOOT, perangkat Anda tidak akan dapat digunakan.
Untuk perintah list
, set
, get
dan load
, Anda dapat menentukan tata letak OTP Anda sendiri dalam file JSON dan meneruskannya dengan argumen -i
. Baris-baris ini akan ditambahkan ke baris default saat penguraian.
$ picotool help otp
OTP:
Commands related to the RP2350 OTP (One-Time-Programmable) Memory
SYNOPSIS:
picotool otp list [-p] [-n] [-i ] [..]
picotool otp get [-c ] [-r] [-e] [-n] [-i ] [device-selection] [-z] [..]
picotool otp set [-c ] [-r] [-e] [-i ] [-z] [device-selection]
picotool otp load [-r] [-e] [-s ] [-i ] [-t ] [device-selection]
picotool otp dump [-r] [-e] [device-selection]
picotool otp permissions [-t ] [--led ] [--hash] [--sign] [] [-t ] [device-selection]
picotool otp white-label -s [-t ] [device-selection]
SUB COMMANDS:
list List matching known registers/fields
get Get the value of one or more OTP registers/fields (RP2350 only)
set Set the value of an OTP row/field (RP2350 only)
load Load the row range stored in a file into OTP and verify. Data is 2 bytes/row for ECC, 4 bytes/row for raw. (RP2350 only)
dump Dump entire OTP (RP2350 only)
permissions Set the OTP access permissions (RP2350 only)
white-label Set the white labelling values in OTP (RP2350 only)
Perintah-perintah ini akan mengatur/mendapatkan baris OTP tertentu. Secara default, mereka akan menulis/membaca semua baris yang berlebihan, tetapi ini dapat ditimpa dengan argumen -c
Perintah ini memungkinkan pemuatan berbagai baris OTP ke perangkat. Sumbernya bisa berupa file biner, atau file JSON seperti yang dihasilkan oleh picotool sign
. Misalnya, jika Anda ingin menandatangani biner dan kemudian menguji boot aman dengannya, Anda dapat menjalankan serangkaian perintah berikut:
$ picotool sign hello_world.elf hello_world.signed.elf private.pem otp.json
$ picotool load hello_world.signed.elf
$ picotool otp load otp.json
$ picotool reboot
Perintah ini memungkinkan pelabelan putih OTP, yang mengatur konfigurasi USB yang digunakan oleh perangkat dalam mode BOOTSEL. Ini dapat dikonfigurasi dari file JSON, contohnya ada di sample-wl.json.
$ picotool help otp white-label
OTP WHITE-LABEL:
Set the white labelling values in OTP
SYNOPSIS:
picotool otp white-label -s [-t ] [device-selection]
OPTIONS:
File with white labelling values
The file name
-t
Specify file type (json) explicitly, ignoring file extension
Target device selection
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
$ picotool otp white-label -s 0x100 ../sample-wl.json
Setting attributes 20e0
0x2e8b, 0x000e, 0x0215, 0x0c09, 0x1090, 0x200c, 0x2615, 0x20e0, 0x310b, 0x3706, 0x3a04, 0x3c04, 0x3e21, 0x4f15, 0x5a0a, 0x5f0a, 0x007a, 0x00df, 0x6c34, 0xd83c, 0xdf4c, 0x0020, 0x0054, 0x0065, 0x0073, 0x0074, 0x0027, 0x0073,
0x0020, 0x0050, 0x0069, 0x0073, 0x6554, 0x7473, 0x5220, 0x3250, 0x3533, 0x3f30, 0x6f6e, 0x6e74, 0x6365, 0x7365, 0x6173, 0x6972, 0x796c, 0x6e61, 0x6d75, 0x6562, 0x0072, 0x6554, 0x7473, 0x6950, 0x4220, 0x6f6f, 0x0074, 0x6554,
0x7473, 0x6950, 0x794d, 0x6950, 0x3876, 0x3739, 0x7468, 0x7074, 0x3a73, 0x2f2f, 0x7777, 0x2e77, 0x6172, 0x7073, 0x6562, 0x7272, 0x7079, 0x2e69, 0x6f63, 0x2f6d, 0x656e, 0x7377, 0x002f, 0x6f53, 0x656d, 0x4e20, 0x7765, 0x2073,
0x6241, 0x756f, 0x2074, 0x7453, 0x6675, 0x0066, 0x794d, 0x5420, 0x7365, 0x2074, 0x6950, 0x5054, 0x2d49, 0x5052, 0x3332, 0x3035,
$ picotool reboot -u
$ lsusb -v -s 1:102
Bus 001 Device 102: ID 2e8b:000e zß水? Test's Pis Test RP2350?
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.10
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x2e8b
idProduct 0x000e
bcdDevice 2.15
iManufacturer 1 zß水? Test's Pis
iProduct 2 Test RP2350?
iSerial 3 notnecessarilyanumber
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0037
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 64mA
...
Perintah ini akan menjalankan biner pada perangkat Anda untuk mengatur izin OTP, karena ini tidak dapat diakses langsung dari picotool
karena pengaturan izin default diperlukan untuk memperbaiki errata XXX pada RP2350. Karena menjalankan biner, biner harus menandatanganinya jika boot aman diaktifkan. Biner akan mencetak apa yang dilakukannya melalui uart, yang dapat dikonfigurasi menggunakan argumen Konfigurasi UART. Anda dapat menentukan izin OTP Anda dalam file json, contohnya ada di sample-permissions.json.
$ picotool help otp permissions
OTP PERMISSIONS:
Set the OTP access permissions
SYNOPSIS:
picotool otp permissions [-t ] [--led ] [--hash] [--sign] [] [-t ] [device-selection]
OPTIONS:
File to load permissions from
The file name
-t
Specify file type (json) explicitly, ignoring file extension
--led
LED Pin to flash; default 25
Signing Configuration
--hash
Hash the executable
--sign
Sign the executable
Key file
The file name
-t
Specify file type (pem) explicitly, ignoring file extension
Target device selection
--bus
Filter devices by USB bus number
--address
Filter devices by USB device address
--vid
Filter by vendor id
--pid
Filter by product id
--ser
Filter by serial number
-f, --force
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
-F, --force-no-reboot
Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the
command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the
RPI-RP2 drive mounted
$ picotool otp permissions --sign private.pem --tx 46 ../sample-permissions.json
Picking file ./xip_ram_perms.elf
page10
page10 = 0
setting page10 -> 4063233
page11
page11 = 0
setting page11 -> 4128781
page12
page12 = 0
setting page12 -> 4128781
tx_pin = 0
setting tx_pin -> 46
Loading into XIP RAM: [==============================] 100%
>>> using flash update boot of 13ffc000
The device was rebooted to start the application.
Informasi biner dapat ditemukan oleh mesin dan umumnya dapat dikonsumsi oleh mesin. Saya katakan secara umum karena siapa pun dapat memasukkan informasi apa pun, dan kami dapat membedakannya dari informasi kami, namun terserah kepada mereka apakah mereka membuat datanya menggambarkan dirinya sendiri.
Perhatikan bahwa kami pasti akan menambahkan lebih banyak info biner seiring berjalannya waktu, tetapi saya ingin set inti minimum disertakan di sebagian besar biner sejak peluncuran!!
Informasi ini sangat berguna ketika Anda mengambil Pico dan tidak tahu apa isinya!
Informasi dasar meliputi
Informasi biner dapat mendeskripsikan dirinya sendiri/dapat diperluas, sehingga program dapat menyertakan informasi yang tidak diketahui oleh picotool (misalnya MicroPython menyertakan daftar perpustakaan bawaan)
Hal ini tentunya berguna ketika Anda memiliki executable bernama 'hello_world.elf' tetapi Anda lupa untuk papan apa ia dibuat...
Penetapan pin statis (tetap) dapat direkam dalam biner dalam bentuk yang sangat ringkas:
$ picotool info --pins sprite_demo.elf
File sprite_demo.elf:
Fixed Pin Information
0-4: Red 0-4
6-10: Green 0-4
11-15: Blue 0-4
16: HSync
17: VSync
18: Display Enable
19: Pixel Clock
20: UART1 TX
21: UART1 RX
Ini sangat berguna jika Anda ingin mengubah parameter dalam biner, tanpa harus mengkompilasi ulang.
$ picotool config -s name Jane
name = "Billy"
setting name -> "Jane"
Informasi biner dideklarasikan dalam program oleh makro (makro yang menyesatkan); untuk contoh pin:
$ picotool info --pins sprite_demo.elf
File sprite_demo.elf:
Fixed Pin Information
0-4: Red 0-4
6-10: Green 0-4
11-15: Blue 0-4
16: HSync
17: VSync
18: Display Enable
19: Pixel Clock
20: UART1 TX
21: UART1 RX
... ada satu baris dalam fungsi setup_default_uart
:
bi_decl_if_func_used ( bi_2pins_with_func ( PICO_DEFAULT_UART_RX_PIN , PICO_DEFAULT_UART_TX_PIN , GPIO_FUNC_UART ));
Dua nomor pin, dan fungsi UART disimpan, kemudian diterjemahkan ke nama fungsi sebenarnya (UART1 TX dll) dengan picotool. bi_decl_if_func_used
memastikan informasi biner hanya disertakan jika fungsi yang memuatnya dipanggil.
Demikian pula, kode video berisi beberapa baris seperti ini:
bi_decl_if_func_used ( bi_pin_mask_with_name ( 0x1f << ( PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_RSHIFT ), "Red 0-4" ));
Untuk contoh konfigurasinya, Anda meletakkan baris
bi_decl ( bi_ptr_string ( 0x1111 , 0x3333 , name , "Billy" , 128 ));
ke dalam kode Anda, yang kemudian akan membuat variabel nama untuk Anda cetak selanjutnya. Parameternya adalah tag, ID, nama variabel, nilai default, dan panjang string maksimum.
printf ( "Name is %sn" , name );
Segala sesuatunya dirancang untuk membuang ruang sesedikit mungkin, tetapi Anda dapat mematikan semuanya dengan variabel praprosesor PICO_NO_BINARY_INFO=1
. Selain itu, kode SDK apa pun yang menyisipkan info biner dapat dikecualikan secara terpisah oleh variabel praprosesornya sendiri.
Anda membutuhkan
#include "pico/binary_info.h"
Pada dasarnya Anda menggunakan bi_decl(bi_blah(...))
untuk penyertaan info biner tanpa syarat bla, atau bi_decl_if_func_used(bi_blah(...))
untuk informasi biner yang dapat dihilangkan jika fungsi penutup tidak disertakan dalam biner dengan tautannya (pikirkan --gc-sections
)
Ada banyak makro bi_ di header
#define bi_binary_end ( end ) ...
#define bi_program_name ( name ) ...
#define bi_program_description ( description ) ...
#define bi_program_version_string ( version_string ) ...
#define bi_program_build_date_string ( date_string ) ...
#define bi_program_url ( url ) ...
#define bi_program_feature ( feature ) ...
#define bi_program_build_attribute ( attr ) ...
#define bi_1pin_with_func ( p0 , func ) ...
#define bi_2pins_with_func ( p0 , p1 , func ) ...
#define bi_3pins_with_func ( p0 , p1 , p2 , func ) ...
#define bi_4pins_with_func ( p0 , p1 , p2 , p3 , func ) ...
#define bi_5pins_with_func ( p0 , p1 , p2 , p3 , p4 , func ) ...
#define bi_pin_range_with_func ( plo , phi , func ) ...
#define bi_pin_mask_with_name ( pmask , label ) ...
#define bi_pin_mask_with_names ( pmask , label ) ...
#define bi_1pin_with_name ( p0 , name ) ...
#define bi_2pins_with_names ( p0 , name0 , p1 , name1 ) ...
#define bi_3pins_with_names ( p0 , name0 , p1 , name1 , p2 , name2 ) ...
#define bi_4pins_with_names ( p0 , name0 , p1 , name1 , p2 , name2 , p3 , name3 ) ...
yang menggunakan makro yang mendasarinya, misalnya
#define bi_program_url ( url ) bi_string(BINARY_INFO_TAG_RASPBERRY_PI, BINARY_INFO_ID_RP_PROGRAM_URL, url)
CATATAN: Sangat mudah untuk lupa menyertakan ini di bi_decl
dll., jadi upaya telah dilakukan (dengan mengorbankan banyak anak kucing) untuk membuat pembangunan gagal dengan pesan kesalahan yang berguna jika Anda melakukannya.
Misalnya, mencoba mengkompilasi
bi_1pin_with_name ( 0 , "Toaster activator" );
memberi
/home/graham/dev/mu/pico_sdk/src/common/pico_binary_info/include/pico/binary_info/code.h:17:55: error: '_error_bi_is_missing_enclosing_decl_261' undeclared here (not in a function)
17 | #define __bi_enclosure_check_lineno_var_name __CONCAT(_error_bi_is_missing_enclosing_decl_,__LINE__)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... more macro call stack of doom
Anda dapat menggunakan
pico_set_program_name(foo "not foo" ) # as "foo" would be the default
pico_set_program_description(foo "this is a foo" )
pico_set_program_version(foo "0.00001a" )
pico_set_program_url(foo "www.plinth.com/foo" )
Perhatikan bahwa semua ini diteruskan sebagai argumen baris perintah ke kompilasi, jadi jika Anda berencana menggunakan tanda kutip, baris baru, dll, Anda mungkin lebih beruntung mendefinisikannya melalui bi_decl dalam kode.
MicroPython dan CircuitPython, pada akhirnya SDK dan lainnya mungkin mendukung satu atau lebih perangkat penyimpanan di flash. Kami sudah memiliki makro untuk mendefinisikannya meskipun picotool belum melakukan apa pun dengannya... tetapi pencadangan/pemulihan/penyalinan file dan bahkan pemasangan sekering di masa mendatang mungkin menarik.
Saya sarankan kita menandai ini sekarang...
Inilah yang ada di benak saya saat ini (pada saat itu)
#define bi_block_device ( _tag , _name , _offset , _size , _extra , _flags )
dengan data yang masuk
typedef struct __packed _binary_info_block_device {
struct _binary_info_core core ;
bi_ptr_of ( const char ) name ; // optional static name (independent of what is formatted)
uint32_t offset ;
uint32_t size ;
bi_ptr_of ( binary_info_t ) extra ; // additional info
uint16_t flags ;
} binary_info_block_device_t ;
Dan
enum {
BINARY_INFO_BLOCK_DEV_FLAG_READ = 1 << 0 , // if not readable, then it is basically hidden, but tools may choose to avoid overwriting it
BINARY_INFO_BLOCK_DEV_FLAG_WRITE = 1 << 1 ,
BINARY_INFO_BLOCK_DEV_FLAG_REFORMAT = 1 << 2 , // may be reformatted..
BINARY_INFO_BLOCK_DEV_FLAG_PT_UNKNOWN = 0 << 4 , // unknown free to look
BINARY_INFO_BLOCK_DEV_FLAG_PT_MBR = 1 << 4 , // expect MBR
BINARY_INFO_BLOCK_DEV_FLAG_PT_GPT = 2 << 4 , // expect GPT
BINARY_INFO_BLOCK_DEV_FLAG_PT_NONE = 3 << 4 , // no partition table
};
Menjalankan perintah dengan -f/F
memerlukan kode yang kompatibel agar dapat dijalankan di perangkat. Definisi kode yang kompatibel untuk keperluan binari yang dikompilasi menggunakan pico-sdk adalah kode itu
-f/F
tidak akan berfungsi - sebagai gantinya Anda dapat mengatur definisi kompilasi PICO_ENTER_USB_BOOT_ON_EXIT
untuk reboot dan dapat diakses oleh picotool setelah kode Anda selesai dieksekusi, misalnya dengan target_compile_definitions( PRIVATE PICO_ENTER_USB_BOOT_ON_EXIT=1)
stdio_init_all()
dan Anda memiliki pico_enable_stdio_usb( 1)
di file CMakeLists.txt maka Anda memenuhi persyaratan ini (lihat contoh hello_usb) Jika Anda ctrl+c di tengah operasi yang panjang, maka libusb tampaknya menjadi sedikit membingungkan, yang berarti kami tidak dapat membuka kunci penguncian penulisan USB MSD (kami telah mematikannya sehingga pengguna tidak menginjak kaki mereka sendiri). Cukup menjalankan lagi picotool info
akan membuka kuncinya dengan benar di lain waktu (atau Anda dapat me-reboot perangkat).