Skip to content

Commit 80065b5

Browse files
authored
Merge pull request #529 from nicholasbishop/bishop-revision-formatting
Fixes and improvements for `Revision`
2 parents 601544f + ad01c57 commit 80065b5

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
- The conversion methods on `DevicePathToText` and `DevicePathFromText`
1515
now return a `uefi::Result` instead of an `Option`.
1616
- `Event` is now a newtype around `NonNull<c_void>` instead of `*mut c_void`.
17+
- Changed `SystemTable::firmware_revision` to return a `u32` instead of
18+
a `Revision`. The firmware revision's format is vendor specific and
19+
may not have the same semantics as the UEFI revision.
20+
- Changed `Revision` to `repr(transparent)`.
21+
- Add `Revision::EFI_2_100` constant.
22+
- The `Revision` type now implements `Display` with correct formatting
23+
for all UEFI versions. The custom `Debug` impl has been removed and
24+
replaced with a derived `Debug` impl.
1725

1826
## uefi-macros - [Unreleased]
1927

src/table/revision.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,32 @@ use core::fmt;
66
///
77
/// The minor revision number is incremented on minor changes,
88
/// it is stored as a two-digit binary-coded decimal.
9-
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
9+
///
10+
/// # Display format
11+
///
12+
/// For major revision 2 and later, if the lower minor digit is zero,
13+
/// the revision is formatted as "major.minor-upper". Otherwise it's
14+
/// formatted as "major.minor-upper.minor-lower". This format is
15+
/// described in the "EFI System Table" section of the UEFI
16+
/// Specification.
17+
///
18+
/// Prior to major version 2, the revision is always formatted as
19+
/// "major.minor", with minor left-padded with zero if minor-upper is
20+
/// zero.
21+
///
22+
/// Examples:
23+
///
24+
/// ```
25+
/// use uefi::table::Revision;
26+
/// assert_eq!(Revision::EFI_1_02.to_string(), "1.02");
27+
/// assert_eq!(Revision::EFI_1_10.to_string(), "1.10");
28+
/// assert_eq!(Revision::EFI_2_00.to_string(), "2.0");
29+
/// assert_eq!(Revision::EFI_2_30.to_string(), "2.3");
30+
/// assert_eq!(Revision::EFI_2_31.to_string(), "2.3.1");
31+
/// assert_eq!(Revision::EFI_2_100.to_string(), "2.10");
32+
/// ```
33+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
34+
#[repr(transparent)]
1035
pub struct Revision(u32);
1136

1237
// Allow missing docs, there's nothing useful to document about these
@@ -26,6 +51,7 @@ impl Revision {
2651
pub const EFI_2_70: Self = Self::new(2, 70);
2752
pub const EFI_2_80: Self = Self::new(2, 80);
2853
pub const EFI_2_90: Self = Self::new(2, 90);
54+
pub const EFI_2_100: Self = Self::new(2, 100);
2955
}
3056

3157
impl Revision {
@@ -48,13 +74,20 @@ impl Revision {
4874
}
4975
}
5076

51-
impl fmt::Debug for Revision {
52-
/// Formats the revision in the `major.minor.patch` format.
77+
impl fmt::Display for Revision {
5378
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5479
let (major, minor) = (self.major(), self.minor());
55-
let minor = minor / 10;
56-
let patch = minor % 10;
57-
write!(f, "{major}.{minor}.{patch}")
80+
81+
if major < 2 {
82+
write!(f, "{major}.{minor:02}")
83+
} else {
84+
let (minor, patch) = (minor / 10, minor % 10);
85+
if patch == 0 {
86+
write!(f, "{major}.{minor}")
87+
} else {
88+
write!(f, "{major}.{minor}.{patch}")
89+
}
90+
}
5891
}
5992
}
6093

src/table/system.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<View: SystemTableView> SystemTable<View> {
5858
}
5959

6060
/// Return the firmware revision
61-
pub fn firmware_revision(&self) -> Revision {
61+
pub fn firmware_revision(&self) -> u32 {
6262
self.table.fw_revision
6363
}
6464

@@ -296,8 +296,7 @@ struct SystemTableImpl {
296296
header: Header,
297297
/// Null-terminated string representing the firmware's vendor.
298298
fw_vendor: *const Char16,
299-
/// Revision of the UEFI specification the firmware conforms to.
300-
fw_revision: Revision,
299+
fw_revision: u32,
301300
stdin_handle: Handle,
302301
stdin: *mut text::Input,
303302
stdout_handle: Handle,

0 commit comments

Comments
 (0)