@@ -134,6 +134,11 @@ enum Trace {
134
134
#[ count( children) ]
135
135
message : SpToHost ,
136
136
} ,
137
+ APOBWriteError {
138
+ offset : u64 ,
139
+ #[ count( children) ]
140
+ err : APOBError ,
141
+ } ,
137
142
}
138
143
139
144
counted_ringbuf ! ( Trace , 20 , Trace :: None ) ;
@@ -160,6 +165,31 @@ enum Timers {
160
165
TxPeriodicZeroByte ,
161
166
}
162
167
168
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , counters:: Count ) ]
169
+ enum APOBError {
170
+ OffsetOverflow {
171
+ offset : u64 ,
172
+ } ,
173
+ NotErased {
174
+ offset : u32 ,
175
+ } ,
176
+ EraseFailed {
177
+ offset : u32 ,
178
+ #[ count( children) ]
179
+ err : drv_hf_api:: HfError ,
180
+ } ,
181
+ WriteFailed {
182
+ offset : u32 ,
183
+ #[ count( children) ]
184
+ err : drv_hf_api:: HfError ,
185
+ } ,
186
+ ReadFailed {
187
+ offset : u32 ,
188
+ #[ count( children) ]
189
+ err : drv_hf_api:: HfError ,
190
+ } ,
191
+ }
192
+
163
193
#[ export_name = "main" ]
164
194
fn main ( ) -> ! {
165
195
let mut server = ServerImpl :: claim_static_resources ( ) ;
@@ -970,7 +1000,10 @@ impl ServerImpl {
970
1000
HostToSp :: APOB { offset } => {
971
1001
Some ( match Self :: apob_write ( & self . hf , offset, data) {
972
1002
Ok ( ( ) ) => SpToHost :: APOBResult ( 0 ) ,
973
- Err ( _) => SpToHost :: APOBResult ( 1 ) ,
1003
+ Err ( err) => {
1004
+ ringbuf_entry ! ( Trace :: APOBWriteError { offset, err } ) ;
1005
+ SpToHost :: APOBResult ( 1 )
1006
+ }
974
1007
} )
975
1008
}
976
1009
} ;
@@ -1008,13 +1041,13 @@ impl ServerImpl {
1008
1041
hf : & HostFlash ,
1009
1042
mut offset : u64 ,
1010
1043
data : & [ u8 ] ,
1011
- ) -> Result < ( ) , drv_hf_api :: HfError > {
1044
+ ) -> Result < ( ) , APOBError > {
1012
1045
for chunk in data. chunks ( drv_hf_api:: PAGE_SIZE_BYTES ) {
1013
1046
Self :: apob_write_page (
1014
1047
hf,
1015
1048
offset
1016
1049
. try_into ( )
1017
- . map_err ( |_| drv_hf_api :: HfError :: BadAddress ) ?,
1050
+ . map_err ( |_| APOBError :: OffsetOverflow { offset } ) ?,
1018
1051
chunk,
1019
1052
) ?;
1020
1053
offset += chunk. len ( ) as u64 ;
@@ -1029,19 +1062,21 @@ impl ServerImpl {
1029
1062
hf : & HostFlash ,
1030
1063
offset : u32 ,
1031
1064
data : & [ u8 ] ,
1032
- ) -> Result < ( ) , drv_hf_api :: HfError > {
1065
+ ) -> Result < ( ) , APOBError > {
1033
1066
if offset as usize % drv_hf_api:: SECTOR_SIZE_BYTES == 0 {
1034
- hf. bonus_sector_erase ( offset) ?;
1067
+ hf. bonus_sector_erase ( offset)
1068
+ . map_err ( |err| APOBError :: EraseFailed { offset, err } ) ?;
1035
1069
} else {
1036
1070
// Read back the page and confirm that it's all empty
1037
1071
let mut scratch = [ 0u8 ; drv_hf_api:: PAGE_SIZE_BYTES ] ;
1038
- hf. bonus_read ( offset, & mut scratch[ ..data. len ( ) ] ) ?;
1072
+ hf. bonus_read ( offset, & mut scratch[ ..data. len ( ) ] )
1073
+ . map_err ( |err| APOBError :: ReadFailed { offset, err } ) ?;
1039
1074
if !scratch[ ..data. len ( ) ] . iter ( ) . all ( |b| * b == 0xFF ) {
1040
- // TODO use a different error here?
1041
- return Err ( drv_hf_api:: HfError :: BadAddress ) ;
1075
+ return Err ( APOBError :: NotErased { offset } ) ;
1042
1076
}
1043
1077
}
1044
1078
hf. bonus_page_program ( offset, data)
1079
+ . map_err ( |err| APOBError :: WriteFailed { offset, err } )
1045
1080
}
1046
1081
1047
1082
fn handle_sprot (
0 commit comments