@@ -242,7 +242,10 @@ pub struct Pfr<State = init_state::Unknown> {
242
242
}
243
243
impl < State > Pfr < State > {
244
244
fn bootloader_api_tree ( ) -> & ' static mut BootloaderTree {
245
- unsafe { core:: mem:: transmute ( 0x130010f0u32 as * const ( ) ) }
245
+ #[ allow( clippy:: transmute_ptr_to_ref) ]
246
+ unsafe {
247
+ core:: mem:: transmute ( 0x130010f0u32 as * const ( ) )
248
+ }
246
249
}
247
250
fn check_error ( err : u32 ) -> Result < ( ) , u32 > {
248
251
if err == 0 {
@@ -252,6 +255,12 @@ impl<State> Pfr<State> {
252
255
}
253
256
}
254
257
}
258
+
259
+ impl Default for Pfr {
260
+ fn default ( ) -> Self {
261
+ Self :: new ( )
262
+ }
263
+ }
255
264
impl Pfr {
256
265
pub fn new ( ) -> Self {
257
266
Self {
@@ -290,7 +299,7 @@ impl Pfr<init_state::Enabled> {
290
299
// heprintln!("cfpa:").ok();
291
300
// dump_hex!(cfpa_bytes, 512);
292
301
293
- let cmpa: & Cmpa = unsafe { core :: mem :: transmute ( cmpa_bytes. as_ptr ( ) ) } ;
302
+ let cmpa: & Cmpa = unsafe { & * ( cmpa_bytes. as_ptr ( ) as * const _ ) } ;
294
303
295
304
Ok ( * cmpa)
296
305
}
@@ -308,6 +317,7 @@ impl Pfr<init_state::Enabled> {
308
317
/// - Immediately after CFPA is updated, this method returns the latest CFPA data.
309
318
/// - After boot/reset, this method will potentially return expected old versions of CFPA.
310
319
/// - There is a pattern of how to increment VERSION to result in this method returning old CFPA versions or not which is impractical.
320
+ ///
311
321
/// It's almost like there is some other cfpa page storage not documented and this bootrom method mismanages the VERSION.
312
322
pub fn read_cfpa_with_bootrom ( & mut self ) -> Result < Cfpa , u32 > {
313
323
let mut cfpa_bytes = [ 0u8 ; 512 ] ;
@@ -322,7 +332,7 @@ impl Pfr<init_state::Enabled> {
322
332
// heprintln!("cfpa:").ok();
323
333
// dump_hex!(cfpa_bytes, 512);
324
334
325
- let cfpa: & Cfpa = unsafe { core :: mem :: transmute ( cfpa_bytes. as_ptr ( ) ) } ;
335
+ let cfpa: & Cfpa = unsafe { & * ( cfpa_bytes. as_ptr ( ) as * const _ ) } ;
326
336
327
337
Ok ( * cfpa)
328
338
}
@@ -350,7 +360,7 @@ impl Pfr<init_state::Enabled> {
350
360
copy_nonoverlapping ( cfpa_ptr, cfpa_bytes. as_mut_ptr ( ) , 128 ) ;
351
361
}
352
362
353
- let cfpa: & Cfpa = unsafe { core :: mem :: transmute ( cfpa_bytes. as_ptr ( ) ) } ;
363
+ let cfpa: & Cfpa = unsafe { & * ( cfpa_bytes. as_ptr ( ) as * const _ ) } ;
354
364
355
365
Ok ( * cfpa)
356
366
}
@@ -363,7 +373,7 @@ impl Pfr<init_state::Enabled> {
363
373
copy_nonoverlapping ( CFPA_PTR , cfpa_bytes. as_mut_ptr ( ) , 128 ) ;
364
374
}
365
375
366
- let cfpa: & Cfpa = unsafe { core :: mem :: transmute ( cfpa_bytes. as_ptr ( ) ) } ;
376
+ let cfpa: & Cfpa = unsafe { & * ( cfpa_bytes. as_ptr ( ) as * const _ ) } ;
367
377
368
378
Ok ( * cfpa)
369
379
}
@@ -376,7 +386,7 @@ impl Pfr<init_state::Enabled> {
376
386
copy_nonoverlapping ( CFPA_PTR , cfpa_bytes. as_mut_ptr ( ) , 128 ) ;
377
387
}
378
388
379
- let cfpa: & Cfpa = unsafe { core :: mem :: transmute ( cfpa_bytes. as_ptr ( ) ) } ;
389
+ let cfpa: & Cfpa = unsafe { & * ( cfpa_bytes. as_ptr ( ) as * const _ ) } ;
380
390
381
391
Ok ( * cfpa)
382
392
}
0 commit comments