This article is about setting up an environment for enbedded Linux application development for loongson. The resulting environment enables cross-platform application development for Loongson mipsel-based SOMs/COMs using Ubuntu18.04 for application development.
Communicate with loongson development board using USB cable
The first thing we need to do is communicating with hardware using USB cable.The boards are equipped with PL2303-based device. To be able to talk to an application, our machine must have appropriate PL2303 drivers. Fortunately, Ubuntu18.04 is default equipped with the PL2030 drivers(we could use lsmod | grep pl2303
to check it). The only thing necessary is to check whether the Ubuntu machine can communicate over USB with the attached loongson development board.
To do this:
- Connect the PC via an USB cable to the USB UART port of the loongson development board.
- Turn the board on.
Note the correspondence between the colored cable and thier pinout:
- Black wire(GND)
- Green wire(RX)
- White wire(TX)
Use lsusb
command to list the usb devices connected to our machine. The output text of this command in terminal is something like this:
1 | Bus 001 Device 007: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller |
This shows that the PL2303 devices on the development board has been detected and that the drivers on the PC are running. To find out what RS232(UART) port is used by the USB driver, type:
1 | dmesg | grep -ie PL2303 |
The return message:
1 | [ 8907.910272] usbcore: registered new interface driver pl2303 |
The message tells us where the driver connects to a TTY port, in this case, usb 1-1.1: pl2303 converter now attached to ttyUSB0
.
picocom
Picocom is a minimal dumb-terminal emulation program that is great for accessing a serial port based Linux console; which is typical done when developing an embedded Linux based product.
Install picocom with this command:
1 | sudo apt-get install picocom |
Now, we know the serial port, set the speed to 115200 baud.
1 | sudo picocom -b 115200 /dev/ttyUSB0 |
Now, we can communicate with the board.
1 | picocom v2.2 |
Cross Compile
Now we should install the cross tool chain. I download the mips-loongson-gcc4.9-2019.08-05.linux-gnu.tar.gz
from the loongson website. Unpack the tar.xz file and move it to the /opt
. Export the environment variables by adding the following lines into the ~/.bashrc
:
1 | export PATH="/opt/gcc-4.3-ls232/bin:$PATH" |
Don’t forget to run command source ~/.bashrc
.
Now, we could compile a.c
:
1 | $ mipsel-linux-gnu-gcc a.c |
tftp server
On ubuntu, run sudo apt-get install tftpd-hpa tftp-hpa
. Then edit the /etc/default/tftpd-hap
:
1 | # /etc/default/tftpd-hpa |
Create file /etc/xinetd.d/tftp
with the following contents:
1 | service tftp |
Create directory /home/readlnh/tftpboot
and set its permissions:
1 | $ sudo mkdir /home/readlnh/tftpboot |
Restart the xinetd
service:
1 | $ sudo service xinetd restart |
We could use ifconfig
to get the ip address of our host machine. Make sure that ethernet cable is plugged into the board and a dhcp server is running in either your host machine or your router. In this case, my host machine’s ip address is 192.168.1.230
. Run ifconfig
to set the ip address of the board to make sure the address fall into the same subnet, here I set it 192.168.1.108
.
Now, we could ping
our host machine by ping 192.168.1.230
:
1 | PING 192.168.1.230 (192.168.1.230): 56 data bytes |
Download the a.out
we compiled before by tftp -r a.out -g 192.168.1.230
:
1 | a.out 100% |*******************************| 7796 0:00:00 ETA |
Run the a.out
:
1 | [root@Loongson:/]#chmod u+x a.out |
Hints
Loongson only provide gcc4.9
for LSC1C0300B, howerver, the mipsel-linux-gnu-gcc
in Ubuntu apt source also works well.