How to Remotely Access a Development Board

How to Remotely Access a Development Board

Follow+Star Public Account Number, don’t miss wonderful content

How to Remotely Access a Development Board

Author | ZhengN

WeChat Public Account | Embedded Miscellaneous

Today I will share the pitfalls I encountered while setting up the network environment and remote login environment on the development board.

WiFi Driver Porting

1. Place the WiFi driver folder in the kernel folder

How to Remotely Access a Development Board

Place the driver folder in Linux-4.9.88/drivers/net/wireless. The WiFi driver can be found online (taking RTL8723 as an example).

2. Modify Kconfig and Makefile

Modify the Kconfig and Makefile files in the Linux-4.9.88/drivers/net/wireless folder.

Add the following content to the Kconfig file:

source "drivers/net/wireless/rtl8723BU/Kconfig"

How to Remotely Access a Development Board

Add the following content to the Makefile:

obj-$(CONFIG_RTL8723BU) += rtl8723BU/

How to Remotely Access a Development Board

3. Configure the kernel with make menuconfig

We need to load the rtl8723BU driver and configure the kernel, such as supporting USB devices, WiFi devices, etc.

Enter the command make menuconfig in the kernel path to enter the kernel configuration interface.

(1) Select the rtl8723BU module

How to Remotely Access a Development Board

(2) Support USB devices

How to Remotely Access a Development Board

How to Remotely Access a Development Board

How to Remotely Access a Development Board

(3) Support WiFi devices

How to Remotely Access a Development Board

(4) Support wireless network IEEE 802.11

How to Remotely Access a Development Board

After configuration, you can compile the rtl8723BU driver into the kernel, or compile it as a kernel module and then load it dynamically.

wpa_supplicant Porting

With the foundation from the previous step, we need to configure the wireless network, which requires some configuration tools, and wpa_supplicant is used to configure the wireless network. Next, we will port wpa_supplicant to the board.

Cross-compiling wpa_supplicant depends on the libnl and openssl libraries, so we need to first cross-compile these two libraries. There are many versions of these libraries, and version mismatch issues may occur. The versions I am using are as follows:

  • openssl-1.0.2
  • libnl-3.2.23
  • wpa_supplicant-2.9

(1) Cross-compile openssl-1.0.2

./config no-asm -shared --prefix=/home/LinuxZn/git_clone/openssl-1.0.2/openssl_build_arm os/compiler:/home/LinuxZn/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
make
make install

You need to execute the config script to generate the Makefile. Here, some configuration parameters are added, and the installation location is configured to the openssl_build_arm folder, and the cross-compiler is set to arm-linux-gnueabihf-gcc.

If make compilation fails, check if the cross-compiler configuration in the Makefile is correct. The correct configuration is as follows:

CROSS_COMPILE= arm-linux-gnueabihf-
CC= /home/LinuxZn/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/$(CROSS_COMPILE)gcc

Compile and obtain:

How to Remotely Access a Development Board

We need to check whether the generated executable program and library are ARM versions; otherwise, there will be issues when cross-compiling wpa_supplicant. For example:

How to Remotely Access a Development Board

(2) Cross-compile libnl-3.2.23

./configure --prefix=/home/LinuxZn/git_clone/libnl-3.2.23/libnl_build_arm --host=arm-linux-gnueabihf
make
make install

Cross-compiled and obtained:

How to Remotely Access a Development Board

(3) Cross-compile wpa_supplicant-2.9

Copy the wpa_supplicant source code to the Linux host and unzip it, then enter the wpa_supplicant directory. Copy the defconfig in the wpa_supplicant directory and rename it to .config, then open the .config file:

cp defconfig .config
vim .config

Add the following content to the .config file, where the paths for openssl and libnl libraries are the installation locations just mentioned:

# Cross-compiler
CC=arm-linux-gnueabihf-gcc
# openssl library and header file path
CFLAGS += -I/home/LinuxZn/git_clone/openssl-1.0.2/openssl_build_arm/include
LIBS += -L/home/LinuxZn/git_clone/openssl-1.0.2/openssl_build_arm/lib
# libnl library and header file path
CFLAGS += -I/home/LinuxZn/git_clone/libnl-3.2.23/libnl_build_arm/include/libnl3
LIBS += -L/home/LinuxZn/git_clone/libnl-3.2.23/libnl_build_arm/lib

Next, you also need to specify the pkgconfig path for the libnl library, and the environment variable PKG_CONFIG_PATH stores the pkgconfig package path:

export PKG_CONFIG_PATH=/home/LinuxZn/git_clone/libnl-3.2.23/libnl_build_arm/lib/pkgconfig:$PKG_CONFIG_PATH 

Compile:

make

The compilation may report the following error. At this time, you can comment out the following two sentences in .config:

#CONFIG_CTRL_IFACE_DBUS_NEW=y
#CONFIG_CTRL_IFACE_DBUS_INTRO=y

After the compilation ends, the wpa_supplicant and wpa_cli tools will be generated in the current directory. Copy these two files to the development board’s /usr/bin directory.

First, create a wpa_supplicant.conf file in the development board’s /etc directory, with the following content:

ctrl_interface=/var/run/wpa_supplicant
update_config=1
ctrl_interface_group=root
ap_scan=1
network={
  ssid="ChinaNet-9ee9"
  psk="s6iyvweq"
  key_mgmt=WPA-PSK
}

Next, create the /var/run/wpa_supplicant directory:

mkdir -p /var/run/wpa_supplicant 

Finally, use the following command to connect to WiFi:

wpa_supplicant -Dwext -c /etc/wpa_supplicant.conf -i wlan1&

The output message (wlan1: CTRL-EVENT-CONNECTED) indicates that the connection is successful.

[root@imx6ull:/etc]# [  968.615223] ------------[ cut here ]------------
[  968.622210] WARNING: CPU: 0 PID: 127 at net/wireless/sme.c:733 __cfg80211_connect_result+0x2e4/0x404
[  968.635489] ---[ end trace c94b130fc23cc767 ]---
wlan1: Associated with 28:bf:89:7b:a1:23
wlan1: WPA: Key negotiation compl[  968.655338] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
eted with 28:bf:89:7b:a1:23 [PTK=CCMP GTK=CCMP]
wlan1: CTRL-EVENT-CONNECTED - Connection to 28:bf:89:7b:a1:23 completed [id=0 id_str=]

At this point, the connection is successful, and you can dynamically obtain the IP address.

udhcpc -i wlan1 //-i specifies the network card

Then execute ifconfig to see the wireless network card that has been assigned an IP address. If wlan1 still does not have an IP address, it may be that the obtained IP address has not been written to the network card device.

The IP assigned to our development board is:

How to Remotely Access a Development Board

At this point, if our router can access the internet, we can ping the external network. If the router does not have internet access, we can ping our Ubuntu host for testing. Here, we ping Baidu for testing, indicating that our development board has set up the network environment:

How to Remotely Access a Development Board

Now we can happily play!

SSH Porting

The previous two steps have enabled our development board to have a wireless network environment. It is necessary to set up a practical environment: the SSH environment.

Secure Shell (SSH) is a secure network protocol established on the application layer by IETF (The Internet Engineering Task Force).

It is a protocol designed to provide security for remote login sessions (and can even be used for file transfer between Windows and Linux servers) and other network services, effectively compensating for vulnerabilities in the network. We often use SSH in our work, and the Ubuntu host can conveniently interact with the development board.

Cross-compiling openssh depends on the zlib and openssl libraries, so we need to first cross-compile these two libraries. There are many versions of these libraries, and version mismatch issues may occur. The versions I am using are as follows:

  • openssl-1.0.2
  • zlib-1.2.3
  • openssh-4.6p1

(1) Cross-compile openssl-1.0.2

The cross-compilation of openssl-1.0.2 has been demonstrated above during the compilation of wpa_supplicant-2.9, so it will not be demonstrated here.

(2) Cross-compile zlib-1.2.3

./configure --prefix=/home/LinuxZn/git_clone/zlib-1.2.3/zlib_build_arm

Obtain the Makefile and modify the CC in it to the cross-compiler:

CC=arm-linux-gnueabihf-gcc

CFLAGS=-O3 -DUSE_MMAP
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DDEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
#           -Wstrict-prototypes -Wmissing-prototypes

LDFLAGS=-L. libz.a
LDSHARED=arm-linux-gnueabihf-gcc
CPP=arm-linux-gnueabihf-gcc -E

Then execute:

make
make install

Compile and obtain:

How to Remotely Access a Development Board

(3) Cross-compile openssh-4.6p1

./configure --host=arm-linux-gnueabihf --with-libs --with-zlib=/home/LinuxZn/git_clone/zlib-1.2.3/zlib_build_arm --with-ssl-dir=/home/LinuxZn/git_clone/openssl-1.0.2/openssl_build_arm --disable-etc-default-login CC=/home/LinuxZn/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc AR=/home/LinuxZn/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar
make

Where the meanings of various parameters are as follows:

  • –host indicates the platform on which it runs.

  • –with-libs indicates the required library files.

  • –with-zlib indicates the installation path of the zlib library.

  • –with-ssl-dir indicates the installation path of the openssl files.

  • –disable-etc-default-login indicates not to use the compiler of the current environment variable, so later configuration parameters directly configure CC and AR as these two compilers.

  • CC indicates the compiler to be used.

  • AR indicates the path of the compiler to be used.

Compile:

make

At this time, the tools scp, sftp, ssh, sshd, ssh-add, ssh-agent, etc. will be generated in the openssh-4.6p1 directory:

How to Remotely Access a Development Board

Create three directories on the board: “/usr/libexec”, “/usr/local/etc”, and “/usr/local/bin”:

mkdir -p /usr/libexec /usr/local/etc /usr/local/bin

Then transfer the relevant tools to the development board for backup:

1. Move the generated “scp, sftp, ssh, sshd, ssh-add, ssh-agent, ssh-keygen, ssh-keyscan” executable files from openssh-6.6p1 to the development board’s /usr/local/bin directory, command:

mv scp sftp ssh sshd ssh-add ssh-agent ssh-keygen ssh-keyscan /usr/local/bin/

2. Move “moduli, ssh_config, sshd_config” to the development board’s /usr/local/etc directory.

mv moduli ssh_config sshd_config /usr/local/etc

3. Move “sftp-server, ssh-keysign” to the development board’s /usr/libexec directory.

mv sftp-server ssh-keysign /usr/libexec

4. Use “ssh-keygen” to generate four key files “ssh_host_rsa_key”, “ssh_host_dsa_key”, “ssh_host_ecdsa_key”, and “ssh_host_ed25519_key”. In the openssh-4.6p1 directory, enter the command:

ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""
ssh-keygen -t dsa -f ssh_host_ed25519_key -N ""

After execution, copy the generated files to the development board’s /usr/local/etc/ directory:

  • ssh_host_rsa_key

  • ssh_host_dsa_key

  • ssh_host_ecdsa_key

  • ssh_host_ed25519_key

Then change their permissions to 600.

mv ssh_host_rsa_key ssh_host_dsa_key ssh_host_ecdsa_key ssh_host_ed25519_key /usr/local/etc/
chmod 600 ssh_host_rsa_key ssh_host_dsa_key ssh_host_ecdsa_key ssh_host_ed25519_key

In the development board terminal, use the command vi /etc/passwd to open the ssh key file, and add the following content at the bottom of the /etc/passwd file:

sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

Next, create a root account on the development board using the command:

passwd root

Then run the sshd binary file on the development board, command:

/usr/local/bin/sshd

It may report an error:

/usr/local/bin/sshd: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such file or directory

Copy the relevant libraries from the cross-compiler to the board. Run again, it may report an error:

Could not load host key: /usr/local/etc/ssh_host_key
Disabling protocol version 1. Could not load host key

But it does not affect usage.

Finally, use ssh to log in to our development board from our Ubuntu host. First, ensure that the IP of our Ubuntu host and the IP of the development board are in the same subnet, such as:

Ubuntu IP: 192.168.1.9
Development Board IP: 192.168.1.10

Log in to the development board using the following command in Ubuntu:

How to Remotely Access a Development Board

At this point, our ssh environment has been successfully set up. Then we can happily play!

———— END ————

How to Remotely Access a Development Board

● Column “Embedded Tools”

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials in Embedded Column

Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

How to Remotely Access a Development Board

How to Remotely Access a Development Board

Click “Read the Original” to see more shares.

Leave a Comment

Your email address will not be published. Required fields are marked *