ArduPilot SITL on FreeBSD 15.0 – successful build and a question about porting

Hello,

Over the last few days I have been experimenting with building and running ArduPilot on FreeBSD 15.0.

My goal was to see whether ArduPilot SITL (Software-In-The-Loop) could be used as a development and training platform on FreeBSD without relying on Linux.

The result was surprisingly good.

The following components are working:

  • ArduPilot SITL
  • MAVProxy
  • MAVProxy Console
  • MAVProxy Map
  • GUIDED mode
  • STABILIZE mode
  • MAVLink telemetry
  • AP_Bootloader build
  • STM32 flashing via dfu-util

System used:

Code:
FreeBSD 15.0-RELEASE-p5 amd64
clang 19
Python 3.11

Build issues encountered

ArduPilot contains a few Linux-specific assumptions that prevent it from building on FreeBSD out of the box.

1. libraries/AP_HAL_SITL/UART_utils.cpp

Build failed with:

Code:
fatal error: 'asm/termbits.h' file not found

The code uses Linux-specific interfaces:

Code:
#include <asm/ioctls.h>
#include <asm/termbits.h>

struct termios2
TCGETS2
TCSETS2
BOTHER

FreeBSD does not provide these APIs.

I modified the code to use the existing POSIX termios path:

Code:
#include <sys/ioctl.h>
#include <termios.h>

and standard termios functionality instead of Linux-specific termios2.

Example diff:

Code:
-#include <asm/ioctls.h>
-#include <asm/termbits.h>
+#include <sys/ioctl.h>
+#include <termios.h>

2. libraries/AP_Filesystem/AP_Filesystem_posix.cpp

Build failed with:

Code:
fatal error: 'sys/vfs.h' file not found

On FreeBSD I replaced it with:

Code:
#ifdef __FreeBSD__
#include <sys/param.h>
#include <sys/mount.h>
#else
#include <sys/vfs.h>
#endif

Example diff:

Code:
+#ifdef __FreeBSD__
+#include <sys/param.h>
+#include <sys/mount.h>
+#else
 #include <sys/vfs.h>
+#endif

Bootloader build

While building AP_Bootloader I encountered errors such as:

Code:
struct _reent declared inside parameter list

The issue turned out not to be ArduPilot itself, but the ARM toolchain.

The FreeBSD package:

Code:
/usr/local/bin/arm-none-eabi-gcc
and
Code:
export PATH=/usr/local/gcc-arm-embedded-14.2.rel1/bin:$PATH
export MAKE=gmake

was built with:

Code:
--without-headers

and therefore lacks the required newlib headers.

After switching to:

Code:
/usr/local/gcc-arm-embedded-14.2.rel1/bin/arm-none-eabi-gcc

the bootloader built successfully without any source code modifications.

Python dependencies

Installed via pip:

Code:
MAVProxy
pymavlink
dronecan
empy
fastcrc
geocoder
pexpect
pyserial
pynmeagps

Installed via pkg:

Code:
opencv
proj
git 
gmake 
python 
py311-pip 
py311-sqlite3

The MAVProxy map module initially failed because OpenCV was missing:

Code:
ModuleNotFoundError: No module named 'cv2'

After installing OpenCV, the map module loaded successfully.

Result

ArduPilot SITL is now running correctly on FreeBSD.

Example commands tested successfully:

Code:
mode guided
arm throttle
takeoff 20
velocity 1 0 0
mode land
link files
Code:
sudo ln -s /usr/local/bin/python3.11 /usr/local/bin/python
sudo ln -s /usr/local/bin/python3.11 /usr/local/bin/python3

MAVProxy Console and Map are both operational.

Question to the FreeBSD community

Would there be any interest in creating a proper FreeBSD port for ArduPilot SITL?

At least for my setup, only two relatively small source code changes were required to get SITL running.

I would be interested in hearing opinions about:

  • Creating a FreeBSD port for ArduPilot SITL
  • Adding official FreeBSD support upstream
  • Maintaining a small FreeBSD compatibility patch set

Perhaps there are already users running ArduPilot or PX4 on FreeBSD who could share their experience.

Thank you.
 

Attachments

  • sitl.jpg
    sitl.jpg
    326.2 KB · Views: 9
  • sitlmap.jpg
    sitlmap.jpg
    329.7 KB · Views: 6
I performed some additional testing after my original post.

Using the same FreeBSD 15.0 setup and the two compatibility patches mentioned above, I was able to build the following ArduPilot vehicle targets successfully:

Code:
./waf plane
./waf rover
./waf sub
./waf heli
./waf blimp

Усі вони були успішно завершені без необхідності будь-яких додаткових змін вихідного коду.
Code:
Tools/autotest/sim_vehicle.py -v Rover --console --map

I also tested an embedded target and successfully built ArduCopter firmware for a SpeedyBee F405 V3 flight controller:

[code]
./waf configure --board speedybeef4v3
./waf copter

Generated files:

Code:
BUILD SUMMARY
Build directory: /home/res2500/code/ardupilot/build/speedybeef4v3
Target          Text (B)  Data (B)  BSS (B)  Total Flash Used (B)  Free Flash (B)  External Flash Used (B)
----------------------------------------------------------------------------------------------------------
bin/arducopter    858612      3060    81320                861672          137748  Not Applicable        

'copter' finished successfully (6m26.456s)
res2500@:~/code/ardupilot $ ll build/speedybeef4v3/bin/
total 3592
drwxr-xr-x   2 res2500 res2500 -     512 12 черв. 17:11 ./
drwxr-xr-x  10 res2500 res2500 -    1024 12 черв. 17:11 ../
-rw-r--r--   1 res2500 res2500 -   13701  5 черв. 20:43 AP_Bootloader.apj
-rwxr-xr-x   1 res2500 res2500 -   13840  5 черв. 20:43 AP_Bootloader.bin*
-rwxr-xr-x   1 res2500 res2500 - 1861168 12 черв. 17:11 arducopter*
-rw-r--r--   1 res2500 res2500 -  785130 12 черв. 17:11 arducopter.apj
-rwxr-xr-x   1 res2500 res2500 -  861676 12 черв. 17:11 arducopter.bin*

Important note regarding the ARM toolchain:

The FreeBSD arm-none-eabi-gcc package was not sufficient for building AP_Bootloader because it was built without the required newlib headers.

I used the ARM GNU Embedded Toolchain instead:

Code:
export PATH=/usr/local/gcc-arm-embedded-14.2.rel1/bin:$PATH
export MAKE=gmake

Verification:

Code:
which arm-none-eabi-gcc
arm-none-eabi-gcc --version

After switching to the ARM GNU Embedded Toolchain, both AP_Bootloader and embedded firmware targets built successfully.

At this point I have successfully tested:

Code:
SITL:
- ArduCopter
- ArduPlane
- Rover
- ArduSub
- Heli
- Blimp

Embedded:
- AP_Bootloader
- SpeedyBee F405 V3 (ArduCopter)

Єдиними змінами вихідного коду, які були потрібні, були два виправлення сумісності з FreeBSD, описані в оригінальному дописі.
Testing is still ongoing. The next step is testing with the QGroundControl ground station.
 
Back
Top