1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-05 04:10:58 +00:00

fix(core): resolve crashes when running without display or with uninitialized display

[no changelog]
This commit is contained in:
tychovrahe 2024-12-10 13:26:15 +01:00 committed by TychoVrahe
parent e6802bdd09
commit 0d3407b075
4 changed files with 27 additions and 5 deletions

View File

@ -55,7 +55,7 @@ pub fn refresh() {
} }
#[cfg(feature = "framebuffer")] #[cfg(feature = "framebuffer")]
pub fn get_frame_buffer() -> (&'static mut [u8], usize) { pub fn get_frame_buffer() -> Option<(&'static mut [u8], usize)> {
let mut fb_info = ffi::display_fb_info_t { let mut fb_info = ffi::display_fb_info_t {
ptr: ptr::null_mut(), ptr: ptr::null_mut(),
stride: 0, stride: 0,
@ -63,6 +63,10 @@ pub fn get_frame_buffer() -> (&'static mut [u8], usize) {
unsafe { ffi::display_get_frame_buffer(&mut fb_info) }; unsafe { ffi::display_get_frame_buffer(&mut fb_info) };
if fb_info.ptr.is_null() {
return None;
}
let fb = unsafe { let fb = unsafe {
core::slice::from_raw_parts_mut( core::slice::from_raw_parts_mut(
fb_info.ptr as *mut u8, fb_info.ptr as *mut u8,
@ -70,5 +74,5 @@ pub fn get_frame_buffer() -> (&'static mut [u8], usize) {
) )
}; };
(fb, fb_info.stride) Some((fb, fb_info.stride))
} }

View File

@ -39,7 +39,13 @@ where
let cache = DrawingCache::new(bump, bump); let cache = DrawingCache::new(bump, bump);
let (fb, fb_stride) = display::get_frame_buffer(); let fb_info = display::get_frame_buffer();
if fb_info.is_none() {
return;
}
let (fb, fb_stride) = fb_info.unwrap();
let mut canvas = unwrap!(Mono8Canvas::new( let mut canvas = unwrap!(Mono8Canvas::new(
Offset::new(width, height), Offset::new(width, height),

View File

@ -32,7 +32,13 @@ where
let cache = DrawingCache::new(bump_a, bump_b); let cache = DrawingCache::new(bump_a, bump_b);
let (fb, fb_stride) = display::get_frame_buffer(); let fb_info = display::get_frame_buffer();
if fb_info.is_none() {
return;
}
let (fb, fb_stride) = fb_info.unwrap();
let mut canvas = unwrap!(Rgb565Canvas::new( let mut canvas = unwrap!(Rgb565Canvas::new(
Offset::new(width, height), Offset::new(width, height),

View File

@ -32,7 +32,13 @@ where
let cache = DrawingCache::new(bump_a, bump_b); let cache = DrawingCache::new(bump_a, bump_b);
let (fb, fb_stride) = display::get_frame_buffer(); let fb_info = display::get_frame_buffer();
if fb_info.is_none() {
return;
}
let (fb, fb_stride) = fb_info.unwrap();
let mut canvas = unwrap!(Rgba8888Canvas::new( let mut canvas = unwrap!(Rgba8888Canvas::new(
Offset::new(width, height), Offset::new(width, height),