Skip to content

Commit

Permalink
removed some debug print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Athryx committed Mar 8, 2024
1 parent c5e2932 commit 1de55b1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 91 deletions.
43 changes: 1 addition & 42 deletions application_processor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ use rand::rngs::ThreadRng;
use rand::Rng;

use bcrypt::bcrypt;
use deployment::{force_rerun, generate_random_bytes, parse_component_id, SecretDb};


struct LineParser<'a> {
data: &'a str,
}
use deployment::{force_rerun, generate_random_bytes, parse_component_id, SecretDb, LineParser};

/*
* Generate an address that is a multiple of 8
Expand All @@ -22,37 +17,6 @@ fn gen_addr(start: u32, end: u32, rng: &mut ThreadRng) -> u32 {
rng.gen_range((start/8 + 1)..(end/8)) * 8
}

impl<'a> LineParser<'a> {
fn take_until_index(&mut self, index: usize) -> &'a str {
let out = &self.data[..index];
self.data = &self.data[index..];
out
}

fn take_token(&mut self) -> Option<&'a str> {
if self.data.len() == 0 {
return None;
}

let out = self.take_until_index(self.data.find(' ').unwrap_or(self.data.len()));
self.data = self.data.trim_start();
Some(out)
}

fn take_string(&mut self) -> Option<&'a str> {
if self.data.get(..1)? != "\"" {
return None;
}

self.data = &self.data[1..];

let out = self.take_until_index(self.data.find('"')?);
self.data = &self.data[1..];

Some(out)
}
}

// this build script just parses ap ectf params from inc/ectf_params.h into a rust file $OUT_DIR/ectf_params.rs
fn main() {
force_rerun();
Expand Down Expand Up @@ -127,11 +91,6 @@ fn main() {

rust_code.push_str("];\n");
},
Some("COMPONENT_CNT") => {
let data = parser.take_token().expect("no parameter for COMPONENT_CNT");

rust_code.push_str(&format!("pub const COMPONENTS_LEN: u8 = {};\n", data));
},
Some("AP_BOOT_MSG") => {
let data = parser.take_string().expect("no parameter for AP_BOOT_MSG");

Expand Down
6 changes: 0 additions & 6 deletions application_processor/src/post_boot/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::ApError;
use crate::ap_driver::ApDriver;

pub fn secure_send(driver: &mut ApDriver, address: I2cAddr, message: &[u8]) -> Result<(), ApError> {
uprintln_debug!("secure send to: {address:x?} {message:?}");
let flash_data = driver.get_flash_data();
let component = flash_data.get_component_for_i2c_addr(address)
.ok_or(ApError::InvalidComponentError)?;
Expand All @@ -34,8 +33,6 @@ pub fn secure_send(driver: &mut ApDriver, address: I2cAddr, message: &[u8]) -> R
signature: signature.into(),
})?;

uprintln_debug!("secure send done");

Ok(())
}

Expand All @@ -44,7 +41,6 @@ pub fn secure_receive(
address: I2cAddr,
recv_buf: &mut [u8; MAX_POST_BOOT_MESSAGE_SIZE]
) -> Result<usize, ApError> {
uprintln_debug!("secure recieve from: {address:x?}");
let flash_data = driver.get_flash_data();
let component = flash_data.get_component_for_i2c_addr(address)
.ok_or(ApError::InvalidComponentError)?;
Expand Down Expand Up @@ -77,7 +73,5 @@ pub fn secure_receive(
let message_len = message.message.len();
recv_buf[..message_len].copy_from_slice(message.message.as_slice());

uprintln_debug!("secure recv done: {:?}", message.message);

Ok(message_len)
}
1 change: 0 additions & 1 deletion application_processor/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fn perform_replace(driver: &mut ApDriver) -> Result<(), ApError> {

driver.save_flash_data(flash_data);

uprintln_debug!("Replaced 0x{:08x} with 0x{:08x}", old_component_id, new_component_id);
uprintln_success!("Replace");

Ok(())
Expand Down
37 changes: 1 addition & 36 deletions component/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::PathBuf;
use std::env;

use rand::rngs::ThreadRng;
use deployment::{SecretDb, parse_component_id, generate_encrypted_rust_const, force_rerun};
use deployment::{SecretDb, parse_component_id, generate_encrypted_rust_const, force_rerun, LineParser};
use rand::Rng;

/*
Expand All @@ -15,41 +15,6 @@ fn gen_addr(start: u32, end: u32, rng: &mut ThreadRng) -> u32 {
rng.gen_range((start/8 + 1)..(end/8)) * 8
}

struct LineParser<'a> {
data: &'a str,
}

impl<'a> LineParser<'a> {
fn take_until_index(&mut self, index: usize) -> &'a str {
let out = &self.data[..index];
self.data = &self.data[index..];
out
}

fn take_token(&mut self) -> Option<&'a str> {
if self.data.len() == 0 {
return None;
}

let out = self.take_until_index(self.data.find(' ').unwrap_or(self.data.len()));
self.data = self.data.trim_start();
Some(out)
}

fn take_string(&mut self) -> Option<&'a str> {
if self.data.get(..1)? != "\"" {
return None;
}

self.data = &self.data[1..];

let out = self.take_until_index(self.data.find('"')?);
self.data = &self.data[1..];

Some(out)
}
}

// this build script just parses ap ectf params from inc/ectf_params.h into a rust file $OUT_DIR/ectf_params.rs
fn main() {
force_rerun();
Expand Down
6 changes: 0 additions & 6 deletions component/src/post_boot/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::ComponentError;
use crate::component_driver::ComponentDriver;

pub fn secure_send(driver: &mut ComponentDriver, message: &[u8]) -> Result<(), ComponentError> {
uprintln!("secure send: {message:?}");
// TODO: send ap error if serialization fails
let post_boot_request: PostBootMessageStart = driver.recv_struct()?;

Expand All @@ -37,16 +36,13 @@ pub fn secure_send(driver: &mut ComponentDriver, message: &[u8]) -> Result<(), C
signature: signature.into(),
})?;

uprintln!("secure send done");

Ok(())
}

pub fn secure_receive(
driver: &mut ComponentDriver,
recv_buf: &mut [u8; MAX_POST_BOOT_MESSAGE_SIZE]
) -> Result<usize, ComponentError> {
uprintln!("secure recieve");
// TODO: send ap error if serialization fails
let post_boot_request: PostBootMessageStart = driver.recv_struct()?;

Expand Down Expand Up @@ -96,7 +92,5 @@ pub fn secure_receive(
let message_len = message.message.len();
recv_buf[..message_len].copy_from_slice(message.message.as_slice());

uprintln!("secure recieve done: {:?}", message.message);

Ok(message_len)
}
35 changes: 35 additions & 0 deletions deployment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,39 @@ pub fn force_rerun() {
write!(file, "a").unwrap();

println!("cargo:rerun-if-changed=.cargo_build_rs_rerun");
}

pub struct LineParser<'a> {
pub data: &'a str,
}

impl<'a> LineParser<'a> {
pub fn take_until_index(&mut self, index: usize) -> &'a str {
let out = &self.data[..index];
self.data = &self.data[index..];
out
}

pub fn take_token(&mut self) -> Option<&'a str> {
if self.data.len() == 0 {
return None;
}

let out = self.take_until_index(self.data.find(' ').unwrap_or(self.data.len()));
self.data = self.data.trim_start();
Some(out)
}

pub fn take_string(&mut self) -> Option<&'a str> {
if self.data.get(..1)? != "\"" {
return None;
}

self.data = &self.data[1..];

let out = self.take_until_index(self.data.find('"')?);
self.data = &self.data[1..];

Some(out)
}
}

0 comments on commit 1de55b1

Please sign in to comment.