-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmod.rs
More file actions
2287 lines (2156 loc) · 80.9 KB
/
mod.rs
File metadata and controls
2287 lines (2156 loc) · 80.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Module to build a portable commandline tool
//!
//! Can be easily re-used from any OS or UEFI shell.
//! We have implemented both in the `framework_tool` and `framework_uefi` crates.
use alloc::format;
use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec;
use guid_create::{CGuid, GUID};
use log::Level;
use num_traits::FromPrimitive;
#[cfg(not(feature = "uefi"))]
pub mod clap_std;
#[cfg(feature = "uefi")]
pub mod uefi;
#[cfg(not(feature = "uefi"))]
use std::fs;
#[cfg(not(feature = "uefi"))]
use std::io::prelude::*;
#[cfg(feature = "rusb")]
use crate::audio_card::check_synaptics_fw_version;
use crate::built_info;
#[cfg(feature = "rusb")]
use crate::camera::check_camera_version;
use crate::capsule;
use crate::capsule_content::{
find_bios_version, find_ec_in_bios_cap, find_pd_in_bios_cap, find_retimer_version,
};
use crate::ccgx::device::{FwMode, PdController, PdPort};
#[cfg(feature = "hidapi")]
use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CARD_PID};
use crate::ccgx::{self, MainPdVersions, PdVersions, SiliconId::*};
use crate::chromium_ec;
use crate::chromium_ec::commands::BoardIdType;
use crate::chromium_ec::commands::DeckStateMode;
use crate::chromium_ec::commands::FpLedBrightnessLevel;
use crate::chromium_ec::commands::RebootEcCmd;
use crate::chromium_ec::commands::RgbS;
use crate::chromium_ec::commands::TabletModeOverride;
use crate::chromium_ec::EcResponseStatus;
use crate::chromium_ec::{print_err, EcFlashType};
use crate::chromium_ec::{EcError, EcResult};
#[cfg(target_os = "linux")]
use crate::csme;
use crate::ec_binary;
use crate::esrt;
#[cfg(feature = "rusb")]
use crate::inputmodule::check_inputmodule_version;
#[cfg(target_os = "linux")]
use crate::nvme;
use crate::os_specific;
use crate::parade_retimer;
use crate::power;
use crate::smbios;
use crate::smbios::ConfigDigit0;
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
#[cfg(feature = "hidapi")]
use crate::touchpad::print_touchpad_fw_ver;
#[cfg(feature = "hidapi")]
use crate::touchscreen;
#[cfg(feature = "uefi")]
use crate::uefi::enable_page_break;
#[cfg(feature = "rusb")]
use crate::usbhub::check_usbhub_version;
use crate::util::{self, Config, Platform, PlatformFamily};
#[cfg(feature = "hidapi")]
use hidapi::HidApi;
use sha2::{Digest, Sha256, Sha384, Sha512};
//use smbioslib::*;
use smbioslib::{DefinedStruct, SMBiosInformation};
#[cfg(feature = "nvidia")]
use nvml_wrapper::{enum_wrappers::device::TemperatureSensor, Nvml};
use crate::chromium_ec::{CrosEc, CrosEcDriverType, HardwareDeviceType};
#[cfg(feature = "uefi")]
use core::prelude::rust_2021::derive;
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
#[derive(Clone, Debug, PartialEq)]
pub enum TabletModeArg {
Auto,
Tablet,
Laptop,
}
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
#[derive(Clone, Debug, PartialEq)]
pub enum ConsoleArg {
Recent,
Follow,
}
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
#[derive(Clone, Debug, PartialEq)]
pub enum RebootEcArg {
Reboot,
JumpRo,
JumpRw,
CancelJump,
DisableJump,
}
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FpBrightnessArg {
High,
Medium,
Low,
UltraLow,
Auto,
}
impl From<FpBrightnessArg> for FpLedBrightnessLevel {
fn from(w: FpBrightnessArg) -> FpLedBrightnessLevel {
match w {
FpBrightnessArg::High => FpLedBrightnessLevel::High,
FpBrightnessArg::Medium => FpLedBrightnessLevel::Medium,
FpBrightnessArg::Low => FpLedBrightnessLevel::Low,
FpBrightnessArg::UltraLow => FpLedBrightnessLevel::UltraLow,
FpBrightnessArg::Auto => FpLedBrightnessLevel::Auto,
}
}
}
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum InputDeckModeArg {
Auto,
Off,
On,
}
impl From<InputDeckModeArg> for DeckStateMode {
fn from(w: InputDeckModeArg) -> DeckStateMode {
match w {
InputDeckModeArg::Auto => DeckStateMode::Required,
InputDeckModeArg::Off => DeckStateMode::ForceOff,
InputDeckModeArg::On => DeckStateMode::ForceOn,
}
}
}
#[derive(Debug)]
pub struct LogLevel(log::LevelFilter);
impl Default for LogLevel {
fn default() -> Self {
LogLevel(log::LevelFilter::Error)
}
}
/// Shadows `clap_std::ClapCli` with extras for UEFI
///
/// The UEFI commandline currently doesn't use clap, so we need to shadow the struct.
/// Also it has extra options.
#[derive(Debug, Default)]
pub struct Cli {
pub verbosity: LogLevel,
pub versions: bool,
pub version: bool,
pub features: bool,
pub esrt: bool,
pub device: Option<HardwareDeviceType>,
pub compare_version: Option<String>,
pub power: bool,
pub thermal: bool,
pub sensors: bool,
pub fansetduty: Option<(Option<u32>, u32)>,
pub fansetrpm: Option<(Option<u32>, u32)>,
pub autofanctrl: Option<Option<u8>>,
pub pdports: bool,
pub privacy: bool,
pub pd_info: bool,
pub pd_reset: Option<u8>,
pub pd_disable: Option<u8>,
pub pd_enable: Option<u8>,
pub dp_hdmi_info: bool,
pub dp_hdmi_update: Option<String>,
pub audio_card_info: bool,
pub pd_bin: Option<String>,
pub ec_bin: Option<String>,
pub capsule: Option<String>,
pub dump: Option<String>,
pub h2o_capsule: Option<String>,
pub dump_ec_flash: Option<String>,
pub flash_ec: Option<String>,
pub flash_ro_ec: Option<String>,
pub flash_rw_ec: Option<String>,
pub driver: Option<CrosEcDriverType>,
pub test: bool,
pub test_retimer: bool,
pub boardid: bool,
pub dry_run: bool,
pub force: bool,
pub intrusion: bool,
pub inputdeck: bool,
pub inputdeck_mode: Option<InputDeckModeArg>,
pub expansion_bay: bool,
pub charge_full: bool,
pub charge_limit_disable: bool,
pub charge_limit: Option<Option<u8>>,
pub charge_current_limit: Option<(u32, Option<u32>)>,
pub charge_rate_limit: Option<(f32, Option<f32>)>,
pub get_gpio: Option<Option<String>>,
pub fp_led_level: Option<Option<FpBrightnessArg>>,
pub fp_brightness: Option<Option<u8>>,
pub kblight: Option<Option<u8>>,
pub remap_key: Option<(u8, u8, u16)>,
pub rgbkbd: Vec<u64>,
pub ps2_enable: Option<bool>,
pub tablet_mode: Option<TabletModeArg>,
pub touchscreen_enable: Option<bool>,
pub stylus_battery: bool,
pub console: Option<ConsoleArg>,
pub reboot_ec: Option<RebootEcArg>,
pub ec_hib_delay: Option<Option<u32>>,
pub uptimeinfo: bool,
pub s0ix_counter: bool,
pub hash: Option<String>,
pub pd_addrs: Option<(u16, u16, u16)>,
pub pd_ports: Option<(u8, u8, u8)>,
pub help: bool,
pub info: bool,
pub flash_gpu_descriptor: Option<(u8, String)>,
pub flash_gpu_descriptor_file: Option<String>,
pub dump_gpu_descriptor_file: Option<String>,
pub nvidia: bool,
// UEFI only
pub allupdate: bool,
pub paginate: bool,
// TODO: This is not actually implemented yet
pub raw_command: Vec<String>,
}
pub fn parse(args: &[String]) -> Cli {
#[cfg(feature = "uefi")]
let cli = uefi::parse(args);
#[cfg(not(feature = "uefi"))]
let cli = clap_std::parse(args);
if cfg!(feature = "readonly") {
// Initialize a new Cli with no arguments
// Set all arguments that are readonly/safe
// We explicitly only cope the safe ones so that if we add new arguments in the future,
// which might be unsafe, we can't forget to exclude them from the safe set.
// TODO: Instead of silently ignoring blocked command, we should remind the user
Cli {
verbosity: cli.verbosity,
versions: cli.versions,
version: cli.version,
features: cli.features,
esrt: cli.esrt,
device: cli.device,
compare_version: cli.compare_version,
power: cli.power,
thermal: cli.thermal,
sensors: cli.sensors,
// fansetduty
// fansetrpm
// autofanctrl
pdports: cli.pdports,
privacy: cli.privacy,
pd_info: cli.version,
// pd_reset
// pd_disable
// pd_enable
dp_hdmi_info: cli.dp_hdmi_info,
// dp_hdmi_update
audio_card_info: cli.audio_card_info,
pd_bin: cli.pd_bin,
ec_bin: cli.ec_bin,
capsule: cli.capsule,
dump: cli.dump,
h2o_capsule: cli.h2o_capsule,
// dump_ec_flash
// flash_ec
// flash_ro_ec
// flash_rw_ec
driver: cli.driver,
test: cli.test,
test_retimer: cli.test_retimer,
boardid: cli.boardid,
dry_run: cli.dry_run,
// force
intrusion: cli.intrusion,
inputdeck: cli.inputdeck,
inputdeck_mode: cli.inputdeck_mode,
expansion_bay: cli.expansion_bay,
// charge_limit
// charge_current_limit
// charge_rate_limit
get_gpio: cli.get_gpio,
fp_led_level: cli.fp_led_level,
fp_brightness: cli.fp_brightness,
kblight: cli.kblight,
remap_key: cli.remap_key,
rgbkbd: cli.rgbkbd,
ps2_enable: cli.ps2_enable,
// tablet_mode
// touchscreen_enable
stylus_battery: cli.stylus_battery,
console: cli.console,
reboot_ec: cli.reboot_ec,
// ec_hib_delay
uptimeinfo: cli.uptimeinfo,
s0ix_counter: cli.s0ix_counter,
hash: cli.hash,
pd_addrs: cli.pd_addrs,
pd_ports: cli.pd_ports,
help: cli.help,
info: cli.info,
// flash_gpu_descriptor
// flash_gpu_descriptor_file
nvidia: cli.nvidia,
// allupdate
paginate: cli.paginate,
// raw_command
..Default::default()
}
} else {
cli
}
}
fn print_single_pd_details(pd: &PdController) {
if let Ok(si) = pd.get_silicon_id() {
println!(" Silicon ID: 0x{:X}", si);
} else {
println!(" Failed to read Silicon ID/Family");
return;
}
if let Ok((mode, frs)) = pd.get_device_info() {
println!(" Mode: {:?}", mode);
println!(" Flash Row Size: {} B", frs);
} else {
println!(" Failed to device info");
}
if let Ok(port_mask) = pd.get_port_status() {
let ports = match port_mask {
1 => "0",
2 => "1",
3 => "0, 1",
_ => "None",
};
println!(" Ports Enabled: {}", ports);
} else {
println!(" Ports Enabled: Unknown");
}
pd.print_fw_info();
}
fn print_pd_details(ec: &CrosEc) {
if !is_framework() {
println!("Only supported on Framework systems");
return;
}
let pd_01 = PdController::new(PdPort::Right01, ec.clone());
let pd_23 = PdController::new(PdPort::Left23, ec.clone());
let pd_back = PdController::new(PdPort::Back, ec.clone());
println!("Right / Ports 01");
print_single_pd_details(&pd_01);
println!("Left / Ports 23");
print_single_pd_details(&pd_23);
println!("Back");
print_single_pd_details(&pd_back);
}
#[cfg(feature = "hidapi")]
const NOT_SET: &str = "NOT SET";
#[cfg(feature = "rusb")]
fn print_audio_card_details() {
check_synaptics_fw_version();
}
#[cfg(feature = "hidapi")]
fn print_dp_hdmi_details(verbose: bool) {
match HidApi::new() {
Ok(api) => {
for dev_info in find_devices(&api, &[HDMI_CARD_PID, DP_CARD_PID], None) {
let vid = dev_info.vendor_id();
let pid = dev_info.product_id();
let device = dev_info.open_device(&api).unwrap();
if let Some(name) = ccgx::hid::device_name(vid, pid) {
println!("{}", name);
}
// On Windows this value is "Control Interface", probably hijacked by the kernel driver
debug!(
" Product String: {}",
dev_info.product_string().unwrap_or(NOT_SET)
);
debug!(
" Serial Number: {}",
dev_info.serial_number().unwrap_or(NOT_SET)
);
check_ccg_fw_version(&device, verbose);
}
}
Err(e) => {
eprintln!("Error: {e}");
}
};
}
fn print_tool_version() {
let q = "?".to_string();
println!("Tool Version Information");
println!(" Version: {}", built_info::PKG_VERSION);
println!(" Built At: {}", built_info::BUILT_TIME_UTC);
println!(
" Git Commit: {}",
built_info::GIT_COMMIT_HASH.unwrap_or(&q)
);
println!(
" Git Dirty: {}",
built_info::GIT_DIRTY
.map(|x| x.to_string())
.unwrap_or(q.clone())
);
if log_enabled!(Level::Info) {
println!(
" Built on CI: {:?}",
built_info::CI_PLATFORM.unwrap_or("None")
);
println!(
" Git ref: {:?}",
built_info::GIT_HEAD_REF.unwrap_or(&q)
);
println!(" rustc Ver: {}", built_info::RUSTC_VERSION);
println!(" Features {:?}", built_info::FEATURES);
println!(" DEBUG: {}", built_info::DEBUG);
println!(" Target OS: {}", built_info::CFG_OS);
}
}
// TODO: Check if HDMI card is same
#[cfg(feature = "hidapi")]
fn flash_dp_hdmi_card(pd_bin_path: &str) {
let data = match fs::read(pd_bin_path) {
Ok(data) => Some(data),
// TODO: Perhaps a more user-friendly error
Err(e) => {
println!("Error {:?}", e);
None
}
};
if let Some(data) = data {
// TODO: Check if exists, otherwise err
//ccgx::hid::find_device().unwrap();
ccgx::hid::flash_firmware(&data);
} else {
error!("Failed to open firmware file");
}
}
fn active_mode(mode: &FwMode, reference: FwMode) -> &'static str {
if mode == &reference {
" (Active)"
} else {
""
}
}
#[cfg(feature = "hidapi")]
fn print_stylus_battery_level() {
loop {
if let Some(level) = touchscreen::get_battery_level() {
println!("Stylus Battery Strength: {}%", level);
return;
} else {
debug!("Stylus Battery Strength: Unknown");
}
}
}
fn print_versions(ec: &CrosEc) {
println!("Tool Version: {}", built_info::PKG_VERSION);
println!("OS Version: {}", os_specific::get_os_version());
println!("Mainboard Hardware");
if let Some(ver) = smbios::get_product_name() {
println!(" Type: {}", ver);
} else {
println!(" Type: Unknown");
}
if let Some(ver) = smbios::get_baseboard_version() {
println!(" Revision: {:?}", ver);
} else {
println!(" Revision: Unknown");
}
println!("UEFI BIOS");
if let Some(smbios) = get_smbios() {
let bios_entries = smbios.collect::<SMBiosInformation>();
if let Some(bios) = bios_entries.first() {
println!(" Version: {}", bios.version());
println!(" Release Date: {}", bios.release_date());
} else {
println!(" Version: Unknown");
}
} else {
println!(" Version: Unknown");
}
println!("EC Firmware");
let ver = print_err(ec.version_info()).unwrap_or_else(|| "UNKNOWN".to_string());
println!(" Build version: {}", ver);
if let Some((ro, rw, curr)) = ec.flash_version() {
if ro != rw || log_enabled!(Level::Info) {
println!(" RO Version: {}", ro);
println!(" RW Version: {}", rw);
}
print!(" Current image: ");
if curr == chromium_ec::EcCurrentImage::RO {
println!("RO");
} else if curr == chromium_ec::EcCurrentImage::RW {
println!("RW");
} else {
println!("Unknown");
}
} else {
println!(" RO Version: Unknown");
println!(" RW Version: Unknown");
println!(" Current image: Unknown");
}
println!("PD Controllers");
let ccgx_pd_vers = ccgx::get_pd_controller_versions(ec);
if let Ok(PdVersions::RightLeft((right, left))) = ccgx_pd_vers {
if let Some(Platform::IntelGen11) = smbios::get_platform() {
if right.main_fw.base != right.backup_fw.base {
println!(" Right (01)");
println!(
" Main: {}{}",
right.main_fw.base,
active_mode(&right.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
right.backup_fw.base,
active_mode(&right.active_fw, FwMode::BackupFw)
);
} else {
println!(
" Right (01): {} ({:?})",
right.main_fw.base, right.active_fw
);
}
} else if right.main_fw.app != right.backup_fw.app {
println!(
" Main: {}{}",
right.main_fw.app,
active_mode(&right.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
right.backup_fw.app,
active_mode(&right.active_fw, FwMode::BackupFw)
);
} else {
println!(
" Right (01): {} ({:?})",
right.main_fw.app, right.active_fw
);
}
if let Some(Platform::IntelGen11) = smbios::get_platform() {
if left.main_fw.base != left.backup_fw.base {
println!(" Left (23)");
println!(
" Main: {}{}",
left.main_fw.base,
active_mode(&left.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
left.backup_fw.base,
active_mode(&left.active_fw, FwMode::BackupFw)
);
} else {
println!(
" Left (23): {} ({:?})",
left.main_fw.base, left.active_fw
);
}
} else if left.main_fw.app != left.backup_fw.app {
println!(" Left (23)");
println!(
" Main: {}{}",
left.main_fw.app,
active_mode(&left.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
left.backup_fw.app,
active_mode(&left.active_fw, FwMode::BackupFw)
);
} else {
println!(
" Left (23): {} ({:?})",
left.main_fw.app, left.active_fw
);
}
} else if let Ok(PdVersions::Many(versions)) = ccgx_pd_vers {
for (i, version) in versions.into_iter().enumerate() {
if version.main_fw.app != version.backup_fw.app {
println!(" PD {}", 1);
println!(
" Main: {}{}",
version.main_fw.app,
active_mode(&version.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
version.backup_fw.app,
active_mode(&version.active_fw, FwMode::BackupFw)
);
} else {
println!(
" PD {}: {} ({:?})",
i, version.main_fw.app, version.active_fw
);
}
}
} else if let Ok(PdVersions::Single(pd)) = ccgx_pd_vers {
if pd.main_fw.app != pd.backup_fw.app {
println!(
" Main: {}{}",
pd.main_fw.app,
active_mode(&pd.active_fw, FwMode::MainFw)
);
println!(
" Backup: {}{}",
pd.backup_fw.app,
active_mode(&pd.active_fw, FwMode::BackupFw)
);
} else {
println!(" Version: {} ({:?})", pd.main_fw.app, pd.active_fw);
}
} else if let Ok(pd_versions) = power::read_pd_version(ec) {
// As fallback try to get it from the EC. But not all EC versions have this command
debug!(" Fallback to PD Host command");
match pd_versions {
MainPdVersions::RightLeft((controller01, controller23)) => {
if let Some(Platform::IntelGen11) = smbios::get_platform() {
println!(" Right (01): {}", controller01.base);
println!(" Left (23): {}", controller23.base);
} else {
println!(" Right (01): {}", controller01.app);
println!(" Left (23): {}", controller23.app);
}
}
MainPdVersions::Single(version) => {
println!(" Version: {}", version.app);
}
MainPdVersions::Many(versions) => {
for (i, version) in versions.into_iter().enumerate() {
println!(" PD {}: {}", i, version.app);
}
}
}
} else {
println!(" Unknown")
}
let has_retimer = matches!(
smbios::get_platform(),
Some(Platform::IntelGen11)
| Some(Platform::IntelGen12)
| Some(Platform::IntelGen13)
| Some(Platform::IntelCoreUltra1)
);
let mut left_retimer: Option<u32> = None;
let mut right_retimer: Option<u32> = None;
if let Some(esrt) = esrt::get_esrt() {
for entry in &esrt.entries {
match GUID::from(entry.fw_class) {
esrt::TGL_RETIMER01_GUID
| esrt::ADL_RETIMER01_GUID
| esrt::RPL_RETIMER01_GUID
| esrt::MTL_RETIMER01_GUID => {
right_retimer = Some(entry.fw_version);
}
esrt::TGL_RETIMER23_GUID
| esrt::ADL_RETIMER23_GUID
| esrt::RPL_RETIMER23_GUID
| esrt::MTL_RETIMER23_GUID => {
left_retimer = Some(entry.fw_version);
}
_ => {}
}
}
}
if has_retimer {
println!("Intel Retimers");
if let Some(fw_version) = left_retimer {
println!(" Left: 0x{:X} ({})", fw_version, fw_version);
}
if let Some(fw_version) = right_retimer {
println!(" Right: 0x{:X} ({})", fw_version, fw_version);
}
if left_retimer.is_none() && right_retimer.is_none() {
// This means there's a bug, we should've found one but didn't
println!(" Unknown");
}
}
match parade_retimer::get_version(ec) {
// Does not exist
Ok(None) => {}
Ok(Some(ver)) => {
println!("Parade Retimers");
if let [a, b, c, d, ..] = ver.as_slice() {
println!(" dGPU: {:X}.{:X}.{:X}.{:X}", a, b, c, d);
} else {
println!(" dGPU: Unknown");
}
}
_err => {
// Only Framework 16 has dGPU support (which has Parade Retimer)
if smbios::get_platform().and_then(Platform::which_family)
== Some(PlatformFamily::Framework16)
{
println!("Parade Retimers");
println!(" Unknown");
}
}
}
#[cfg(target_os = "linux")]
if smbios::get_platform().and_then(Platform::which_cpu_vendor) != Some(util::CpuVendor::Amd) {
println!("CSME");
if let Ok(csme) = csme::csme_from_sysfs() {
info!(" Enabled: {}", csme.enabled);
println!(" Firmware Version: {}", csme.main_ver);
if csme.main_ver != csme.recovery_ver || csme.main_ver != csme.fitc_ver {
println!(" Recovery Ver: {}", csme.recovery_ver);
println!(" Original Ver: {}", csme.fitc_ver);
}
} else {
println!(" Unknown");
}
}
#[cfg(feature = "rusb")]
let _ignore_err = check_camera_version();
#[cfg(feature = "rusb")]
let _ignore_err = check_usbhub_version();
#[cfg(feature = "rusb")]
let _ignore_err = check_inputmodule_version();
#[cfg(feature = "hidapi")]
let _ignore_err = print_touchpad_fw_ver();
#[cfg(feature = "hidapi")]
if let Some(Platform::Framework12IntelGen13) = smbios::get_platform() {
let _ignore_err = touchscreen::print_fw_ver();
}
#[cfg(feature = "hidapi")]
print_dp_hdmi_details(false);
#[cfg(target_os = "linux")]
for i in 0..4 {
let device = format!("/dev/nvme{i}");
match nvme::get_nvme_firmware_version(&device) {
Ok(dev) => {
println!("NVMe Device: {}", device);
println!(" Model Number: {}", dev.model_number);
println!(" Firmware Version: {}", dev.firmware_version);
}
Err(_e) => {
// TODO: Maybe print errors but ignore "Not such file or directory"
// eprintln!("Failed to get firmware version for {}: {}", device, e);
}
}
}
#[cfg(feature = "nvidia")]
print_nvidia_details();
}
#[cfg(feature = "nvidia")]
fn probably_has_nvidia() -> bool {
match smbios::get_platform().and_then(Platform::which_family) {
Some(PlatformFamily::Framework12) => false,
Some(PlatformFamily::Framework13) => false,
Some(PlatformFamily::FrameworkDesktop) => true,
Some(PlatformFamily::Framework16) => true,
_ => true,
}
}
/// Brief NVIDIA details for --version output
#[cfg(feature = "nvidia")]
fn print_nvidia_details() {
let probably_has_nvidia = probably_has_nvidia();
let nvml = match Nvml::init() {
Ok(nvml) => nvml,
Err(err) => {
if probably_has_nvidia {
error!("Nvidia, library init fail: {:?}", err);
}
return;
}
};
let device = match nvml.device_by_index(0) {
Ok(device) => device,
Err(err) => {
if probably_has_nvidia {
error!("Nvidia, device not found: {:?}", err);
}
return;
}
};
println!("NVIDIA GPU");
println!(
" Name: {}",
device.name().unwrap_or("Unknown".to_string())
);
println!(
" VBIOS Version: {}",
device.vbios_version().unwrap_or("Unknown".to_string())
);
}
/// Detailed NVIDIA information for --nvidia command
#[cfg(feature = "nvidia")]
fn print_nvidia_info() {
let probably_has_nvidia = probably_has_nvidia();
let nvml = match Nvml::init() {
Ok(nvml) => nvml,
Err(err) => {
if probably_has_nvidia {
error!("Nvidia, library init fail: {:?}", err);
}
return;
}
};
let device = match nvml.device_by_index(0) {
Ok(device) => device,
Err(err) => {
if probably_has_nvidia {
error!("Nvidia, device not found: {:?}", err);
}
return;
}
};
println!("NVIDIA GPU");
// Basic identification
println!("Identification");
println!(
" Name: {}",
device.name().unwrap_or("Unknown".to_string())
);
if let Ok(arch) = device.architecture() {
println!(" Architecture: {:?}", arch);
}
if let Ok(serial) = device.serial() {
println!(" Serial Number: {}", serial);
}
if let Ok(part_number) = device.board_part_number() {
println!(" Part Number: {}", part_number);
}
if let Ok(board_id) = device.board_id() {
println!(" Board ID: {}", board_id);
}
// Firmware versions
println!("Firmware");
println!(
" VBIOS Version: {}",
device.vbios_version().unwrap_or("Unknown".to_string())
);
println!(
" InfoROM Version: {}",
device
.info_rom_image_version()
.unwrap_or("Unknown".to_string())
);
// PCI information
println!("PCI");
if let Ok(pci) = device.pci_info() {
println!(" Bus: {:02X}", pci.bus);
println!(" Device: {:02X}", pci.device);
println!(" Domain: {:04X}", pci.domain);
println!(" Device ID: {:04X}", pci.pci_device_id);
if let Some(sub_id) = pci.pci_sub_system_id {
println!(" Subsystem ID: {:08X}", sub_id);
}
}
// Power information
println!("Power");
if let Ok(state) = device.performance_state() {
println!(" Performance State: {:?}", state);
}
if let Ok(power) = device.power_usage() {
println!(" Current Usage: {:.2} W", power as f64 / 1000.0);
}
if let Ok(limit) = device.power_management_limit() {
println!(" Power Limit: {:.2} W", limit as f64 / 1000.0);
}
if let Ok(default) = device.power_management_limit_default() {
println!(" Default Limit: {:.2} W", default as f64 / 1000.0);
}
if let Ok(constraints) = device.power_management_limit_constraints() {
println!(
" Min Limit: {:.2} W",
constraints.min_limit as f64 / 1000.0
);
println!(
" Max Limit: {:.2} W",
constraints.max_limit as f64 / 1000.0
);
}
if let Ok(energy) = device.total_energy_consumption() {
println!(" Total Energy: {:.2} J", energy as f64 / 1000.0);
}
// Thermal information
println!("Thermal");
if let Ok(temp) = device.temperature(TemperatureSensor::Gpu) {
println!(" GPU Temperature: {}C", temp);
}
if let Ok(num_fans) = device.num_fans() {
println!(" Number of Fans: {}", num_fans);
}
// Throttling
if let Ok(throttle) = device.current_throttle_reasons() {
println!("Throttle Reasons");
if throttle.is_empty() {
println!(" None");
} else {
if throttle.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::GPU_IDLE) {
println!(" GPU Idle");
}
if throttle.contains(
nvml_wrapper::bitmasks::device::ThrottleReasons::APPLICATIONS_CLOCKS_SETTING,
) {
println!(" Applications Clocks Setting");
}
if throttle.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::SW_POWER_CAP) {
println!(" Software Power Cap");
}
if throttle.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::HW_SLOWDOWN) {
println!(" Hardware Slowdown");
}
if throttle.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::SYNC_BOOST) {
println!(" Sync Boost");
}
if throttle
.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::SW_THERMAL_SLOWDOWN)
{
println!(" Software Thermal Slowdown");
}
if throttle
.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::HW_THERMAL_SLOWDOWN)
{
println!(" Hardware Thermal Slowdown");
}
if throttle
.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::HW_POWER_BRAKE_SLOWDOWN)
{
println!(" Hardware Power Brake Slowdown");
}
if throttle
.contains(nvml_wrapper::bitmasks::device::ThrottleReasons::DISPLAY_CLOCK_SETTING)
{
println!(" Display Clock Setting");
}
}
}
// Utilization
println!("Utilization");
if let Ok(util) = device.utilization_rates() {
println!(" GPU: {}%", util.gpu);
println!(" Memory: {}%", util.memory);
}
// Memory information
println!("Memory");
if let Ok(mem) = device.memory_info() {
let total_gb = mem.total as f64 / (1024.0 * 1024.0 * 1024.0);
let used_gb = mem.used as f64 / (1024.0 * 1024.0 * 1024.0);
let free_gb = mem.free as f64 / (1024.0 * 1024.0 * 1024.0);
println!(" Total: {:.2} GB", total_gb);
println!(" Used: {:.2} GB", used_gb);