rpremote 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +24 -0
- data/LICENSE +21 -0
- data/README.ja.md +122 -0
- data/README.md +124 -0
- data/RELEASING.md +54 -0
- data/THIRD_PARTY_NOTICES.md +29 -0
- data/exe/rpremote +7 -0
- data/lib/rpremote/build_command.rb +38 -0
- data/lib/rpremote/builder.rb +123 -0
- data/lib/rpremote/checksum.rb +27 -0
- data/lib/rpremote/cli.rb +267 -0
- data/lib/rpremote/config.rb +137 -0
- data/lib/rpremote/device.rb +56 -0
- data/lib/rpremote/dfu_command.rb +155 -0
- data/lib/rpremote/dfu_compiler.rb +50 -0
- data/lib/rpremote/flash_command.rb +45 -0
- data/lib/rpremote/flasher.rb +131 -0
- data/lib/rpremote/help.rb +60 -0
- data/lib/rpremote/language.rb +15 -0
- data/lib/rpremote/language_source.rb +126 -0
- data/lib/rpremote/mrbgems.rb +288 -0
- data/lib/rpremote/mrbgems_command.rb +48 -0
- data/lib/rpremote/picomodem.rb +293 -0
- data/lib/rpremote/remote_path.rb +27 -0
- data/lib/rpremote/resetter.rb +73 -0
- data/lib/rpremote/runner.rb +48 -0
- data/lib/rpremote/serial.rb +72 -0
- data/lib/rpremote/setup_command.rb +34 -0
- data/lib/rpremote/shell.rb +161 -0
- data/lib/rpremote/target.rb +46 -0
- data/lib/rpremote/terminal.rb +91 -0
- data/lib/rpremote/version.rb +5 -0
- data/lib/rpremote.rb +30 -0
- data/sig/rpremote.rbs +404 -0
- data/tasks/firmware_build.rb +108 -0
- data/tasks/release.rake +12 -0
- data/tasks/release_check.rb +83 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ccf42c1aa0428ee4996626537122a820d94aac064a8bd40e15defb4b31c76901
|
|
4
|
+
data.tar.gz: f7d7ac9163993a8c8075861bb750ebda0ba9031f9c4393be77be93428eae5d2d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 01e9ec8f0d4df3d3979903eea9c823bbd8224432c9b6ab246737f499ddb096e908fa2a613d92cddbffa7c53dd5163ceaf22e9c1e50c8f3d664ea5aeae3ae1ff3
|
|
7
|
+
data.tar.gz: ec02c4c3bb3b1bd28c51b56fb63895d48bac3afcc5c5211308be1f5112d161e175d5710aaa3ebdce24ff31104bc3569a2e49e5af7c3d712903b62444f7abdd12
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-08-24
|
|
8
|
+
|
|
9
|
+
- Add `setup`, `build`, and RP2350 BOOTSEL `flash` commands for custom
|
|
10
|
+
PicoRuby R2P2 firmware on Raspberry Pi Pico 2 and Pico 2 W.
|
|
11
|
+
- Add target configuration for language, language version, board, cache,
|
|
12
|
+
firmware path, serial port, and timeouts, with command-line precedence.
|
|
13
|
+
- Add `Mrbgems` and `Mrbgems.lock` support for reproducible public and local
|
|
14
|
+
mrbgems, including automatic regeneration of PicoRuby build output when a
|
|
15
|
+
custom mrbgem changes.
|
|
16
|
+
- Add PicoModem DFU staging, status, compatible bytecode compilation, and
|
|
17
|
+
A/B-slot rollback support for Ruby and `.mrb` applications.
|
|
18
|
+
- Add binary-safe file transfer and remote filesystem commands, plus `run`,
|
|
19
|
+
`exec`, `monitor`, `repl`, and reset with reconnect waiting.
|
|
20
|
+
- Add macOS R2P2 serial-port detection for Raspberry Pi Pico 2 and Pico 2 W.
|
|
21
|
+
- Add bilingual repository, package, configuration, firmware, mrbgem, DFU,
|
|
22
|
+
and electronic-craft example documentation.
|
|
23
|
+
- Add RBS signatures, automated tests, macOS CI, and release validation with
|
|
24
|
+
isolated gem installation and CLI smoke testing.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ogom
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.ja.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# rpremote
|
|
2
|
+
|
|
3
|
+
[English](README.md)
|
|
4
|
+
|
|
5
|
+
Raspberry Pi Pico向けのカスタムPicoRuby R2P2ファームウェアを準備、ビルド、
|
|
6
|
+
書き込み、操作するためのコマンドラインツールです。
|
|
7
|
+
|
|
8
|
+
公開mrbgemとローカルmrbgemを再現可能なファームウェアへ組み込み、生成したUF2の
|
|
9
|
+
BOOTSEL書き込み、R2P2経由のバイナリ安全なファイル転送とRuby実行を行えます。
|
|
10
|
+
|
|
11
|
+
## 必要環境
|
|
12
|
+
|
|
13
|
+
- macOSとRuby 4.0以降
|
|
14
|
+
- ファームウェアビルド用のGit、GNU Make、CMake、Arm GNU Toolchain
|
|
15
|
+
- 選択したR2P2ビルド設定に対応するRaspberry Pi Picoボード
|
|
16
|
+
- R2P2ビルド設定を含むPicoRuby
|
|
17
|
+
|
|
18
|
+
## インストール
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
gem install rpremote
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## クイックスタート
|
|
25
|
+
|
|
26
|
+
プロジェクトのディレクトリで実行します。
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
rpremote setup
|
|
30
|
+
rpremote build
|
|
31
|
+
rpremote flash --mount /Volumes/RP2350
|
|
32
|
+
rpremote run main.rb
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
既定では`firmware/picoruby-4.0.3/`にソースを準備し、
|
|
36
|
+
`firmware/picoruby-4.0.3-pico2.uf2`を生成します。対象ボードを明示する必要がある
|
|
37
|
+
場合は、`rpremote ports`でR2P2のCDC 0ポートを確認してください。
|
|
38
|
+
|
|
39
|
+
## mrbgemを追加する
|
|
40
|
+
|
|
41
|
+
プロジェクト直下に`Mrbgems`を作成します。ローカルパスはこのファイルを基準にします。
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
vm :mrubyc
|
|
45
|
+
|
|
46
|
+
gem github: "ksbmyk/picoruby-ws2812-plus", branch: "main"
|
|
47
|
+
gem path: "../mrbgems/my-device"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
依存関係を検査、固定してビルドします。
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
rpremote mrbgems check
|
|
54
|
+
rpremote mrbgems lock
|
|
55
|
+
rpremote build
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`Mrbgems.lock`はGitHubのcommitとローカルgemの内容hashを固定します。`build`は
|
|
59
|
+
既存lockを再利用し、`rpremote mrbgems update`だけが新しいcommitを解決します。
|
|
60
|
+
|
|
61
|
+
## 対象を選択する
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
rpremote setup --language picoruby --language-version 3.4.2
|
|
65
|
+
rpremote build --language picoruby --language-version 3.4.2 --board pico2
|
|
66
|
+
rpremote flash --language picoruby --language-version 3.4.2 --board pico2 \
|
|
67
|
+
--mount /Volumes/RP2350
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
コマンドラインオプションは`config/setting.json`より優先されます。現在実装されて
|
|
71
|
+
いるのはPicoRubyです。将来のMicroPythonと追加Picoボード対応に備え、
|
|
72
|
+
`language`と`board`はインターフェースに残しています。
|
|
73
|
+
|
|
74
|
+
## コマンド
|
|
75
|
+
|
|
76
|
+
| コマンド | 説明 |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `rpremote setup` | 設定を作成し、言語ソースを準備します。 |
|
|
79
|
+
| `rpremote build` | mrbgemを含むカスタムUF2をビルドします。 |
|
|
80
|
+
| `rpremote build clean` | 中間ビルドファイルを削除します。 |
|
|
81
|
+
| `rpremote dfu app FILE` | PicoModem DFUでRubyまたは版を照合したバイトコードのアプリを更新します。 |
|
|
82
|
+
| `rpremote dfu compile FILE` | DFU用にPicoRuby版と一致する`.mrb`を生成します。 |
|
|
83
|
+
| `rpremote dfu status` | DFUのアクティブおよび起動候補スロットを表示します。 |
|
|
84
|
+
| `rpremote mrbgems …` | mrbgemを検査、表示、固定、更新します。 |
|
|
85
|
+
| `rpremote flash` | 選択したUF2をBOOTSEL経由で書き込む。 |
|
|
86
|
+
| `rpremote ports` | R2P2シリアルポートを表示します。 |
|
|
87
|
+
| `rpremote run FILE` | Rubyファイルを転送して実行します。 |
|
|
88
|
+
| `rpremote exec CODE` | 短いRubyコードを実行します。 |
|
|
89
|
+
| `rpremote monitor` / `repl` | 対話型シリアルセッションを開く。 |
|
|
90
|
+
| `rpremote reset` | R2P2を再起動して再接続まで待つ。 |
|
|
91
|
+
| `rpremote fs cp/cat/ls/rm/mkdir` | R2P2ファイルシステムを操作します。 |
|
|
92
|
+
|
|
93
|
+
完全な構文は`rpremote --help`で確認できます。`monitor`と`repl`は`Ctrl-]`で
|
|
94
|
+
終了します。
|
|
95
|
+
|
|
96
|
+
## ドキュメントとサンプル
|
|
97
|
+
|
|
98
|
+
[GitHubリポジトリ](https://github.com/ogom/rpremote)に、英語・日本語のガイド、
|
|
99
|
+
設定リファレンス、Mrbgems.lockの解説、カスタムファームウェア手順、電子工作
|
|
100
|
+
サンプルがあります。
|
|
101
|
+
|
|
102
|
+
## 関連プロジェクト
|
|
103
|
+
|
|
104
|
+
- [mbremote](https://github.com/ogom/mbremote)は、BBC micro:bit向けの
|
|
105
|
+
MicroPython/PicoRubyプロジェクトをビルド、書き込み、操作する、同じコンセプトの
|
|
106
|
+
ツールです。
|
|
107
|
+
|
|
108
|
+
## 開発
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
bundle install
|
|
112
|
+
bundle exec rake
|
|
113
|
+
bundle exec rbs -I sig validate
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
公開前は`bundle exec rake release:check`を実行し、
|
|
117
|
+
[RELEASING.md](RELEASING.md)に従ってください。
|
|
118
|
+
|
|
119
|
+
## ライセンス
|
|
120
|
+
|
|
121
|
+
[MIT](LICENSE)です。外部ソフトウェアについては
|
|
122
|
+
[第三者ソフトウェアに関する通知](THIRD_PARTY_NOTICES.md)を参照してください。
|
data/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# rpremote
|
|
2
|
+
|
|
3
|
+
[日本語](README.ja.md)
|
|
4
|
+
|
|
5
|
+
Command-line tools for preparing, building, flashing, and controlling custom
|
|
6
|
+
PicoRuby R2P2 firmware on Raspberry Pi Pico boards.
|
|
7
|
+
|
|
8
|
+
rpremote embeds public and local mrbgems in reproducible firmware, flashes the
|
|
9
|
+
generated UF2 through BOOTSEL, and provides binary-safe file transfer and Ruby
|
|
10
|
+
execution through R2P2.
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- macOS and Ruby 4.0 or later
|
|
15
|
+
- Git, GNU Make, CMake, and the Arm GNU Toolchain for firmware builds
|
|
16
|
+
- A Raspberry Pi Pico board supported by the selected R2P2 build configuration
|
|
17
|
+
- A PicoRuby version providing the R2P2 build configuration
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
gem install rpremote
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
Run these commands in a project directory:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
rpremote setup
|
|
31
|
+
rpremote build
|
|
32
|
+
rpremote flash --mount /Volumes/RP2350
|
|
33
|
+
rpremote run main.rb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The defaults prepare `firmware/picoruby-4.0.3/` and create
|
|
37
|
+
`firmware/picoruby-4.0.3-pico2.uf2`. Use `rpremote ports` to locate the R2P2
|
|
38
|
+
CDC 0 port when a board must be selected explicitly.
|
|
39
|
+
|
|
40
|
+
## Add mrbgems
|
|
41
|
+
|
|
42
|
+
Create a project-level `Mrbgems` file. Local paths are relative to that file.
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
vm :mrubyc
|
|
46
|
+
|
|
47
|
+
gem github: "ksbmyk/picoruby-ws2812-plus", branch: "main"
|
|
48
|
+
gem path: "../mrbgems/my-device"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Then validate, lock, and build the dependencies:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
rpremote mrbgems check
|
|
55
|
+
rpremote mrbgems lock
|
|
56
|
+
rpremote build
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`Mrbgems.lock` pins GitHub commits and hashes local gem contents. Existing
|
|
60
|
+
locks are reused by `build`; `rpremote mrbgems update` deliberately resolves
|
|
61
|
+
new commits.
|
|
62
|
+
|
|
63
|
+
## Select a target
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
rpremote setup --language picoruby --language-version 3.4.2
|
|
67
|
+
rpremote build --language picoruby --language-version 3.4.2 --board pico2
|
|
68
|
+
rpremote flash --language picoruby --language-version 3.4.2 --board pico2 \
|
|
69
|
+
--mount /Volumes/RP2350
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Command-line options override `config/setting.json`. PicoRuby is implemented
|
|
73
|
+
today; `language` and `board` are retained for planned MicroPython and
|
|
74
|
+
additional Pico board support.
|
|
75
|
+
|
|
76
|
+
## Commands
|
|
77
|
+
|
|
78
|
+
| Command | Description |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `rpremote setup` | Create configuration and prepare language sources. |
|
|
81
|
+
| `rpremote build` | Build a custom UF2 with project mrbgems. |
|
|
82
|
+
| `rpremote build clean` | Remove intermediate build files. |
|
|
83
|
+
| `rpremote dfu app FILE` | Stage a Ruby or version-checked bytecode app through PicoModem DFU. |
|
|
84
|
+
| `rpremote dfu compile FILE` | Compile `.rb` to matching PicoRuby bytecode for DFU. |
|
|
85
|
+
| `rpremote dfu status` | Show the active and candidate DFU slots. |
|
|
86
|
+
| `rpremote mrbgems …` | Check, list, lock, or update mrbgems. |
|
|
87
|
+
| `rpremote flash` | Flash the selected UF2 through BOOTSEL. |
|
|
88
|
+
| `rpremote ports` | List detected R2P2 serial ports. |
|
|
89
|
+
| `rpremote run FILE` | Upload and run a Ruby file. |
|
|
90
|
+
| `rpremote exec CODE` | Run a short Ruby expression. |
|
|
91
|
+
| `rpremote monitor` / `repl` | Open an interactive serial session. |
|
|
92
|
+
| `rpremote reset` | Reboot R2P2 and wait for reconnection. |
|
|
93
|
+
| `rpremote fs cp/cat/ls/rm/mkdir` | Operate on the R2P2 filesystem. |
|
|
94
|
+
|
|
95
|
+
Run `rpremote --help` for complete syntax. `monitor` and `repl` exit with
|
|
96
|
+
`Ctrl-]`.
|
|
97
|
+
|
|
98
|
+
## Documentation and examples
|
|
99
|
+
|
|
100
|
+
The [GitHub repository](https://github.com/ogom/rpremote) contains the full
|
|
101
|
+
English and Japanese guides, configuration reference, Mrbgems.lock reference,
|
|
102
|
+
custom firmware guide, and electronic-craft examples.
|
|
103
|
+
|
|
104
|
+
## Related projects
|
|
105
|
+
|
|
106
|
+
- [mbremote](https://github.com/ogom/mbremote) is a tool with the same concept
|
|
107
|
+
for building, flashing, and controlling MicroPython and PicoRuby projects on
|
|
108
|
+
BBC micro:bit boards.
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
bundle install
|
|
114
|
+
bundle exec rake
|
|
115
|
+
bundle exec rbs -I sig validate
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Before publishing, run `bundle exec rake release:check` and follow
|
|
119
|
+
[RELEASING.md](RELEASING.md).
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
[MIT](LICENSE). See [Third-Party Notices](THIRD_PARTY_NOTICES.md) for
|
|
124
|
+
externally downloaded software.
|
data/RELEASING.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Releasing rpremote
|
|
2
|
+
|
|
3
|
+
This checklist prepares and publishes one immutable gem version. Run every
|
|
4
|
+
command from `packages/rpremote`.
|
|
5
|
+
|
|
6
|
+
## 1. Prepare the version
|
|
7
|
+
|
|
8
|
+
1. Update `Rpremote::VERSION` in `lib/rpremote/version.rb`.
|
|
9
|
+
2. Add the same version and release date to `CHANGELOG.md`.
|
|
10
|
+
3. Commit all intended files and verify that `git status --short` is empty.
|
|
11
|
+
4. Run the non-publishing release check:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
bundle exec rake release:check
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The check runs the specs, RuboCop, and RBS validation; builds the gem; checks
|
|
18
|
+
its metadata and packaged documentation; installs it into a temporary isolated
|
|
19
|
+
gem directory; and executes the installed `rpremote --version` command.
|
|
20
|
+
|
|
21
|
+
## 2. Prepare publishing services
|
|
22
|
+
|
|
23
|
+
The repository must have an `origin` remote before releasing. Confirm it with:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
git remote -v
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For the first RubyGems.org release, confirm that the `rpremote` name is
|
|
30
|
+
available and configure either RubyGems MFA for a manual push or a pending
|
|
31
|
+
trusted publisher for GitHub Actions. Never commit an API key or
|
|
32
|
+
`~/.gem/credentials`.
|
|
33
|
+
|
|
34
|
+
## 3. Publish deliberately
|
|
35
|
+
|
|
36
|
+
`bundle exec rake release` is a publishing command: it creates and pushes the
|
|
37
|
+
version tag and pushes the built gem to RubyGems.org. Run it only after the
|
|
38
|
+
release check passes and the working tree is clean:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
bundle exec rake release
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
After the tag exists on GitHub, create a GitHub Release and attach the exact
|
|
45
|
+
gem that passed validation. `--verify-tag` prevents GitHub CLI from silently
|
|
46
|
+
creating a tag at another commit:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
gh release create v0.1.0 rpremote-0.1.0.gem \
|
|
50
|
+
--verify-tag --generate-notes
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Replace `0.1.0` in both places for later versions. Finally, install from
|
|
54
|
+
RubyGems.org in a fresh environment and run `rpremote --version`.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Third-Party Notices
|
|
2
|
+
|
|
3
|
+
`rpremote` does not bundle R2P2 firmware. The `setup` command downloads a
|
|
4
|
+
selected PicoRuby/R2P2 4.0.3 or 3.4.2 release from the PicoRuby project and
|
|
5
|
+
verifies its published SHA-256 digest.
|
|
6
|
+
|
|
7
|
+
## PicoRuby and R2P2
|
|
8
|
+
|
|
9
|
+
Source: <https://github.com/picoruby/picoruby>
|
|
10
|
+
|
|
11
|
+
Copyright © 2020 HASUMI Hitoshi
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
14
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
15
|
+
the Software without restriction, including without limitation the rights to
|
|
16
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
18
|
+
so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
data/exe/rpremote
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
|
|
5
|
+
module Rpremote
|
|
6
|
+
class BuildCommand
|
|
7
|
+
def self.run(args, defaults:, output: $stdout, error: $stderr, builder: Builder.new)
|
|
8
|
+
if args.first == "clean"
|
|
9
|
+
args.shift
|
|
10
|
+
raise ArgumentError, "build clean does not accept arguments" unless args.empty?
|
|
11
|
+
|
|
12
|
+
builder.clean(output: output)
|
|
13
|
+
return
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
options = {
|
|
17
|
+
language: Target::DEFAULT_LANGUAGE,
|
|
18
|
+
language_version: Target::DEFAULT_LANGUAGE_VERSION,
|
|
19
|
+
board: Target::DEFAULT_BOARD,
|
|
20
|
+
cache_dir: defaults.fetch(:cache, Target::DEFAULT_CACHE_DIR),
|
|
21
|
+
firmware: defaults[:firmware],
|
|
22
|
+
mrbgems: nil
|
|
23
|
+
}.merge(defaults.except(:cache))
|
|
24
|
+
OptionParser.new do |parser|
|
|
25
|
+
parser.on("--language LANGUAGE") { |value| options[:language] = value }
|
|
26
|
+
parser.on("--language-version VERSION") { |value| options[:language_version] = value }
|
|
27
|
+
parser.on("--board BOARD") { |value| options[:board] = value }
|
|
28
|
+
parser.on("--firmware FILE") { |value| options[:firmware] = value }
|
|
29
|
+
parser.on("--cache DIR") { |value| options[:cache_dir] = value }
|
|
30
|
+
parser.on("--mrbgems FILE") { |value| options[:mrbgems] = value }
|
|
31
|
+
parser.on("--no-mrbgems") { options[:mrbgems] = false }
|
|
32
|
+
end.parse!(args)
|
|
33
|
+
raise ArgumentError, "build does not accept arguments" unless args.empty?
|
|
34
|
+
|
|
35
|
+
builder.build(**options, output: output, error: error)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbconfig"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "rubygems/version"
|
|
6
|
+
require_relative "mrbgems"
|
|
7
|
+
|
|
8
|
+
module Rpremote
|
|
9
|
+
class Builder
|
|
10
|
+
class Error < Rpremote::Error; end
|
|
11
|
+
|
|
12
|
+
def initialize(root: Dir.pwd, runner: nil, mrbgems_class: Mrbgems)
|
|
13
|
+
@root = File.expand_path(root)
|
|
14
|
+
@runner = runner || method(:run_command)
|
|
15
|
+
@mrbgems_class = mrbgems_class
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build(output: $stdout, error: $stderr, **options)
|
|
19
|
+
target = Target.new(**options.slice(:language, :language_version, :board, :cache_dir, :firmware))
|
|
20
|
+
script = File.expand_path("../../tasks/firmware_build.rb", __dir__)
|
|
21
|
+
raise Error, "rpremote installation has no firmware build script: #{script}" unless File.file?(script)
|
|
22
|
+
|
|
23
|
+
Language.validate!(target.language)
|
|
24
|
+
|
|
25
|
+
source_dir = source_for(target)
|
|
26
|
+
environment = {
|
|
27
|
+
"RPREMOTE_LANGUAGE" => target.language,
|
|
28
|
+
"RPREMOTE_LANGUAGE_VERSION" => target.language_version,
|
|
29
|
+
"RPREMOTE_BOARD" => target.board,
|
|
30
|
+
"RPREMOTE_ROOT" => root,
|
|
31
|
+
"PICORUBY_DIR" => source_dir
|
|
32
|
+
}
|
|
33
|
+
build_options = options.merge(
|
|
34
|
+
language: target.language,
|
|
35
|
+
language_version: target.language_version,
|
|
36
|
+
board: target.board
|
|
37
|
+
)
|
|
38
|
+
add_mrbgems_environment!(environment, build_options, source_dir, output)
|
|
39
|
+
environment["RPREMOTE_FIRMWARE"] = target.firmware_path(root: root)
|
|
40
|
+
success = runner.call(
|
|
41
|
+
environment,
|
|
42
|
+
RbConfig.ruby,
|
|
43
|
+
script,
|
|
44
|
+
chdir: root,
|
|
45
|
+
out: output,
|
|
46
|
+
err: error
|
|
47
|
+
)
|
|
48
|
+
raise Error, "custom firmware build failed" unless success
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def clean(output: $stdout)
|
|
52
|
+
directory = File.join(root, "build")
|
|
53
|
+
unless File.directory?(directory)
|
|
54
|
+
output.puts("no build files: #{directory}")
|
|
55
|
+
return
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
FileUtils.rm_rf(directory)
|
|
59
|
+
output.puts("removed build files: #{directory}")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
attr_reader :root, :runner, :mrbgems_class
|
|
65
|
+
|
|
66
|
+
def add_mrbgems_environment!(environment, options, source_dir, output)
|
|
67
|
+
definition = mrbgems_definition(options[:mrbgems])
|
|
68
|
+
return unless definition
|
|
69
|
+
|
|
70
|
+
manager = mrbgems_class.new(path: definition, cwd: root)
|
|
71
|
+
config_language = mrbgems_config_language(
|
|
72
|
+
manager.vm, options.fetch(:language), options.fetch(:language_version)
|
|
73
|
+
)
|
|
74
|
+
config_name = "r2p2-#{config_language}-#{options.fetch(:board)}"
|
|
75
|
+
base_config = File.join(source_dir, "build_config", "#{config_name}.rb")
|
|
76
|
+
raise Error, "PicoRuby build config not found: #{base_config}" unless File.file?(base_config)
|
|
77
|
+
|
|
78
|
+
overlay = manager.generate_overlay(
|
|
79
|
+
base_config: base_config,
|
|
80
|
+
target: config_name,
|
|
81
|
+
directory: File.join(root, "build", "mrbgems")
|
|
82
|
+
)
|
|
83
|
+
environment["RPREMOTE_CONFIG_NAME"] = config_name
|
|
84
|
+
environment["RPREMOTE_MRUBY_CONFIG"] = overlay.path
|
|
85
|
+
environment["RPREMOTE_MRBGEMS_FINGERPRINT"] = overlay.fingerprint
|
|
86
|
+
output.puts("using Mrbgems: #{manager.path}")
|
|
87
|
+
output.puts("using Mrbgems.lock: #{manager.lock_path}")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def mrbgems_config_language(vm_name, language, version)
|
|
91
|
+
return language unless vm_name
|
|
92
|
+
|
|
93
|
+
modern = Gem::Version.new(version) >= Gem::Version.new("4.0.0")
|
|
94
|
+
return modern ? "femtoruby" : "picoruby" if vm_name == :mrubyc
|
|
95
|
+
|
|
96
|
+
modern ? "picoruby" : "microruby"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def mrbgems_definition(option)
|
|
100
|
+
return if option == false
|
|
101
|
+
|
|
102
|
+
candidate = File.expand_path(option || Mrbgems::DEFAULT_PATH, root)
|
|
103
|
+
return candidate if File.file?(candidate)
|
|
104
|
+
raise Error, "mrbgems definition does not exist: #{candidate}" if option
|
|
105
|
+
|
|
106
|
+
nil
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def source_for(target)
|
|
110
|
+
source = target.source_dir(root: root)
|
|
111
|
+
return source if File.directory?(source)
|
|
112
|
+
|
|
113
|
+
raise Error,
|
|
114
|
+
"#{target.language} #{target.language_version} source not found: #{source}\n" \
|
|
115
|
+
"Run `rpremote setup --language #{target.language} " \
|
|
116
|
+
"--language-version #{target.language_version} --cache #{target.cache_dir}` first."
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def run_command(...)
|
|
120
|
+
system(...)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "zlib"
|
|
4
|
+
|
|
5
|
+
module Rpremote
|
|
6
|
+
module Checksum
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def crc16(data, initial = 0xFFFF)
|
|
10
|
+
data.each_byte.reduce(initial) do |crc, byte|
|
|
11
|
+
crc ^= byte << 8
|
|
12
|
+
8.times do
|
|
13
|
+
crc = if crc.nobits?(0x8000)
|
|
14
|
+
crc << 1
|
|
15
|
+
else
|
|
16
|
+
(crc << 1) ^ 0x1021
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
crc & 0xFFFF
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def crc32(data, initial = 0)
|
|
24
|
+
Zlib.crc32(data, initial)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|