miksadikov / kvim3TPM

Сonnecting and using the TPM (Trusted Platform Module) on Khadas VIM3 SBC
1 stars 0 forks source link

Trying the same things on Khadas Edge V #1

Open Eznopot opened 4 months ago

Eznopot commented 4 months ago

Hello, I came across your Guide to using a TPM 2.0 module on Khadas VIM3. I'm trying to do the same thing but on a Khadas Edge V. I have no particular knowledge of linux kernel and hardware and having to transpose what you do in your guide, I can't manage to do part 2 of your guide on the Edge V, in particular, I'm trying to do option 2: "make an overlay, which will add the necessary functionality on top of the device tree. See the second option below.". But it doesn't work. I'd be very grateful if you'd take the time to help me or have a look. Thanks in advance

miksadikov commented 4 months ago

Hello, Please write in as much detail as possible about what you did and what didn’t work. Please provide log files, error messages, etc. Now, unfortunately, I don’t have Khadas VIM3 and TPM at hand, but I will try to help.

Eznopot commented 4 months ago

Hello, thank you for your reply. I will try to document as much as possible what we have done.

We have followed your recommendations concerning the linux kernel configuration (Step 1 of your guide):

Screenshot 2024-07-03 at 13 13 33 Screenshot 2024-07-03 at 13 14 38

After that we try the second option of the Step 2 of your guide: We use a Khadas Edge V and kernel 6.0 so we don't have overlay in the directory arch/arm64/boot/dts/rockchip. So we have created the overlays folder and i have created a tpm.dts file:

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&spi3>;

        __overlay__ {
            spidev@0 {
                status = "disabled";
            };
        };
    };

    fragment@1 {
        target = <&spi3>;

        __overlay__ {
            status = "okay";

            tpm_tis_spi:tpm@0 {
                status = "okay";
                compatible = "infineon,slb9670", "tcg,tpm_tis_spi";
                reg = <0>;
                spi-max-frequency = <43000000>;
            };
       };
   };
};

I set the target to &spi3 because I didn't find any reference to &spicc1 in other .dts or .dtbfile. Because the folder overlays don't exist I also copy/paste spi3.dts from the 4.4 kernel in the overlays folder:

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&spi3>;
        __overlay__ {
            status = "okay";
        };
    };
};

I have modify the Makefile to compile all .dts in the folder overlays.

After we use Fenix to compile an Ubuntu server image by doing make:

***********************PARAMETERS************************
Fenix Version: 1.6.9.1
Khadas Board: Edge1
Uboot Version: mainline
Uboot Configuration: khadas-edge-captain-rk3399_defconfig
Uboot Branch: master
Linux Version: mainline
Linux Configuration: edges_defconfig
Linux DTB: /arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtb
Linux Branch: khadas-linux-6.0.y
Distribution: Ubuntu
Distribution Release: focal
Distribution Type: server
Distribution Arch: arm64
Install Type: SD-USB
Final Image: edge1-ubuntu-20.04-server-linux-6.0-fenix-1.6.9.1-240703-develop.img
Compressed Image: edge1-ubuntu-20.04-server-linux-6.0-fenix-1.6.9.1-240703-develop.img.xz
*********************************************************

It generate the image and we flash it on the SD Card. The compilation create these .dtbo in the path:

image (2)

After the first boot we modify the /boot/env.txt and set:

image (1)

But after a reboot, command dmesg | grep -I tpm don't print anything and /dev/tpm0 don't appear.

Note: We actually use this TPM: Asus TPM 2.0 SPI

Thanks in adavance for your help.

miksadikov commented 4 months ago

As far as I understand, the manufacturer (Khadas) already provides a overlay for spi3. This overlay is mentioned in the /boot/env.txt file - Device tree overlays: spi3. You need to decompile overlay for spi3 using a device tree compiler and see how spi3 is described there. Based on this overlay for spi3 you need to prepare an overlay for tpm. There is no need to write your own overlay file for spi3. Search the build system and send me an overlay for spi3. Remove your own overlay for spi3 in build system.

If nothing works with overlays, you can simply edit file rk3399-khadas-edge.dtsi (or something like that) - add tpm node there and disable spidev.

miksadikov commented 3 months ago

Hello, did you succeed, did the TPM finally work?

Eznopot commented 3 months ago

Hi ! Unfortunately, we couldn't get the TPM to work... In the meantime, we've recovered a VIM3l, and we're going to try with this version, which is closer to the one you used in your guide. I'll let you know if it works or not, have a nice day!

Eznopot commented 3 months ago

Hello, we still haven't managed to get the TPM 2.0 to work. We've also switched back to EdgeV because we haven't made any more progress on vim3l and we really need to use EdgeV. Following on from the messages above, here's how the spi3 overlay is described:

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&spi3>;
        __overlay__ {
            status = "okay";
        };
    };
};

So for the 2.2 version i add tpm.dts like this:

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&spi3>;

        __overlay__ {
            spidev@0 {
                status = "disabled";
            };
        };
    };

    fragment@1 {
        target = <&spi3>;

        __overlay__ {
            status = "okay";

            tpm_tis_spi:tpm@0 {
                status = "okay";
                compatible = "infineon,slb9670", "tcg,tpm_tis_spi";
                reg = <0>;
                spi-max-frequency = <43000000>;
            };
       };
   };
};

is that OK ? Also for the 2.1 when you say add to dts somewhere near: in the 2.1.1 in your guide, do we need to add this before or in 'spi@15000 ' like this :

spi@15000 {
     compatible = "amlogic,meson-g12a-spicc";
     ...
     tpm_tis_spi:@0 {
       status = "okay";
       compatible = "infineon,slb9670", "tcg,tpm_tis_spi";
       reg = <0>;
       spi-max-frequency = <43000000>;
     };

or this:

tpm_tis_spi:@0 {
     status = "okay";
     compatible = "infineon,slb9670", "tcg,tpm_tis_spi";
     reg = <0>;
     spi-max-frequency = <43000000>;
};
spi@15000 {
     compatible = "amlogic,meson-g12a-spicc";
     ...
}

Thanks for your help !

miksadikov commented 3 months ago

Hi! I was on vacation, so I couldn't answer earlier. Option 1 is correct:

spi@15000 {
     compatible = "amlogic,meson-g12a-spicc";
     ...
     tpm_tis_spi:@0 {
       status = "okay";
       compatible = "infineon,slb9670", "tcg,tpm_tis_spi";
       reg = <0>;
       spi-max-frequency = <43000000>;
     };

Let's try to enter from the other side - make sure that the TPM is connected correctly. For this we need a spidev device. Here is an example of testing the correct connection of the TPM module: SPI communication with Asus E15028 (Nuvoton NPCT750)

./spidev_test -D /dev/spidev0.0 -v -s43000000 -p "\x80\xd4\x00\x00\x00"

spidev-test can be found here