Skip to content

Commit

Permalink
Move loader.rs to td-shim-interface crate
Browse files Browse the repository at this point in the history
Signed-off-by: OuyangHang33 <[email protected]>
  • Loading branch information
OuyangHang33 authored and jyao1 committed Mar 7, 2024
1 parent 3ebd63b commit 6c780e6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Meta data check
run: |
cargo run -p td-shim-tools --bin td-shim-checker --no-default-features --features=loader,read_file -- target/release/final.bin
cargo run -p td-shim-tools --bin td-shim-checker --no-default-features --features=loader -- target/release/final.bin
- name: Build debug image without payload
run: |
Expand Down
1 change: 1 addition & 0 deletions td-shim-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use scroll::{Pread, Pwrite};

pub mod acpi;
pub mod loader;
pub mod metadata;
pub mod td_uefi_pi;

Expand Down
12 changes: 7 additions & 5 deletions td-shim-tools/src/loader.rs → td-shim-interface/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) 2022 Intel Corporation
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
extern crate alloc;

use core::convert::TryInto;
use log::error;
use scroll::Pread;
use td_shim_interface::metadata::{
use crate::metadata::{
self, TdxMetadataDescriptor, TdxMetadataGuid, TdxMetadataSection, TDX_METADATA_DESCRIPTOR_LEN,
TDX_METADATA_GUID_LEN, TDX_METADATA_OFFSET, TDX_METADATA_SECTION_LEN,
};
use alloc::vec::Vec;
use core::convert::TryInto;
use log::error;
use scroll::Pread;

pub struct TdShimLoader;

Expand All @@ -18,7 +20,7 @@ impl TdShimLoader {
/// # Arguments
///
/// * `filename` - The td-shim binary which contains TdxMetadata
pub fn parse(binary_file: Vec<u8>) -> Option<(TdxMetadataDescriptor, Vec<TdxMetadataSection>)> {
pub fn parse(binary_file: &[u8]) -> Option<(TdxMetadataDescriptor, Vec<TdxMetadataSection>)> {
let file_size = binary_file.len();
// Then read 4 bytes at the pos of [file_len - 0x20]
// This is the offset of TdxMetadata
Expand Down
7 changes: 3 additions & 4 deletions td-shim-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ required-features = ["signer"]

[[bin]]
name = "td-shim-checker"
required-features = ["loader", "read_file"]
required-features = ["loader"]

[[bin]]
name = "td-shim-strip-info"
Expand Down Expand Up @@ -61,12 +61,11 @@ byteorder = { version = "1.4.3", optional = true }
parse_int = { version = "0.6.0", optional = true }

[features]
default = ["enroller", "linker", "signer", "loader", "tee", "calculator", "read_file"]
default = ["enroller", "linker", "signer", "loader", "tee", "calculator"]
enroller = ["clap", "der", "env_logger", "log", "ring", "td-shim/secure-boot"]
linker = ["clap", "env_logger", "log", "parse_int", "serde_json", "serde", "td-loader"]
signer = ["clap", "der", "env_logger", "log", "ring", "td-shim/secure-boot"]
loader = ["clap", "env_logger", "log"]
read_file = ["clap", "env_logger", "log", "anyhow"]
loader = ["clap", "env_logger", "log", "anyhow"]
tee = ["clap", "env_logger", "log", "serde_json", "serde", "hex", "sha2", "byteorder"]
calculator = ["clap", "hex", "parse_int", "sha2", "anyhow", "block-padding"]
exec-payload-section = []
4 changes: 2 additions & 2 deletions td-shim-tools/src/bin/td-shim-checker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use log::{error, LevelFilter};
use std::str::FromStr;
use std::vec::Vec;
use std::{env, io};
use td_shim_interface::loader::TdShimLoader;
use td_shim_interface::metadata::{TdxMetadataDescriptor, TdxMetadataSection};
use td_shim_tools::loader::TdShimLoader;
use td_shim_tools::read_file::read_from_binary_file;

struct Config {
Expand Down Expand Up @@ -104,7 +104,7 @@ fn main() -> io::Result<()> {
);

let tdx_file_buff = read_from_binary_file(&config.input).unwrap();
let tdx_metadata = TdShimLoader::parse(tdx_file_buff);
let tdx_metadata = TdShimLoader::parse(&tdx_file_buff);
if tdx_metadata.is_none() {
println!(
"Failed to parse td-shim binary [{}] to get TdxMetadata",
Expand Down
3 changes: 0 additions & 3 deletions td-shim-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ pub mod metadata;
pub mod signer;

#[cfg(feature = "loader")]
pub mod loader;

#[cfg(feature = "read_file")]
pub mod read_file;

#[cfg(feature = "tee")]
Expand Down
2 changes: 1 addition & 1 deletion td-shim-tools/src/read_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::debug;
use std::fs;
use std::io::Read;
use std::io::Seek;
use td_shim::metadata::TDX_METADATA_OFFSET;
use td_shim_interface::metadata::TDX_METADATA_OFFSET;

fn read_from_file(file: &mut std::fs::File, pos: u64, buffer: &mut [u8]) -> Result<()> {
debug!("Read at pos={0:X}, len={1:X}", pos, buffer.len());
Expand Down

0 comments on commit 6c780e6

Please sign in to comment.