You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@teaclave.apache.org by "ivila (via GitHub)" <gi...@apache.org> on 2024/12/20 09:05:44 UTC
[PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
ivila opened a new pull request, #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156
1. add optee-utee-build crate to make building process simpler
2. use optee-utee-build to build hello_world example
3. fix pipeline
this PR relates to #155, and should resolves #135 too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2566088023
update to add reviewer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897929125
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,193 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a default configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
+ pub uuid: uuid::Uuid,
+ pub ta_flags: u32,
+ pub ta_data_size: u32,
+ pub ta_stack_size: u32,
+ pub ta_version: String,
+ pub ta_description: String,
+ pub trace_level: i32,
+ pub trace_ext_prefix: String,
+ pub ta_framework_stack_size: u32,
+ pub ext_properties: Vec<Property>,
+}
+
+impl TAConfig {
+ /// Generate a default config by uuid, this is a wrapper of `new_default`
+ /// function, it retrieves version and description from cargo.toml by
Review Comment:
"cargo.toml" => "your TA's Cargo.toml"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898181649
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
I agree with @b49020, let's just make things simpler, we just tell TA developers setting their `CROSS_COMPILE` env, and that's enough.
But currently cargo do not allow change linker from with build script, so it still need to be done by Makefile.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897789938
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
> As you mentioned above, it's really the good point for solving another building issue #135.
>
> BTW Could you provide some short guidance on how to build examples on ARM host machine (and the choice of linker) at https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/main/README.md#setup-building-environment Such as adding two sections: "building on ARM" , "cross compile on x86_64"? I think it's valuable for our developers.
Actually there is no difference between the two environments when developing (same commands, same linux packages, same environments), I think I should just add a notification about the linker problem so that developers will know more about the building process (especially for the C developers, they may not know that there are `build script binary` and `source code binary`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2563420350
Once this PR gets merged, let's make all the examples to use `optee-utee-build` crate too which can be a followup PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2566051296
Is there anything I miss? I think this PR is inactive for a long time.π
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2577513064
FYI the `optee-utee-build` crate has been published on https://crates.io/crates/optee-utee-build
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2556590802
> 1. add optee-utee-build crate to make building process simpler
> 2. use optee-utee-build to build hello_world example
Split these into separate commits and also add documentation as a separate commit to describe APIs exposed by `optee-utee-build` for TA developers.
> 3. fix pipeline
I suppose it's independent of this PR which is something @DemesneGH should be able to fix in the dockerfile with required dependencies for CI. We want to keep testing with latest OP-TEE mainline build rather than sticking to a stable release.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH merged PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898177988
##########
optee-utee-build/src/linker.rs:
##########
@@ -0,0 +1,182 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::io::{BufRead, BufReader};
+use std::path::PathBuf;
+
+use crate::Error;
+
+/// The type of the linker, there are difference when using gcc/cc or ld/lld as linker,
+/// For example, `--sort-section=alignment` parameter changes to `-Wl,--sort-section=alignment`
+/// when using gcc as linker.
+///
+/// CC: gcc, cc, etc.
+/// LD: ld, lld, ld.bfd, ld.gold, etc.
+#[derive(Debug, Clone)]
+pub enum LinkerType {
+ CC,
+ LD,
+}
+
+/// Linker of ta, use it to handle all linking stuff
+///
+/// Use only if you just want to handle the linking stuff, and use a hand written user_ta_header.rs,
+/// or you should use Builder instead
+/// Usage:
+///
+/// ```no_run
+/// use optee_utee_build::Linker;
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::auto().link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// We detect the type of the linker automatically, you can set it manually if you met some
+/// problems with it.
+/// ```no_run
+/// use optee_utee_build::{Linker, LinkerType};
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::new(LinkerType::CC).link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+pub struct Linker {
+ linker_type: LinkerType,
+}
+
+impl Linker {
+ pub fn new(linker_type: LinkerType) -> Self {
+ Self { linker_type }
+ }
Review Comment:
I will leave some comments on it, or `cargo fmt` would remove the empty line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898316277
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
@b49020 How about add "**Currently, we support building on both aarch64 and amd64 host machines, and they share the same steps.**β under [Setup Building Environment](https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/main/README.md#setup-building-environment), I feel like the [Platforms section]( https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/main/README.md#platforms) more like **running and debugging** rather than **building**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897601358
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
> Using the `ld.bfd` works as well, right?
Yes, it did on cross_compiling, but not working if you compile on arm host machine, as ld.bfd defaultly trying to link to libgcc_s.so instead of libgcc.a if not cross compile(and the argument is `-lgcc_s`).

and with `-Bstatic` provided, it tries to find `libgcc_s.a`, but this is not valid as it should be in the name of `libgcc.a`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2556626849
> also add documentation as a separate commit
@b49020 May I ask what the documentation you points to, the README.md or the comments in rust codes?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2557443686
I still have some changes to make and I am writing the document of how to use this crate, everything should be done in 3 days, so we can pause reviewing this PR and wait until I am finish with it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2558828896
@b49020 @DemesneGH PR fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2560905404
> > I suppose it's independent of this PR which is something @DemesneGH should be able to fix in the dockerfile with required dependencies for CI.
>
> Sure, I'm working on that.
The PR for CI fix: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/157.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897931847
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,187 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a standard configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
+ pub uuid: uuid::Uuid,
+ pub ta_flags: u32,
+ pub ta_data_size: u32,
+ pub ta_stack_size: u32,
+ pub ta_version: String,
+ pub ta_description: String,
+ pub trace_level: i32,
+ pub trace_ext_prefix: String,
+ pub ta_framework_stack_size: u32,
+ pub ext_properties: Vec<Property>,
+}
+
+impl TAConfig {
+ /// generate a standard config by uuid, retrieve version and description from cargo.toml
+ pub fn new_standard_with_cargo_env(uuid_str: &str) -> Result<Self, Error> {
Review Comment:
I agree with this and it will simplify the configuration, we can read the `version` and `description` from `Cargo.toml` then we don't have to set the TA's constants like the previous:
```
const TA_VERSION: &[u8] = b"0.1\0";
const TA_DESCRIPTION: &[u8] = b"This is a hello world example.\0";
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1899886164
##########
optee-utee-build/src/error.rs:
##########
@@ -0,0 +1,43 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#[derive(Debug)]
+pub enum Error {
+ Env(std::env::VarError),
+ IO(std::io::Error),
+ UUID(uuid::Error),
Review Comment:
UUID => Uuid
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2557069760
> I suppose it's independent of this PR which is something @DemesneGH should be able to fix in the dockerfile with required dependencies for CI.
Sure, I'm working on that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2556637389
> > also add documentation as a separate commit
>
> @b49020 May I ask what the documentation you points to, the README.md or the comments in rust codes?
I will suggest to create a dedicated document titled something like "Tutorial: Writing Rust TAs using optee-utee-build" under https://github.com/apache/incubator-teaclave-trustzone-sdk/tree/main/docs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897749388
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
> > Using the `ld.bfd` works as well, right?
>
> Yes, it did on cross_compiling, but not working if you compile on arm host machine, as ld.bfd defaultly trying to link to libgcc_s.so instead of libgcc.a if not cross compile(and the argument is `-lgcc_s`).  and with `-Bstatic` provided, it tries to find `libgcc_s.a`, but this is not valid as it should be in the name of `libgcc.a`
@DemesneGH sorry for my previous misleading response, actually when using `ld.bfd` as linker, its argument is `-Bdynamic -lgcc_s`, the problem of `cannot find -lgcc_s` is that ld.bfd defaultly do not know how to find the libgcc_s.so in host machine (actually gcc has a bunch of undocument configs in it).
Here is how it happens:
1. we have a build.rs, so cargo will need to build a `build script binary` first, the target is the same as host machine, in x64 is **x86_64-unknown-linux-gnu**, in aarch64 is **aarch64-unknown-linux-gnu**.
2. we set linker config by `target.aarch64-unknown-linux-gnu="aarch64-linux-gnu-ld.bfd"`, please keep in mind this change the linker of target **aarch64-unknown-linux-gnu**.
3. then run `make` to build ta, it tries to build a `build script binary` first and then use it to build our source codes, and things going bad starts from here. When building the `build script binary` it requires libunwind for backtrace, adds the requirement of `gcc_s` (yes, this is not added by our source codes but the `build.rs`), but we change the linker (and yes, the target of build script is **aarch64-unknown-linux-gnu** when your host is aarch64 host), so everything fuckup, you will get a link error as you cannot find libgcc_s.so(only gcc knows how to find it, for example, on my coolpi4B with ubuntu23, it is /lib/aarch64-linux-gnu/libgcc_s.so.1).
So my answer is, never use ld.bfd as default linker in if your target is the same as your host machine(aka not cross compiling)
> ### Why it works on x64 host?
> as what I described above, the target of build script is **x86_64-unknown-linux-gnu**, and the target of our source codes is **aarch64-unknown-linux-gnu**, we just change the linker of **aarch64-unknown-linux-gnu**, the build script is fine here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897632803
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
As you mentioned above, it's really the good point for solving another building issue https://github.com/apache/incubator-teaclave-trustzone-sdk/issues/135.
BTW Could you provide some short guidance on how to build examples on ARM host machine (and the choice of linker) at https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/main/README.md#setup-building-environment
Such as adding two sections: "building on ARM" , "cross compile on x86_64"? I think it's valuable for our developers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1899886089
##########
optee-utee-build/src/error.rs:
##########
@@ -0,0 +1,43 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#[derive(Debug)]
+pub enum Error {
+ Env(std::env::VarError),
+ IO(std::io::Error),
Review Comment:
IO => Io
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2566091035
> @ivila CI failed because:
>
> ```
> 24-12-31T02:52:27.0302935Z Compiling ta v0.2.0 (/__w/incubator-teaclave-trustzone-sdk/incubator-teaclave-trustzone-sdk/examples/hello_world-rs/ta)
> 2024-12-31T02:52:27.0773416Z error[E0432]: unresolved import `optee_utee_build::TAConfig`
> 2024-12-31T02:52:27.0774266Z --> build.rs:19:24
> 2024-12-31T02:52:27.0774662Z |
> 2024-12-31T02:52:27.0775144Z 19 | use optee_utee_build::{TAConfig, RustEdition, Error};
> 2024-12-31T02:52:27.0776717Z | ^^^^^^^^
> 2024-12-31T02:52:27.0777049Z | |
> 2024-12-31T02:52:27.0777428Z | no `TAConfig` in the root
> 2024-12-31T02:52:27.0777908Z | help: a similar name exists in the module: `TaConfig`
> 2024-12-31T02:52:27.0778270Z
> 2024-12-31T02:52:27.0819894Z For more information about this error, try `rustc --explain E0432`.
> 2024-12-31T02:52:27.0909479Z error: could not compile `ta` (build script) due to 1 previous error
> ```
Sorry about that, I always miss the `example` partπ
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897914040
##########
optee-utee-build/src/linker.rs:
##########
@@ -0,0 +1,182 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::io::{BufRead, BufReader};
+use std::path::PathBuf;
+
+use crate::Error;
+
+/// The type of the linker, there are difference when using gcc/cc or ld/lld as linker,
+/// For example, `--sort-section=alignment` parameter changes to `-Wl,--sort-section=alignment`
+/// when using gcc as linker.
+///
+/// CC: gcc, cc, etc.
+/// LD: ld, lld, ld.bfd, ld.gold, etc.
+#[derive(Debug, Clone)]
+pub enum LinkerType {
+ CC,
+ LD,
+}
+
+/// Linker of ta, use it to handle all linking stuff
+///
+/// Use only if you just want to handle the linking stuff, and use a hand written user_ta_header.rs,
+/// or you should use Builder instead
+/// Usage:
+///
+/// ```no_run
+/// use optee_utee_build::Linker;
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::auto().link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// We detect the type of the linker automatically, you can set it manually if you met some
+/// problems with it.
+/// ```no_run
+/// use optee_utee_build::{Linker, LinkerType};
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::new(LinkerType::CC).link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+pub struct Linker {
+ linker_type: LinkerType,
+}
+
+impl Linker {
+ pub fn new(linker_type: LinkerType) -> Self {
+ Self { linker_type }
+ }
+ pub fn auto() -> Self {
+ Self {
+ linker_type: Self::auto_detect_linker_type(),
+ }
+ }
+ pub fn link_all<P: Into<PathBuf>>(self, out_dir: P) -> Result<(), Error> {
+ const ENV_TA_DEV_KIT_DIR: &str = "TA_DEV_KIT_DIR";
+ println!("cargo:rerun-if-env-changed={}", ENV_TA_DEV_KIT_DIR);
+ let ta_dev_kit_dir = PathBuf::from(std::env::var(ENV_TA_DEV_KIT_DIR)?);
+ let out_dir: PathBuf = out_dir.into();
+
+ self.write_and_set_linker_script(out_dir.clone(), ta_dev_kit_dir.clone())?;
+
+ let search_path = ta_dev_kit_dir.join("lib");
+ println!("cargo:rustc-link-search={}", search_path.display());
+ println!("cargo:rustc-link-lib=static=utee");
+ println!("cargo:rustc-link-lib=static=utils");
+ println!("cargo:rustc-link-arg=-e__ta_entry");
+ println!("cargo:rustc-link-arg=-pie");
+ println!("cargo:rustc-link-arg=-Os");
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--sort-section=alignment"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--sort-section=alignment"),
+ };
+ let mut dyn_list = File::create(out_dir.join("dyn_list"))?;
+ write!(
+ dyn_list,
+ "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n"
+ )?;
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--dynamic-list=dyn_list"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"),
+ }
+
+ Ok(())
+ }
+}
+
+impl Linker {
+ // generate a link script file for cc/ld, and link to it
+ fn write_and_set_linker_script(
+ &self,
+ out_dir: PathBuf,
+ ta_dev_kit_dir: PathBuf,
+ ) -> Result<(), Error> {
+ const ENV_TARGET_TA: &str = "TARGET_TA";
+ println!("cargo:rerun-if-env-changed={}", ENV_TARGET_TA);
+ let mut aarch64_flag = true;
+ match env::var(ENV_TARGET_TA) {
+ Ok(ref v) if v == "arm-unknown-linux-gnueabihf" || v == "arm-unknown-optee" => {
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--no-warn-mismatch"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--no-warn-mismatch"),
+ };
+ aarch64_flag = false;
+ }
+ _ => {}
+ };
+
+ let f = BufReader::new(File::open(ta_dev_kit_dir.join("src/ta.ld.S"))?);
+ let ta_lds_file_path = out_dir.join("ta.lds");
+ let mut ta_lds = File::create(ta_lds_file_path.clone())?;
+ for line in f.lines() {
+ let l = line?;
+
+ if aarch64_flag {
+ if l.starts_with('#')
+ || l == "OUTPUT_FORMAT(\"elf32-littlearm\")"
+ || l == "OUTPUT_ARCH(arm)"
+ {
+ continue;
+ }
+ } else {
+ if l.starts_with('#')
+ || l == "OUTPUT_FORMAT(\"elf64-littleaarch64\")"
+ || l == "OUTPUT_ARCH(aarch64)"
+ {
+ continue;
+ }
+ }
+
+ if l == "\t. = ALIGN(4096);" {
+ write!(ta_lds, "\t. = ALIGN(65536);\n")?;
+ } else {
+ write!(ta_lds, "{}\n", l)?;
+ }
+ }
+
+ println!("cargo:rustc-link-search={}", out_dir.display());
+ println!("cargo:rerun-if-changed={}", ta_lds_file_path.display());
+ println!("cargo:rustc-link-arg=-T{}", ta_lds_file_path.display());
+ Ok(())
+ }
+
+ fn auto_detect_linker_type() -> LinkerType {
+ const ENV_RUSTC_LINKER: &str = "RUSTC_LINKER";
Review Comment:
Do you expect auto-detection with `RUSTC_LINKER` works when the TA developer has to setup `--config $(LINKER_CFG)` manually? Is there a possibility that we can move that manual linker configuration to this `optee-utee-build` crate too?
##########
optee-utee-build/src/linker.rs:
##########
@@ -0,0 +1,182 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::io::{BufRead, BufReader};
+use std::path::PathBuf;
+
+use crate::Error;
+
+/// The type of the linker, there are difference when using gcc/cc or ld/lld as linker,
+/// For example, `--sort-section=alignment` parameter changes to `-Wl,--sort-section=alignment`
+/// when using gcc as linker.
+///
+/// CC: gcc, cc, etc.
+/// LD: ld, lld, ld.bfd, ld.gold, etc.
+#[derive(Debug, Clone)]
+pub enum LinkerType {
+ CC,
+ LD,
+}
+
+/// Linker of ta, use it to handle all linking stuff
+///
+/// Use only if you just want to handle the linking stuff, and use a hand written user_ta_header.rs,
+/// or you should use Builder instead
+/// Usage:
+///
+/// ```no_run
+/// use optee_utee_build::Linker;
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::auto().link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// We detect the type of the linker automatically, you can set it manually if you met some
+/// problems with it.
+/// ```no_run
+/// use optee_utee_build::{Linker, LinkerType};
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::new(LinkerType::CC).link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+pub struct Linker {
+ linker_type: LinkerType,
+}
+
+impl Linker {
+ pub fn new(linker_type: LinkerType) -> Self {
+ Self { linker_type }
+ }
Review Comment:
nit: prefer space between functions here and below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897353918
##########
docs/migrating-to-new-building-env.md:
##########
@@ -2,6 +2,8 @@
permalink: /trustzone-sdk-docs/migrating-to-new-building-env.md
---
+> After optee-utee-build release, this doc is keeping for developers who intend to know the detail of building process, we suggest use optee-utee-build for building instead.
Review Comment:
Please rewrap the new part to match the line wrapping style of the rest of the document
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
Using the `ld.bfd` works as well, right?
##########
docs/writing-rust-tas-using-optee-utee-build.md:
##########
@@ -0,0 +1,183 @@
+---
+permalink: /trustzone-sdk-docs/writing-rust-tas-using-optee-utee-build.md
+---
+
Review Comment:
When finalizing this documentation, please rewrap all text in this document at 80 characters, this helps to further review and see changes.
Reference: https://thoughtbot.com/blog/wrap-existing-text-at-80-characters-in-vim
##########
optee-utee-build/Cargo.toml:
##########
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+name = "optee-utee-build"
Review Comment:
Do we need a publish of this crate on `crates.io`? After this PR merged I can do that.
##########
docs/writing-rust-tas-using-optee-utee-build.md:
##########
@@ -0,0 +1,183 @@
+---
+permalink: /trustzone-sdk-docs/writing-rust-tas-using-optee-utee-build.md
+---
+
+Currently we provide a `optee-utee-build` crate to simplify the compilcated building process of TA, and we recommend everyone use it in future developement.
+
Review Comment:
Recommend adding index for this document, something like this:
- For legacy app structures migrating to use this crate, refer to [link to Migration Guide]
- If you're new to development, start with [Minimal Example]
- To customize the build process, see [Customization]
##########
.licenserc.yaml:
##########
@@ -31,3 +31,4 @@ header:
- 'DISCLAIMER-WIP'
- '*.json'
- 'examples/tls_server-rs/ta/test-ca/**'
+ - 'optee-utee-build/test_files/**'
Review Comment:
Could the license header be added to the `test_files`?
##########
optee-utee-build/src/linker.rs:
##########
@@ -0,0 +1,175 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::io::{BufRead, BufReader};
+use std::path::PathBuf;
+
+use crate::Error;
+
+/// The type of the linker, there are difference when using gcc/cc or ld/lld as linker,
+/// For example, `--sort-section=alignment` parameter changes to `-Wl,--sort-section=alignment`
+/// when using gcc as linker.
+///
+/// CC: gcc, cc, etc.
+/// LD: ld, lld, ld.bfd, ld.gold, etc.
+#[derive(Debug, Clone)]
+pub enum LinkerType {
+ CC,
+ LD,
+}
+
+/// Linker of ta, use it to handle all linking stuff
+///
+/// Use only if you just want to handle the linking stuff, and use a hand written user_ta_header.rs,
+/// or you should use Builder instead
+/// Usage:
+///
+/// ```no_run
+/// use optee_utee_build::Linker;
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::auto().link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// We detect the type of the linker automatically, you can set it manually if you met some
+/// problems with it.
+/// ```no_run
+/// use optee_utee_build::{Linker, LinkerType};
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::new(LinkerType::CC).link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+pub struct Linker {
+ linker_type: LinkerType,
+}
+
+impl Linker {
+ pub fn new(linker_type: LinkerType) -> Self {
+ Self { linker_type }
+ }
+ pub fn auto() -> Self {
+ Self { linker_type: Self::auto_detect_linker_type() }
+ }
+ pub fn link_all<P: Into<PathBuf>>(self, out_dir: P) -> Result<(), Error> {
+ const ENV_TA_DEV_KIT_DIR: &str = "TA_DEV_KIT_DIR";
+ println!("cargo:rerun-if-env-changed={}", ENV_TA_DEV_KIT_DIR);
+ let ta_dev_kit_dir = PathBuf::from(std::env::var(ENV_TA_DEV_KIT_DIR)?);
+ let out_dir: PathBuf = out_dir.into();
+
+ self.write_and_set_linker_script(out_dir.clone(), ta_dev_kit_dir.clone())?;
+
+ let search_path = ta_dev_kit_dir.join("lib");
+ println!("cargo:rustc-link-search={}", search_path.display());
+ println!("cargo:rustc-link-lib=static=utee");
+ println!("cargo:rustc-link-lib=static=utils");
+ println!("cargo:rustc-link-arg=-e__ta_entry");
+ println!("cargo:rustc-link-arg=-pie");
+ println!("cargo:rustc-link-arg=-Os");
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--sort-section=alignment"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--sort-section=alignment"),
+ };
+ let mut dyn_list = File::create(out_dir.join("dyn_list"))?;
+ write!(
+ dyn_list,
+ "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n"
+ )?;
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--dynamic-list=dyn_list"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"),
+ }
+
+ Ok(())
+ }
+}
+
+impl Linker {
+ // generate a link script file for cc/ld, and link to it
+ fn write_and_set_linker_script(&self, out_dir: PathBuf, ta_dev_kit_dir: PathBuf) -> Result<(), Error> {
+ const ENV_TARGET_TA: &str = "TARGET_TA";
+ println!("cargo:rerun-if-env-changed={}", ENV_TARGET_TA);
+ let mut aarch64_flag = true;
+ match env::var(ENV_TARGET_TA) {
+ Ok(ref v) if v == "arm-unknown-linux-gnueabihf" || v == "arm-unknown-optee" => {
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--no-warn-mismatch"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--no-warn-mismatch"),
+ };
+ aarch64_flag = false;
+ }
+ _ => {}
+ };
+
+ let f = BufReader::new(File::open(ta_dev_kit_dir.join("src/ta.ld.S"))?);
+ let ta_lds_file_path = out_dir.join("ta.lds");
+ let mut ta_lds = File::create(ta_lds_file_path.clone())?;
+ for line in f.lines() {
+ let l = line?;
+
+ if aarch64_flag {
+ if l.starts_with('#')
+ || l == "OUTPUT_FORMAT(\"elf32-littlearm\")"
+ || l == "OUTPUT_ARCH(arm)"
+ {
+ continue;
+ }
+ } else {
+ if l.starts_with('#')
+ || l == "OUTPUT_FORMAT(\"elf64-littleaarch64\")"
+ || l == "OUTPUT_ARCH(aarch64)"
+ {
+ continue;
+ }
+ }
+
+ if l == "\t. = ALIGN(4096);" {
+ write!(ta_lds, "\t. = ALIGN(65536);\n")?;
+ } else {
+ write!(ta_lds, "{}\n", l)?;
+ }
+ }
+
+ println!("cargo:rustc-link-search={}", out_dir.display());
+ println!("cargo:rerun-if-changed={}", ta_lds_file_path.display());
+ println!("cargo:rustc-link-arg=-T{}", ta_lds_file_path.display());
+ Ok(())
+ }
+
+ fn auto_detect_linker_type() -> LinkerType {
+ const ENV_RUSTC_LINKER: &str = "RUSTC_LINKER";
+ println!("cargo:rerun-if-env-changed={}", ENV_RUSTC_LINKER);
+ match env::var(ENV_RUSTC_LINKER) {
+ Ok(ref linker_name) if linker_name.ends_with("ld") || linker_name.ends_with("ld.bfd") => {
+ return LinkerType::LD;
+ },
+ _ => {},
+ };
+ return LinkerType::CC;
Review Comment:
simplify to:
Ok(xxxx) => LinkerType::LD,
_ => LinkerType::CC
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,187 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a standard configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
+ pub uuid: uuid::Uuid,
+ pub ta_flags: u32,
+ pub ta_data_size: u32,
+ pub ta_stack_size: u32,
+ pub ta_version: String,
+ pub ta_description: String,
+ pub trace_level: i32,
+ pub trace_ext_prefix: String,
+ pub ta_framework_stack_size: u32,
+ pub ext_properties: Vec<Property>,
+}
+
+impl TAConfig {
+ /// generate a standard config by uuid, retrieve version and description from cargo.toml
+ pub fn new_standard_with_cargo_env(uuid_str: &str) -> Result<Self, Error> {
Review Comment:
1. How about naming this to "default config"?
`new_default_with_cargo_env`
`new_default`
2. Could we have some description of when we should use `new_standard_with_cargo_env`? Why we read these values `CARGO_PKG_VERSION` `CARGO_PKG_DESCRIPTION`?
##########
optee-utee-build/Cargo.toml:
##########
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+name = "optee-utee-build"
+version = "0.2.0"
+authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+license = "Apache-2.0"
+repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git"
+edition = "2018"
+description = "Build tool for TA"
+
Review Comment:
When finalizing, please run `cargo fmt` for this crate
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,187 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a standard configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
+ pub uuid: uuid::Uuid,
+ pub ta_flags: u32,
+ pub ta_data_size: u32,
+ pub ta_stack_size: u32,
+ pub ta_version: String,
+ pub ta_description: String,
+ pub trace_level: i32,
+ pub trace_ext_prefix: String,
+ pub ta_framework_stack_size: u32,
+ pub ext_properties: Vec<Property>,
+}
+
+impl TAConfig {
+ /// generate a standard config by uuid, retrieve version and description from cargo.toml
+ pub fn new_standard_with_cargo_env(uuid_str: &str) -> Result<Self, Error> {
+ Self::new_standard(
+ uuid_str,
+ std::env::var("CARGO_PKG_VERSION")?.as_str(),
+ std::env::var("CARGO_PKG_DESCRIPTION")?.as_str(),
+ )
+ }
+ /// generate a standard config
+ pub fn new_standard(
+ uuid_str: &str,
+ ta_version: &str,
+ ta_description: &str,
+ ) -> Result<Self, Error> {
+ Ok(Self {
+ uuid: uuid_str.try_into()?,
+ ta_flags: 0,
+ ta_data_size: 1 * 1024 * 1024,
+ ta_stack_size: 2 * 1024,
Review Comment:
Keep the default values same as the which in optee_examples: https://github.com/linaro-swg/optee_examples/blob/master/hello_world/ta/user_ta_header_defines.h#L47-L50
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898288529
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
Okay, that's fine. Let's do following additionally to further clarify things:
1. Add comment as @DemesneGH described above:
> How about keeping this modification and add a simple comment upon this:
>
> ```
> -LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
> + # Configure the linker to use GCC, which works on both cross-compilation and ARM machines
> +LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
> ```
2. Update https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/main/README.md#platforms with a subsection to say the supported host machines as `x86-64` and `arm64`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898200336
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
After further investigation, I found that `aarch64-linux-gnu-gcc` and `arm-linux-gnueabihf-gcc` exists on aarch64 hosts too, so I will just change `setup.sh` to install the right toolchains on aarch64 host, and keep all the steps all the same on different hosts (it's more platform-independent because, when using Rust, there shouldn't be any difference regardless of the host system developers on)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1899884166
##########
docs/migrating-to-new-building-env.md:
##########
@@ -2,6 +2,10 @@
permalink: /trustzone-sdk-docs/migrating-to-new-building-env.md
---
+> After optee-utee-build release, this doc is keeping for developers
+who intend to know the detail of building process, we suggest use
+optee-utee-build for building instead.
Review Comment:
Add the link to optee-utee-build doc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2561148340
update to use latest ci
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2566091919
update to fix the `compilation error of hello-world example`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897749388
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
> > Using the `ld.bfd` works as well, right?
>
> Yes, it did on cross_compiling, but not working if you compile on arm host machine, as ld.bfd defaultly trying to link to libgcc_s.so instead of libgcc.a if not cross compile(and the argument is `-lgcc_s`).  and with `-Bstatic` provided, it tries to find `libgcc_s.a`, but this is not valid as it should be in the name of `libgcc.a`
@DemesneGH @b49020 @msgilligan sorry for my previous wrong response, actually when using `ld.bfd` as linker, its argument is `-Bdynamic -lgcc_s`, the problem of `cannot find -lgcc_s` is that ld.bfd defaultly do not know how to find the libgcc_s.so in host machine (actually gcc has a bunch of undocument configs in it).
Here is how it happens:
1. we have a build.rs, so cargo will need to build a `build script binary` first, the target is the same as host machine, in x64 is **x86_64-unknown-linux-gnu**, in aarch64 is **aarch64-unknown-linux-gnu**.
2. we set linker config by `target.aarch64-unknown-linux-gnu="aarch64-linux-gnu-ld.bfd"`, please keep in mind this change the linker of target **aarch64-unknown-linux-gnu**.
3. then run `make` to build ta, it tries to build a `build script binary` first and then use it to build our source codes, and things going bad starts from here. When building the `build script binary` it requires libunwind for backtrace, adds the requirement of `gcc_s` (yes, this is not added by our source codes but the `build.rs`), but we change the linker (and yes, the target of build script is **aarch64-unknown-linux-gnu** when your host is aarch64 host), so everything fuckup, you will get a link error as you cannot find libgcc_s.so(only gcc knows how to find it, for example, on my coolpi4B with ubuntu23, it is /lib/aarch64-linux-gnu/libgcc_s.so.1).
So my answer is, never use ld.bfd as default linker in if your target is the same as your host machine(aka not cross compiling)
> ### Why it works on x64 host?
> as what I described above, the target of build script is **x86_64-unknown-linux-gnu**, and the target of our source codes is **aarch64-unknown-linux-gnu**, we just change the linker of **aarch64-unknown-linux-gnu**, the build script is fine here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898320578
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
> "Currently, we support building on both aarch64 and amd64 host machines, and they share the same steps.β under [Setup Building Environment](https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/main/README.md#setup-building-environment),
Let's rather be specific regarding host machines as output of command `uname -m` which gives you `x86_64` and `aarch64`. I don't have strong preference for the section to put this under.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897603501
##########
optee-utee-build/Cargo.toml:
##########
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+name = "optee-utee-build"
Review Comment:
Yes, thanks in advance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1899885335
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,193 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a default configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
Review Comment:
Use UpperCamelCase "TaConfig" according to Rust's naming conventions. Reference: https://rust-lang.github.io/api-guidelines/naming.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2566088393
Thanks! Will merge after the CI passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1899885847
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,193 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a default configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_default(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
+ pub uuid: uuid::Uuid,
+ pub ta_flags: u32,
+ pub ta_data_size: u32,
+ pub ta_stack_size: u32,
+ pub ta_version: String,
+ pub ta_description: String,
+ pub trace_level: i32,
+ pub trace_ext_prefix: String,
+ pub ta_framework_stack_size: u32,
+ pub ext_properties: Vec<Property>,
+}
+
+impl TAConfig {
+ /// Generate a default config by uuid, this is a wrapper of `new_default`
+ /// function, it retrieves version and description from your TA's cargo.toml
+ /// by environment-variables provided by cargo for building script, make
+ /// constructor simpler.
+ ///
+ /// If your version and description of TA are different with the version and
+ /// description of your crate, use `new_default` to provide them manually.
+ pub fn new_default_with_cargo_env(uuid_str: &str) -> Result<Self, Error> {
+ Self::new_default(
+ uuid_str,
+ std::env::var("CARGO_PKG_VERSION")?.as_str(),
+ std::env::var("CARGO_PKG_DESCRIPTION")?.as_str(),
+ )
+ }
+ /// generate a default config
+ pub fn new_default(
+ uuid_str: &str,
+ ta_version: &str,
+ ta_description: &str,
+ ) -> Result<Self, Error> {
+ Ok(Self {
+ uuid: uuid_str.try_into()?,
+ ta_flags: 0,
+ ta_data_size: 32 * 1024,
+ ta_stack_size: 2 * 1024,
+ ta_version: ta_version.to_string(),
+ ta_description: ta_description.to_string(),
+ trace_level: 4,
+ trace_ext_prefix: "TA".to_string(),
+ ta_framework_stack_size: 2048,
+ ext_properties: Vec::new(),
+ })
+ }
+ pub fn ta_flags(mut self, flags: u32) -> Self {
+ self.ta_flags = flags;
+ self
+ }
+ pub fn ta_stack_size(mut self, stack_size: u32) -> Self {
+ self.ta_stack_size = stack_size;
+ self
+ }
+ pub fn ta_data_size(mut self, size: u32) -> Self {
+ self.ta_data_size = size;
+ self
+ }
+ pub fn trace_level(mut self, level: i32) -> Self {
+ self.trace_level = level;
+ self
+ }
+ pub fn trace_ext_prefix<S: Into<String>>(mut self, prefix: S) -> Self {
+ self.trace_ext_prefix = prefix.into();
+ self
+ }
+ pub fn ta_framework_stack_size(mut self, stack_size: u32) -> Self {
+ self.ta_framework_stack_size = stack_size;
+ self
+ }
+ pub fn add_ext_property(mut self, name: &str, value: PropertyValue) -> Self {
+ self.ext_properties.push(Property::new(name, value));
+ self
+ }
+}
+
+/// An enum of PropertyValue, with its type and value combined
+///
+/// Usage:
+/// ```rust
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// # use optee_utee_build::PropertyValue;
+/// # use std::convert::TryInto;
+/// # const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// # const LOGIN: u32 = 1;
+/// PropertyValue::Bool(true);
+/// PropertyValue::U32(1);
+/// PropertyValue::UUID(UUID.try_into()?);
+/// PropertyValue::Identity(LOGIN, UUID.try_into()?);
+/// // a string value, must not append '\0' at last, we will add it for you.
+/// PropertyValue::Str("hello world".to_string());
+/// // a base64 string value, must not append '\0' at last, we will add it for you.
+/// PropertyValue::BinaryBlock("c2RmYXNm".to_string());
+/// PropertyValue::U64(1);
+/// # Ok(())
+/// # }
+#[derive(Debug, Clone)]
+pub enum PropertyValue {
+ Bool(bool),
+ U32(u32),
+ UUID(uuid::Uuid),
Review Comment:
naming convention: UUID => Uuid
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1899887752
##########
optee-utee-build/src/linker.rs:
##########
@@ -0,0 +1,190 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::io::{BufRead, BufReader};
+use std::path::PathBuf;
+
+use crate::Error;
+
+/// The type of the linker, there are difference when using gcc/cc or ld/lld as
+/// linker, For example, `--sort-section=alignment` parameter changes to
+/// `-Wl,--sort-section=alignment` when using gcc as linker.
+///
+/// CC: gcc, cc, etc.
+/// LD: ld, lld, ld.bfd, ld.gold, etc.
+#[derive(Debug, Clone)]
+pub enum LinkerType {
+ CC,
+ LD,
Review Comment:
Cc,
Ld
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2566090547
@ivila CI failed because:
```
24-12-31T02:52:27.0302935Z Compiling ta v0.2.0 (/__w/incubator-teaclave-trustzone-sdk/incubator-teaclave-trustzone-sdk/examples/hello_world-rs/ta)
2024-12-31T02:52:27.0773416Z error[E0432]: unresolved import `optee_utee_build::TAConfig`
2024-12-31T02:52:27.0774266Z --> build.rs:19:24
2024-12-31T02:52:27.0774662Z |
2024-12-31T02:52:27.0775144Z 19 | use optee_utee_build::{TAConfig, RustEdition, Error};
2024-12-31T02:52:27.0776717Z | ^^^^^^^^
2024-12-31T02:52:27.0777049Z | |
2024-12-31T02:52:27.0777428Z | no `TAConfig` in the root
2024-12-31T02:52:27.0777908Z | help: a similar name exists in the module: `TaConfig`
2024-12-31T02:52:27.0778270Z
2024-12-31T02:52:27.0819894Z For more information about this error, try `rustc --explain E0432`.
2024-12-31T02:52:27.0909479Z error: could not compile `ta` (build script) due to 1 previous error
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2559028681
Update to remove the confusing extra properties of `gp.ta.version` and `gp.ta.description`, as in this [commit](https://github.com/linaro-swg/optee_examples/commit/20e5a612e6303820c1e41faf8aa265404b28de82#diff-a0e1cb79ba65ecda7851beef61ad66d58e4cfdc1568b0cfd58118e6442a0ab28L27) [jforissier](https://github.com/linaro-swg/optee_examples/commits?author=jforissier) said they are just `misleading TA properties`:

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897920854
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
How about keeping this modification and add a simple comment upon this:
```
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+ # Configure the linker to use GCC, which works on both cross-compilation and ARM machines
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
```
Since it will be added into each example's Makefile, I'm not sure if we need to explain the details such as `build script binary` and `source code binary` here.
Would it be more reasonable to create a separate short doc for the building process in `docs/`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897926780
##########
examples/hello_world-rs/ta/Makefile:
##########
@@ -20,7 +20,7 @@ UUID ?= $(shell cat "../uuid.txt")
TARGET ?= aarch64-unknown-linux-gnu
CROSS_COMPILE ?= aarch64-linux-gnu-
OBJCOPY := $(CROSS_COMPILE)objcopy
-LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)ld.bfd\"
+LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
Review Comment:
I think it's more preferable for `optee_utee_build` crate to consume `CROSS_COMPILE` environment variable and setup linker configuration accordingly.
And regarding documentation update, I don't think we want developers to learn about how `optee_utee_build` crate figures out linker given the `CROSS_COMPILE` path. Instead the documentation should rather be just about letting the user know how to build Rust TAs in either cross-compiled environment (x86 host) or native environment (arm64 host). I think that will just boil down to the value of `CROSS_COMPILE` variable being empty ("") for native compilation and ("path-to-gcc-cross-compiler") for cross compilation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "b49020 (via GitHub)" <gi...@apache.org>.
b49020 commented on PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#issuecomment-2563362200
Thanks @ivila for your efforts addressing review comments, the last one pending for me is [here](https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898288529). With that addressed, feel free to add:
`Reviewed-by: Sumit Garg <su...@linaro.org>`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1897604567
##########
optee-utee-build/src/ta_config.rs:
##########
@@ -0,0 +1,187 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use crate::Error;
+use std::convert::TryInto;
+
+/// Configuration options for TA
+///
+/// Examples
+///
+/// # use a standard configuration
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// and since we already have `version` and `description` in `cargo.toml`,
+/// we can make it simpler by using them as parameters:
+///
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard_with_cargo_env(UUID)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// # make some modifications
+/// ```rust
+/// use optee_utee_build::TAConfig;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// const UUID: &str = "d93c2970-b1a6-4b86-90ac-b42830e78d9b";
+/// let ta_config = TAConfig::new_standard(
+/// UUID,
+/// "0.1.0",
+/// "hello world",
+/// )?.ta_stack_size(10 * 1024).ta_data_size(32 * 1024);
+/// # Ok(())
+/// # }
+/// ```
+#[derive(Debug, Clone)]
+pub struct TAConfig {
+ pub uuid: uuid::Uuid,
+ pub ta_flags: u32,
+ pub ta_data_size: u32,
+ pub ta_stack_size: u32,
+ pub ta_version: String,
+ pub ta_description: String,
+ pub trace_level: i32,
+ pub trace_ext_prefix: String,
+ pub ta_framework_stack_size: u32,
+ pub ext_properties: Vec<Property>,
+}
+
+impl TAConfig {
+ /// generate a standard config by uuid, retrieve version and description from cargo.toml
+ pub fn new_standard_with_cargo_env(uuid_str: &str) -> Result<Self, Error> {
Review Comment:
> How about naming this to "default config"?
changed
> Could we have some description of when we should use new_standard_with_cargo_env?
done
> Why we read these values CARGO_PKG_VERSION CARGO_PKG_DESCRIPTION
those values are provided by cargo, see [Environment variables Cargo sets for crates](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org
Re: [PR] Add optee-utee-build crate [incubator-teaclave-trustzone-sdk]
Posted by "ivila (via GitHub)" <gi...@apache.org>.
ivila commented on code in PR #156:
URL: https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/156#discussion_r1898177017
##########
optee-utee-build/src/linker.rs:
##########
@@ -0,0 +1,182 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::io::{BufRead, BufReader};
+use std::path::PathBuf;
+
+use crate::Error;
+
+/// The type of the linker, there are difference when using gcc/cc or ld/lld as linker,
+/// For example, `--sort-section=alignment` parameter changes to `-Wl,--sort-section=alignment`
+/// when using gcc as linker.
+///
+/// CC: gcc, cc, etc.
+/// LD: ld, lld, ld.bfd, ld.gold, etc.
+#[derive(Debug, Clone)]
+pub enum LinkerType {
+ CC,
+ LD,
+}
+
+/// Linker of ta, use it to handle all linking stuff
+///
+/// Use only if you just want to handle the linking stuff, and use a hand written user_ta_header.rs,
+/// or you should use Builder instead
+/// Usage:
+///
+/// ```no_run
+/// use optee_utee_build::Linker;
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::auto().link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+/// We detect the type of the linker automatically, you can set it manually if you met some
+/// problems with it.
+/// ```no_run
+/// use optee_utee_build::{Linker, LinkerType};
+/// use std::env;
+/// # use optee_utee_build::Error;
+/// # fn main() -> Result<(), Error> {
+/// let out_dir = env::var("OUT_DIR")?;
+/// Linker::new(LinkerType::CC).link_all(out_dir)?;
+/// # Ok(())
+/// # }
+/// ```
+///
+pub struct Linker {
+ linker_type: LinkerType,
+}
+
+impl Linker {
+ pub fn new(linker_type: LinkerType) -> Self {
+ Self { linker_type }
+ }
+ pub fn auto() -> Self {
+ Self {
+ linker_type: Self::auto_detect_linker_type(),
+ }
+ }
+ pub fn link_all<P: Into<PathBuf>>(self, out_dir: P) -> Result<(), Error> {
+ const ENV_TA_DEV_KIT_DIR: &str = "TA_DEV_KIT_DIR";
+ println!("cargo:rerun-if-env-changed={}", ENV_TA_DEV_KIT_DIR);
+ let ta_dev_kit_dir = PathBuf::from(std::env::var(ENV_TA_DEV_KIT_DIR)?);
+ let out_dir: PathBuf = out_dir.into();
+
+ self.write_and_set_linker_script(out_dir.clone(), ta_dev_kit_dir.clone())?;
+
+ let search_path = ta_dev_kit_dir.join("lib");
+ println!("cargo:rustc-link-search={}", search_path.display());
+ println!("cargo:rustc-link-lib=static=utee");
+ println!("cargo:rustc-link-lib=static=utils");
+ println!("cargo:rustc-link-arg=-e__ta_entry");
+ println!("cargo:rustc-link-arg=-pie");
+ println!("cargo:rustc-link-arg=-Os");
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--sort-section=alignment"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--sort-section=alignment"),
+ };
+ let mut dyn_list = File::create(out_dir.join("dyn_list"))?;
+ write!(
+ dyn_list,
+ "{{ __elf_phdr_info; trace_ext_prefix; trace_level; ta_head; }};\n"
+ )?;
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--dynamic-list=dyn_list"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--dynamic-list=dyn_list"),
+ }
+
+ Ok(())
+ }
+}
+
+impl Linker {
+ // generate a link script file for cc/ld, and link to it
+ fn write_and_set_linker_script(
+ &self,
+ out_dir: PathBuf,
+ ta_dev_kit_dir: PathBuf,
+ ) -> Result<(), Error> {
+ const ENV_TARGET_TA: &str = "TARGET_TA";
+ println!("cargo:rerun-if-env-changed={}", ENV_TARGET_TA);
+ let mut aarch64_flag = true;
+ match env::var(ENV_TARGET_TA) {
+ Ok(ref v) if v == "arm-unknown-linux-gnueabihf" || v == "arm-unknown-optee" => {
+ match self.linker_type {
+ LinkerType::CC => println!("cargo:rustc-link-arg=-Wl,--no-warn-mismatch"),
+ LinkerType::LD => println!("cargo:rustc-link-arg=--no-warn-mismatch"),
+ };
+ aarch64_flag = false;
+ }
+ _ => {}
+ };
+
+ let f = BufReader::new(File::open(ta_dev_kit_dir.join("src/ta.ld.S"))?);
+ let ta_lds_file_path = out_dir.join("ta.lds");
+ let mut ta_lds = File::create(ta_lds_file_path.clone())?;
+ for line in f.lines() {
+ let l = line?;
+
+ if aarch64_flag {
+ if l.starts_with('#')
+ || l == "OUTPUT_FORMAT(\"elf32-littlearm\")"
+ || l == "OUTPUT_ARCH(arm)"
+ {
+ continue;
+ }
+ } else {
+ if l.starts_with('#')
+ || l == "OUTPUT_FORMAT(\"elf64-littleaarch64\")"
+ || l == "OUTPUT_ARCH(aarch64)"
+ {
+ continue;
+ }
+ }
+
+ if l == "\t. = ALIGN(4096);" {
+ write!(ta_lds, "\t. = ALIGN(65536);\n")?;
+ } else {
+ write!(ta_lds, "{}\n", l)?;
+ }
+ }
+
+ println!("cargo:rustc-link-search={}", out_dir.display());
+ println!("cargo:rerun-if-changed={}", ta_lds_file_path.display());
+ println!("cargo:rustc-link-arg=-T{}", ta_lds_file_path.display());
+ Ok(())
+ }
+
+ fn auto_detect_linker_type() -> LinkerType {
+ const ENV_RUSTC_LINKER: &str = "RUSTC_LINKER";
Review Comment:
> Do you expect auto-detection with RUSTC_LINKER works when the TA developer has to setup `--config $(LINKER_CFG)` manually?
Actually the environment `RUSTC_LINKER` indicate what developers setup for linker, it would be empty if TA developer didn't setup `--config $(LINKER_CFG)`, so yes, it would work if TA developer has to setup `--config $(LINKER_CFG)`.
> Is there a possibility that we can move that manual linker configuration to this optee-utee-build crate too?
No, currently cargo not allow the linker to be changed by build script.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org