apache / incubator-teaclave-trustzone-sdk

Teaclave TrustZone SDK enables safe, functional, and ergonomic development of trustlets.
https://teaclave.apache.org
Apache License 2.0
203 stars 58 forks source link

./hello_world-rs not found in shared folder #94

Closed HakonToemte closed 1 year ago

HakonToemte commented 1 year ago

Hello, I wish to develop a new CA/TA in OPTEE using Rust with QEMUv8. I have been following this guide, and created a shared folder to run these applications in QEMU. I am now trying to see if i can alter hello_world-rs to use a different number than the original example does. But even though it seems that i have succesfully shared the installed examples, I get error: not found. Issue

I found this issue, and I can run hello_world-rs, but that's the original and unaltered example. I want to run my new, altered version. image The file should be executable. image

I am very thankful for any help with this!

DemesneGH commented 1 year ago

Hi @HakonToemte , Seems this error occurs in some cases, but I've not reproduced it. Let's check these items to figure it out:

Thanks!

HakonToemte commented 1 year ago

Thanks for the quick response! My building environment is built by first following OP-TEE with Rust, then Build & Install, then Run Rust applications. I have not used docker. I hope that answers the first question. I am also using Ubuntu 22.04 if thats relevant.

file ./hello_world-rs image

ldd ./hello_world-rs image

DemesneGH commented 1 year ago

@HakonToemte It seems the hello_world-rs you built is a 32-bit (arm) ELF which is not compatible with the 64-bit (aarch64) QEMUv8 platform. Suggest to unset ARCH and rebuild the host app, reference: https://github.com/apache/incubator-teaclave-trustzone-sdk#build--install.

HakonToemte commented 1 year ago

image It works now :) So now if i want to change the value, i just change 29 to 30 for example, then compile the example again and update the shared_folder? I ask because i often end up doing something wrong, and then normal world won't start and i end up building everything from scratch again. If I want to create a new CA/TA, is there a good guide for that? Either way thanks :)

DemesneGH commented 1 year ago

then compile the example again and update the shared_folder

Yes, you just need to recompile the example you've modified:

$ make -C examples/your-example

Then copy the CA and TA into shared_folder:

$ cp example/your-example/host/target/aarch64-unknown-linux-gnu/release/[your CA] path/to/shared/folder
$ cp example/your-example/ta/target/aarch64-unknown-optee-trustzone/release/[your TA] path/to/shared/folder

After copying ta into /lib/optee_armtz you can run the new CA you built.

If I want to create a new CA/TA, is there a good guide for that?

There is no documentation about writing a new CA/TA now. You can follow these steps to write your Rust example:

  1. Duplicate the hello_world-rs example and modify the code upon it.
  2. Decide commands the host app sends to TA, and modify proto/src/lib.rs
  3. In host:
    • modify the app name in host/Makefile and host/Cargo.toml
    • write your logic in host/src/main.rs
  4. In TA:
    • generate a random uuid and modify uuid.txt
    • write your logic in ta/src/main.rs
  5. build your example
HakonToemte commented 1 year ago

That was tremendous help, thank you very much!