Skip to content

Commit 81e1d2b

Browse files
committed
implement retaining FTPR modules
Signed-off-by: Daniel Maslowski <info@orangecms.org>
1 parent c8d74fb commit 81e1d2b

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

src/clean.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use intel_fw::{
22
ifd::{IFD, IfdError},
33
me::ME,
4+
part::part::ClearOptions,
45
};
56
use log::warn;
67

78
pub struct Options {
9+
pub keep_modules: bool,
810
pub relocate: bool,
911
pub disable_me: bool,
1012
pub disable_me_only: bool,
@@ -36,7 +38,10 @@ pub fn clean(
3638
}
3739
}
3840
let mut new_me = me.clone();
39-
new_me.fpt_area.clean();
41+
let opts = ClearOptions {
42+
keep_modules: options.keep_modules,
43+
};
44+
new_me.fpt_area.clean(&opts);
4045
if options.relocate {
4146
if let Err(e) = new_me.fpt_area.relocate_partitions() {
4247
warn!("Could not relocate: {e}")

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ fn main() {
184184
return;
185185
};
186186
let opts = clean::Options {
187+
keep_modules,
187188
relocate,
188189
disable_me: soft_disable,
189190
disable_me_only: soft_disable_only,

src/me.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::dir::{
1515
use crate::part::gen2::Gen2Partition;
1616
use crate::part::{
1717
fpt::{FPT, MIN_FPT_SIZE},
18+
part::ClearOptions,
1819
partitions::Partitions,
1920
};
2021
use crate::ver::Version;
@@ -50,12 +51,12 @@ pub struct FPTArea {
5051

5152
impl FPTArea {
5253
/// Clear out fully removable partitions and adjust FPT
53-
pub fn clean(&mut self) {
54+
pub fn clean(&mut self, options: &ClearOptions) {
5455
let mut fpt = self.fpt.clone();
5556
fpt.clear();
5657
self.fpt = fpt;
5758
let mut parts = self.partitions.clone();
58-
parts.clear();
59+
parts.clear(options);
5960
self.partitions = parts;
6061
let debug = true;
6162
if debug {

src/part/gen2.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use crate::dir::gen2::{ALWAYS_RETAIN, Directory, LUT_HEADER_SIZE};
55
use crate::dump48;
66
use crate::part::{
77
fpt::{FPT, FPTEntry, FTPR},
8-
part::{DataPartition, Partition, UnknownOrMalformedPartition, dir_clean, strs_to_strings},
8+
part::{
9+
ClearOptions, DataPartition, Partition, UnknownOrMalformedPartition, dir_clean,
10+
strs_to_strings,
11+
},
912
};
1013

1114
#[derive(Serialize, Deserialize, Clone, Debug)]
@@ -122,7 +125,7 @@ pub fn parse(fpt: &FPT, data: &[u8], debug: bool) -> Vec<Gen2Partition> {
122125
parts
123126
}
124127

125-
pub fn clean(parts: &Vec<Gen2Partition>) -> Vec<Gen2Partition> {
128+
pub fn clean(parts: &Vec<Gen2Partition>, options: &ClearOptions) -> Vec<Gen2Partition> {
126129
use log::info;
127130
let res = parts
128131
.iter()
@@ -138,7 +141,7 @@ pub fn clean(parts: &Vec<Gen2Partition>) -> Vec<Gen2Partition> {
138141
})
139142
.map(|p| {
140143
let mut p = p.clone();
141-
if p.entry().name() == FTPR {
144+
if p.entry().name() == FTPR && !options.keep_modules {
142145
let offset = p.entry().offset();
143146
info!("FTPR @ {offset:08x}");
144147
// TODO: Extend with user-provided list

src/part/gen3.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::dir::{
77
use crate::dump48;
88
use crate::part::{
99
fpt::{DIR_PARTS, FPT, FPTEntry, FS_PARTS, FTPR, REMOVABLE_PARTS},
10-
part::{Partition, UnknownOrMalformedPartition, dir_clean, strs_to_strings},
10+
part::{ClearOptions, Partition, UnknownOrMalformedPartition, dir_clean, strs_to_strings},
1111
};
1212

1313
#[derive(Serialize, Deserialize, Clone, Debug)]
@@ -148,7 +148,7 @@ pub fn parse(fpt: &FPT, data: &[u8], debug: bool) -> Vec<Gen3Partition> {
148148
parts
149149
}
150150

151-
pub fn clean(parts: &Vec<Gen3Partition>) -> Vec<Gen3Partition> {
151+
pub fn clean(parts: &Vec<Gen3Partition>, options: &ClearOptions) -> Vec<Gen3Partition> {
152152
use log::info;
153153
// Step 1: Reduce down to the partitions to be kept, i.e., non-removable
154154
// ones.
@@ -166,6 +166,9 @@ pub fn clean(parts: &Vec<Gen3Partition>) -> Vec<Gen3Partition> {
166166
})
167167
.map(|p| p.clone())
168168
.collect::<Vec<Gen3Partition>>();
169+
if options.keep_modules {
170+
return reduced;
171+
}
169172
// Step 2: Clean the FTPR directory, retaining non-removable modules.
170173
if let Some(p) = reduced.iter_mut().find(|p| p.entry().name() == FTPR) {
171174
let offset = p.entry().offset();

src/part/part.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub fn strs_to_strings(strs: &[&str]) -> Vec<String> {
5959
Vec::from(strs).iter().map(|s| String::from(*s)).collect()
6060
}
6161

62+
pub struct ClearOptions {
63+
pub keep_modules: bool,
64+
}
65+
6266
// Clear out removable ranges in the FTPR directory
6367
pub fn dir_clean(dir: &dyn Removables, retention_list: &Vec<String>, data: &mut Vec<u8>) {
6468
use log::info;

src/part/partitions.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use zerocopy::IntoBytes;
55

66
use crate::EMPTY;
77
use crate::dir::gen3::CPD_MAGIC_BYTES;
8+
use crate::part::part::ClearOptions;
89
use crate::part::{
910
fpt::{FPT, FPTEntry},
1011
gen2::{self, Gen2Partition},
@@ -116,14 +117,14 @@ impl Partitions {
116117

117118
// TODO: retention list
118119
/// Clear out fully removable partitions, adjusting header and checksum
119-
pub fn clear(&mut self) {
120+
pub fn clear(&mut self, options: &ClearOptions) {
120121
let parts = match &self {
121122
Partitions::Gen2(parts) => {
122-
let res = gen2::clean(&parts);
123+
let res = gen2::clean(&parts, options);
123124
Partitions::Gen2(res)
124125
}
125126
Partitions::Gen3(parts) => {
126-
let res = gen3::clean(&parts);
127+
let res = gen3::clean(&parts, options);
127128
Partitions::Gen3(res)
128129
}
129130
Partitions::Unknown(p) => {

0 commit comments

Comments
 (0)