libmetal のインストール

(849d) 更新


電気回路/zynq

結論

どうやらこういう風に使うものじゃなさそう、 ということがようやくわかってきました。

以下の内容にはあまり意味が無いことになってしまいました。

libmetal

https://github.com/OpenAMP/libmetal

linux, freertos, baremetal で共通に使えるライブラリ API を提供し、 デバイスへのアクセスや割り込み制御、メモリ確保、その他ユーティリティ機能を提供するもの のようです。

  • Linux user space (based on UIO and VFIO support in the kernel)
  • RTOS (with and without virtual memory)
  • Bare-metal environments

となっているので、metal_xxx という共通の名前の関数ではあるものの、 環境によって実装を変え、適切な API 呼び出しに変換してくれる、ということみたい。

petalinux ではチェックボックス一つでインストール可能?

petalinux-config -c rootfs で選択できるので、 これでインストールできルっぽい?

ただこれでやるとユーザープロジェクトもすべて petalinux のビルドシステムを使わなければならなくなってややこしい。

GitHub で公開されているソースから単独でインストールできないものか、 と四苦八苦しているのがこのページです。

libhugetlbfs-dev が必要

make には cmake, doxygen, libsysfs-dev, libhugetlbfs-dev が必要になりますが、 Debian stretch には libhugetlbfs-dev が含まれていませんでした。Ubuntu には含まれていました。

cmake では out-of-source build が推奨されているそうで

http://stackoverflow.com/questions/27247123/how-to-clean-up-the-project-files-generated-by-cmake
cmake は out-of-source build が推奨されているそうで・・・最初、これがわからず苦労しました。

LANG:console
$ cd ~/z-turn
$ git clone https://github.com/OpenAMP/libmetal.git
$ cd libmetal
$ mkdir build
$ cd build
$ cmake ..
 -- The C compiler identification is GNU 5.4.0
 -- Check for working C compiler: /usr/bin/cc
 -- Check for working C compiler: /usr/bin/cc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Detecting C compile features
 -- Detecting C compile features - done
 -- Host:    Linux/x86_64
 -- Target:  Linux/x86_64
 -- Machine: Generic
 -- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
 -- Looking for include file stdatomic.h
 -- Looking for include file stdatomic.h - found
 -- Looking for include file linux/futex.h
 -- Looking for include file linux/futex.h - found
 -- Found HUGETLBFS: /usr/lib/libhugetlbfs.so
 -- Found LIBSYSFS: /usr/lib/x86_64-linux-gnu/libsysfs.so
 -- Looking for pthread.h
 -- Looking for pthread.h - found
 -- Looking for pthread_create
 -- Looking for pthread_create - not found
 -- Looking for pthread_create in pthreads
 -- Looking for pthread_create in pthreads - not found
 -- Looking for pthread_create in pthread
 -- Looking for pthread_create in pthread - found
 -- Found Threads: TRUE
 -- Found LibRt: /usr/lib/x86_64-linux-gnu/librt.so
 -- Configuring done
 -- Generating done
 -- Build files have been written to: /home/osamu/z-turn/libmetal/build
$ ls
 CMakeCache.txt  CTestTestfile.cmake  cmake_install.cmake  lib/
 CMakeFiles/     Makefile             doc/                 test/
$ make doc
$ browse doc/html

ドキュメントは見られるようになったけれど・・・
Target が Linux/x86_64 になってしまっている?

zynq7 用の設定を読み込む

Target を arm にするにはどうするのか、

LANG:console
$ cd ~/z-turn/libmetal
$ grep -s CROSS `find`
 ./build/CMakeFiles/3.5.1/CMakeSystem.cmake:set(CMAKE_CROSSCOMPILING "FALSE")
 ./cmake/platforms/zynq7-freertos.cmake:set (CROSS_PREFIX           "arm-none-eabi-" CACHE STRING "")
 ./cmake/platforms/cross-linux-gcc.cmake:set (CMAKE_C_COMPILER   "${CROSS_PREFIX}gcc" CACHE STRING "")
 ./cmake/platforms/cross-linux-gcc.cmake:set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++" CACHE STRING "")
 ./cmake/platforms/cross-generic-iar.cmake:CMAKE_FORCE_C_COMPILER   ("icc${CROSS_SUFFIX}" IAR)
 ./cmake/platforms/cross-generic-iar.cmake:CMAKE_FORCE_CXX_COMPILER ("icc${CROSS_SUFFIX} --eec++" IAR)
 ./cmake/platforms/zynqmp-a53-generic.cmake:set (CROSS_PREFIX           "aarch64-none-elf-" CACHE STRING "")
 ./cmake/platforms/zynqmp-r5-generic.cmake:set (CROSS_PREFIX           "armr5-none-eabi-" CACHE STRING "")
 ./cmake/platforms/zynqmp-r5-freertos.cmake:set (CROSS_PREFIX           "armr5-none-eabi-" CACHE STRING "")
 ./cmake/platforms/zynq7-linux.cmake:set (CROSS_PREFIX           "arm-xilinx-linux-gnueabi-" CACHE STRING "")
 ./cmake/platforms/zynq7-generic.cmake:set (CROSS_PREFIX           "arm-none-eabi-" CACHE STRING "")
 ./cmake/platforms/zynq7-generic-iar.cmake:set (CROSS_SUFFIX           "arm" CACHE STRING "")
 ./cmake/platforms/zynqmp-linux.cmake:set (CROSS_PREFIX           "aarch64-linux-gnu-" CACHE STRING "")
 ./cmake/platforms/cross-generic-gcc.cmake:CMAKE_FORCE_C_COMPILER   ("${CROSS_PREFIX}gcc" GNU)
 ./cmake/platforms/cross-generic-gcc.cmake:CMAKE_FORCE_CXX_COMPILER ("${CROSS_PREFIX}g++" GNU)
$ arm-^T
 ...
 arm-linux-gnueabihf-gcc
 ...
 arm-none-eabi-gcc
 ...
$ cat cmake/platforms/zynq7-generic.cmake
 set (CMAKE_SYSTEM_PROCESSOR "arm"              CACHE STRING "")
 set (MACHINE "zynq7" CACHE STRING "")
 set (CROSS_PREFIX           "arm-none-eabi-" CACHE STRING "")
 
 set (CMAKE_C_FLAGS          "-mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -O2 -g" CACHE STRING "")
 
 include (cross-generic-gcc)
 
 # vim: expandtab:ts=2:sw=2:smartindent
$ cat cmake/platforms/cross-generic-gcc.cmake
 set (CMAKE_SYSTEM_NAME "Generic"             CACHE STRING "")
 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "")
 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "")
 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "")
 
 include (CMakeForceCompiler)
 CMAKE_FORCE_C_COMPILER   ("${CROSS_PREFIX}gcc" GNU)
 CMAKE_FORCE_CXX_COMPILER ("${CROSS_PREFIX}g++" GNU)
 
 # vim: expandtab:ts=2:sw=2:smartindent
$

なので、

  • platforms/zynq7-freertos.cmake
  • platforms/zynq7-linux.cmake
  • platforms/zynq7-generic.cmake

のいずれかが読み込まれてくれると良さそうなのだけれど、、、 実は zynq7-linux だと CROSS_PREFIX が arm-linux-gnueabihf- となってほしいところ、 arm-xilinx-linux-gnueabi- となってしまう?

とにかくこの platforms/*.cmake を読み込ませてみよう、 となったのですが、指定するための正規の方法がわかりませんでした。

むりやり platform を指定してみる (zynq7-linux 編)

そこで、CMakeLists.txt に

LANG:cmake
   cmake_minimum_required (VERSION 2.6)
   
   list (APPEND CMAKE_MODULE_PATH
         "${CMAKE_SOURCE_DIR}/cmake"
         "${CMAKE_SOURCE_DIR}/cmake/modules"
         "${CMAKE_SOURCE_DIR}/cmake/platforms")
  
   project (metal C)
   
 + include (${PLATFORM_NAME})
 +
   include (CheckIncludeFiles)
   include (CheckCSourceCompiles)
   include (collect)
   include (options)
   include (depends)
   ...

のようにして PLATFORM_NAME へ platform 名を渡せるようにしてみたところ、

LANG:console
$ cd ~/z-turn/libmetal
$ mkdir build_zynq7-linux
$ cd build_zynq7-linux
$ cmake -DPLATFORM_NAME=zynq7-linux ..
 -- The C compiler identification is GNU 5.4.0
 -- Check for working C compiler: /usr/bin/cc
 -- Check for working C compiler: /usr/bin/cc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Detecting C compile features
 -- Detecting C compile features - done
 -- Host:    Linux/x86_64
 -- Target:  Linux/arm
 -- Machine: Generic
 -- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
 -- Looking for include file stdatomic.h
 -- Looking for include file stdatomic.h - found
 -- Looking for include file linux/futex.h
 -- Looking for include file linux/futex.h - found
 -- Found HUGETLBFS: /usr/lib/libhugetlbfs.so
 -- Found LIBSYSFS: /usr/lib/x86_64-linux-gnu/libsysfs.so
 -- Looking for pthread.h
 -- Looking for pthread.h - found
 -- Looking for pthread_create
 -- Looking for pthread_create - not found
 -- Looking for pthread_create in pthreads
 -- Looking for pthread_create in pthreads - not found
 -- Looking for pthread_create in pthread
 -- Looking for pthread_create in pthread - found
 -- Found Threads: TRUE
 -- Found LibRt: /usr/lib/x86_64-linux-gnu/librt.so
 -- Configuring done
 -- Generating done
 -- Build files have been written to: /home/osamu/z-turn/libmetal/build_zynq7-linux
$ ls
 CMakeCache.txt  CTestTestfile.cmake  cmake_install.cmake  lib
 CMakeFiles      Makefile             doc                  test
$ make
 Scanning dependencies of target metal-shared
 [  1%] Building C object lib/CMakeFiles/metal-shared.dir/device.c.o
 [  2%] Building C object lib/CMakeFiles/metal-shared.dir/init.c.o
 [  3%] Building C object lib/CMakeFiles/metal-shared.dir/log.c.o
 [  5%] Building C object lib/CMakeFiles/metal-shared.dir/shmem.c.o
 [  6%] Building C object lib/CMakeFiles/metal-shared.dir/version.c.o
 [  7%] Building C object lib/CMakeFiles/metal-shared.dir/dma.c.o
 [  8%] Building C object lib/CMakeFiles/metal-shared.dir/io.c.o
 [ 10%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/device.c.o
 [ 11%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/init.c.o
 [ 12%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/shmem.c.o
 [ 13%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/utilities.c.o
 [ 15%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/condition.c.o
 [ 16%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/irq.c.o
 [ 17%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/cache.c.o
 [ 18%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/io.c.o
 [ 20%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/time.c.o
 [ 21%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/sleep.c.o
 [ 22%] Linking C shared library libmetal.so
 [ 22%] Built target metal-shared
 Scanning dependencies of target metal-static
 [ 23%] Building C object lib/CMakeFiles/metal-static.dir/device.c.o
 [ 25%] Building C object lib/CMakeFiles/metal-static.dir/init.c.o
 [ 26%] Building C object lib/CMakeFiles/metal-static.dir/log.c.o
 [ 27%] Building C object lib/CMakeFiles/metal-static.dir/shmem.c.o
 [ 28%] Building C object lib/CMakeFiles/metal-static.dir/version.c.o
 [ 30%] Building C object lib/CMakeFiles/metal-static.dir/dma.c.o
 [ 31%] Building C object lib/CMakeFiles/metal-static.dir/io.c.o
 [ 32%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/device.c.o
 [ 33%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/init.c.o
 [ 35%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/shmem.c.o
 [ 36%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/utilities.c.o
 [ 37%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/condition.c.o
 [ 38%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/irq.c.o
 [ 40%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/cache.c.o
 [ 41%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/io.c.o
 [ 42%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/time.c.o
 [ 43%] Building C object lib/CMakeFiles/metal-static.dir/system/linux/sleep.c.o
 [ 45%] Linking C static library libmetal.a
 [ 45%] Built target metal-static
 Scanning dependencies of target test-metal-shared
 [ 46%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/main.c.o
 [ 47%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/atomic.c.o
 [ 48%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/mutex.c.o
 [ 50%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/shmem.c.o
 [ 51%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/condition.c.o
 [ 52%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/threads.c.o
 [ 53%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/spinlock.c.o
 [ 55%] Building C object test/CMakeFiles/test-metal-shared.dir/system/linux/alloc.c.o
 [ 56%] Building C object test/CMakeFiles/test-metal-shared.dir/version.c.o
 [ 57%] Building C object test/CMakeFiles/test-metal-shared.dir/metal-test.c.o
 [ 58%] Linking C executable test-metal-shared
 [ 58%] Built target test-metal-shared
 Scanning dependencies of target test-metal-static
 [ 60%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/main.c.o
 [ 61%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/atomic.c.o
 [ 62%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/mutex.c.o
 [ 63%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/shmem.c.o
 [ 65%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/condition.c.o
 [ 66%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/threads.c.o
 [ 67%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/spinlock.c.o
 [ 68%] Building C object test/CMakeFiles/test-metal-static.dir/system/linux/alloc.c.o
 [ 70%] Building C object test/CMakeFiles/test-metal-static.dir/version.c.o
 [ 71%] Building C object test/CMakeFiles/test-metal-static.dir/metal-test.c.o
 [ 72%] Linking C executable test-metal-static
 [ 72%] Built target test-metal-static
 Scanning dependencies of target metal-headers
 [ 73%] Building C object test/CMakeFiles/metal-headers.dir/metal-atomic-h.c.o
 [ 75%] Building C object test/CMakeFiles/metal-headers.dir/metal-compiler-h.c.o
 [ 76%] Building C object test/CMakeFiles/metal-headers.dir/metal-config-h.c.o
 [ 77%] Building C object test/CMakeFiles/metal-headers.dir/metal-device-h.c.o
 [ 78%] Building C object test/CMakeFiles/metal-headers.dir/metal-io-h.c.o
 [ 80%] Building C object test/CMakeFiles/metal-headers.dir/metal-list-h.c.o
 [ 81%] Building C object test/CMakeFiles/metal-headers.dir/metal-log-h.c.o
 [ 82%] Building C object test/CMakeFiles/metal-headers.dir/metal-mutex-h.c.o
 [ 83%] Building C object test/CMakeFiles/metal-headers.dir/metal-condition-h.c.o
 [ 85%] Building C object test/CMakeFiles/metal-headers.dir/metal-shmem-h.c.o
 [ 86%] Building C object test/CMakeFiles/metal-headers.dir/metal-sys-h.c.o
 [ 87%] Building C object test/CMakeFiles/metal-headers.dir/metal-utilities-h.c.o
 [ 88%] Building C object test/CMakeFiles/metal-headers.dir/metal-version-h.c.o
 [ 90%] Building C object test/CMakeFiles/metal-headers.dir/metal-cpu-h.c.o
 [ 91%] Building C object test/CMakeFiles/metal-headers.dir/metal-spinlock-h.c.o
 [ 92%] Building C object test/CMakeFiles/metal-headers.dir/metal-irq-h.c.o
 [ 93%] Building C object test/CMakeFiles/metal-headers.dir/metal-alloc-h.c.o
 [ 95%] Building C object test/CMakeFiles/metal-headers.dir/metal-cache-h.c.o
 [ 96%] Building C object test/CMakeFiles/metal-headers.dir/metal-dma-h.c.o
 [ 97%] Building C object test/CMakeFiles/metal-headers.dir/metal-time-h.c.o
 [ 98%] Building C object test/CMakeFiles/metal-headers.dir/metal-sleep-h.c.o
 [100%] Linking C static library libmetal-headers.a
 [100%] Built target metal-headers
 Scanning dependencies of target doc
 /home/osamu/z-turn/libmetal/lib/io.h:381: warning: end of file while inside a group
 
 /home/osamu/z-turn/libmetal/lib/system/freertos/irq.h:44: warning: argument 'interrupt' of command @param is not found in the argument list of metal_irq_isr(unsigned int vector)
 /home/osamu/z-turn/libmetal/lib/system/freertos/irq.h:47: warning: The following parameters of metal_irq_isr(unsigned int vector) are not documented:
   parameter 'vector'
 /home/osamu/z-turn/libmetal/lib/system/freertos/irq.h:44: warning: argument 'interrupt' of command @param is not found in the argument list of metal_irq_isr(unsigned int vector)
 /home/osamu/z-turn/libmetal/lib/system/generic/irq.h:47: warning: The following parameters of metal_irq_isr(unsigned int vector) are not documented:
   parameter 'vector'
 /home/osamu/z-turn/libmetal/lib/system/freertos/irq.h:44: warning: argument 'interrupt' of command @param is not found in the argument list of metal_irq_isr(unsigned int vector)
 /home/osamu/z-turn/libmetal/lib/system/freertos/irq.c:182: warning: The following parameters of metal_irq_isr(unsigned int vector) are not documented:
   parameter 'vector'
 [100%] Built target doc

として、なぜかちゃんとビルドできました?!

LANG:console
$ file lib/libmetal.so.0.1.0
 lib/libmetal.so.0.1.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=398b57d8d9b6c74b202d3abb480b317926bd8028, not stripped

x86-64 用のバイナリが生成している。
いやいやそれじゃダメでしょ。

どうしてこうなった?

LANG:console
$ grep -s CROSS `find`
 ./CMakeFiles/3.5.1/CMakeSystem.cmake:set(CMAKE_CROSSCOMPILING "FALSE")
 ./CMakeCache.txt:CROSS_PREFIX:STRING=arm-xilinx-linux-gnueabi-
$ grep -s arm-xilinx- `find`
 ./CMakeCache.txt:CMAKE_CXX_COMPILER:STRING=arm-xilinx-linux-gnueabi-g++
 ./CMakeCache.txt:CROSS_PREFIX:STRING=arm-xilinx-linux-gnueabi-
$ which arm-xilinx-linux-gnueabi-g++
$ grep -s CMAKE_CXX_COMPILER `find`
 ./CMakeCache.txt:CMAKE_CXX_COMPILER:STRING=arm-xilinx-linux-gnueabi-g++

CMAKE_CXX_COMPILER に指定された arm-xilinx-linux-gnueabi-g++ は存在しないし、

そもそも CMAKE_CXX_COMPILER 自体使われていない orz

CMakeFiles/3.5.1/CMakeSystem.cmake の set(CMAKE_CROSSCOMPILING "FALSE") が怪しすぎるので調べる。

https://cmake.org/cmake/help/v3.7/variable/CMAKE_CROSSCOMPILING.html

によると、Host 環境と Target 環境が異なれば勝手に TRUE になるものっぽい?

http://stackoverflow.com/questions/40528254/how-do-i-detect-that-i-am-cross-compiling-in-cmakelists-txt

によると、project ( ) の指定後に使えるようになる、と書いてある!
project の後に platform 指定を読んだのでは遅いということか。

正しく zynq7-linux を指定する

たぶん、https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html#variable:CMAKE_TOOLCHAIN_FILE
これを使うべき。

上で手を入れた CMakeLists.txt を元に戻して、 コマンド引数で CMAKE_TOOLCHAIN_FILE を指定する。

LANG:console
$ cd ~/z-turn/libmetal/build_zynq7-linux
$ rm -r *
$ jed ../CMakeLists.txt
   ...
   project (metal C)

 - include (${PLATFORM_NAME})
 - 
   include (CheckIncludeFiles)
   ...
$ cmake -DCMAKE_TOOLCHAIN_FILE=zynq7-linux ..
 -- The C compiler identification is unknown
 CMake Error at CMakeLists.txt:8 (project):
   The CMAKE_C_COMPILER:
 
     arm-xilinx-linux-gnueabi-gcc
 
   is not a full path and was not found in the PATH.
 
   Tell CMake where to find the compiler by setting either the environment
   variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
   the compiler, or to the compiler name if it is in the PATH.
 
 -- Configuring incomplete, errors occurred!
 See also "/home/osamu/z-turn/libmetal/build_zynq7-linux/CMakeFiles/CMakeOutput.log".
 See also "/home/osamu/z-turn/libmetal/build_zynq7-linux/CMakeFiles/CMakeError.log".

このエラーが出たのは前進した証。

arm-xilinx-linux-gnueabi-gcc は無いので、
arm-linux-gnueabihf-gcc を使わなきゃならない。

LANG:console
$ arm-linux-gnueabihf-gcc --version
 arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005
 Copyright (C) 2015 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ which arm-linux-gnueabihf-gcc
 /home/osamu/z-turn/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc
$ cp ../cmake/platforms/zynq7-linux.cmake zynq7-linux-mine.cmake
$ jed my-zynq7-linux.cmake
   set (CMAKE_SYSTEM_PROCESSOR "arm"                       CACHE STRING "")
 - set (CROSS_PREFIX           "arm-xilinx-linux-gnueabi-" CACHE STRING "")
 + set (CROSS_PREFIX           "arm-linux-gnueabihf-"      CACHE STRING "")
   include (cross-linux-gcc)
$ rm -r CMake*
$ cmake -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake ..
 -- The C compiler identification is GNU 5.2.1
 -- Check for working C compiler: /home/osamu/z-turn/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc
 -- Check for working C compiler: /home/osamu/z-turn/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Detecting C compile features
 -- Detecting C compile features - done
 -- Host:    Linux/x86_64
 -- Target:  Linux/arm
 -- Machine: Generic
 -- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
 -- Looking for include file stdatomic.h
 -- Looking for include file stdatomic.h - found
 -- Looking for include file linux/futex.h
 -- Looking for include file linux/futex.h - found
 -- Found HUGETLBFS: /usr/lib/libhugetlbfs.so
 -- Could NOT find LIBSYSFS (missing:  LIBSYSFS_LIBRARY)
 -- Looking for pthread.h
 -- Looking for pthread.h - found
 -- Looking for pthread_create
 -- Looking for pthread_create - not found
 -- Looking for pthread_create in pthreads
 -- Looking for pthread_create in pthreads - not found
 -- Looking for pthread_create in pthread
 -- Looking for pthread_create in pthread - found
 -- Found Threads: TRUE
 CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
   Could NOT find LibRt (missing: LIBRT_LIBRARIES)
 Call Stack (most recent call first):
   /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
   cmake/modules/FindLibRt.cmake:36 (find_package_handle_standard_args)
   cmake/depends.cmake:19 (find_package)
   CMakeLists.txt:14 (include)
 
 -- Configuring incomplete, errors occurred!
 See also "/home/osamu/z-turn/libmetal/build_zynq7-linux/CMakeFiles/CMakeOutput.log".
 See also "/home/osamu/z-turn/libmetal/build_zynq7-linux/CMakeFiles/CMakeError.log".
$ ls /lib/x86_64-linux-gnu/librt.so.1
 /lib/x86_64-linux-gnu/librt.so.1
$ ls /lib/x86_64-linux-gnu/libsysfs.so.2
 /lib/x86_64-linux-gnu/libsysfs.so.2

シェアドライブラリが足りないと言っている。

インストール済みの librt.so や libsysfs.so は x86_64-linux-gnu 向けのものなので、 armhf 向けのものが無いということ。

armhf 版のライブラリをインストールする

https://wiki.debian.org/Multiarch/HOWTO を見ながら、

LANG:console
$ sudo jed /etc/apt/sources.list
 deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
 deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
 deb [arch=amd64,i386] http://jp.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
 deb [arch=amd64,i386] http://archive.canonical.com/ubuntu xenial partner
 deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
 
 deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse
 deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted universe multiverse
 deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse
 deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe multiverse
$ sudo dpkg --add-architecture armhf
$ sudo apt update
$ sudo apt-get install libc6:armhf libsysfs-dev:armhf

入った。

改めて cmake

LANG:console
$ cd ~/z-turn/libmetal/build_zynq7-linux
$ rm -r [!z]*
$ cmake -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake ..
 ...
 -- Could NOT find LIBSYSFS (missing:  LIBSYSFS_LIBRARY)
 ...
 CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
   Could NOT find LibRt (missing: LIBRT_LIBRARIES)
 Call Stack (most recent call first):
   /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
   cmake/modules/FindLibRt.cmake:36 (find_package_handle_standard_args)
   cmake/depends.cmake:19 (find_package)
   CMakeLists.txt:14 (include)
 ..

変わらない?!

LANG:console
$ ls /lib/arm-linux-gnueabihf/librt.so.1
 /lib/arm-linux-gnueabihf/librt.so.1
$ ls /lib/arm-linux-gnueabihf/libsysfs.so.2
 /lib/arm-linux-gnueabihf/libsysfs.so.2
$ cat /etc/ld.so.conf.d/arm-linux-gnueabihf.conf
 # Multiarch support
 /lib/arm-linux-gnueabihf
 /usr/lib/arm-linux-gnueabihf

パスは通ってそうなのだけれど・・・

あ、うまく行っているときのメッセージは

-- Found LibRt: /usr/lib/x86_64-linux-gnu/librt.so

だから、

/lib/arm-linux-gnueabihf/librt.so.1

ではダメで、

/lib/arm-linux-gnueabihf/librt.so

が必要ということ?

でもそれはそれで x86_64-linux-gnu/librt.so とかち合いそうな気がするなあ。。。

LANG:console
$ sudo ln -s /lib/arm-linux-gnueabihf/librt.so.1 /lib/arm-linux-gnueabihf/librt.so
$ sudo ln -s /lib/arm-linux-gnueabihf/libsysfs.so.2 /lib/arm-linux-gnueabihf/libsysfs.so
$ cmake -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake ..
  (同じエラー)
$ cmake -DCMAKE_LIBRARY_PATH=/lib/arm-linux-gnueabihf -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake ..
 -- The C compiler identification is GNU 5.2.1
 -- Check for working C compiler: /home/osamu/z-turn/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc
 -- Check for working C compiler: /home/osamu/z-turn/petalinux/tools/linux-i386/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Detecting C compile features
 -- Detecting C compile features - done
 -- Host:    Linux/x86_64
 -- Target:  Linux/arm
 -- Machine: Generic
 -- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
 -- Looking for include file stdatomic.h
 -- Looking for include file stdatomic.h - found
 -- Looking for include file linux/futex.h
 -- Looking for include file linux/futex.h - found
 -- Found HUGETLBFS: /usr/lib/libhugetlbfs.so
 -- Found LIBSYSFS: /lib/arm-linux-gnueabihf/libsysfs.so
 -- Looking for pthread.h
 -- Looking for pthread.h - found
 -- Looking for pthread_create
 -- Looking for pthread_create - not found
 -- Looking for pthread_create in pthreads
 -- Looking for pthread_create in pthreads - not found
 -- Looking for pthread_create in pthread
 -- Looking for pthread_create in pthread - found
 -- Found Threads: TRUE
 -- Found LibRt: /lib/arm-linux-gnueabihf/librt.so
 -- Configuring done
 -- Generating done
 -- Build files have been written to: /home/osamu/z-turn/libmetal/build_zynq7-linux
$ make
 Scanning dependencies of target metal-shared
 [  1%] Building C object lib/CMakeFiles/metal-shared.dir/device.c.o
 In file included from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/sys.h:108:0,
                  from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/io.h:44,
                  from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/device.h:40,
                  from /home/osamu/z-turn/libmetal/lib/device.c:33:
 /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/system/linux/sys.h:61:28: fatal error: sysfs/libsysfs.h: No such file or directory
 compilation terminated.
 lib/CMakeFiles/metal-shared.dir/build.make:62: ターゲット 'lib/CMakeFiles/metal-shared.dir/device.c.o' のレシピで失敗しました
 make[2]: *** [lib/CMakeFiles/metal-shared.dir/device.c.o] エラー 1
 CMakeFiles/Makefile2:95: ターゲット 'lib/CMakeFiles/metal-shared.dir/all' のレシピで失敗しました
 make[1]: *** [lib/CMakeFiles/metal-shared.dir/all] エラー 2
 Makefile:138: ターゲット 'all' のレシピで失敗しました
 make: *** [all] エラー 2
$ ls /usr/include/sysfs/libsysfs.h
 /usr/include/sysfs/libsysfs.h
$ rm -r [!z]* ; cmake -DCMAKE_INCLUDE_PATH=/usr/include -DCMAKE_LIBRARY_PATH=/lib/arm-linux-gnueabihf -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake .. ; make
 (変わらない)
$ jed zynq7-linux-mine.cmake
 + include_directories(/usr/include)
$ rm -r [!z]* ; cmake -DCMAKE_LIBRARY_PATH=/lib/arm-linux-gnueabihf -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake .. ; make
 (変わらない)
$ jed zynq7-linux-mine.cmake
 - include_directories(/usr/include)
$ rm -r [!z]* ; cmake -DCMAKE_LIBRARY_PATH=/lib/arm-linux-gnueabihf -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake ..

本当にそうだった。

で、cmake は通ったけれど、今度はインクルードファイルが見つからないと言っている。

/usr/include/sysfs/libsysfs.h は存在しているので、インクルードパスが正しく設定されていないことになる。
何のための cmake ?

CMAKE_INCLUDE_PATH というのも違うらしいし、include_directories も違うらしい。

で、直接 CMAKE_C_FLAGS を指定すると

LANG:console
$ rm -r [!z]* ; cmake -DCMAKE_C_FLAGS="-I/usr/include" -DCMAKE_LIBRARY_PATH=/lib/arm-linux-gnueabihf -DCMAKE_TOOLCHAIN_FILE=./zynq7-linux-mine.cmake .. ; make
 ...
 Scanning dependencies of target metal-shared
 [  1%] Building C object lib/CMakeFiles/metal-shared.dir/device.c.o
 In file included from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/system/linux/sys.h:47:0,
                  from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/sys.h:108,
                  from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/io.h:44,
                  from /home/osamu/z-turn/libmetal/build_zynq7-linux/lib/include/metal/device.h:40,
                  from /home/osamu/z-turn/libmetal/lib/device.c:33:
 /usr/include/pthread.h:681:6: error: '__regparm__' attribute directive ignored [-Werror=attributes]
       __cleanup_fct_attribute;
       ^
 /usr/include/pthread.h:693:3: error: '__regparm__' attribute directive ignored [-Werror=attributes]
    __cleanup_fct_attribute;
    ^
 /usr/include/pthread.h:738:6: error: '__regparm__' attribute directive ignored [-Werror=attributes]
       ;
       ^
 cc1: all warnings being treated as errors
 lib/CMakeFiles/metal-shared.dir/build.make:62: ターゲット 'lib/CMakeFiles/metal-shared.dir/device.c.o' のレシピで失敗しました
 make[2]: *** [lib/CMakeFiles/metal-shared.dir/device.c.o] エラー 1
 CMakeFiles/Makefile2:95: ターゲット 'lib/CMakeFiles/metal-shared.dir/all' のレシピで失敗しました
 make[1]: *** [lib/CMakeFiles/metal-shared.dir/all] エラー 2
 Makefile:138: ターゲット 'all' のレシピで失敗しました
 make: *** [all] エラー 2

のように、少し進んだ。

今度は error: 'regparm' attribute directive ignored で止まった。

https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html などによると、regparm は gcc の x86 向けのディレクティブで、 関数の引数をレジスタにセットして渡すためのものらしい。

armhf 向けの gcc ではこのディレクティブを無視するぞ、という警告が出て、-Werror のために警告が即エラーになっている。

/usr/include/pthread.h が x86_64 向けのもので、armhf 向けのもので無いのが問題。

これ、根が深い感じがする。。。

むしろ z-turn 用の rootfs 上で make した方が良いのか?

z-turn 用 rootfs 上で試す

arm エミュレータ上でビルドしてみる。

LANG:console
$ sudo chroot ~/z-turn/rootfs
$ gcc --version
 gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
 Copyright (C) 2015 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ file `which gcc`
 /usr/bin/gcc: symbolic link to gcc-5
$ file `which gcc-5`
 /usr/bin/gcc-5: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=19b884a267df643610ef98058f555de373f9e457, stripped
$ cd /root
$ git clone https://github.com/OpenAMP/libmetal.git
 Cloning into 'libmetal'...
 fatal: unable to access 'https://github.com/OpenAMP/libmetal.git/': Problem with the SSL CA cert (path? access rights?)
$ apt install ca-certificates
$ git clone https://github.com/OpenAMP/libmetal.git
$ cd libmetal/
$ mkdir build_zynq7-linux
$ cd build_zynq7-linux
$ cmake ..
 -- The C compiler identification is GNU 5.4.0
 -- Check for working C compiler: /usr/bin/cc
 -- Check for working C compiler: /usr/bin/cc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Detecting C compile features
 -- Detecting C compile features - done
 -- Host:    Linux/armv7l
 -- Target:  Linux/armv7l
 -- Machine: Generic
 -- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
 -- Looking for include file stdatomic.h
 -- Looking for include file stdatomic.h - found
 -- Looking for include file linux/futex.h
 -- Looking for include file linux/futex.h - found
 -- Found HUGETLBFS: /usr/lib/libhugetlbfs.so
 -- Found LIBSYSFS: /usr/lib/arm-linux-gnueabihf/libsysfs.so
 -- Looking for pthread.h
 -- Looking for pthread.h - found
 -- Looking for pthread_create
 -- Looking for pthread_create - not found
 -- Looking for pthread_create in pthreads
 -- Looking for pthread_create in pthreads - not found
 -- Looking for pthread_create in pthread
 -- Looking for pthread_create in pthread - found
 -- Found Threads: TRUE
 -- Found LibRt: /usr/lib/arm-linux-gnueabihf/librt.so
 CMake Error at lib/processor/CMakeLists.txt:1 (add_subdirectory):
   add_subdirectory given source "armv7l" which is not an existing directory.
 
 -- Configuring incomplete, errors occurred!
 See also "/root/libmetal/build_zynq7-linux/CMakeFiles/CMakeOutput.log".
 See also "/root/libmetal/build_zynq7-linux/CMakeFiles/CMakeError.log".
$ cat ../lib/processor/CMakeLists.txt
 add_subdirectory (${PROJECT_PROCESSOR})
 
 # vim: expandtab:ts=2:sw=2:smartindent
$ ls ../lib/processor/
 CMakeLists.txt  aarch64  arm  x86_64
$ cmake -DCMAKE_SYSTEM_PROCESSOR=arm -DCMAKE_TOOLCHAIN_FILE=cross-linux-gcc ..
 (成功)
$ make
 ...
 [ 22%] Linking C shared library libmetal.so
 [ 22%] Built target metal-shared
 ...
 [ 45%] Linking C static library libmetal.a
 [ 45%] Built target metal-static
 ...
 [ 58%] Linking C executable test-metal-shared
 [ 58%] Built target test-metal-shared
 ...
 [ 72%] Linking C executable test-metal-static
 [ 72%] Built target test-metal-static
 ...
 [100%] Linking C static library libmetal-headers.a
 [100%] Built target metal-headers
 ...
 [100%] Built target doc
$ make help
 The following are some of the valid targets for this Makefile:
 ... all (the default if no target is provided)
 ... clean
 ... depend
 ... rebuild_cache
 ... edit_cache
 ... install/strip
 ... install/local
 ... install
 ... test
 ... list_install_components
 ... metal-shared
 ... metal-static
 ... test-metal-shared
 ... test-metal-static
 ... metal-headers
 ... doc
$ make -n install/local
 ...
 /usr/bin/cmake -P cmake_install.cmake
$ cat cmake_install.cmake
 # Install script for directory: /root/libmetal
 
 # Set the install prefix
 if(NOT DEFINED CMAKE_INSTALL_PREFIX)
   set(CMAKE_INSTALL_PREFIX "/usr/local")
 endif()
 string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
 
 # Set the install configuration name.
 if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
   if(BUILD_TYPE)
     string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
            CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
   else()
     set(CMAKE_INSTALL_CONFIG_NAME "")
   endif()
   message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
 endif()
 
 # Set the component getting installed.
 if(NOT CMAKE_INSTALL_COMPONENT)
   if(COMPONENT)
     message(STATUS "Install component: \"${COMPONENT}\"")
     set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
   else()
     set(CMAKE_INSTALL_COMPONENT)
   endif()
 endif()
 
 # Install shared libraries without execute permission?
 if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
   set(CMAKE_INSTALL_SO_NO_EXE "1")
 endif()
 
 if(NOT CMAKE_INSTALL_LOCAL_ONLY)
   # Include the install script for each subdirectory.
   include("/root/libmetal/build_zynq7-linux/lib/cmake_install.cmake")
   include("/root/libmetal/build_zynq7-linux/test/cmake_install.cmake")
   include("/root/libmetal/build_zynq7-linux/doc/cmake_install.cmake")
 
 endif()
 
 if(CMAKE_INSTALL_COMPONENT)
   set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
 else()
   set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
 endif()
 
 string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
        "${CMAKE_INSTALL_MANIFEST_FILES}")
 file(WRITE "/root/libmetal/build_zynq7-linux/${CMAKE_INSTALL_MANIFEST}"
      "${CMAKE_INSTALL_MANIFEST_CONTENT}")

ビルドできた。

cmake で作られていると、make -n で見ても何をするかがわからなくていやな感じ。

CMAKE_INSTALL_PREFIX は /usr/local になっているので、 make install をそのまま実行しても Ubuntu の流儀とは反していない気がするけれど・・・

とりあえず install/local してみる。

LANG:console
$ make install/local
 [ 22%] Built target metal-shared
 [ 45%] Built target metal-static
 [ 58%] Built target test-metal-shared
 [ 72%] Built target test-metal-static
 [100%] Built target metal-headers
 /root/libmetal/lib/io.h:381: warning: end of file while inside a group
 
 /root/libmetal/lib/system/freertos/irq.h:44: warning: argument 'interrupt' of command @param is not found in the argument list of metal_irq_isr(unsigned int vector)
 /root/libmetal/lib/system/freertos/irq.h:47: warning: The following parameters of metal_irq_isr(unsigned int vector) are not documented:
   parameter 'vector'
 /root/libmetal/lib/system/freertos/irq.h:44: warning: argument 'interrupt' of command @param is not found in the argument list of metal_irq_isr(unsigned int vector)
 /root/libmetal/lib/system/generic/irq.h:47: warning: The following parameters of metal_irq_isr(unsigned int vector) are not documented:
   parameter 'vector'
 /root/libmetal/lib/system/freertos/irq.h:44: warning: argument 'interrupt' of command @param is not found in the argument list of metal_irq_isr(unsigned int vector)
 /root/libmetal/lib/system/freertos/irq.c:182: warning: The following parameters of metal_irq_isr(unsigned int vector) are not documented:
   parameter 'vector'
 [100%] Built target doc
 Installing only the local directory...
 -- Install configuration: ""
$ 

うわ、何されたか全然わからない。

いろいろ調べてみたけれど、 install_manifest.txt という空のファイルができただけな気がする?

lib や inclide/metal にはちゃんと libmetal.so やらインクルードファイルやらができているので、 make install すればこれらが /usr/local/lib やらにコピーされて一件落着、となるはず。

rootfs を参照すればクロスコンパイルもできるのでは?

libc6:armhf libsysfs-dev:armhf とか入れるんじゃ無くて、 z-turn 用に作った rootfs 内のライブラリを読ませてみる。

LANG:console
$ sudo apt purge libc6:armhf libsysfs-dev:armhf
$ cd ~/z-turn/libmetal/build_zynq7-linux
$ rm -r * ; cmake -DCMAKE_SYSTEM_PROCESSOR=arm -DCROSS_PREFIX=arm-linux-gnueabihf- -DCMAKE_TOOLCHAIN_FILE=cross-linux-gcc -DCMAKE_LIBRARY_PATH=~/z-turn/rootfs/usr/lib/arm-linux-gnueabihf -DCMAKE_INCLUDE_PATH=~/z-turn/rootfs/usr/include .. ; make
 ...
 [ 21%] Building C object lib/CMakeFiles/metal-shared.dir/system/linux/sleep.c.o
 make[2]: *** 'lib/libmetal.so.0.1.0' に必要なターゲット '/home/osamu/z-turn/rootfs/usr/lib/arm-linux-gnueabihf/libsysfs.so' を make するルールがありません.  中止.
 CMakeFiles/Makefile2:95: ターゲット 'lib/CMakeFiles/metal-shared.dir/all' のレシピで失敗しました
 make[1]: *** [lib/CMakeFiles/metal-shared.dir/all] エラー 2
 Makefile:138: ターゲット 'all' のレシピで失敗しました
 make: *** [all] エラー 2
$ file /home/osamu/z-turn/rootfs/usr/lib/arm-linux-gnueabihf/libsysfs.so
 /home/osamu/z-turn/rootfs/usr/lib/arm-linux-gnueabihf/libsysfs.so: broken symbolic link to /lib/arm-linux-gnueabihf/libsysfs.so.2
$ 

ああ、chroot していないから、フルパスで作成されているシンボリックリンクが全部壊れちゃうのか。

ややこしすぎる。

結局、arm エミュレータ上、あるいは実機上でコンパイルするしか無いのかしら???

zynq-generic 用のビルド

LANG:console
$ mkdir build_zynq7-generic
$ cd build_zynq7-generic
$ cmake -DCMAKE_TOOLCHAIN_FILE=zynq7-generic ..
 -- Host:    Linux/x86_64
 -- Target:  Generic/arm
 -- Machine: zynq7
 -- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
 -- Looking for include file stdatomic.h
 -- Looking for include file stdatomic.h - found
 -- Configuring done
 -- Generating done
 -- Build files have been written to: /home/osamu/z-turn/libmetal/build_zynq7-generic
$ ls -F
 CMakeCache.txt  CTestTestfile.cmake  cmake_install.cmake  lib/
 CMakeFiles/     Makefile             doc/
$ make
 Scanning dependencies of target metal-static
 [  5%] Building C object lib/CMakeFiles/metal-static.dir/device.c.o
 In file included from /home/osamu/z-turn/libmetal/build_zynq7-generic/lib/include/metal/system/generic/sys.h:52:0,
                  from /home/osamu/z-turn/libmetal/build_zynq7-generic/lib/include/metal/sys.h:108,
                  from /home/osamu/z-turn/libmetal/build_zynq7-generic/lib/include/metal/io.h:44,
                  from /home/osamu/z-turn/libmetal/build_zynq7-generic/lib/include/metal/device.h:40,
                  from /home/osamu/z-turn/libmetal/lib/device.c:33:
 /home/osamu/z-turn/libmetal/build_zynq7-generic/lib/include/metal/system/generic/./zynq7/sys.h:40:21: fatal error: xscugic.h: No such file or directory
 compilation terminated.
 lib/CMakeFiles/metal-static.dir/build.make:62: ターゲット 'lib/CMakeFiles/metal-static.dir/device.c.o' のレシピで失敗しました
 make[2]: *** [lib/CMakeFiles/metal-static.dir/device.c.o] エラー 1
 CMakeFiles/Makefile2:93: ターゲット 'lib/CMakeFiles/metal-static.dir/all' のレシピで失敗しました
 make[1]: *** [lib/CMakeFiles/metal-static.dir/all] エラー 2
 Makefile:138: ターゲット 'all' のレシピで失敗しました
 make: *** [all] エラー 2

cmake は成功するものの、 make では一部のヘッダーファイルが足りないようで失敗してしまいました。

xscugic.h は xilinx の gic = 割り込みコントローラ関連のヘッダーファイルのようです。
https://github.com/Xilinx/embeddedsw/blob/master/XilinxProcessorIPLib/drivers/scugic/src/xscugic.h

vivado をインストールすると、
C:\Xilinx\SDK\2016.4\data\embeddedsw\XilinxProcessorIPLib\drivers\scugic_v3_5\src\xscugic.h
に保存されています。

ん~と、これ、どういう風にインストールしたら良いんだろう???
zynq7-linux の場合と同様、petalinux があまりにブラックボックスすぎて困ってしまいます。

LANG:console
$ cd ~/z-turn
$ git clone https://github.com/Xilinx/embeddedsw.git
$ ls embeddedsw/
 README.txt  XilinxProcessorIPLib  lib          mcap
 ThirdParty  doc                   license.txt
$ ls embeddedsw/XilinxProcessorIPLib/drivers/scugic/src/xscugic.h
 embeddedsw/XilinxProcessorIPLib/drivers/scugic/src/xscugic.h
$ rm -r * ; cmake -DCMAKE_TOOLCHAIN_FILE=zynq7-generic .. -DCMAKE_INCLUDE_PATH=~/z-turn/embeddedsw/XilinxProcessorIPLib/drivers/scugic/src/
 (成功)
$ make
 ...
 /home/osamu/z-turn/embeddedsw/XilinxProcessorIPLib/drivers/scugic/src/xscugic.h:175:21: fatal error: xstatus.h: No such file or directory
$ find ~/z-turn/embeddedsw/XilinxProcessorIPLib/drivers/ | grep xstatus.h
 /home/osamu/z-turn/embeddedsw/XilinxProcessorIPLib/drivers/common/src/xstatus.h

drivers/*/src をすべてインクルードパスに入れるのはちょっと馬鹿げている気がするのだけれど。。。

ビルド方法を発見

embeddedsw/ThirdParty/sw_services/libmetal/data/libmetal.tcl
に libmetal をビルドするための tcl ファイルがあった。

embeddedsw/ThirdParty/sw_services/openamp/data/openamp.tcl
もある。

Xilinx SDK にも、
C:\Xilinx\SDK\2016.4\data\embeddedsw\ThirdParty\sw_services/*
に libmetal や openamp が含まれていた。

もしかして、こちらを使ってビルドした方が楽なのかもしれない・・・
(これだけやっておいて orz)

電気回路/zynq/Linux に平行してベアメタルプログラムを走らせる#u1313afb から再開します


Counter: 3678 (from 2010/06/03), today: 7, yesterday: 0