【Raspberry Pi】u-bootでTFTPサーバからイーサネット経由のファイル読込み

スポンサーリンク

前の記事で、UbuntuでTFTPサーバを動かすようにした。

【Ubuntu 20.04/18.04 LTS Server】TFTPサーバを動かす
以前の記事で「Ubuntu 18.04 LTS Server」をインストールした。そのマシンで「TFTPサーバ」を動かしたので備忘録を残す。 2020/8/13追記 「Ubuntu 20.04 LTS Server」でも同様に動作する事を確...

そこで、Ubuntu Linux上の「TFTPサーバ」にファイルを置き、Raspberry Piのu-bootからTFTP通信を使ってイーサネット経由でファイルの読み出しが出来たので備忘録を残す。

経緯

以前の記事で、Raspberry Piでu-bootを動かした。

【Raspberry Pi】u-bootを動かす
前の記事で作成した、u-bootを、「Raspberry Pi」に入れて、動かしてみる。 シリアル接続の準備 u-bootでは、シリアル通信を使って、コマンド入出力する。 シリアル-USB変換ケーブルが必要で、私はアマゾンから下記を入手。搭...

又、前の記事で紹介したT-Kernelを、Raspberry Piで動作確認したりするのに、毎回プログラムファイルをSDカードにコピーして実行していたが、けっこう手間がかかる。

【T-Kernel】Raspberry Pi と Renesas RZ/T1 用の T-Kernel「rtk_kernel」をGitHubに公開
以前の記事で紹介した、Raspberry Pi用にポーティングしたT-Kernel(rpi_t-kernel)の構成を見直し、RTOS(T-Kernel)部分のみを分離した「rtk_kernel」をGitHubに公開した。 概要 T-Ker

そこで、プログラムファイルをRaspberry Piのu-bootからTFTP通信を使ってイーサネット経由でロード&ブート出来るようにする。

Raspberry Piの設定

Raspberry Pi2での実行例。(他機種でも同様)

Raspberry Pi のIPアドレスを設定

自動起動に設定している場合は、電源投入時に何かキーを押してコマンドプロンプトにする。

U-Boot 2016.09-rc1-00469-gdc09431 (Aug 18 2016 - 11:23:43 +0900)

DRAM:  128 MiB
RPI 2 Model B (0xa21041)
MMC:   bcm2835_sdhci: 0
reading uboot.env
CACHE: Misaligned operation at range [07ff01d4, 07ff01d8]
In:    serial
Out:   lcd
Err:   lcd
Net:   Net Initialization Skipped
No ethernet found.
starting USB...
USB0:   Core Release: 2.80a
scanning bus 0 for devices... 3 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
       scanning usb for ethernet devices... 1 Ethernet Device(s) found
Hit any key to stop autoboot:  0
U-Boot>
  • ここで「No ethernet found.」と表示されているが使えるが、LANコネクタは使える模様。
U-Boot> setenv ipaddr 192.168.1.10
U-Boot> setenv netmask 255.255.255.0
  • MACアドレスは設定されていたが、必要があれば「setenv ethaddr 02:11:22:33:44:55」などのように設定する。

接続先のTFTPサーバアドレスを指定

U-Boot> setenv serverip 192.168.1.208
  • setenv gatewayip <addr>」で、ルータ経由で異なるセグメントへ接続する場合には、ゲートウェイアドレスを指定。
  • setenv dnsip <addr>」で、DNSサーバアドレスを指定できるらしい。(未確認)

環境設定を保存。

U-Boot> saveenv
  • 保存した環境設定は、「printenv」コマンドで表示確認できる。
  • 設定してある環境変数の削除は、「env delete <var>」コマンド。

サーバと通信できるか確認

U-Boot> ping 192.168.1.208
Waiting for Ethernet connection... done.
Using sms0 device
host 192.168.1.208 is alive
  • 上のように「is alive」と表示されればOK。応答がない時は「is not alive」と表示される。

Raspberry PiでTFTP通信を使う

TFTPサーバ上の格納先フォルダには、事前に必要なファイルを書き込んでおく。

TFTPサーバからファイルの読み出し

必要なファイルをRaspbery Piにロードする。

U-Boot> tftp 8000 tmonitor.bin
Waiting for Ethernet connection... done.
Using sms0 device
TFTP from server 192.168.1.208; our IP address is 192.168.1.10
Filename 'tmonitor.bin'.
Load address: 0x8000
Loading: ##################################################  41.1 KiB
         7.8 KiB/s
done
Bytes transferred = 42104 (a478 hex)
CACHE: Misaligned operation at range [00008000, 00012478]

U-Boot> tftp 4000 rominfo-rom.bin
Waiting for Ethernet connection... done.
Using sms0 device
TFTP from server 192.168.1.208; our IP address is 192.168.1.10
Filename 'rominfo-rom.bin'.
Load address: 0x4000
Loading: ##################################################  673 Bytes
         0 Bytes/s
done
Bytes transferred = 673 (2a1 hex)
CACHE: Misaligned operation at range [00004000, 000042a1]

U-Boot> tftp 30000 kernel-rom.bin
Waiting for Ethernet connection... done.
Using sms0 device
TFTP from server 192.168.1.208; our IP address is 192.168.1.10
Filename 'kernel-rom.bin'.
Load address: 0x30000
Loading: ##################################################  120 KiB
         23.4 KiB/s
done
Bytes transferred = 122880 (1e000 hex)

T-Kernelを起動

プログラムの先頭番地を指定して実行開始。

U-Boot> go 8000
## Starting application at 0x00008000 ...

T-Kernel Version 2.02.00 for RPi2 r0.60 [Thu Oct 10 16:58:26 JST 2019]

ConsoleIO - OK
userinit(0x80000) code not found.
usermain start.
T2EX >>
# [cmd]     exec t-monitor command
?           command help
<command>   misc. command
T2EX >>
  • U-Bootでは環境変数に設定しておく事で、上記手順を自動起動させる事も可能。

便利になった^^。

u-bootのコマンドヘルプ(参考)

U-Boot> ?
?       - alias for 'help'
base    - print or set address offset
bdinfo  - print Board Info structure
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootefi - Boots an EFI payload from memory
bootelf - Boot from an ELF image in memory
bootm   - boot application image from memory
bootp   - boot image via network using BOOTP/TFTP protocol
bootvx  - Boot vxWorks from an ELF image
bootz   - boot Linux zImage image from memory
cls     - clear screen
cmp     - memory compare
coninfo - print console devices and information
cp      - memory copy
crc32   - checksum calculation
dhcp    - boot image via network using DHCP/TFTP protocol
dm      - Driver model low level access
echo    - echo args to console
editenv - edit environment variable
env     - environment handling commands
exit    - exit script
ext2load- load binary file from a Ext2 filesystem
ext2ls  - list files in a directory (default /)
ext4load- load binary file from a Ext4 filesystem
ext4ls  - list files in a directory (default /)
ext4size- determine a file's size
false   - do nothing, unsuccessfully
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls   - list files in a directory (default /)
fatsize - determine a file's size
fatwrite- write file into a dos filesystem
fdt     - flattened device tree utility commands
fstype  - Look up a filesystem type
go      - start application at address 'addr'
gpio    - query and control gpio pins
help    - print command description/usage
iminfo  - print header information for application image
imxtract- extract a part of a multi-image
itest   - return true/false on integer compare
lcdputs - print string on lcd-framebuffer
load    - load binary file from a filesystem
loadb   - load binary file over serial line (kermit mode)
loads   - load S-Record file over serial line
loadx   - load binary file over serial line (xmodem mode)
loady   - load binary file over serial line (ymodem mode)
loop    - infinite loop on address range
ls      - list files in a directory (default /)
md      - memory display
mii     - MII utility commands
mm      - memory modify (auto-incrementing address)
mmc     - MMC sub system
mmcinfo - display MMC info
mw      - memory write (fill)
nfs     - boot image via network using NFS protocol
nm      - memory modify (constant address)
part    - disk partition related commands
ping    - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
pxe     - commands to get and boot from pxe files
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
save    - save file to a filesystem
saveenv - save environment variables to persistent storage
setcurs - set cursor position within screen
setenv  - set environment variables
setexpr - set environment variable as the result of eval expression
showvar - print local hushshell variables
size    - determine a file's size
sleep   - delay execution for some time
source  - run script from memory
sysboot - command to get and boot from syslinux files
test    - minimal test like /bin/sh
tftpboot- boot image via network using TFTP protocol
true    - do nothing, successfully
usb     - USB sub-system
usbboot - boot from USB device
version - print monitor, compiler and linker version
  • tftpコマンドはヘルプに出てこないが使えた。

関連記事

【Ubuntu 18.04 LTS】標準COMポートにアクセスし「C-Kermit」でシリアル通信する
以前の記事で「Ubuntu 18.04 LTS Desktop」をインストールした。 そこで、UbuntuパソコンのCOMポートにアクセスし、シリアル通信できたので備忘録を残す。 COMポートのデバイス名確認 パソコン標準装備のCOMポート...

参考

  1. U-Boot で Ethernet の簡易テストを行う方法
  2. [RPi][Linux] boot upstream Linux from U-boot on Raspberry Pi 3
  3. Raspberry Pi BrusterにTFTPサーバーを設定する

コメント

タイトルとURLをコピーしました