Skip to content

Update to zerocopy 0.8 #2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
444 changes: 293 additions & 151 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ toml = { version = "0.7", default-features = false, features = ["parse", "displa
toml_edit = { version = "0.19", default-features = false }
vcell = { version = "0.1.2", default-features = false }
walkdir = { version = "2.0.0", default-features = false }
zerocopy = { version = "0.6.1", default-features = false }
zerocopy = { version = "0.8.25", default-features = false }
zerocopy-derive = { version = "0.8.25", default-features = false }
zeroize = { version = "1.5.7", default-features = false, features = ["zeroize_derive"] }
zip = { version = "0.6", default-features = false, features = ["bzip2", "deflate", "zstd"] }

Expand All @@ -147,8 +148,8 @@ gimlet-inspector-protocol = { git = "https://github.com/oxidecomputer/gimlet-ins
hif = { git = "https://github.com/oxidecomputer/hif", default-features = false }
humpty = { git = "https://github.com/oxidecomputer/humpty", default-features = false, version = "0.1.3" }
hubtools = { git = "https://github.com/oxidecomputer/hubtools", default-features = false, version = "0.4.6" }
idol = { git = "https://github.com/oxidecomputer/idolatry.git", default-features = false }
idol-runtime = { git = "https://github.com/oxidecomputer/idolatry.git", default-features = false }
idol = { git = "https://github.com/oxidecomputer/idolatry.git", branch = "eliza/zerocopy-0.8", default-features = false }
idol-runtime = { git = "https://github.com/oxidecomputer/idolatry.git", branch = "eliza/zerocopy-0.8", default-features = false }
lpc55_sign = { git = "https://github.com/oxidecomputer/lpc55_support", default-features = false }
ordered-toml = { git = "https://github.com/oxidecomputer/ordered-toml", default-features = false }
pmbus = { git = "https://github.com/oxidecomputer/pmbus", default-features = false }
Expand Down
4 changes: 1 addition & 3 deletions app/cosmo/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ notifications = ["socket"]
[tasks.control_plane_agent]
name = "task-control-plane-agent"
priority = 8
max-sizes = {flash = 131072, ram = 32768}
# This can probably overkill and can be tuned later
stacksize = 6000
stacksize = 6256
start = true
uses = ["usart1"]
task-slots = [
Expand Down
4 changes: 1 addition & 3 deletions app/gimlet/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ notifications = ["socket"]
[tasks.control_plane_agent]
name = "task-control-plane-agent"
priority = 7
max-sizes = {flash = 131072, ram = 32768}
# This can probably overkill and can be tuned later
stacksize = 6000
stacksize = 6256
start = true
uses = ["usart1"]
task-slots = [
Expand Down
4 changes: 1 addition & 3 deletions app/gimletlet/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ tasks = ["control_plane_agent", "caboose_reader"]
[tasks.control_plane_agent]
name = "task-control-plane-agent"
priority = 7
max-sizes = {flash = 131072, ram = 32768}
stacksize = 6000
stacksize = 6256
start = true
uses = ["usart1"]
task-slots = [
Expand Down Expand Up @@ -281,4 +280,3 @@ stacksize = 3800
start = true
task-slots = ["i2c_driver", "sensor"]
notifications = ["timer"]

4 changes: 1 addition & 3 deletions app/grapefruit/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ notifications = ["jefe-state-change", "usart-irq", "multitimer", "control-plane-
[tasks.control_plane_agent]
name = "task-control-plane-agent"
priority = 7
max-sizes = {flash = 131072, ram = 32768}
# This can probably overkill and can be tuned later
stacksize = 6000
stacksize = 6256
start = true
uses = ["usart1"]
task-slots = [
Expand Down
4 changes: 1 addition & 3 deletions app/psc/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ notifications = ["spi-irq"]
[tasks.control_plane_agent]
name = "task-control-plane-agent"
priority = 6
max-sizes = {flash = 131072, ram = 32768}
# This is probably a bit overkill and can be tuned later
stacksize = 6000
stacksize = 6256
start = true
uses = []
task-slots = [
Expand Down
1 change: 0 additions & 1 deletion app/sidecar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ task-slots = ["sys", "packrat", { seq = "sequencer" }, "jefe"]
[tasks.control_plane_agent]
name = "task-control-plane-agent"
priority = 7
max-sizes = {flash = 142900, ram = 65536 }
# This is a big number -- do we need to tune this?
stacksize = 12000
start = true
Expand Down
2 changes: 1 addition & 1 deletion build/xtask/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use lpc55_rom_data::FLASH_PAGE_SIZE as LPC55_FLASH_PAGE_SIZE;
use multimap::MultiMap;
use path_slash::{PathBufExt, PathExt};
use sha3::{Digest, Sha3_256};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::{
caboose_pos,
Expand Down
11 changes: 5 additions & 6 deletions doc/guide/servers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ the `hl` conveniences.
#![no_main]

use userlib::{hl, FromPrimitive}; // <1>
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

#[derive(FromPrimitive)]
enum Op { // <2>
Expand All @@ -184,7 +184,7 @@ pub fn main() -> ! {

loop {
hl::recv_without_notification( // <7>
argument.as_bytes_mut(), // <8>
argument.as_mut_bytes(), // <8>
|op, msg| -> Result<(), ResponseCode> { // <9>
let (msg, caller) = msg.fixed::<u32, u32>() // <10>
.ok_or(ResponseCode::BadArg)?; // <11>
Expand Down Expand Up @@ -219,7 +219,7 @@ same argument type, `u32`, `hl` lets us use it directly instead of dealing in
byte arrays.
<7> `recv_without_notification` wraps up the open receive pattern used by most
servers.
<8> We pass the argument buffer in using `zerocopy::AsBytes`.
<8> We pass the argument buffer in using `zerocopy::IntoBytes`.
<9> This closure handles messages. The `op` parameter is automatically converted
to the `Op` enum by `hl`.
<10> The `fixed` operation requires that the argument exactly match the size of
Expand Down Expand Up @@ -279,7 +279,7 @@ want to retry on server restart:
use abi::TaskId;
use core::cell::Cell;
use userlib::sys_send;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

enum Op { // <1>
Add = 0,
Expand Down Expand Up @@ -312,7 +312,7 @@ impl IntServer {
loop { // <3>
let target = self.0.get();
let (code, response_len) = // <4>
sys_send(target, op, value.as_bytes(), response.as_bytes_mut());
sys_send(target, op, value.as_bytes(), response.as_mut_bytes());

if code == 0 && response_len == 4 {
return response; // <5>
Expand Down Expand Up @@ -385,4 +385,3 @@ NOTE: Remember that tasks can restart -- any table tracking per-task state
should be indexed by task _index_ and record the generation. If a new request
arrives from the same task index but a different generation, the request should
be halted and replaced.

1 change: 1 addition & 0 deletions drv/auxflash-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ num-traits.workspace = true
sha3.workspace = true
tlvc.workspace = true
zerocopy.workspace = true
zerocopy-derive.workspace = true

counters = { path = "../../lib/counters" }
derive-idol-err = { path = "../../lib/derive-idol-err" }
Expand Down
12 changes: 7 additions & 5 deletions drv/auxflash-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use derive_idol_err::IdolError;
use sha3::{Digest, Sha3_256};
use tlvc::{TlvcRead, TlvcReader};
use userlib::{sys_send, FromPrimitive};
use zerocopy::{AsBytes, FromBytes};
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};

pub use drv_qspi_api::{PAGE_SIZE_BYTES, SECTOR_SIZE_BYTES};

Expand Down Expand Up @@ -52,19 +52,21 @@ pub enum AuxFlashError {
ServerRestarted,
}

#[derive(Copy, Clone, FromBytes, AsBytes)]
#[derive(Copy, Clone, FromBytes, IntoBytes, Immutable, KnownLayout)]
#[repr(transparent)]
pub struct AuxFlashId(pub [u8; 20]);

#[derive(Copy, Clone, PartialEq, Eq, FromBytes, AsBytes)]
#[derive(
Copy, Clone, PartialEq, Eq, FromBytes, IntoBytes, Immutable, KnownLayout,
)]
#[repr(transparent)]
pub struct AuxFlashChecksum(pub [u8; 32]);

#[derive(Copy, Clone, FromBytes, AsBytes)]
#[derive(Copy, Clone, FromBytes, IntoBytes, Immutable, KnownLayout)]
#[repr(transparent)]
pub struct AuxFlashTag(pub [u8; 4]);

#[derive(Copy, Clone, FromBytes, AsBytes)]
#[derive(Copy, Clone, FromBytes, IntoBytes, Immutable, KnownLayout)]
#[repr(C)]
pub struct AuxFlashBlob {
pub slot: u32,
Expand Down
1 change: 1 addition & 0 deletions drv/auxflash-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ num-traits = { workspace = true }
stm32h7 = { workspace = true }
tlvc = { workspace = true }
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }

drv-auxflash-api = { path = "../auxflash-api" }
drv-stm32h7-qspi = { path = "../stm32h7-qspi" }
Expand Down
1 change: 1 addition & 0 deletions drv/cosmo-hf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ stm32h7 = { workspace = true }
serde = { workspace = true }
hubpack = { workspace = true }
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }

[build-dependencies]
build-util = { path = "../../build/util" }
Expand Down
4 changes: 2 additions & 2 deletions drv/cosmo-hf/src/hf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use idol_runtime::{
};
use ringbuf::ringbuf_entry_root as ringbuf_entry;
use userlib::{task_slot, RecvMessage, UnwrapLite};
use zerocopy::{AsBytes, FromBytes};
use zerocopy::{FromZeros, IntoBytes};

use crate::{
FlashAddr, FlashDriver, Trace, PAGE_SIZE_BYTES, SECTOR_SIZE_BYTES,
Expand Down Expand Up @@ -137,7 +137,7 @@ impl ServerImpl {
self.drv
.flash_read(
Self::flash_addr_for(addr, dev).unwrap_lite(),
&mut data.as_bytes_mut(),
&mut data.as_mut_bytes(),
)
.unwrap_lite(); // flash_read is infallible when using a slice
best = best.max(Some(data).filter(|d| d.is_valid()));
Expand Down
1 change: 1 addition & 0 deletions drv/cosmo-seq-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cfg-if = { workspace = true }
idol-runtime.workspace = true
num-traits = { workspace = true }
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }

[build-dependencies]
build-fpga-regmap = { path = "../../build/fpga-regmap" }
Expand Down
1 change: 1 addition & 0 deletions drv/cpu-power-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
userlib = { path = "../../sys/userlib" }
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }
num-traits = { workspace = true }
counters = { path = "../../lib/counters", features = ["derive"] }

Expand Down
13 changes: 11 additions & 2 deletions drv/cpu-power-state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
#![no_std]

use userlib::FromPrimitive;
use zerocopy::AsBytes;
use zerocopy::{Immutable, IntoBytes, KnownLayout};

#[derive(
Copy, Clone, Debug, FromPrimitive, PartialEq, Eq, AsBytes, counters::Count,
Copy,
Clone,
Debug,
FromPrimitive,
PartialEq,
Eq,
IntoBytes,
Immutable,
KnownLayout,
counters::Count,
)]
#[repr(u8)]
pub enum PowerState {
Expand Down
1 change: 1 addition & 0 deletions drv/cpu-seq-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
idol-runtime = { workspace = true }
num-traits.workspace = true
zerocopy.workspace = true
zerocopy-derive.workspace = true

counters = { path = "../../lib/counters", features = ["derive"] }
derive-idol-err = { path = "../../lib/derive-idol-err" }
Expand Down
15 changes: 13 additions & 2 deletions drv/cpu-seq-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use counters::Count;
use derive_idol_err::IdolError;
use userlib::{sys_send, FromPrimitive};
use zerocopy::AsBytes;
use zerocopy::{Immutable, IntoBytes, KnownLayout};

// Re-export PowerState for client convenience.
pub use drv_cpu_power_state::PowerState;
Expand All @@ -32,7 +32,18 @@ pub enum SeqError {
ServerRestarted,
}

#[derive(Copy, Clone, Debug, FromPrimitive, Eq, PartialEq, AsBytes, Count)]
#[derive(
Copy,
Clone,
Debug,
FromPrimitive,
Eq,
PartialEq,
IntoBytes,
Immutable,
KnownLayout,
Count,
)]
#[repr(u8)]
pub enum StateChangeReason {
/// No reason was provided.
Expand Down
1 change: 1 addition & 0 deletions drv/eeprom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
idol-runtime = { workspace = true }
num-traits = { workspace = true }
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }

derive-idol-err = {path = "../../lib/derive-idol-err" }
drv-i2c-api = {path = "../i2c-api"}
Expand Down
1 change: 1 addition & 0 deletions drv/fpga-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ num-traits = { workspace = true }
sha3 = { workspace = true, optional = true }
tlvc = { workspace = true, optional = true}
zerocopy = { workspace = true }
zerocopy-derive = { workspace = true }

counters = { path = "../../lib/counters" }
drv-auxflash-api = { path = "../../drv/auxflash-api", optional = true }
Expand Down
Loading
Loading