linux-sunxi / sunxi-tools

A collection of command line tools for ARM devices with Allwinner SoCs.
http://linux-sunxi.org/
GNU General Public License v2.0
579 stars 421 forks source link

fatal error: sys/mman.h: No such file or directory #196

Closed Fusseldieb closed 1 year ago

Fusseldieb commented 1 year ago

When compiling the target-tools for the Allwinner SoC, I get the following error:

fusseldieb@***-PC-UBUNTU:~/sunxi-tools$ make target-tools
arm-none-eabi-gcc -std=c99 -Wall -Wextra -Wno-unused-result -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE -D_DEFAULT_SOURCE -Iinclude/ -static  -o sunxi-meminfo meminfo.c
meminfo.c:22:10: fatal error: sys/mman.h: No such file or directory
   22 | #include <sys/mman.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:198: sunxi-meminfo] Error 1
fusseldieb@***-PC-UBUNTU:~/sunxi-tools$ 

Note that all tools are installed as mentioned in the README.md file. "make" without any argument does work, but as mentioned in the README does not produce the SoC files.

A Google search indicates that "libc6-dev" should be installed, which is!

Running on following system (real system, not wsl2!):

fusseldieb@***-PC-UBUNTU:~/sunxi-tools$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:    22.04
Codename:   jammy
paulkocialkowski commented 1 year ago

Looks like your cross-compiling setup is not right. Are you actually trying to cross-compile here? If not you should call: make tools instead.

In any case there's nothing wrong with the code or the Makefile here, it's on your side.

Fusseldieb commented 1 year ago

Looks like your cross-compiling setup is not right. Are you actually trying to cross-compile here? If not you should call: make tools instead.

In any case there's nothing wrong with the code or the Makefile here, it's on your side.

Yes, I am trying to cross-compile for the SoC. My computer runs x64 and the SoC is arm. No matter which libraries I install or which arguments I use I always get this error.

@paulkocialkowski Coming from a relatively clean Ubuntu setup, the README is lacking information about the setup, since I couldn't get it to work.

paulkocialkowski commented 1 year ago

It looks like your cross-compiling setup is not right then, as it cannot find system headers (sys/mman.h is a really really basic one). This is nothing specific to this project so there's no reason it should be in the README, which assumes you have a working cross-compiling setup.

Did you install arm-none-eabi-gcc from your distro?

Fusseldieb commented 1 year ago

It looks like your cross-compiling setup is not right then, as it cannot find system headers (sys/mman.h is a really really basic one). This is nothing specific to this project so there's no reason it should be in the README, which assumes you have a working cross-compiling setup.

Did you install arm-none-eabi-gcc from your distro?

I installed everything via apt, and since that apparently didn't suffice (as it doesn't work), I tried it with these instructions, but it still claims the exact same error.

apritzel commented 1 year ago

Please note that target-tools is just about meminfo, which is ancient and only gives useful output up to A23/A33 SoCs. As such it's highly optional. If you don't need it (and chances are high you don't), then just don't compile it, that's the reason we have a separate make target. Regarding the libraries: you need libc-dev for the target architecture, so gnueabihf, probably. Just some arm-none-eabi cross-compiler won't cut it for meminfo, although that works for the bare metal snippets that sunxi-tools uses elsewhere. On Ubuntu you need to add it to the list of installed architectures: dpkg --add-architecture armhf, then install the libraries: apt update; apt install libc-dev:armhf.

Fusseldieb commented 1 year ago

Please note that target-tools is just about meminfo, which is ancient and only gives useful output up to A23/A33 SoCs. As such it's highly optional. If you don't need it (and chances are high you don't), then just don't compile it, that's the reason we have a separate make target. Regarding the libraries: you need libc-dev for the target architecture, so gnueabihf, probably. Just some arm-none-eabi cross-compiler won't cut it for meminfo, although that works for the bare metal snippets that sunxi-tools uses elsewhere. On Ubuntu you need to add it to the list of installed architectures: dpkg --add-architecture armhf, then install the libraries: apt update; apt install libc-dev:armhf.

Thanks for the answer @apritzel and @paulkocialkowski . Hmm, maybe it's not so useful then. I was actually trying to cross-compile "uart0-helloworld-sdboot.c" and thought that target-tools would also include it.

I installed all the libraries suggested by apritzel and ran both commands. No avail, still no sys/mman.

Digging deeper, I found that mman isn't even available. But why? I just installed the whole ARM GNU toolchain (or so I think)!

fusseldieb@***-PC-UBUNTU:~/sunxi-tools$ ls /usr/share/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/arm-none-eabi/include/sys/
cdefs.h           dirent.h  features.h  _intsup.h  _pthreadtypes.h  sched.h    stat.h     syslimits.h  _timespec.h  _types.h       utime.h
config.h          dir.h     fenv.h      _locale.h  queue.h          select.h   _stdint.h  timeb.h      timespec.h   types.h        wait.h
custom_file.h     errno.h   file.h      lock.h     reent.h          signal.h   stdio.h    time.h       _timeval.h   _tz_structs.h
_default_fcntl.h  fcntl.h   iconvnls.h  param.h    resource.h       _sigset.h  string.h   times.h      tree.h       unistd.h

Was this file moved? Or isn't it included in newer arm gnu toolchain distributions?

The primary goal was to cross-compile only "uart0-helloworld-sdboot.c", so above probably isn't needed. However, the issue with missing headers still exists, and will probably bite someone else down the road. I think that README should explicitly state which packages to install. It kinda already does, but apparently this isn't enough... Maybe provide links or instructions to specific tar packages?

paulkocialkowski commented 1 year ago

Was this file moved?

That's a very common header, there is really no chance that it was moved.

Anyway the issue is probably that you're using a bare-metal (none) toolchain which doesn't include libc headers. Try with a libc-enabled toolchain.

apritzel commented 1 year ago

As @paulkocialkowski mentioned, you probably need to install crossbuild-essential-armhf. That would give you a arm-linux-gnueabihf-gcc compiler, along with the basic libraries and headers to compile Linux programs for ARM32 machines with hard floating point support. You also need to make sure that the Makefile picks that compiler up, and not arm-none-eabi-gcc. Cross compiling fully-functional Linux tools is not trivial, though support has improved much in the last years in major distributions. That's why many places used to recommend the none toolchain, which is easier to install (because it has less dependencies and libraries), but is less capable. It's good enough for firmware, bootloaders, kernels and small code snippets like those used in sunxi-fel, though, which fits many use cases already. But it cannot create Linux executables. Support for that is different in each distro, which is why the README might not be the right place to describe this. If you run Ubuntu, I'd recommend you uninstall the none cross-compiler, and install the fully featured one (armhf), which is normally a superset of the none version (minus a few exotic examples that rely on newlib). The Makefile (more precisely find-arm-gcc.sh) should then pick up this compiler, and it should work. If you feel that deserves explanation in the README, feel free to send a patch.