0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picotoolをインストールする

Posted at

はじめに

Ubuntu環境ででRP2040の開発が必要になったので備忘録。picotoolをaptやpipでインストール可能だと思っていたが、調べてみるとどうやら違ったので、セルフビルドすることになった...残念!!

dedianのpicotoolあるはずなんだけど、なんでできなかったんだろう...

とりあえずソースからビルドとインストールができたので、以下に成功した手順をまとめる。

(gitが入っていない人はsudo apt install gitしてgitを入れておいてください)

私の環境について

OS: Ubuntu 24.04.3 LTS (Noble Numbat) x86_64
Host: 21G2CTO1WW (ThinkPad P14s Gen 5)
Kernel: Linux 6.14.0-33-generic
CPU: Intel(R) Core(TM) Ultra 9 185H (22) @ 5.10 GHz

今回登場するGitHubリポジトリは以下の2つ。

Step1 依存関係をインストール

ビルドに必要なライブラリやツールをインストールする。これには、C/C++コンパイラ、CMake(ビルドシステム)、Git(ソースコード取得用)、およびlibusb(USB通信用)が含まれる。

sudo apt update
sudo apt install cmake build-essential libusb-1.0-0-dev git

Step2 picotoolのソースコードをダウンロード

gitでcloneする。

まずはpicotoolのclone

git clone https://github.com/raspberrypi/picotool.git

次にpicotool-sdkのclone

git clone https://github.com/raspberrypi/pico-sdk.git

picotool-sdkをcloneしたら、gitのsubmodule機能を使って更にソースコードをダウンロードする。
picotool-sdkのディレクトリに移動

cd pico-sdk
git submodule update --init
cd ..

Step3 picotoolのビルド

ダウンロードしたディレクトリに移動し、cmake を使ってビルド(コンパイル)を実行.

# picotoolディレクトリに移動
cd picotool

# ビルド用の一時ディレクトリを作成
mkdir build
cd build

# ビルド構成を生成
cmake .. -DPICO_SDK_PATH=../../pico-sdk

# ビルドを実行
make

ビルドが成功するとこのような表示になるはず

[ 86%] Linking C static library libmbedtls.a
[ 86%] Built target mbedtls
[ 86%] Building CXX object bintool/CMakeFiles/bintool.dir/bintool.cpp.o
[ 87%] Building C object bintool/CMakeFiles/bintool.dir/mbedtls_wrapper.c.o
[ 88%] Linking CXX static library libbintool.a
[ 88%] Built target bintool
[ 89%] Generating /home/tomixrm/Downloads/picotool/build/rp2350_otp_contents.json
[ 89%] Configuring rp2350.json.h
[ 89%] Built target generate_otp_header
[ 90%] Configuring enc_bootloader_elf.h
[ 90%] Configuring enc_bootloader_mbedtls_elf.h
[ 90%] Built target embedded_data_no_libusb
[ 91%] Configuring xip_ram_perms_elf.h
[ 92%] Configuring flash_id_bin.h
[ 92%] Built target embedded_data
[ 93%] Building CXX object elf2uf2/CMakeFiles/elf2uf2.dir/elf2uf2.cpp.o
[ 93%] Linking CXX static library libelf2uf2.a
[ 93%] Built target elf2uf2
[ 93%] Building CXX object CMakeFiles/picotool.dir/data_locs.cpp.o
[ 94%] Building CXX object CMakeFiles/picotool.dir/get_enc_bootloader.cpp.o
[ 95%] Building CXX object CMakeFiles/picotool.dir/otp.cpp.o
[ 96%] Building CXX object CMakeFiles/picotool.dir/main.cpp.o
[ 96%] Building CXX object CMakeFiles/picotool.dir/get_xip_ram_perms.cpp.o
[ 97%] Building C object CMakeFiles/picotool.dir/lib/whereami/whereami.c.o
[ 98%] Building CXX object CMakeFiles/picotool.dir/lib/whereami/whereami++.cpp.o
[ 98%] Building CXX object CMakeFiles/picotool.dir/picoboot_connection/picoboot_connection_cxx.cpp.o
[ 99%] Building C object CMakeFiles/picotool.dir/picoboot_connection/picoboot_connection.c.o
[100%] Linking CXX executable picotool
[100%] Built target picotool

Step4 インストール

  1. ビルドしたディレクトリにpicotoolがあるか確認する。
ls

以下のように表示されるはず。picotoolのバイナリがいれば成功

ls
bintool                enc_bootloader                picoboot_connection
boot_bootrom_headers   enc_bootloader_elf.h          picoboot_flash_id
boot_picobin_headers   enc_bootloader_mbedtls        pico_platform
boot_picoboot_headers  enc_bootloader_mbedtls_elf.h  picotool
boot_uf2_headers       errors                        picotoolConfig.cmake
CMakeCache.txt         flash_id_bin.h                picotoolConfigVersion.cmake
CMakeFiles             lib                           pico_usb_reset_interface_headers
cmake_install.cmake    Makefile                      rp2350.json.h
data_locs.cpp          model                         rp2350_otp_contents.json
elf                    otp_header_parser             xip_ram_perms
elf2uf2                pico_binary_info              xip_ram_perms_elf.h

  1. ビルドが完了したら、実行ファイルを/usr/local/bin/にコピーする。
sudo cp picotool /usr/local/bin/

新しいターミナルを作成し、picotool infoと入力し、以下のような表示が出ればpicotoolのインストールは成功です。

❯ picotool info
No accessible RP-series devices in BOOTSEL mode were found.

but:

RP2040 device at bus 3, address 35 appears to be in BOOTSEL mode, but picotool was unable to connect. Maybe
    try 'sudo' or check your permissions.

しかし、ここで私の環境ではpermissionエラーが出てしまったので、このエラーを解決していく。

Step5 permission errorを解決

先程cloneした`picotoolにはpermission errorを解決するための設定ファイルがすでに含まれている。この設定ファイルでudevルールを更新する。

  1. picotool/udevに移動すると60-picotool.rulesが見つかるはず。とりあえずなんとか.rulesなはず。これを/etc/udev/rules/dにコピーする
sudo cp 60-picotool.rules /etc/udev/rules.d/
  1. ルールの適応(リロード)

次に、OSのudevサービスに対して「新しいルールが追加されたから、今すぐ読み込み直して!」と指示を出す。

# ルールファイルをディスクから再読み込みさせます
sudo udevadm control --reload-rules

# 現在接続されているデバイスに新しいルールを強制的に適用(トリガー)させます
sudo udevadm trigger

これでsudoしなくてもpicotool infoができるようになる。

お疲れ様でした!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?