@@ -10,7 +10,7 @@ use regex::Regex;
10
10
use serde:: { Deserialize , Deserializer , Serialize } ;
11
11
12
12
use crate :: error:: {
13
- CSVError , DuplicatePartitionsError , InvalidSubTypeError , NoFactoryAppError ,
13
+ CSVError , DuplicatePartitionsError , InvalidSubTypeError , NoAppError ,
14
14
OverlappingPartitionsError , PartitionTableError , UnalignedPartitionError ,
15
15
} ;
16
16
@@ -264,6 +264,10 @@ impl PartitionTable {
264
264
self . partitions . iter ( ) . find ( |& p| p. name == name)
265
265
}
266
266
267
+ pub fn find_by_type ( & self , ty : Type ) -> Option < & Partition > {
268
+ self . partitions . iter ( ) . find ( |& p| p. ty == ty)
269
+ }
270
+
267
271
fn validate ( & self , source : & str ) -> Result < ( ) , PartitionTableError > {
268
272
for partition in & self . partitions {
269
273
if let Some ( line) = & partition. line {
@@ -318,10 +322,8 @@ impl PartitionTable {
318
322
}
319
323
}
320
324
321
- if self . find ( "factory" ) . is_none ( ) {
322
- return Err ( PartitionTableError :: NoFactoryApp ( NoFactoryAppError :: new (
323
- source,
324
- ) ) ) ;
325
+ if self . find_by_type ( Type :: App ) . is_none ( ) {
326
+ return Err ( PartitionTableError :: NoApp ( NoAppError :: new ( source) ) ) ;
325
327
}
326
328
327
329
Ok ( ( ) )
@@ -590,6 +592,24 @@ phy_init, data, phy, 0xf000, 0x1000,
590
592
factory, app, factory, 0x10000, 1M,
591
593
a, data, spiffs, 0x110000, 1M,
592
594
b, data, spiffs, 0x210000, 1M,
595
+ " ;
596
+
597
+ const PTABLE_NO_FACTORY : & str = "
598
+ # ESP-IDF Partition Table
599
+ # Name, Type, SubType, Offset, Size, Flags
600
+ nvs, data, nvs, 0x9000, 0x4000,
601
+ otadata, data, ota, 0xd000, 0x2000,
602
+ phy_init, data, phy, 0xf000, 0x1000,
603
+ ota_0, app, ota_0, , 1M,
604
+ ota_1, app, ota_1, , 1M,
605
+ " ;
606
+
607
+ const PTABLE_NO_APP : & str = "
608
+ # ESP-IDF Partition Table
609
+ # Name, Type, SubType, Offset, Size, Flags
610
+ nvs, data, nvs, 0x9000, 0x4000,
611
+ otadata, data, ota, 0xd000, 0x2000,
612
+ phy_init, data, phy, 0xf000, 0x1000,
593
613
" ;
594
614
595
615
#[ test]
@@ -629,6 +649,11 @@ b, data, spiffs, 0x210000, 1M,
629
649
630
650
let pt_spiffs = PartitionTable :: try_from_str ( PTABLE_SPIFFS ) ;
631
651
assert ! ( pt_spiffs. is_ok( ) ) ;
652
+
653
+ PartitionTable :: try_from_str ( PTABLE_NO_FACTORY )
654
+ . expect ( "Failed to parse partition table without factory partition" ) ;
655
+ PartitionTable :: try_from_str ( PTABLE_NO_APP )
656
+ . expect_err ( "Failed to reject partition table without factory or ota partition" ) ;
632
657
}
633
658
634
659
#[ test]
0 commit comments