Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/i2c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ fn i2c(context: &mut ExecutionContext) -> Result<()> {
let block_size = 16u16;
let nibble_size = block_size + addr_size;

let data_size = context.data_size();
let data_size = context.data_size()?;
let mut chunk: usize = data_size - (data_size % nibble_size as usize);
let mut offset = 0u16;

Expand Down
4 changes: 2 additions & 2 deletions cmd/qspi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ fn write(
context.get_function("QspiPageProgram", 3)?
};

let data_size = context.data_size() as u32;
let data_size = context.data_size()? as u32;
let chunk = data_size - (data_size % device.block_size);
let mut offset = 0;

Expand Down Expand Up @@ -639,7 +639,7 @@ fn qspi(context: &mut ExecutionContext) -> Result<()> {
//
// Now we're ready to write/verify in units of blocksize.
//
let data_size = context.data_size() as u32;
let data_size = context.data_size()? as u32;
let chunk = data_size - (data_size % BLOCK_SIZE);
let mut offset = 0;

Expand Down
8 changes: 6 additions & 2 deletions humility-auxflash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ impl<'a> AuxFlashHandler<'a> {
}
}

// Get the hiffy data size before doing any work, because this could
// fail (if we're on a backend that doesn't support data transfers)
let data_size = self.context.data_size()?;

humility::msg!("erasing slot {slot}");
self.slot_erase(slot)?;

Expand All @@ -252,8 +256,8 @@ impl<'a> AuxFlashHandler<'a> {
.template("humility: writing [{bar:30}] {bytes}/{total_bytes}"),
);
bar.set_length(data.len() as u64);
for (i, chunk) in data.chunks(self.context.data_size()).enumerate() {
let offset = i * self.context.data_size();
for (i, chunk) in data.chunks(data_size).enumerate() {
let offset = i * data_size;
let value = humility_hiffy::hiffy_call(
self.hubris,
self.core,
Expand Down
1 change: 1 addition & 0 deletions humility-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub trait Core {
pub enum NetAgent {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this non_exhaustive to make additions like this not a breaking change (after this one)? Do we care about breaking changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so – this is only ever used as an input, so it would be weird for outside the net core to match on it.

In general, we (Hubris / Humility) don't care much about breaking changes to quasi-internal Rust APIs, where no one is consuming them besides us and blast radius is a single repository (no one is using NetAgent outside of the humility repo). This could change as Humility gets library-ified, but even then I suspect we'll err on the side of breaking things freely.

UdpRpc,
DumpAgent,
Hiffy,
}

pub fn attach_dump(
Expand Down
40 changes: 40 additions & 0 deletions humility-core/src/hubris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,13 @@ impl HubrisArchive {
}
}

pub fn lookup_module_by_name(&self, name: &str) -> Result<&HubrisModule> {
match self.modules.values().find(|m| m.name == name) {
Some(module) => Ok(module),
None => Err(anyhow!("no such task: {name}")),
}
}

pub fn lookup_module_by_iface(&self, name: &str) -> Option<&HubrisModule> {
(0..self.ntasks())
.map(|t| self.lookup_module(HubrisTask::Task(t as u32)).unwrap())
Expand Down Expand Up @@ -6632,6 +6639,39 @@ impl HubrisModule {
}
}
}

/// Looks up enum variants by name, casting to a particular integer type
pub fn get_enum_variants_by_name<T: TryFrom<u64> + TryFrom<i64>>(
&self,
hubris: &HubrisArchive,
name: &str,
) -> Result<BTreeMap<String, T>>
where
<T as TryFrom<i64>>::Error: std::error::Error + Send + Sync + 'static,
<T as TryFrom<u64>>::Error: std::error::Error + Send + Sync + 'static,
{
let Some(enum_ty) = self.lookup_enum_byname(hubris, name)? else {
bail!("could not find enum `{name}`");
};
enum_ty
.variants
.iter()
.map(|v| {
let Some(tag) = v.tag else {
bail!("variant `{}` has no tag", v.name);
};
let t = match tag {
Tag::Signed(i) => T::try_from(i).with_context(|| {
format!("variant tag {i} for {} does not fit", v.name)
})?,
Tag::Unsigned(i) => T::try_from(i).with_context(|| {
format!("variant tag {i} for {} does not fit", v.name)
})?,
};
Ok((v.name.clone(), t))
})
.collect::<Result<BTreeMap<_, _>>>()
}
}

#[derive(Copy, Clone, Debug, Default)]
Expand Down
16 changes: 15 additions & 1 deletion humility-doppel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use humility::reflect::{self, Base, Load, Ptr, Value};
use indexmap::IndexMap;
use std::convert::TryInto;
use std::fmt;
use zerocopy::{AsBytes, LittleEndian, U16, U64};
use zerocopy::{AsBytes, LittleEndian, U16, U32, U64};

#[derive(Copy, Clone, Debug, Eq, PartialEq, Load)]
pub struct TaskDesc {
Expand Down Expand Up @@ -430,6 +430,20 @@ pub struct RpcHeader {
pub nbytes: U16<LittleEndian>,
}

/// Double of the RPC types from `hiffy` (with the `net` feature enabled)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth it to extract this into a shared crate somehow to avoid the risk of unsync'd changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, that would be the most robust option – but in practice, we've got a few of these internal message types and they're primitive enough to never change. There's also the fact that if they did change, we'd want to support both versions in Humility, because Humility wants to talk to every Hubris image.

pub mod hiffy {
use super::*;

#[derive(Copy, Clone, Debug, AsBytes)]
#[repr(C)]
pub struct RpcHeader {
pub image_id: U64<LittleEndian>,
pub version: U16<LittleEndian>,
pub operation: U16<LittleEndian>,
pub arg: U32<LittleEndian>,
}
}

impl humility::reflect::Load for CountedRingbuf {
fn from_value(v: &Value) -> Result<Self> {
let rb_struct = v.as_struct()?;
Expand Down
2 changes: 1 addition & 1 deletion humility-dump-agent/src/hiffy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl DumpAgent for HiffyDumpAgent<'_> {
// returned data size and the Hiffy context's `rdata` array size.
let op = self.hubris.get_idol_command("DumpAgent.read_dump")?;
let rsize = self.hubris.lookup_type(op.ok)?.size(self.hubris)?;
let chunksize = (self.context.rdata_size() / rsize) - 1;
let chunksize = (self.context.rstack_size() / rsize) - 1;

let mut rval = vec![];
loop {
Expand Down
1 change: 1 addition & 0 deletions humility-hiffy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hif.workspace = true
idol.workspace = true
parse_int.workspace = true
postcard.workspace = true
thiserror.workspace = true
zerocopy.workspace = true

humility.workspace = true
Expand Down
Loading
Loading