OP-TEE/optee_os

How to Enable I2C on NW Kernel for Raspberry Pi

Closed this issue · 10 comments

Hello,

I have been able to successfully boot Ubuntu 18.04 64 bit image as NW FS for Raspberry Pi 3 with OPTEE (I am using v3.1.0 that uses a busybox-based kernel for NW) -- I copied everything from boot and also the library/TA/supplicant etc. files to /lib and /bin. The example applications runs fine in the image.

However, I could not able to enable I2C in the Raspberry Pi. I tried to change config.txt (in /boot) by enabling dtparam=i2c_arm=on however this does not work. It seems the kernel image in /boot directory does not support I2C/Device tree? I do see the file bcm2710-rpi-3-b.dtb exists though. If I boot with the other kernel comes with Ubuntu (say kernel=kernel8.bin in config.txt) then I2C works fine (however, this disables TZ/OPTEE). Any pointer how can I enable I2C from the busybox or the OPTEE kernel in /boot?

A wild guess from my side is that it might be that it's not enabled in the .config. I would cross check that also and if it's not enabled, then it should be possible to enable it from here: https://github.com/OP-TEE/build/blob/master/kconfigs/rpi3.conf (in case you are using build.git etc for your OP-TEE / RPi3 environment).

Sorry perhaps I am missing something -- what would be the flag that I should use in kconfigs/rpi3.conf to enable I2C? Yes, I am using https://github.com/OP-TEE/build -- though not the master branch (pulled from tag v3.1)

what would be the flag that I should use in ...

I don't know, that's what I hinted that you need to figure out (this not really an OP-TEE question, it's a pure Linux kernel related question). I imagine there are many I2C flags in Linux kernel depending on what device you are running. So the first steps are to figure out, what is the correct I2C flag for the device you intend to use (RPi3 ...) and then see if it is already enabled, if not ... enabled it in the file I referred to.

Here seems to be some hints for RPi3 specific config:

Thanks. I already used dtparam=i2c_arm=on in /boot/firmware/config.txt as in the first link -- but it didn't work. My guess is that the kernel somehow doesn't know about the device tree used in RPi3. Let me check how vanilla Raspbian kernel uses this and update kconfigs/rpi3.conf in OPTEE build accordingly.

The problem was with the U-Boot -- it does not recognize device-tree-overlays. This can be solved if we use the recent version of the U-Boot (say the one in the master branch manifest) and also add I2C in the config: dtparam=i2c_arm=on in /boot/firmware/config.txt.

Thanks @mnwrhsn , your findings might be useful in the future for other people, so we appreciate that you've taken the time to post the solution here.

@jbech-linaro We were thinking of taking this up. You had also mentioned adding (as a ToDo) support for i2c in your mail as well. But it appears, adding support for i2c is just a matter of enabling the right kernel configs or using the correct u-boot version.

Could you advise if this needs to be pursued? Otherwise, we will look at something else to work on.

@jbech-linaro We were thinking of taking this up. You had also mentioned adding (as a ToDo) support for i2c in your mail as well. But it appears, adding support for i2c is just a matter of enabling the right kernel configs or using the correct u-boot version.

Could you advise if this needs to be pursued? Otherwise, we will look at something else to work on.

@johnphilby , there are two different things here, OP wants to use I2C from RPi in Linux, but what I referred to in our email discussion was about adding I2C support in the TEE itself. I.e, something similiar to what we did with SPI (https://github.com/OP-TEE/optee_os/blob/master/core/include/spi.h), but for I2C instead. There are peripherals, that could also be usable in a TEE that communicates using I2C. I've for example seen NFC readers, fingerprint readers etc that are using I2C as the communication protocol. So, having the ability to use I2C, protect the I2C peripheral from normal world access would be a useful thing in OP-TEE. IIRC no-one have started to actually do that work, so if this sounds interesting and useful for you also, then by all means, go a head and start look into that.

@jbech-linaro Excellent. We will start work on this right away.

@vvramya Please take this task up in earnest and see it to completion. We can even procure i2c NFC/fingerprint readers for this.