libmetal のインストール の履歴(No.1)
更新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-linux 用の設定を読み込む†
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- となってしまう?
ただ、CMakeLists.txt を読んでもこの platform を指定する方法がわかりませんでした。
そこで、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
ダメっぽい???
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++ $ cat CMakeFiles/3.5.1/CMakeSystem.cmake set(CMAKE_HOST_SYSTEM "Linux-4.4.0-62-generic") set(CMAKE_HOST_SYSTEM_NAME "Linux") set(CMAKE_HOST_SYSTEM_VERSION "4.4.0-62-generic") set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") set(CMAKE_SYSTEM "Linux-4.4.0-62-generic") set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_VERSION "4.4.0-62-generic") set(CMAKE_SYSTEM_PROCESSOR "x86_64") set(CMAKE_CROSSCOMPILING "FALSE") set(CMAKE_SYSTEM_LOADED 1) $ grep -s CMakeSystem `find` ./CMakeFiles/Makefile.cmake: "CMakeFiles/3.5.1/CMakeSystem.cmake" ./CMakeFiles/Makefile.cmake: "/usr/share/cmake-3.5/Modules/CMakeSystem.cmake.in" ./CMakeFiles/Makefile.cmake: "/usr/share/cmake-3.5/Modules/CMakeSystemSpecificInformation.cmake" ./CMakeFiles/Makefile.cmake: "/usr/share/cmake-3.5/Modules/CMakeSystemSpecificInitialize.cmake" ./CMakeFiles/Makefile.cmake: "CMakeFiles/3.5.1/CMakeSystem.cmake" $
zynq-generic 用のビルド†
LANG:console $ mkdir build_zynq7-generic $ cd build_zynq7-generic $ cmake -DPLATFORM_NAME=zynq7-generic .. -- 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: 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
に保存されています。
ん~と、これ、どういう風にインストールしたら良いんだろう???
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 $