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?

Zephyr(その7:LinuxとMac上で使う)

0
Posted at

LinuxやMac上でZephyr

LinuxやMac上で、簡単にZephyrを動作させることができるとのこと。トライ。適宜、AIさん利用。

環境構築

本家サイト(下記)に従って構築する。

Linux

ここでは、Ubuntu環境。Build時に、ボードとして「native_sim」を使う。Native Simulationの略であろう、ホストの環境をSimulationするということと推測。

Hello World

$ west build -p -b native_sim samples/hello_world/

実行。

$ west build -t run

*** Booting Zephyr OS build v4.4.0-4296-g3701def3699d ***
Hello World! native_sim/native

ネットワーク

ホストとブリッジで接続し、DHCPクライアントを動かしてみる。まずはBuild。

$ west build -p -b native_sim samples/net/dhcpv4_client

仮想I/Fをホスト側で作成。「tools/net-tools」ディレクトリにある「net-setup.sh」を用いて実施。

$ sudo ./net-setup.sh -i zeth0
Using ./zeth.conf configuration file.
Creating zeth0

上記は、起動したままとする。ブリッジ作成およびメンバ追加。

$ sudo ip link add name br0 type bridge
$ sudo ip link set dev enp3s0f0 master br0
$ sudo ip link set dev zeth0 master br0
$ sudo ip link set dev br0 up

$ brctl show
bridge name	bridge id		STP enabled	interfaces
br0		8000.82db447ec99e	no		enp3s0f0
							zeth0

なお、WiFi I/Fでは、うまく動作せず。上記「enp3s0f0」はEthernet。

実行。小生の環境では、直接zephyr.exeを呼び出す必要があった。

$ /home/NAME/proj/zephyrpj/zephyr/build/zephyr/zephyr.exe -eth-if=zeth0
WARNING: Using a test - not safe - entropy source
uart connected to pseudotty: /dev/pts/3
*** Booting Zephyr OS build v4.4.0-4296-g3701def3699d ***
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on zeth0: index=1
[00:00:02.160,000] <inf> net_dhcpv4: Received: 192.168.2.125
[00:00:02.160,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.168.2.125
[00:00:02.160,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
[00:00:02.160,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.168.2.1
[00:00:02.160,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 3600 seconds

IPアドレスが取得できている。ターミナル(Zephyrシェル)に入ってみる。上記の「uart connected to pseudotty: /dev/pts/3」から、「/dev/pts/3」がデバイス。

$ screen /dev/pts/3

uart:~$ net iface
Default interface: 1


Interface eth0 (0x80834fc) (Ethernet) [1]
===================================
Link addr : 02:00:5E:00:53:31
MTU       : 1500
Flags     : AUTO_START,IPv4
Device    : zeth0 (0x807d388)
Status    : oper=UP, admin=UP, carrier=ON
Ethernet capabilities supported:
        TXTIME
        TXTIME supported
Ethernet PHY device: <none> ((nil))
IPv4 unicast addresses (max 1):
        192.168.2.125/255.255.255.0 DHCP preferred
IPv4 multicast addresses (max 2):
        224.0.0.1
IPv4 gateway : 192.168.2.1
DHCPv4 lease time : 3600
DHCPv4 renew time : 1800
DHCPv4 server     : 192.168.2.1
DHCPv4 requested  : 192.168.2.125
DHCPv4 state      : bound
DHCPv4 attempts   : 1
DHCPv4 state      : bound

類似情報が見える。各種情報およびpingの実施。

uart:~$ device list
devices:
- rng (READY)
  DT node labels: rng
- uart (READY)
  DT node labels: uart0
- zeth0 (READY)

uart:~$ kernel version
Zephyr version 4.4.99

uart:~$ net ping 8.8.8.8
PING 8.8.8.8
28 bytes from 8.8.8.8 to 192.168.2.125: icmp_seq=1 ttl=115 time=30 ms
28 bytes from 8.8.8.8 to 192.168.2.125: icmp_seq=2 ttl=115 time=40 ms
28 bytes from 8.8.8.8 to 192.168.2.125: icmp_seq=3 ttl=115 time=50 ms

Mac

Macでも類似の内容を実施。ただし、「native_sim」は使えず。QEMU利用。

環境変数

Buildなどのため、下記設定が必要であった。

$ export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
$ export ZEPHYR_SDK_INSTALL_DIR=/Users/NAME/zephyr-sdk-1.0.1

Hello World

Build。

$ west build -p -b qemu_cortex_m3 -d build_m4 samples/hello_world

用いたMacはM4であったが、「qemu_cortex_m4」は存在せず、「qemu_cortex_m3」を利用。QEMUによるSimulation/Emulationなので、この辺りは、あまり関係ないであろう。実行する。

% west build -d build_m4 -t run
-- west build: running target run
[0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: cortex-m3
qemu-system-arm: warning: nic stellaris_enet.0 has no peer
*** Booting Zephyr OS build v4.4.0-1647-g29d97bdaf61b ***
Hello World! qemu_cortex_m3/ti_lm3s6965

ネットワーク

ここでも、DHCPクライアントを動かす。まずはBuild。

$ west build -p -b qemu_cortex_m3 -d build_m4 samples/net/dhcpv4_client

ブリッジ

実行。

% sudo /opt/homebrew/bin/qemu-system-arm \
  -cpu cortex-m3 \
  -machine lm3s6965evb \
  -nographic \
  -kernel /Users/undeux3/zephyrproject/zephyr/build_m4/zephyr/zephyr.elf \
  -netdev vmnet-bridged,id=net0,ifname=en0 \
  -net nic,netdev=net0,model=stellaris_enet

[00:00:00.000,000] <wrn> net_if: You have 1 IPv4 net_if addresses but 2 network interfaces
[00:00:00.000,000] <wrn> net_if: Consider increasing CONFIG_NET_IF_MAX_IPV4_COUNT value.
*** Booting Zephyr OS build v4.4.0-1647-g29d97bdaf61b ***
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on ethernet@40048000: index=1
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on slip: index=2
[00:00:08.320,000] <inf> net_dhcpv4: Received: 192.168.10.107
[00:00:08.320,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.168.10.107
[00:00:08.320,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
[00:00:08.320,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.168.10.1
[00:00:08.320,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 86400 seconds

「vmnet-bridged」がブリッジ指定を意味し、「en0」がホスト(Mac)のI/Fである。各種情報およびpingの実施。

uart:~$ device list
devices:
- uart@4000e000 (READY)
  DT node labels: uart2
- uart@4000d000 (READY)
  DT node labels: uart1
- uart@4000c000 (READY)
  DT node labels: uart0
- slip (READY)
- ethernet@40048000 (READY)
  DT node labels: eth

uart:~$ kernel version
Zephyr version 4.4.99

uart:~$ net iface
Default interface: 1


Interface eth0 (0x20000498) (Ethernet) [1]
===================================
Link addr : 00:00:94:00:83:00
MTU       : 1500
Flags     : AUTO_START,IPv4
Device    : ethernet@40048000 (0x1c85c)
Status    : oper=UP, admin=UP, carrier=ON
Ethernet capabilities supported:
Ethernet PHY device: <none> (0)
IPv4 unicast addresses (max 1):
	192.168.10.107/255.255.255.0 DHCP preferred
IPv4 multicast addresses (max 2):
	224.0.0.1
IPv4 gateway : 192.168.10.1
DHCPv4 lease time : 86400
DHCPv4 renew time : 43200
DHCPv4 server     : 192.168.10.1
DHCPv4 requested  : 192.168.10.107
DHCPv4 state      : bound
DHCPv4 attempts   : 1
DHCPv4 state      : bound

Interface slip (0x20000528) (Ethernet) [2]
===================================
Link addr : 00:00:5E:00:53:49
MTU       : 1500
Flags     : AUTO_START,IPv4
Device    : slip (0x1c83c)
Status    : oper=UP, admin=UP, carrier=ON
Ethernet capabilities supported:
	Virtual LAN
Ethernet PHY device: <none> (0)
IPv4 not enabled for this interface.
DHCPv4 lease time : 0
DHCPv4 renew time : 0
DHCPv4 server     : 0.0.0.0
DHCPv4 requested  : 0.0.0.0
DHCPv4 state      : selecting
DHCPv4 attempts   : 6
DHCPv4 state      : selecting

uart:~$ net ping 8.8.4.4
PING 8.8.4.4
28 bytes from 8.8.4.4 to 192.168.10.107: icmp_seq=1 ttl=118 time=16 ms
28 bytes from 8.8.4.4 to 192.168.10.107: icmp_seq=2 ttl=118 time=11 ms
28 bytes from 8.8.4.4 to 192.168.10.107: icmp_seq=3 ttl=118 time=11 ms

NAT

実行。

% sudo /opt/homebrew/bin/qemu-system-arm \
  -cpu cortex-m3 \
  -machine lm3s6965evb \
  -nographic \
  -kernel /Users/undeux3/zephyrproject/zephyr/build_m4/zephyr/zephyr.elf \
  -netdev vmnet-shared,id=net0 \
  -net nic,netdev=net0,model=stellaris_enet

[00:00:00.000,000] <wrn> net_if: You have 1 IPv4 net_if addresses but 2 network interfaces
[00:00:00.000,000] <wrn> net_if: Consider increasing CONFIG_NET_IF_MAX_IPV4_COUNT value.
*** Booting Zephyr OS build v4.4.0-1647-g29d97bdaf61b ***
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Run dhcpv4 client
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on ethernet@40048000: index=1
[00:00:00.000,000] <inf> net_dhcpv4_client_sample: Start on slip: index=2
[00:00:05.080,000] <inf> net_dhcpv4: Received: 192.168.2.2
[00:00:05.080,000] <inf> net_dhcpv4_client_sample:    Address[1]: 192.168.2.2
[00:00:05.080,000] <inf> net_dhcpv4_client_sample:     Subnet[1]: 255.255.255.0
[00:00:05.080,000] <inf> net_dhcpv4_client_sample:     Router[1]: 192.168.2.1
[00:00:05.080,000] <inf> net_dhcpv4_client_sample: Lease time[1]: 3600 seconds

「vmnet-shared」がNAT指定を意味する。pingを実施する。

uart:~$ net ping 8.8.8.8
PING 8.8.8.8
28 bytes from 8.8.8.8 to 192.168.2.2: icmp_seq=1 ttl=117 time=12 ms
28 bytes from 8.8.8.8 to 192.168.2.2: icmp_seq=2 ttl=117 time=16 ms
28 bytes from 8.8.8.8 to 192.168.2.2: icmp_seq=3 ttl=117 time=11 ms

補足

lm3s6965evb, stellaris_enet

前者はボード(Cortex-M3搭載)、後者は同ボード上のNICであり、QEMUが確実にシミュレートできるものらしい。ここは、AIさんに言われるまま利用。

% /opt/homebrew/bin/qemu-system-arm -machine help

にて、QEMUがサポートしているボードを確認できる。

終わりに

物理ボードがなくても、RTOSを実践できる環境は素晴らしい。どうも、FreeRTOSもLinux上で動かせるらしい。そのうち、トライしてみる。

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?