Without further ado, let’s get to the point. Last year, I made a small news about getting the latest version of Arduino IDE running on Loongson Fedora 21, but later I found that the serial monitor and serial plotter were completely unusable, which made it very inconvenient to debug Arduino boards on Loongson computers. A few days ago, I tinkered with it again on Loongson and finally solved all the issues. Now, let me talk about the entire porting process (this post aims to inspire discussion; if there are any shortcomings, please point them out for correction).
The Fedora 21/25 software repository also provides the Arduino IDE package, but the version is really too old. In addition, Arduino IDE is open-source software, and most of the code is written in Java. According to Java’s “compile once, run anywhere” feature, here we only modify the pre-compiled compressed package. Interested friends can compile from the source code and then make modifications.
Testing Environment:Loongson 3A1000 + Fedora 21, Fedora 25
1. Preliminary Preparation
First, we need to download the pre-compiled version. Download link: www.arduino.cc/en/Main/Software, choose to download the Linux 64 bits package. After downloading, use the command tar -xvf to unzip the compressed package, and then use the cd command to enter that folder.
2. Remove X86_64 related binary files
Delete the java folder to remove the Java files for x64. Then delete the executable files arduino-builder, tools/ctags/5.8-arduino11/ctags; hardware/tools/avr directory, and the library files lib/liblistSerialsj.so and lib/libastylej.so.
3. Compile required library files
Step 2 removed the two library files liblistSerialsj.so and astylej.so for the X64 platform; now we need to provide these two library files for the Loongson platform.
First, compile the required liblistSerialsj.so, ensuring that the Loongson computer has git and java-devel installed.
git clone https://github.com/facchinm/listSerialPortsC –recursive
cd listSerialPortsC
Open compile_linux.sh and change the JAVA_INCLUDE_PATH line to
JAVA_INCLUDE_PATH=/usr/lib/jvm/java-1.8.0/include/
Additionally, since we are using a 64-bit operating system, there is no need to compile this library for 32-bit systems and ARM platforms, so we need to delete the line mkdir -p distrib/linux32 and all subsequent lines from compile_linux.sh. Then execute compile_linux.sh to complete the compilation, and copy the generated library file distrib/linux64/liblistSerialsj.so to the lib directory under the Arduino IDE directory.
sh compile_linux.sh
cp distrib/linux64/liblistSerialsj.so ~/arduino-1.8.2/lib/
For astylej.so, it can be provided by the system’s astyle software package. Use the yum package manager to install astyle, and then copy /usr/lib64/libastyle-2.04.so to the lib folder of the Arduino IDE directory and rename it to libastylej.so.
yum install astyle
cp /usr/lib64/libastyle-2.04.so ~/arduino-1.8.2/lib/libastylej.so // This command is only for Fedora 21 system; modify according to the actual situation for Fedora 25.
4. Compile arduino-builder
Please ensure that the golang compiler is installed! After compilation, copy the generated arduino-builder binary file to the Arduino IDE directory.
git clone https://github.com/arduino/arduino-builder/
cd arduino-builder
export GOPATH=$(pwd) // Set the GOPATH variable
go get github.com/go-errors/errors
go get github.com/stretchr/testify
go get github.com/jstemmer/go-junit-report
go build arduino.cc/arduino-builder
cp arduino-builder ~/arduino-1.8.2/
5. Compile ctags
The ctags in the Fedora 21 software repository does not support Arduino, so we must use the ctags provided by Arduino official.
git clone https://github.com/arduino/ctags
cd ctags
sh configure
make -j4
cp ctags ~/arduino-1.8.2/tools-builder/ctags/5.8-arduino11/
6. Modify configuration files
Use the toolchain and avrdude flashing tool provided by the system.
cd ~/arduino-1.8.2/hardware/arduino/avr/
Use a text editor to open platform.txt, and modify the contents as follows:
diff –git a/platform.txt b/platform.txt
index 3985678..b2ad919 100644
— a/platform.txt
+++ b/platform.txt
@@ -18,6 +18,7 @@ compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra
# Default “compiler.path” is correct, change only if you want to override the initial value
+runtime.tools.avr-gcc.path=/usr
compiler.path={runtime.tools.avr-gcc.path}/bin/
compiler.c.cmd=avr-gcc
compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects
@@ -91,9 +92,9 @@ recipe.preproc.macros=”{compiler.path}{compiler.cpp.cmd}” {compiler.cpp.flags} {
# AVR Uploader/Programmers tools
# ——————————
-tools.avrdude.path={runtime.tools.avrdude.path}
-tools.avrdude.cmd.path={path}/bin/avrdude
-tools.avrdude.config.path={path}/etc/avrdude.conf
+tools.avrdude.path=/
+tools.avrdude.cmd.path={path}usr/bin/avrdude
+tools.avrdude.config.path={path}etc/avrdude/avrdude.conf
tools.avrdude.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
7. Fix the issue of the serial monitor/plotter not working
The jssc module in the Arduino IDE does not work properly on the Loongson platform, causing the serial monitor/plotter to be unusable or even unable to select the port for the development board. Therefore, we need to compile the jssc from the Fedora 25 software repository to replace the jssc module in the Arduino IDE.
wget http://mirrors.ustc.edu.cn/fedora/releases/25/Everything/source/tree/Packages/j/jssc-2.8.0-5.fc24.src.rpm
rpmbuild –clean –rebuild jssc-2.8.0-5.fc24.src.rpm
sudo yum install rpmbuild/RPMS/mips64el/jssc-2.8.0-5.fc21.loongson.mips64el.rpm
cp /usr/lib/java/jssc.jar ~/arduino-1.8.2/lib/jssc-2.8.0.jar
8. Upgrade toolchain (only for Fedora 21 system)
Under Fedora 21, when compiling programs, an error “this program has been built without plugin support” will occur. Upgrading avr-binutils will resolve this. Here, we choose to use the srpm from the Fedora 25 software repository for compilation and installation for easier management.
First, install the rpm packaging tool rpm-build, then download the srpm of avr-binutils for packaging and installation.
wget http://mirrors.ustc.edu.cn/fedora/releases/25/Everything/source/tree/Packages/a/avr-binutils-2.26-1.fc25.src.rpm
rpmbuild –rebuild –clean avr-binutils-2.26-1.fc25.src.rpm
sudo yum install ~/rpmbuild/RPMS/mips64el/avr-binutils-2.26-1.fc21.loongson.mips64el.rpm
At this point, the entire porting task is complete. We can install the toolchain and flashing tools using the following command to connect our Arduino development board, open the Arduino IDE for development.
sudo yum install avr-libc avr-gcc avrdude avr-binutils
In the Arduino IDE directory, you can execute the install.sh script to add a launcher to the startup menu, and later you can find the Arduino IDE startup menu in Applications -> Programming. Additionally, to ensure the current user has permission to read and write to the device, use the following command to add the user to the dialout group, log out and log back in.
usermod -a -G dialout USER
This article is from: Loongson Open Source Community Author: luoxiao95
Leave a Comment
Your email address will not be published. Required fields are marked *