@@ -20,6 +20,7 @@ pub enum TbfHeaderTypes {
20
20
KernelVersion = 8 ,
21
21
Program = 9 ,
22
22
ShortId = 10 ,
23
+ Position = 11 ,
23
24
24
25
Credentials = 128 ,
25
26
}
@@ -132,6 +133,18 @@ struct TbfHeaderShortId {
132
133
short_id : u32 ,
133
134
}
134
135
136
+ pub enum PositionConfiguration {
137
+ RopiRwpi = 0 ,
138
+ Pie = 1 ,
139
+ }
140
+
141
+ #[ repr( C ) ]
142
+ #[ derive( Clone , Copy , Debug ) ]
143
+ struct TbfHeaderPosition {
144
+ base : TbfHeaderTlv ,
145
+ configuration : u32 ,
146
+ }
147
+
135
148
#[ repr( C ) ]
136
149
#[ derive( Debug ) ]
137
150
pub struct TbfFooterCredentials {
@@ -285,7 +298,6 @@ impl fmt::Display for TbfHeaderKernelVersion {
285
298
286
299
impl fmt:: Display for TbfHeaderShortId {
287
300
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
288
- // ^x.y means >= x.y, < (x+1).0
289
301
writeln ! (
290
302
f,
291
303
"
@@ -295,6 +307,17 @@ impl fmt::Display for TbfHeaderShortId {
295
307
}
296
308
}
297
309
310
+ impl fmt:: Display for TbfHeaderPosition {
311
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
312
+ writeln ! (
313
+ f,
314
+ "
315
+ Position Independent: {}" ,
316
+ self . configuration
317
+ )
318
+ }
319
+ }
320
+
298
321
const FLAGS_ENABLE : u32 = 0x0000_0001 ;
299
322
300
323
pub struct TbfHeader {
@@ -308,6 +331,7 @@ pub struct TbfHeader {
308
331
hdr_persistent : Option < TbfHeaderPersistentAcl > ,
309
332
hdr_kernel_version : Option < TbfHeaderKernelVersion > ,
310
333
hdr_short_id : Option < TbfHeaderShortId > ,
334
+ hdr_position : Option < TbfHeaderPosition > ,
311
335
package_name : String ,
312
336
package_name_pad : usize ,
313
337
}
@@ -340,6 +364,7 @@ impl TbfHeader {
340
364
hdr_persistent : None ,
341
365
hdr_kernel_version : None ,
342
366
hdr_short_id : None ,
367
+ hdr_position : None ,
343
368
package_name : String :: new ( ) ,
344
369
package_name_pad : 0 ,
345
370
}
@@ -363,6 +388,7 @@ impl TbfHeader {
363
388
storage_ids : ( Option < u32 > , Option < Vec < u32 > > , Option < Vec < u32 > > ) ,
364
389
kernel_version : Option < ( u16 , u16 ) > ,
365
390
short_id : Option < u32 > ,
391
+ position_configuration : Option < PositionConfiguration > ,
366
392
disabled : bool ,
367
393
) -> usize {
368
394
// Need to calculate lengths ahead of time. Need the base and the
@@ -573,6 +599,17 @@ impl TbfHeader {
573
599
} ) ;
574
600
}
575
601
602
+ // If the position configuration is set, include that header.
603
+ if let Some ( position_configuration) = position_configuration {
604
+ self . hdr_position = Some ( TbfHeaderPosition {
605
+ base : TbfHeaderTlv {
606
+ tipe : TbfHeaderTypes :: Position ,
607
+ length : 4 ,
608
+ } ,
609
+ configuration : position_configuration as u32 ,
610
+ } )
611
+ }
612
+
576
613
// Return the length by generating the header and seeing how long it is.
577
614
self . generate ( )
578
615
. expect ( "No header was generated" )
0 commit comments