PeterHuewe / tpm-emulator

The famous tpm-emulator by Mario Strasser, previously hosted on BerliOs. It supports TPM1.2 only!
GNU General Public License v2.0
177 stars 75 forks source link

TPM-emulator, #22

Closed senioruos closed 5 years ago

senioruos commented 7 years ago

Hello,

Im trying to install the TPM emulator on my Raspberry Pi 3 from github using the 'clone or download' option, and i followed the commands:

mkdir build cd build cmake ../ make

when in the 'make' command it gives the following error:

"Scanning dependencies of target tpmd_dev [ 96%] Generating linux/tpmd_dev.ko make[4]: /lib/modules/4.4.38-v7+/build: No such file or directory. Stop. Makefile:22: recipe for target 'all' failed make[3]: [all] Error 2 tpmd_dev/CMakeFiles/tpmd_dev.dir/build.make:62: recipe for target 'tpmd_dev/linux/tpmd_dev.ko' failed make[2]: [tpmd_dev/linux/tpmd_dev.ko] Error 2 CMakeFiles/Makefile2:383: recipe for target 'tpmd_dev/CMakeFiles/tpmd_dev.dir/all' failed make[1]: [tpmd_dev/CMakeFiles/tpmd_dev.dir/all] Error 2 Makefile:149: recipe for target 'all' failed make: *** [all] Error 2"

can anyone help me please? ps: im installing it in my raspberry pi 3

golubevmikhail commented 7 years ago

Hi senioruos, You should cross-compile it against your current running kernel. Start with build.sh. I have the following build script for TI board:

!/bin/sh

BUILD_DIR="build"

if [ "$1" = "clean" ]; then rm -rf $BUILD_DIR fi

if [ ! -d $BUILD_DIR ]; then mkdir $BUILD_DIR || exit 1 fi

TI_SDK_PATH="/home/mike/ti-sdk" LINUX_DEVKIT_PATH="${TI_SDK_PATH}/linux-devkit" SYSROOT="${LINUX_DEVKIT_PATH}/sysroots/armv7ahf-neon-linux-gnueabi" CROSS_COMPILE="${LINUX_DEVKIT_PATH}/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-" CC="${CROSS_COMPILE}gcc" LD="${CROSS_COMPILE}ld" AR="${CROSS_COMPILE}ar" RANLIB="${CROSS_COMPILE}ranlib"

KERNEL_BUILD="${TI_SDK_PATH}/board-support/processor-sdk-linux"

INSTALL_PREFIX="${TI_SDK_PATH}/targetNFS" DESTDIR=${INSTALL_PREFIX}

cd build cmake ../ -DCMAKE_C_COMPILER=${CC} -DCMAKE_LINKER=${LD} -DCMAKE_AR=${AR} -DCMAKE_RANLIB=${RANLIB} -DCMAKE_SYSROOT=${SYSROOT} -DCMAKE_C_FLAGS="-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard" -DCMAKE_ARCH=arm -DCMAKE_KERNEL_BUILD=${KERNEL_BUILD} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DCMAKE_DESTDIR=${DESTDIR}

-DMTM_EMULATOR=ON

make sudo make install cd ..

exit 0

senioruos commented 7 years ago

hello @golubevmikhail thanks for your prompt reply! I tried to include this code in my build.sh but it does not work. I still get the same error.. Is it because I am using a Raspberry Pi?

golubevmikhail commented 7 years ago

@senioruos I also have one more modification:

diff --git a/tpmd_dev/CMakeLists.txt b/tpmd_dev/CMakeLists.txt
index aadc877..a5cedef 100644
--- a/tpmd_dev/CMakeLists.txt
+++ b/tpmd_dev/CMakeLists.txt
@@ -10,8 +10,8 @@ set(tpmd_dev_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/linux")
 set(tpmd_dev_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/linux")
 set(tpmd_dev_OBJ "${tpmd_dev_BINARY_DIR}/tpmd_dev.ko")
 if(CMAKE_COMPILER_IS_GNUCC)
-  set(tpmd_dev_BUILD_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER})
-  set(tpmd_dev_INSTALL_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER} install)
+  set(tpmd_dev_BUILD_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER} ARCH=${CMAKE_ARCH} KERNEL_BUILD=${CMAKE_KERNEL_BUILD})
+  set(tpmd_dev_INSTALL_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER} ARCH=${CMAKE_ARCH} KERNEL_BUILD=${CMAKE_KERNEL_BUILD} DESTDIR=${CMAKE_DESTDIR} install)
 else()
   set(tpmd_dev_BUILD_CMD make -C ${tpmd_dev_BINARY_DIR})
   set(tpmd_dev_INSTALL_CMD make -C ${tpmd_dev_BINARY_DIR} install)
senioruos commented 7 years ago

@golubevmikhail can you please tell me where to include this modification?

Thanks a lot !

golubevmikhail commented 7 years ago

@senioruos one patch to roll 'em all. $ git clone https://github.com/PeterHuewe/tpm-emulator.git $ cp cross_compile.patch tpm-emulator/ $ cd tpm-emulator/ $ git apply cross_compile.patch (modify build_cross.sh according to your environment) $ ./build_cross.sh

Here is cross_compile.patch:

From 25ed2b0253f292c7dd272de0433dbb2c0dc128b1 Mon Sep 17 00:00:00 2001
From: Mikhail Golubev <golubev.mikhail@gmail.com>
Date: Wed, 15 Mar 2017 17:47:32 +0300
Subject: [PATCH] ARM cross compile

---
 build_cross.sh          | 35 +++++++++++++++++++++++++++++++++++
 tpmd_dev/CMakeLists.txt |  4 ++--
 2 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100755 build_cross.sh

diff --git a/build_cross.sh b/build_cross.sh
new file mode 100755
index 0000000..0133ba3
--- /dev/null
+++ b/build_cross.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+BUILD_DIR="build"
+
+if [ "$1" = "clean" ]; then
+  rm -rf $BUILD_DIR
+fi
+
+if [ ! -d $BUILD_DIR ]; then
+  mkdir $BUILD_DIR || exit 1
+fi
+
+TI_SDK_PATH="/home/mike/ti-sdk"
+LINUX_DEVKIT_PATH="${TI_SDK_PATH}/linux-devkit"
+SYSROOT="${LINUX_DEVKIT_PATH}/sysroots/armv7ahf-neon-linux-gnueabi"
+CROSS_COMPILE="${LINUX_DEVKIT_PATH}/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-"
+CC="${CROSS_COMPILE}gcc"
+LD="${CROSS_COMPILE}ld"
+AR="${CROSS_COMPILE}ar"
+RANLIB="${CROSS_COMPILE}ranlib"
+
+KERNEL_BUILD="${TI_SDK_PATH}/board-support/processor-sdk-linux"
+
+INSTALL_PREFIX="${TI_SDK_PATH}/targetNFS"
+DESTDIR=${INSTALL_PREFIX}
+
+cd build
+cmake ../ -DCMAKE_C_COMPILER=${CC} -DCMAKE_LINKER=${LD} -DCMAKE_AR=${AR} -DCMAKE_RANLIB=${RANLIB} -DCMAKE_SYSROOT=${SYSROOT} -DCMAKE_C_FLAGS="-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard" -DCMAKE_ARCH=arm -DCMAKE_KERNEL_BUILD=${KERNEL_BUILD} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DCMAKE_DESTDIR=${DESTDIR}
+#-DMTM_EMULATOR=ON 
+make
+sudo make install
+cd ..
+
+exit 0
+
diff --git a/tpmd_dev/CMakeLists.txt b/tpmd_dev/CMakeLists.txt
index aadc877..a5cedef 100644
--- a/tpmd_dev/CMakeLists.txt
+++ b/tpmd_dev/CMakeLists.txt
@@ -10,8 +10,8 @@ set(tpmd_dev_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/linux")
 set(tpmd_dev_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/linux")
 set(tpmd_dev_OBJ "${tpmd_dev_BINARY_DIR}/tpmd_dev.ko")
 if(CMAKE_COMPILER_IS_GNUCC)
-  set(tpmd_dev_BUILD_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER})
-  set(tpmd_dev_INSTALL_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER} install)
+  set(tpmd_dev_BUILD_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER} ARCH=${CMAKE_ARCH} KERNEL_BUILD=${CMAKE_KERNEL_BUILD})
+  set(tpmd_dev_INSTALL_CMD make -C ${tpmd_dev_BINARY_DIR} CC=${CMAKE_C_COMPILER} LD=${CMAKE_LINKER} ARCH=${CMAKE_ARCH} KERNEL_BUILD=${CMAKE_KERNEL_BUILD} DESTDIR=${CMAKE_DESTDIR} install)
 else()
   set(tpmd_dev_BUILD_CMD make -C ${tpmd_dev_BINARY_DIR})
   set(tpmd_dev_INSTALL_CMD make -C ${tpmd_dev_BINARY_DIR} install)
-- 
2.7.4
senioruos commented 7 years ago

@PeterHuewe Can you please help me solve the issue? Thanks alot

senioruos commented 7 years ago

@golubevmikhail

I am a beginner to this, so what I understood I should do is either add (+) or remove (-) the lines of code in CMakeList.text and update the build.sh file based on your very first reply?

is it that whats needed? If yes, I did that and yet I face same issue..

and thanks for your help

PeterHuewe commented 7 years ago

He is not cross compiling. Please just install your kernel headers and sources via apt. Peter

PeterHuewe commented 7 years ago

See https://github.com/raspberrypi/firmware/issues/63

-- Sent from my mobile

senioruos commented 7 years ago

@PeterHuewe Thanks!

PeterHuewe commented 7 years ago

@senioruos can we close this?

saifuddin123 commented 6 years ago

Hi Peter, I am seeing the same issue on raspberrypi 3 armhf. I am not an expert in this area so want to make sure if i am doing right as per your reference above raspberrypi/firmware#63. Are below the series of commands i need to execute?

git clone --depth=1 git://github.com/raspberrypi/linux.git rpi-linux git checkout rpi-3.18.y make bcmrpi_defconfig make prepare headers_install git pull && make clean bcmrpi_defconfig prepare headers_install

git clone https://github.com/PeterHuewe/tpm-emulator.git cd tpm_emulator mkdir build cd build cmake ../ make

Thank you..

PeterHuewe commented 5 years ago

I close this for now as it seems solved. Feel free to open a new issue if needed.

saifuddin123 commented 5 years ago

sorry, i didn't had a chance to work on this. I was actually confirming on the steps, if that's the sequence to be executed.