Skip to content

Commit 2a11f9d

Browse files
committed
Merge branch 'main' of github.com:betrusted-io/xous-core into main
2 parents 1ca0ef7 + fa90e74 commit 2a11f9d

File tree

11 files changed

+121
-47
lines changed

11 files changed

+121
-47
lines changed

services/gam/src/contexts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ impl ContextManager {
330330
token: [u32; 4],
331331
clear: bool,
332332
) -> Result<(), xous::Error> {
333+
//log::set_max_level(log::LevelFilter::Trace);
333334
self.notify_app_switch(token).ok();
334335

335336
let mut leaving_visibility: bool = false;
@@ -483,6 +484,7 @@ impl ContextManager {
483484
self.redraw().expect("couldn't redraw the currently focused app");
484485
}
485486
}
487+
//log::set_max_level(log::LevelFilter::Info);
486488
Ok(())
487489
}
488490
pub(crate) fn set_pred_api_token(&mut self, at: ApiToken) {

services/gam/src/layouts/modal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use graphics_server::*;
88
use crate::{LayoutApi, LayoutBehavior};
99

1010
use crate::contexts::MISC_CONTEXT_DEFAULT_TRUST;
11-
const TRUST_OFFSET: u8 = 1;
11+
const TRUST_OFFSET: u8 = 16;
1212

1313
#[derive(Debug, Copy, Clone)]
1414
pub(crate) struct ModalLayout {

services/graphics-server/src/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ pub(crate) enum Opcode {
119119
/// SuspendResume callback
120120
SuspendResume,
121121

122+
/// draw the boot logo (for continuity as apps initialize)
123+
DrawBootLogo,
124+
122125
Quit,
123126
}
124127

services/graphics-server/src/backend/betrusted.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ impl XousDisplay {
6868
display
6969
.susres
7070
.push(RegOrField::Field(utra::memlcd::PRESCALER_PRESCALER), None);
71-
display.sync_clear();
7271

7372
/*
7473
use log::{error, info};
@@ -255,6 +254,7 @@ impl XousDisplay {
255254

256255
/// "synchronous clear" -- must be called on init, so that the state of the LCD
257256
/// internal memory is consistent with the state of the frame buffer
257+
/*
258258
fn sync_clear(&mut self) {
259259
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
260260
for words in 0..FB_SIZE {
@@ -267,6 +267,7 @@ impl XousDisplay {
267267
self.update_all(); // because we force an all update here
268268
while self.busy() {}
269269
}
270+
*/
270271

271272
fn busy(&self) -> bool {
272273
self.csr.rf(utra::memlcd::BUSY_BUSY) == 1

services/graphics-server/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ impl Gfx {
108108
.map(|_| ())
109109
}
110110

111+
pub fn draw_boot_logo(&self) -> Result<(), xous::Error> {
112+
send_message(
113+
self.conn,
114+
Message::new_scalar(Opcode::DrawBootLogo.to_usize().unwrap(), 0, 0, 0, 0),
115+
)
116+
.map(|_| ())
117+
}
118+
111119
pub fn screen_size(&self) -> Result<Point, xous::Error> {
112120
let response = send_message(
113121
self.conn,

services/graphics-server/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ fn wrapped_main() -> ! {
112112
log::info!("my PID is {}", xous::process::id());
113113

114114
let mut display = XousDisplay::new();
115+
draw_boot_logo(&mut display); // bring this up as soon as possible
115116
let fontregion = map_fonts();
116117

117118
// install the graphical panic handler. It won't catch really early panics, or panics in this crate,
@@ -139,8 +140,6 @@ fn wrapped_main() -> ! {
139140
.register_name(api::SERVER_NAME_GFX, Some(1))
140141
.expect("can't register server");
141142

142-
draw_boot_logo(&mut display);
143-
144143
let screen_clip = Rectangle::new(Point::new(0, 0), display.screen_size());
145144

146145
display.redraw();
@@ -459,6 +458,11 @@ fn wrapped_main() -> ! {
459458
display.update();
460459
display.redraw();
461460
}),
461+
Some(Opcode::DrawBootLogo) => msg_scalar_unpack!(msg, _, _, _, _, {
462+
display.blit_screen(&poweron::LOGO_MAP);
463+
display.update();
464+
display.redraw();
465+
}),
462466
Some(Opcode::Devboot) => msg_scalar_unpack!(msg, ena, _, _, _, {
463467
if ena != 0 {
464468
display.set_devboot(true);

services/pddb/locales/i18n.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しください。",
1414
"zh": "密码错误。"
1515
},
16+
"pddb.waitmount": {
17+
"en": "Mounting PDDB, please wait...",
18+
"en-tts": "Mounting PDDB, please wait...",
19+
"fr": "Montage de PDDB, veuillez patienter...*MT*",
20+
"ja": "PDDB をマウントしています。お待ちください...",
21+
"zh": "正在挂载 PDDB,请稍候..."
22+
},
1623
"pddb.basisname": {
1724
"en": "Basis Name:",
1825
"en-tts": "Enter name of Basis",

services/pddb/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,11 +1940,14 @@ fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs, _pw_cid: xous:
19401940
fn try_mount_or_format(modals: &modals::Modals, pddb_os: &mut PddbOs, basis_cache: &mut BasisCache, pw_state: PasswordState, time_resetter: xous::CID) -> bool {
19411941
log::info!("Attempting to mount the PDDB");
19421942
if pw_state == PasswordState::Correct {
1943+
modals.dynamic_notification(Some(t!("pddb.waitmount", xous::LANG)), None).unwrap();
19431944
if let Some(sys_basis) = pddb_os.pddb_mount() {
19441945
log::info!("PDDB mount operation finished successfully");
19451946
basis_cache.basis_add(sys_basis);
1947+
modals.dynamic_notification_close().unwrap();
19461948
return true
19471949
}
1950+
modals.dynamic_notification_close().unwrap();
19481951
}
19491952
// correct password but no mount -> offer to format; uninit -> offer to format
19501953
if pw_state == PasswordState::Correct || pw_state == PasswordState::Uninit {
@@ -2001,12 +2004,14 @@ fn try_mount_or_format(modals: &modals::Modals, pddb_os: &mut PddbOs, basis_cach
20012004
0, 0, 0, 0
20022005
)
20032006
).expect("couldn't reset time");
2004-
2007+
modals.dynamic_notification(Some(t!("pddb.waitmount", xous::LANG)), None).unwrap();
20052008
if let Some(sys_basis) = pddb_os.pddb_mount() {
20062009
log::info!("PDDB mount operation finished successfully");
20072010
basis_cache.basis_add(sys_basis);
2011+
modals.dynamic_notification_close().unwrap();
20082012
true
20092013
} else {
2014+
modals.dynamic_notification_close().unwrap();
20102015
log::error!("Despite formatting, no PDDB was found!");
20112016
let mut err = String::from(t!("pddb.internalerror", xous::LANG));
20122017
err.push_str(" #1"); // punt and leave an error code, because this "should" be rare

services/shellchat/locales/i18n.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,12 @@
1212
"fr": "",
1313
"ja": "",
1414
"zh": ""
15+
},
16+
"shellchat.bootwait": {
17+
"en": "Please wait...",
18+
"en-tts": "Please wait...",
19+
"fr": "S'il vous plaît, attendez*MT*",
20+
"ja": "お待ちください...",
21+
"zh": "请稍等..."
1522
}
1623
}

services/shellchat/src/main.rs

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ Check for more detailed docs under Modules/cmds "Shell Chat" below
3232
use log::info;
3333

3434
use core::fmt::Write;
35+
use core::sync::atomic::{AtomicBool, Ordering};
3536

3637
use gam::UxRegistration;
3738
use graphics_server::{Gid, Point, Rectangle, TextBounds, TextView, DrawStyle, PixelColor};
3839
use graphics_server::api::GlyphStyle;
3940
use xous::MessageEnvelope;
4041
use xous_ipc::Buffer;
4142

43+
use locales::t;
44+
use std::thread;
45+
use std::sync::Arc;
46+
4247
#[doc = include_str!("../README.md")]
4348
mod cmds;
4449
use cmds::*;
@@ -202,7 +207,7 @@ impl Repl{
202207
}
203208

204209
/// update the loop, in response to various inputs
205-
fn update(&mut self, was_callback: bool) -> Result<(), xous::Error> {
210+
fn update(&mut self, was_callback: bool, init_done: bool) -> Result<(), xous::Error> {
206211
let debug1 = false;
207212
// if we had an input string, do something
208213
if let Some(local) = &self.input {
@@ -219,7 +224,7 @@ impl Repl{
219224

220225
// redraw UI once upon accepting all input
221226
if !was_callback { // don't need to redraw on a callback, save some cycles
222-
self.redraw().expect("can't redraw");
227+
self.redraw(init_done).expect("can't redraw");
223228
}
224229

225230
let mut dirty = true;
@@ -265,7 +270,7 @@ impl Repl{
265270
self.msg = None;
266271
// redraw UI now that we've responded
267272
if dirty {
268-
self.redraw().expect("can't redraw");
273+
self.redraw(init_done).expect("can't redraw");
269274
}
270275

271276
if debug1 {
@@ -286,10 +291,28 @@ impl Repl{
286291
}
287292
)).expect("can't clear content area");
288293
}
289-
fn redraw(&mut self) -> Result<(), xous::Error> {
294+
fn redraw(&mut self, init_done: bool) -> Result<(), xous::Error> {
290295
log::trace!("going into redraw");
291296
self.clear_area();
292297

298+
if !init_done {
299+
let mut init_tv = TextView::new(
300+
self.content,
301+
TextBounds::CenteredTop(
302+
Rectangle::new(
303+
Point::new(0, self.screensize.y / 3 - 64),
304+
Point::new(self.screensize.x, self.screensize.y / 3)
305+
)
306+
)
307+
);
308+
init_tv.style = GlyphStyle::Bold;
309+
init_tv.draw_border = false;
310+
write!(init_tv.text, "{}", t!("shellchat.bootwait", xous::LANG)).ok();
311+
self.gam.post_textview(&mut init_tv).expect("couldn't render wait text");
312+
self.gam.redraw().expect("couldn't redraw screen");
313+
return Ok(())
314+
}
315+
293316
// this defines the bottom border of the text bubbles as they stack up wards
294317
let mut bubble_baseline = self.screensize.y - self.margin.y;
295318

@@ -393,8 +416,57 @@ fn wrapped_main() -> ! {
393416
let mut was_callback = false;
394417

395418
let mut allow_redraw = true;
396-
log::trace!("starting main loop");
419+
let pddb_init_done = Arc::new(AtomicBool::new(false));
420+
421+
// spawn a thread to auto-mount the PDDB. It's important that this spawn happens after
422+
// our GAM context has been registered (which happened in the `Repl::new()` call above)
423+
repl.redraw(false).ok();
424+
let _ = thread::spawn({
425+
let pddb_init_done = pddb_init_done.clone();
426+
let main_conn = xous::connect(shch_sid).unwrap();
427+
move || {
428+
let tt = ticktimer_server::Ticktimer::new().unwrap();
429+
let xns = xous_names::XousNames::new().unwrap();
430+
let gam = gam::Gam::new(&xns).unwrap();
431+
while !gam.trusted_init_done().unwrap() {
432+
tt.sleep_ms(50).ok();
433+
}
434+
loop {
435+
let (no_retry_failure, count) = pddb::Pddb::new().try_mount();
436+
pddb_init_done.store(true, Ordering::SeqCst);
437+
if no_retry_failure {
438+
// this includes both successfully mounted, and user abort of mount attempt
439+
break;
440+
} else {
441+
// this indicates system was guttered due to a retry failure
442+
let xns = xous_names::XousNames::new().unwrap();
443+
let susres = susres::Susres::new_without_hook(&xns).unwrap();
444+
let llio = llio::Llio::new(&xns);
445+
if ((llio.adc_vbus().unwrap() as u32) * 503) < 150_000 {
446+
// try to force suspend if possible, so that users who are just playing around with
447+
// the device don't run the battery down accidentally.
448+
susres.initiate_suspend().ok();
449+
tt.sleep_ms(1000).unwrap();
450+
let modals = modals::Modals::new(&xns).unwrap();
451+
modals.show_notification(
452+
&t!("login.fail", xous::LANG).replace("{fails}", &count.to_string()),
453+
None
454+
).ok();
455+
} else {
456+
// otherwise force a reboot cycle to slow down guessers
457+
susres.reboot(true).expect("Couldn't reboot after too many failed password attempts");
458+
tt.sleep_ms(5000).unwrap();
459+
}
460+
}
461+
}
462+
tt.sleep_ms(100).ok(); // this allows the shellchat context to foreground before calling the redraw
463+
xous::send_message(main_conn,
464+
xous::Message::new_scalar(ShellOpcode::Redraw.to_usize().unwrap(), 0, 0, 0, 0)
465+
).ok();
466+
}
467+
});
397468

469+
log::trace!("starting main loop");
398470
#[cfg(feature = "autobasis-ci")]
399471
{
400472
log::info!("starting autobasis CI launcher");
@@ -420,7 +492,7 @@ fn wrapped_main() -> ! {
420492
}
421493
Some(ShellOpcode::Redraw) => {
422494
if allow_redraw {
423-
repl.redraw().expect("REPL couldn't redraw");
495+
repl.redraw(pddb_init_done.load(Ordering::SeqCst)).expect("REPL couldn't redraw");
424496
}
425497
}
426498
Some(ShellOpcode::ChangeFocus) => xous::msg_scalar_unpack!(msg, new_state_code, _, _, _, {
@@ -446,7 +518,7 @@ fn wrapped_main() -> ! {
446518
}
447519
}
448520
if update_repl {
449-
repl.update(was_callback).expect("REPL had problems updating");
521+
repl.update(was_callback, pddb_init_done.load(Ordering::SeqCst)).expect("REPL had problems updating");
450522
update_repl = false;
451523
}
452524
log::trace!("reached bottom of main loop");

services/status/src/main.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -633,41 +633,6 @@ fn wrapped_main() -> ! {
633633
#[cfg(any(feature="precursor", feature="renode"))]
634634
llio.clear_wakeup_alarm().unwrap(); // this is here to clear any wake-up alarms that were set by a prior coldboot command
635635

636-
// spawn a thread to auto-mount the PDDB
637-
let _ = thread::spawn({
638-
move || {
639-
let tt = ticktimer_server::Ticktimer::new().unwrap();
640-
tt.sleep_ms(2000).unwrap(); // a brief pause, to allow the other startup bits to finish running
641-
loop {
642-
let (no_retry_failure, count) = pddb::Pddb::new().try_mount();
643-
if no_retry_failure {
644-
// this includes both successfully mounted, and user abort of mount attempt
645-
break;
646-
} else {
647-
// this indicates system was guttered due to a retry failure
648-
let xns = xous_names::XousNames::new().unwrap();
649-
let susres = susres::Susres::new_without_hook(&xns).unwrap();
650-
let llio = llio::Llio::new(&xns);
651-
if ((llio.adc_vbus().unwrap() as u32) * 503) < 150_000 {
652-
// try to force suspend if possible, so that users who are just playing around with
653-
// the device don't run the battery down accidentally.
654-
susres.initiate_suspend().ok();
655-
tt.sleep_ms(1000).unwrap();
656-
let modals = modals::Modals::new(&xns).unwrap();
657-
modals.show_notification(
658-
&t!("login.fail", xous::LANG).replace("{fails}", &count.to_string()),
659-
None
660-
).ok();
661-
} else {
662-
// otherwise force a reboot cycle to slow down guessers
663-
susres.reboot(true).expect("Couldn't reboot after too many failed password attempts");
664-
tt.sleep_ms(5000).unwrap();
665-
}
666-
}
667-
}
668-
}
669-
});
670-
671636
pump_run.store(true, Ordering::Relaxed); // start status thread updating
672637
loop {
673638
let msg = xous::receive_message(status_sid).unwrap();

0 commit comments

Comments
 (0)