开源RTOS(实时操作系统):nuttx 编译
开源RTOS(实时操作系统):nuttx 编译
手册:Installing — NuttX latest documentation
源码:GitHub - apache/nuttx: Apache NuttX is a mature, real-time embedded operating system (RTOS)
Installing
The first step to get started with NuttX is to install a series of required tools, a toolchain for the architecture you will be working with and, finally, download NuttX source code itself.
Prerequisites
First, install the following set of system dependencies according to your Operating System:
Linux (debian based)Linux (Fedora / RPM based)macOSWindows / WSLWindows/Cygwin
Run the following command to install packages:
$ sudo apt install \ $ bison flex gettext texinfo libncurses5-dev libncursesw5-dev xxd \ $ git gperf automake libtool pkg-config build-essential gperf genromfs \ $ libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ $ libexpat1-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux
KConfig frontend
NuttX configuration system uses KConfig which is exposed via a series of interactive menu-based frontends, part of the kconfig-frontends
package. Depending on your OS you may use a precompiled package or you will have to build it from source, which is available in the NuttX tools repository:
Ubuntu 20.04 LTS and laterUbuntu 18.04 LTS and earlierFedoramacOS
$ sudo apt install kconfig-frontends
NuttX also supports kconfiglib by default, which is a Kconfig tool implemented in Python 2/3. Compared with kconfig-frontends
, kconfiglib provides NuttX with the possibility of multi-platform support(configure NuttX in Windows native/Visual Studio), and also kconfiglib
has a stronger Kconfig syntax check, this will help developers to avoid some Kconfig syntax errors. Install kconfiglib via following command:
sudo apt install python3-kconfiglib
If you are a working on Windows, which also need the support of windows-curses:
pip install windows-curses
Toolchain
To build Apache NuttX you need the appropriate toolchain according to your target platform. Some Operating Systems such as Linux distribute toolchains for various architectures. This is usually an easy choice however you should be aware that in some cases the version offered by your OS may have problems and it may be better to use a widely used build from another source.
The following example shows how to install a toolchain for ARM architecture:
Ubuntu (deb)macOSFrom arm.com
$ sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
Tip
There are hints on how to get the latest tool chains for most supported architectures in the Apache NuttX CI helper script and Docker container
Todo
Required toolchain should be part of each arch documentation (see relevant issue).
Download NuttX
Apache NuttX is actively developed on GitHub. There are two main repositories, nuttx and apps, where the latter is technically optional (but recommended for complete set of features). If you intend to contribute changes, you need the absolute latest version or you simply prefer to work using git, you should clone these repositories (recommended). Otherwise you can choose to download any stable release archive.
Clone git repositoriesDownload stable release
$ mkdir nuttxspace $ cd nuttxspace $ git clone https://github.com/apache/nuttx.git nuttx $ git clone https://github.com/apache/nuttx-apps apps
The development source code is also available as a compressed archive, should you need it:
$ mkdir nuttxspace $ cd nuttxspace $ curl -L https://github.com/apache/nuttx/tarball/master -o nuttx.tar.gz $ curl -L https://github.com/apache/nuttx-apps/tarball/master -o apps.tar.gz $ tar zxf nuttx.tar.gz --one-top-level=nuttx --strip-components 1 $ tar zxf apps.tar.gz --one-top-level=apps --strip-components 1
There are also .zip
archives available (useful for Windows users): just replace tarball
with zipball
.
在Windows10的WSL Ubuntu22.04环境下实践安装Nuttx
首先进入WSL
安装基本库
sudo apt install \
bison flex gettext texinfo libncurses5-dev libncursesw5-dev xxd \
git gperf automake libtool pkg-config build-essential gperf genromfs \
libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \
libexpat1-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux
安装KConfig frontend
sudo apt install kconfig-frontends
安装工具链
sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
这个占用空间较大,需要2.5G空间
下载源代码
mkdir nuttxspace
cd nuttxspace
git clone https://github.com/apache/nuttx.git nuttx
git clone https://github.com/apache/nuttx-apps apps
如果github抽风,可以使用镜像加速
使用make进行编译
初始化配置
cd nuttx
./tools/configure.sh -L | less
哇塞,这个支持的实在太多了!光esp的就这么多:
esp32c3-devkit:efuseesp32c3-devkit:watchdogesp32c3-devkit:pwmesp32c3-devkit:gdbstubesp32c3-devkit:moduleesp32c3-devkit:watcheresp32c3-devkit:wifiesp32c3-devkit:romfsesp32c3-devkit:ticklessesp32c3-devkit:coremarkesp32c3-devkit:sotestesp32c3-devkit:bmp180esp32c3-devkit:randomesp32c3-devkit:rtcesp32c3-devkit:bleesp32c3-devkit:twaiesp32c3-devkit:ostestesp32c3-devkit:usbconsoleesp32c3-devkit:autopmesp32c3-devkit:oneshotesp32c3-devkit:pmesp32c3-devkit:knshesp32c3-devkit:gpioesp32c3-devkit:nvcfgdataesp32c3-devkit:sta_softapesp32c3-devkit:nshesp32c3-devkit:lvglesp32c3-devkit:timeresp32c3-devkit:mcuboot_slot_confirmesp32c3-devkit:cxxesp32c3-devkit:spiflashesp32c3-devkit:cryptoesp32c3-devkit:uidesp32c3-devkit:elfesp32c3-devkit:adcesp32c3-devkit-rust-1:nshesp32c3-devkit-rust-1:brickmatchesp32h2-devkit:i2cesp32h2-devkit:efuseesp32h2-devkit:watchdogesp32h2-devkit:pwmesp32h2-devkit:timersesp32h2-devkit:ticklessesp32h2-devkit:i2scharesp32h2-devkit:bmp180esp32h2-devkit:spiesp32h2-devkit:randomesp32h2-devkit:rtcesp32h2-devkit:buttonsesp32h2-devkit:twaiesp32h2-devkit:ostestesp32h2-devkit:qencoderesp32h2-devkit:captureesp32h2-devkit:usbconsoleesp32h2-devkit:motoresp32h2-devkit:gpioesp32h2-devkit:nshesp32h2-devkit:temperature_sensoresp32h2-devkit:rmtesp32h2-devkit:spiflashesp32h2-devkit:sdmesp32h2-devkit:mcuboot_nshesp32h2-devkit:adcesp32c3-xiao:wifiesp32c3-xiao:bleesp32c3-xiao:usbnshesp32c3-xiao:gpioesp32c3-xiao:nshesp32c3-generic:i2cesp32c3-generic:efuseesp32c3-generic:watchdogesp32c3-generic:pwmesp32c3-generic:timersesp32c3-generic:nimbleesp32c3-generic:wifiesp32c3-generic:ticklessesp32c3-generic:i2scharesp32c3-generic:bmp180esp32c3-generic:spiesp32c3-generic:randomesp32c3-generic:rtcesp32c3-generic:buttonsesp32c3-generic:bleesp32c3-generic:twaiesp32c3-generic:ostestesp32c3-generic:usbconsoleesp32c3-generic:gpioesp32c3-generic:sta_softapesp32c3-generic:nshesp32c3-generic:temperature_sensoresp32c3-generic:rmtesp32c3-generic:spiflashesp32c3-generic:sdmesp32c3-generic:mcuboot_nshesp32c3-generic:adcesp32c6-devkitm:i2cesp32c6-devkitm:efuseesp32c6-devkitm:watchdogesp32c6-devkitm:pwmesp32c6-devkitm:timersesp32c6-devkitm:wifiesp32c6-devkitm:ticklessesp32c6-devkitm:i2scharesp32c6-devkitm:bmp180esp32c6-devkitm:spiesp32c6-devkitm:randomesp32c6-devkitm:rtcesp32c6-devkitm:buttonsesp32c6-devkitm:spislvesp32c6-devkitm:twaiesp32c6-devkitm:ostestesp32c6-devkitm:usbconsoleesp32c6-devkitm:gpioesp32c6-devkitm:sta_softapesp32c6-devkitm:nshesp32c6-devkitm:rmtesp32c6-devkitm:spiflashesp32c6-devkitm:mcuboot_nshesp32c6-devkitc:i2cesp32c6-devkitc:efuseesp32c6-devkitc:watchdogesp32c6-devkitc:pwmesp32c6-devkitc:timersesp32c6-devkitc:mpu60x0esp32c6-devkitc:wifiesp32c6-devkitc:ticklessesp32c6-devkitc:i2scharesp32c6-devkitc:bmp180esp32c6-devkitc:spiesp32c6-devkitc:randomesp32c6-devkitc:rtcesp32c6-devkitc:buttonsesp32c6-devkitc:spislvesp32c6-devkitc:twaiesp32c6-devkitc:ostestesp32c6-devkitc:qencoderesp32c6-devkitc:captureesp32c6-devkitc:usbconsoleesp32c6-devkitc:motoresp32c6-devkitc:gpioesp32c6-devkitc:sta_softapesp32c6-devkitc:nshesp32c6-devkitc:temperature_sensoresp32c6-devkitc:rmtesp32c6-devkitc:spiflashesp32c6-devkitc:sdmesp32c6-devkitc:mcuboot_nshesp32c6-devkitc:adcesp32c6-xiao:wifiesp32c6-xiao:usbnshesp32c6-xiao:gpioesp32c6-xiao:nshesp32s3-eye:i2cesp32s3-eye:wifiesp32s3-eye:usbnshesp32s3-eye:gpioesp32s3-eye:nshesp32s3-eye:lcdesp32s3-lcd-ev:buttonsesp32s3-lcd-ev:ws2812esp32s3-lcd-ev:audioesp32s3-lcd-ev:nshesp32s3-lcd-ev:lcdesp32s3-lcd-ev:lvglesp32s3-lhcbit:usbnshesp32s3-korvo-2:rtptoolsesp32s3-korvo-2:sdmmcesp32s3-korvo-2:audioesp32s3-korvo-2:nshesp32s3-box:lvgl-3esp32s3-box:buttonsesp32s3-box:nshesp32s3-box:touchscreenesp32s3-box:lvglesp32s3-devkit:psram_octalesp32s3-devkit:i2cesp32s3-devkit:watchdogesp32s3-devkit:pwmesp32s3-devkit:nxlooperesp32s3-devkit:usb_deviceesp32s3-devkit:wifiesp32s3-devkit:pythonesp32s3-devkit:qemu_toywasmesp32s3-devkit:sdmmcesp32s3-devkit:ticklessesp32s3-devkit:psram_quadesp32s3-devkit:ksta_softapesp32s3-devkit:coremarkesp32s3-devkit:sotestesp32s3-devkit:i2scharesp32s3-devkit:spiesp32s3-devkit:randomesp32s3-devkit:smpesp32s3-devkit:qemu_openethesp32s3-devkit:rtcesp32s3-devkit:buttonsesp32s3-devkit:bleesp32s3-devkit:twaiesp32s3-devkit:qencoderesp32s3-devkit:audioesp32s3-devkit:captureesp32s3-devkit:txtableesp32s3-devkit:usbnshesp32s3-devkit:psram_usrheapesp32s3-devkit:oneshotesp32s3-devkit:adbesp32s3-devkit:pmesp32s3-devkit:knshesp32s3-devkit:motoresp32s3-devkit:blewifiesp32s3-devkit:gpioesp32s3-devkit:sta_softapesp32s3-devkit:nshesp32s3-devkit:usbmscesp32s3-devkit:qemu_debugesp32s3-devkit:temperature_sensoresp32s3-devkit:timeresp32s3-devkit:rmtesp32s3-devkit:eth_lan9250esp32s3-devkit:stackesp32s3-devkit:cxxesp32s3-devkit:spiflashesp32s3-devkit:sdmesp32s3-devkit:toywasmesp32s3-devkit:mcuboot_nshesp32s3-devkit:elfesp32s3-devkit:fastbootesp32s3-devkit:adcesp32s3-xiao:usbnshesp32s3-xiao:comboesp32s3-meadow:usbnshesp32s3-meadow:nshlckfb-szpi-esp32s3:pwmlckfb-szpi-esp32s3:usb_devicelckfb-szpi-esp32s3:pca9557lckfb-szpi-esp32s3:txtablelckfb-szpi-esp32s3:adblckfb-szpi-esp32s3:gpiolckfb-szpi-esp32s3:nshlckfb-szpi-esp32s3:psramlckfb-szpi-esp32s3:lcdlckfb-szpi-esp32s3:lvgllckfb-szpi-esp32s3:fastbootesp32-wrover-kit:nxesp32-wrover-kit:wifiesp32-wrover-kit:ledsesp32-wrover-kit:lcd1602esp32-wrover-kit:bmp180esp32-wrover-kit:rtcesp32-wrover-kit:buttonsesp32-wrover-kit:autopmesp32-wrover-kit:oneshotesp32-wrover-kit:luaesp32-wrover-kit:mmcsdspiesp32-wrover-kit:gpioesp32-wrover-kit:nshesp32-wrover-kit:lvglesp32-devkitc:efuseesp32-devkitc:watchdogesp32-devkitc:ms5611esp32-devkitc:pwmesp32-devkitc:nxlooperesp32-devkitc:mcuboot_update_agentesp32-devkitc:modbusesp32-devkitc:softapesp32-devkitc:moduleesp32-devkitc:nxdiagesp32-devkitc:watcheresp32-devkitc:wifiesp32-devkitc:ticklessesp32-devkitc:coremarkesp32-devkitc:mcp2515esp32-devkitc:wifishareesp32-devkitc:ledsesp32-devkitc:sotestesp32-devkitc:mqttcesp32-devkitc:i2scharesp32-devkitc:bmp280esp32-devkitc:max6675esp32-devkitc:randomesp32-devkitc:smpesp32-devkitc:qemu_openethesp32-devkitc:rtcesp32-devkitc:buttonsesp32-devkitc:wamr_wasi_debugesp32-devkitc:bleesp32-devkitc:twaiesp32-devkitc:ostestesp32-devkitc:qencoderesp32-devkitc:audioesp32-devkitc:captureesp32-devkitc:dacesp32-devkitc:autopmesp32-devkitc:snakeesp32-devkitc:psram_usrheapesp32-devkitc:oneshotesp32-devkitc:pmesp32-devkitc:knshesp32-devkitc:motoresp32-devkitc:wifi_smpesp32-devkitc:blewifiesp32-devkitc:espnowesp32-devkitc:sta_softapesp32-devkitc:nshesp32-devkitc:psramesp32-devkitc:timeresp32-devkitc:mcuboot_slot_confirmesp32-devkitc:rmtesp32-devkitc:cxxesp32-devkitc:spiflashesp32-devkitc:sdmesp32-devkitc:wifinshesp32-devkitc:mcuboot_nshesp32-devkitc:elfesp32-devkitc:brickmatchesp32-devkitc:adcttgo_lora_esp32:sx127xttgo_lora_esp32:nshttgo_t_display_esp32:lvgl_fbttgo_t_display_esp32:nshttgo_t_display_esp32:lvgl_lcdesp32-audio-kit:wifiesp32-audio-kit:audioesp32-audio-kit:nshesp32-pico-kit:nshesp32-2432S028:nshesp32-2432S028:lvglesp32-ethernet-kit:ethernetesp32-ethernet-kit:wifiesp32-ethernet-kit:rtcesp32-ethernet-kit:buttonsesp32-ethernet-kit:autopmesp32-ethernet-kit:oneshotesp32-ethernet-kit:nshesp32-sparrow-kit:wifiesp32-sparrow-kit:mqttcesp32-sparrow-kit:nshesp32-lyrat:nxrecorderesp32-lyrat:rtptoolsesp32-lyrat:wifiesp32-lyrat:buttonsesp32-lyrat:audioesp32-lyrat:mmcsdspiesp32-lyrat:nshesp32s2-kaluga-1:i2cesp32s2-kaluga-1:watchdogesp32s2-kaluga-1:nxlooperesp32s2-kaluga-1:rtcesp32s2-kaluga-1:buttonsesp32s2-kaluga-1:twaiesp32s2-kaluga-1:audioesp32s2-kaluga-1:nshesp32s2-kaluga-1:lvgl_ili9341esp32s2-kaluga-1:lvgl_st7789esp32s2-saola-1:i2cesp32s2-saola-1:watchdogesp32s2-saola-1:pwmesp32s2-saola-1:nxlooperesp32s2-saola-1:wifiesp32s2-saola-1:coremarkesp32s2-saola-1:sotestesp32s2-saola-1:i2scharesp32s2-saola-1:randomesp32s2-saola-1:rtcesp32s2-saola-1:buttonsesp32s2-saola-1:twaiesp32s2-saola-1:ostestesp32s2-saola-1:qencoderesp32s2-saola-1:audioesp32s2-saola-1:oneshotesp32s2-saola-1:gpioesp32s2-saola-1:sta_softapesp32s2-saola-1:nshesp32s2-saola-1:temperature_sensoresp32s2-saola-1:timeresp32s2-saola-1:rmtesp32s2-saola-1:cxxesp32s2-saola-1:spiflashesp32s2-saola-1:sdmesp32s2-saola-1:mcuboot_nshesp32s2-saola-1:adc
列出所有的esp32c3
./tools/configure.sh -L |grep esp32c3esp32c3-devkit:efuseesp32c3-devkit:watchdogesp32c3-devkit:pwmesp32c3-devkit:gdbstubesp32c3-devkit:moduleesp32c3-devkit:watcheresp32c3-devkit:wifiesp32c3-devkit:romfsesp32c3-devkit:ticklessesp32c3-devkit:coremarkesp32c3-devkit:sotestesp32c3-devkit:bmp180esp32c3-devkit:randomesp32c3-devkit:rtcesp32c3-devkit:bleesp32c3-devkit:twaiesp32c3-devkit:ostestesp32c3-devkit:usbconsoleesp32c3-devkit:autopmesp32c3-devkit:oneshotesp32c3-devkit:pmesp32c3-devkit:knshesp32c3-devkit:gpioesp32c3-devkit:nvcfgdataesp32c3-devkit:sta_softapesp32c3-devkit:nshesp32c3-devkit:lvglesp32c3-devkit:timeresp32c3-devkit:mcuboot_slot_confirmesp32c3-devkit:cxxesp32c3-devkit:spiflashesp32c3-devkit:cryptoesp32c3-devkit:uidesp32c3-devkit:elfesp32c3-devkit:adcesp32c3-devkit-rust-1:nshesp32c3-devkit-rust-1:brickmatchesp32c3-xiao:wifiesp32c3-xiao:bleesp32c3-xiao:usbnshesp32c3-xiao:gpioesp32c3-xiao:nshesp32c3-generic:i2cesp32c3-generic:efuseesp32c3-generic:watchdogesp32c3-generic:pwmesp32c3-generic:timersesp32c3-generic:nimbleesp32c3-generic:wifiesp32c3-generic:ticklessesp32c3-generic:i2scharesp32c3-generic:bmp180esp32c3-generic:spiesp32c3-generic:randomesp32c3-generic:rtcesp32c3-generic:buttonsesp32c3-generic:bleesp32c3-generic:twaiesp32c3-generic:ostestesp32c3-generic:usbconsoleesp32c3-generic:gpioesp32c3-generic:sta_softapesp32c3-generic:nshesp32c3-generic:temperature_sensoresp32c3-generic:rmtesp32c3-generic:spiflashesp32c3-generic:sdmesp32c3-generic:mcuboot_nshesp32c3-generic:adc
配置 esp32c3-devkit:nsh
cd nuttx
./tools/configure.sh -l esp32c3-devkit:nsh
完成显示:
configuration written to .config
make menuconfig
cd nuttx
make menuconfig
出现菜单界面
对于ammy 也就是Ubuntu 22.04版本,需要加上参数make CONFIG_LIBM=y
在library Routines里加上本地math库的支持:
选择-> Library Routines (库函数) -> Select math library (Math library from NuttX) -> Math library from NuttX
设好后,保存退出
make
make
make输出
make
Create version.h
LN: platform/board to /home/skywalk/github/nuttxspace/apps/platform/dummy
Register: dd
Register: dumpstack
Register: nsh
Register: sh
CPP: /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld.tmCPP: /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld.tmCPP: /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sections.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sectioLD: nuttx
Memory region Used Size Region Size %age Used
iram0_0_seg: 6624 B 321296 B 2.06%
irom0_0_seg: 107028 B 4194272 B 2.55%
dram0_0_seg: 13792 B 321296 B 4.29%
drom0_0_seg: 147892 B 4194272 B 3.53%
rtc_seg: 0 GB 8 KB 0.00%
CP: nuttx.hex
MKIMAGE: ESP32-C3 binary
esptool.py not found. Please run: 'pip install esptool'
Run make again to create the nuttx.bin image.
make: *** [tools/Unix.mk:559: nuttx] Error 1
按照提示,安装esptool
pip install esptool
然后再make
输出:
LD: nuttx
Memory region Used Size Region Size %age Usediram0_0_seg: 6624 B 321296 B 2.06%irom0_0_seg: 107028 B 4194272 B 2.55%dram0_0_seg: 13792 B 321296 B 4.29%drom0_0_seg: 147892 B 4194272 B 3.53%rtc_seg: 0 GB 8 KB 0.00%
CP: nuttx.hex
MKIMAGE: ESP32-C3 binary
esptool.py -c esp32c3 elf2image -fs 4MB -fm dio -ff 40m -o nuttx.bin nuttx
esptool.py v4.8.1
Creating esp32c3 image...
Merged 1 ELF section
Successfully created esp32c3 image.
Generated: nuttx.bin (ESP32-C3 compatible)
使用Cmake
先安装cmake
sudo apt isntall cmake
cd nuttx
cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja
cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja
配置管理
cmake --build build -t menuconfig
cmake失败
烧录
烧录之前安装esptool工具
pip install esptool
使用这条命令:
esptool --chip esp32c3 --port com3 --baud 460800 write_flash -z 0x0 E:\tmp\nuttx.bin
显示:
esptool --chip esp32c3 --port com3 --baud 460800 write_flash -z 0x0 E:\tmp\nuttx.bin
esptool.py v4.8.1
Serial port com3
Connecting...
Failed to get PID of a device on com3, using standard reset sequence.
.
Chip is ESP32-C3 (QFN32) (revision v0.4)
Features: WiFi, BLE
Crystal is 40MHz
MAC: e4:b0:63:22:df:68
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x0002afff...
Compressed 172640 bytes to 81799...
Wrote 172640 bytes (81799 compressed) at 0x00000000 in 2.3 seconds (effective 610.2 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
也不知道是否成功了...
至少生成了文件:
-rwxr-xr-x 1 skywalk skywalk 2808092 May 17 19:08 nuttx
-rw-r--r-- 1 skywalk skywalk 172640 May 17 19:08 nuttx.bin
-rw-r--r-- 1 skywalk skywalk 369186 May 17 19:08 nuttx.hex
-rw-r--r-- 1 skywalk skywalk 47 May 17 19:08 nuttx.manifest
-rw-r--r-- 1 skywalk skywalk 1660487 May 17 19:08 nuttx.map
就先到这里吧!
调试
编译报错ERROR: riscv64-unknown-elf-gcc failed: 1
make
Create version.h
LN: platform/board to /home/skywalk/github/nuttxspace/apps/platform/dummy
Register: dd
Register: dumpstack
Register: nsh
Register: sh
./stdlib/lib_strtold.c:42:10: fatal error: math.h: No such file or directory
42 | #include <math.h>
| ^~~~~~~~
compilation terminated.
ERROR: riscv64-unknown-elf-gcc failed: 1
command: riscv64-unknown-elf-gcc -MT bin/lib_strtold.o -M '-fno-common' '-Wall' '-Wstrict-prototypes' '-Wshadow' '-Wundef' '-Wno-attributes' '-Wno-unknown-pragmas' '-Wno-psabi' '-Os' '-fno-strict-aliasing' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ffunction-sections' '-fdata-sections' '-nostdlib' '-g' '-march=rv32imc' '-mabi=ilp32' '-isystem' '/home/skywalk/github/nuttxspace/nuttx/include' '-D__NuttX__' '-DNDEBUG' '-D__KERNEL__' '-Werror=return-type' '-I' '/home/skywalk/github/nuttxspace/nuttx/libs/libc' ./stdlib/lib_strtold.c
make[2]: *** [/home/skywalk/github/nuttxspace/nuttx/tools/Config.mk:232: lib_strtold.ddc] Error 1
make[1]: *** [Makefile:202: .depend] Error 2
make: *** [tools/Unix.mk:660: pass2dep] Error 2
又重新make了一下,报错简化成:
make
CC: stdlib/lib_strtold.c stdlib/lib_strtold.c:42:10: fatal error: math.h: No such file or directory
42 | #include <math.h>
| ^~~~~~~~
compilation terminated.
make[1]: *** [Makefile:156: bin/lib_strtold.o] Error 1
make: *** [tools/LibTargets.mk:196: libs/libc/libc.a] Error 2
检查math.h
是否存在
find /usr/include -name math.h
find /usr/include -name math.h
/usr/include/newlib/math.h
/usr/include/newlib/c++/10.3.1/math.h
/usr/include/newlib/c++/10.3.1/tr1/math.h
/usr/include/math.h
/usr/include/c++/11/math.h
/usr/include/c++/11/tr1/math.h
检查编译器路径
echo | gcc -E -v -
看到这句
#include <...> search starts here:/usr/lib/gcc/x86_64-linux-gnu/11/include/usr/local/include/usr/include/x86_64-linux-gnu/usr/include
证明应该可以看到math.h文件啊!
检查这两项:
7. 检查环境变量
确保环境变量 CC
和 CFLAGS
没有错误配置。例如:
export CC=gcc
export CFLAGS="-I/usr/include"
8. 检查 Makefile
配置
检查 Makefile
中是否有错误的配置,例如缺少 -lm
链接数学库。在 Makefile
中添加以下内容:
LDFLAGS += -lm
问题解决
最终发现,这是已知的问题:`rv-virt:nsh64` can't build with stock gcc-riscv64-unknown-elf on Ubuntu Jammy · Issue #11341 · apache/nuttx
This is a know issue. Ubuntu release of RISC-V GCC is compiled without math libs. We can do nothing with that, but you can enable NuttX native math libraries support via CONFIG_ LIBM=y
and still use RISC-V GCC provided by Ubuntu apt
or pick another more mature toolchain
👍1
直接用命令:
make CONFIG_LIBM=y
哇塞,终于过去了
cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja报错
cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja
CMake Error at CMakeLists.txt:89 (message):
Kconfig environment depends on kconfiglib, Please install:
(APT source)
$ sudo apt install python3-kconfiglib
or (pip source)
$ pip install kconfiglib
or (After Ubuntu 24.04)
$ pip install kconfiglib --break-system-packages
-- Configuring incomplete, errors occurred!
放弃cmake
make报错esptool.py not found. Please run: 'pip install esptool'
make
Create version.h
LN: platform/board to /home/skywalk/github/nuttxspace/apps/platform/dummy
Register: dd
Register: dumpstack
Register: nsh
Register: sh
CPP: /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld.tmCPP: /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld.tmCPP: /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sections.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sectioLD: nuttx
Memory region Used Size Region Size %age Used
iram0_0_seg: 6624 B 321296 B 2.06%
irom0_0_seg: 107028 B 4194272 B 2.55%
dram0_0_seg: 13792 B 321296 B 4.29%
drom0_0_seg: 147892 B 4194272 B 3.53%
rtc_seg: 0 GB 8 KB 0.00%
CP: nuttx.hex
MKIMAGE: ESP32-C3 binary
esptool.py not found. Please run: 'pip install esptool'
Run make again to create the nuttx.bin image.
make: *** [tools/Unix.mk:559: nuttx] Error 1
按照提示的运行
pip install esptool