Skip to content

Commit

Permalink
Add platform::update::is_supported() (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored Dec 6, 2023
1 parent 0b91a03 commit 96a87ec
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/api-desc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Minor

- Add `platform::update::is_supported()`
- Add `platform::update` module
- Add `platform` module with `platform::reboot()` function
- Call some `env_dispatch` function instead of panicking in `native`
Expand Down
7 changes: 7 additions & 0 deletions crates/api-desc/src/platform/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ pub(crate) fn new() -> Item {
};
let name = "update".into();
let items = vec![
item! {
/// Whether platform update is supported.
fn is_supported "pus" {} -> {
/// 1 if supported, 0 otherwise.
supported: usize,
}
},
item! {
/// Returns the metadata of the platform.
///
Expand Down
1 change: 1 addition & 0 deletions crates/prelude/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Minor

- Add `platform::update::is_supported()`
- Add `platform::update` module
- Add `platform` module with `platform::reboot()` function
- Use `wasefire-sync` to provide `sync::Mutex`
Expand Down
6 changes: 6 additions & 0 deletions crates/prelude/src/platform/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ use alloc::boxed::Box;

use wasefire_applet_api::platform::update as api;

/// Returns whether platform update is supported.
pub fn is_supported() -> bool {
let api::is_supported::Results { supported } = unsafe { api::is_supported() };
supported != 0
}

/// Returns the metadata of the platform.
///
/// This typically contains the version and side (A or B) of the running platform.
Expand Down
1 change: 1 addition & 0 deletions crates/scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Minor

- Support `platform::update::is_supported()`
- Support `platform::update`
- Support `platform` and `platform::reboot()`
- Add more debug logging in native mode
Expand Down
12 changes: 11 additions & 1 deletion crates/scheduler/src/call/platform/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@

use wasefire_applet_api::platform::update::{self as api, Api};
use wasefire_board_api::platform::update::Api as _;
use wasefire_board_api::{self as board, Api as Board};
use wasefire_board_api::{self as board, Api as Board, Support};

use crate::applet::store::MemoryApi;
use crate::{DispatchSchedulerCall, SchedulerCall, Trap};

pub fn process<B: Board>(call: Api<DispatchSchedulerCall<B>>) {
match call {
Api::IsSupported(call) => is_supported(call),
Api::Metadata(call) => metadata(call),
Api::Initialize(call) => initialize(call),
Api::Process(call) => process_(call),
Api::Finalize(call) => finalize(call),
}
}

fn is_supported<B: Board>(call: SchedulerCall<B, api::is_supported::Sig>) {
let api::is_supported::Params {} = call.read();
let results = try {
let supported = board::platform::Update::<B>::SUPPORT as u32;
api::is_supported::Results { supported: supported.into() }
};
call.reply(results)
}

fn metadata<B: Board>(mut call: SchedulerCall<B, api::metadata::Sig>) {
let api::metadata::Params { ptr: ptr_ptr, len: len_ptr } = call.read();
let scheduler = call.scheduler();
Expand Down
6 changes: 6 additions & 0 deletions examples/assemblyscript/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,12 @@
// All operations are abstract over the update content such that they can work on all
// platforms. In particular, chunks and errors are platform-specific. Applets with
// knowledge about their platform may actually inspect that content for additional checks.
// Whether platform update is supported.
@external("env", "pus")
export declare function platform_update_is_supported(
// 1 if supported, 0 otherwise.
): usize

// Returns the metadata of the platform.
//
// This typically contains the version and side (A or B) of the running platform.
Expand Down
1 change: 1 addition & 0 deletions examples/rust/update/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
wasefire::applet!();

fn main() {
assert!(platform::update::is_supported());
let metadata = platform::update::metadata().unwrap();
debug!("{metadata:02x?}");
let serial = usb::serial::UsbSerial;
Expand Down

0 comments on commit 96a87ec

Please sign in to comment.