raspberry-piipyoctoscpmeta-raspberrypi

Get IP address on RaspberryPi 4 running Yocto image


I used bitbake to generate a Linux image for my raspberry pi 4 board following the instructions provided in the meta-raspberrypi layer (https://github.com/agherzan/meta-raspberrypi). I am able to connect to my board using an FTDI USB to UART cable and running minicom on my host machine. However, I need to transfer files to my board using SCP. For that, I need the IP address and when I execute "ip a" command in my RPi4 board, I get the output below showing no IP address that I can use. Can you please provide some guidance? Do I need to add something to my conf or bblayers files?

root@raspberrypi4-64:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq qlen 1000
    link/ether dc:a6:32:57:bb:1f brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether dc:a6:32:57:bb:21 brd ff:ff:ff:ff:ff:ff

Solution

  • Since RaspberryPi 4 has both Ethernet and WiFi interfaces available, you can connect to a network using one or the other (or both).

    If you have a cable connected to your Ethernet port, you just need to request a DHCP lease. You should be able to do that by running udhcpc -i eth0. If udhcpc command is not available, you'll need to find the recipe providing it (might be hidden in a Busybox configuration file though) or add any other DHCP client to your image.

    If you plan to connect to your network over WiFi, you need first to connect to the network and then request a DHCP lease. The former can be done with wpa_supplicant, connman, nmcli, etc. They probably aren't available in your image so you would need to add one first. To connect with wpa_supplicant, do the following: wpa_passphrase "<SSID>" > wpa.conf replacing <SSID> with the SSID (name) of the network you want to connect to. It'll then wait for you to input the password of this network. Then, run wpa_supplicant -iwlan0 -cwpa.conf&. This will start a connection in background. If the connection is successful in the logs, you can continue. Then, run udhcpc -iwlan0 to get a DHCP lease and then you're good to go!

    If there are no DHCP server on your network (direct connection to your host machine for example), you need to assign an IP address manually with e.g.: ip addr add <IP addr> dev <iface> replacing <IP addr> with a valid (in the same subnet as the other computer(s) in the network) IP address (and maybe subnet after it? e.g. 192.168.1.153/24) and <iface> with eth0 or wlan0.