RasPi4 Bootloader - h-sendai/RaspberryPi GitHub Wiki
Raspberry Pi 4 EEPROM内ブートローダーの書き換え
これはEEPROM内のブートローダー書き換えメモである。
Raspberry Pi 4からEEPROMが付き、その中にブートローダーが格納 されている。
ブート順番はブートローダー内で設定されている。ネットワークブート する場合にはブートローダーを書き換え、ブート順番を変更する必要がある。
URLメモ
Raspberry Pi財団のドキュメント:
- https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md
- https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md
ブートローダーバージョン、設定値の取得
現在のブートローダーのバージョンは下のコマンドで取得できる:
sudo vcgencmd bootloader_version
現在のブートローダー設定値は下のコマンドで取得できる:
sudo vcgencmd bootloader_config
あるいは
sudo rpi-eeprom-config
ファームウェアの更新
aptコマンドを使うとファームウェアファイルも他のパッケージとともにダウンロードされ、 最新リリース版がEEPROMに書き込まれる。
apt update
apt upgrade
apt full-upgrade
(reboot)
ファームウェアファイルは /lib/firmware/raspberrypi/bootloader/ 以下にバージョン毎にある。
critical/ == default/: 最新の工場出荷バージョン
latest/ == stable/ : 最新の安定バージョン
https://akkiesoft.hatenablog.jp/entry/20200904/1599230508
ブートローダー設定値の変更
ブートローダー設定値(ブートに使うメディアの優先順位など)は
ファームウェア内に組み込まれている。変更するには
rpi-eeprom-config --edit
コマンドを使う。
sudo rpi-eeprom-config --edit
実行するとnanoが起動し設定値を編集できる。セーブしてリブートすると 変更結果が反映される。 設定可能な値は https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md に書かれている。
nanoを抜けたあとの例:
Updating bootloader EEPROM
image: /lib/firmware/raspberrypi/bootloader/default/pieeprom-2020-09-03.bin
config_src: vcgencmd bootloader_config
config: /tmp/tmpzb6q2kk7/boot.conf
################################################################################
[all]
BOOT_UART=1
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0
DHCP_TIMEOUT=45000
DHCP_REQ_TIMEOUT=4000
TFTP_FILE_TIMEOUT=30000
TFTP_IP=
TFTP_PREFIX=0
BOOT_ORDER=0x21
SD_BOOT_MAX_RETRIES=3
NET_BOOT_MAX_RETRIES=5
[none]
FREEZE_VERSION=0
################################################################################
*** To cancel this update run 'sudo rpi-eeprom-update -r' ***
BCM2711 detected
Dedicated VL805 EEPROM detected
*** INSTALLING /tmp/tmpzb6q2kk7/pieeprom.upd ***
BOOTFS /boot
EEPROM update pending. Please reboot to apply the update.
nanoを抜けたあと更新をやめるには上のメッセージにあるように
sudo rpi-eeprom-update -r
を実行する。
設定値の例
設定可能な値は https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md に書いてある。
BOOT_UART
1ならブート時にデバッグ出力がGPIO 14 15のUARTにでる。 デフォルト値は0。
BOOT_ORDER
デフォルト値は0xf41 (SDカード、USB mass storageの順に無限回試みる)。 ビットマップではなくて最大8桁の整数。右側(位がちいさいほう)が有線。
- 0x0 NONE
- 0x1 SD card
- 0x2 Network
- 0x3 RPIBOOT
- 0x4 USB mass storage
- 0x5 BCM-USB mass storage
- 0xf start again with the first boot order field
(例1) まずSD cardからのブートを試みて、 だめならネットワークブート に切り替える場合は0x21とセットする。
(例2) BOOT_ORDERを0x41に書き換え、 USBメモリにRaspberry Pi OS imageをddで書いてそれをRPi 4に接続し、SDカードなしの 状態で起動するとSDカードと同様にUSBメモリから起動する。 最終手段としてSDカードから起動というのを残しておくために0x41と最後の桁に 1を書いておく。
リカバリ
変になってしまった場合はdownloadページからrecoveryイメージをダウンロードし SDカードに書き、そのSDカードから起動する。やったことはない。
イメージのダウンロードは以前はあったような気がしたんだが、いまは みつからない。
https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md にはRaspberry Pi Imagerを使うのが簡単でこれを起動して Choose OS -> Misc utility images -> Raspberry Pi EEPROM boot recoveryと進む と書いてある。 できたSDカードをRPi 4にさして電源をいれる。 書き換えが終了するとHDMIディスプレイが緑色を表示し、緑LEDが点滅すると書いてある。
Windows用のRaspberry Pi Imagerをダウンロードして試してみた。 SDカードを選択するところではUSBメモリを選択することもできた。 recovery用のを選択して作ってみるとUSBメモリ上に以下の内容のものができた。
# fdisk -l /dev/sdg
Disk /dev/sdg: 3.7 GiB, 4003463168 bytes, 7819264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xff2d76e2
Device Boot Start End Sectors Size Id Type
/dev/sdg1 128 7819263 7819136 3.7G c W95 FAT32 (LBA)
# ls -l /mnt
total 720
-rwxr-xr-x. 1 root root 1029 Aug 13 02:51 README.txt*
-rwxr-xr-x. 1 root root 524288 Sep 8 02:41 pieeprom.bin*
-rwxr-xr-x. 1 root root 79 Sep 8 02:42 pieeprom.sig*
-rwxr-xr-x. 1 root root 98196 Sep 8 02:41 recovery.bin*
-rwxr-xr-x. 1 root root 99224 Sep 8 02:42 vl805.bin*
-rwxr-xr-x. 1 root root 76 Aug 13 02:46 vl805.sig*
# cat /mnt/README.txt
Raspberry Pi 4 EEPROM bootloader rescue image
*********************************************
The Raspberry Pi4 has a small EEPROM used to store the bootloader.
This rescue image reverts the bootloader EEPROM to factory default settings.
This rescue image also updates the USB 3.0 (VL805) firmware to the latest
version (138a1) with better full-speed Isochronous endpoint support.
To re-flash the EEPROM(s)
1. Unzip the contents of this zip file to a blank FAT formatted SD-SDCARD.
2. Power off the Raspberry Pi
3. Insert the sd-card.
4. Power on Raspberry Pi
5. Wait at least 10 seconds.
This easiest method for creating and formatting the SD-CARD is to use the
Raspberry Pi Imager from https://raspberrypi.org/downloads
If successful, the green LED light will blink rapidly (forever), otherwise
an error pattern will be displayed.
If a HDMI display is attached then screen will display green for success
or red if failure a failure occurs.
N.B. This image is not a bootloader it simply replaces the on-board bootloader.
Raspberry Pi Imagerは https://www.raspberrypi.org/software/にWindows用、macOS用、Ubuntu用のがある。 raspi自身でも apt install rpi-imagerで使えるようになるらしい。
以下以前の方法
ファームウェアファイルの作成
次のコマンドでファームウェアファイルを作る。 pieeprom-new.binが作られたファームウェアファイル。
rpi-eeprom-config --out pieeprom-new.bin --config bootconf.txt pieeprom.bin
EEPROMに書く
次のコマンドでEEPROMに書く。
# sudo rpi-eeprom-update -d -f ./pieeprom-new.bin
BCM2711 detected
*** INSTALLING ./pieeprom-new.bin ***
EEPROM update pending. Please reboot to apply the update.
# sudo reboot
設定値の取り出し
変更するには
- ファームウェアから設定値をとりだす
- 設定値を変更する
- 変更した設定値をもとにファームウェアファイルを作る
- ファームウェアファイルをEEPROMに書く
という順で作業する。
mkdir eeprom (作業ディレクトリの作成、移動)
cd eeprom
cp /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2020-01-17.bin pieeprom.bin
rpi-eeprom-config pieeprom.bin > bootconf.txt
これで設定値が書かれたファイルbootconf.txtができる。これを編集する。
デフォルトでは以下のようなbootconf.txtになっている。
[all]
BOOT_UART=0
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0
DHCP_TIMEOUT=45000
DHCP_REQ_TIMEOUT=4000
TFTP_FILE_TIMEOUT=30000
TFTP_IP=
TFTP_PREFIX=0
BOOT_ORDER=0x1
SD_BOOT_MAX_RETRIES=3
NET_BOOT_MAX_RETRIES=5
[none]
FREEZE_VERSION=0