@@ -94,6 +94,45 @@ typedef struct {
9494 };
9595} whNvmFlashLogMetadata ;
9696
97+ /* do a blank check + program + verify */
98+ static int nfl_FlashProgramHelper (whNvmFlashLogContext * ctx , uint32_t off ,
99+ const uint8_t * data , uint32_t len )
100+ {
101+ int ret ;
102+
103+ if (ctx == NULL || (data == NULL && len > 0 ))
104+ return WH_ERROR_BADARGS ;
105+
106+ ret = ctx -> flash_cb -> BlankCheck (ctx -> flash_ctx , off , len );
107+ if (ret != 0 )
108+ return ret ;
109+ ret = ctx -> flash_cb -> Program (ctx -> flash_ctx , off , len , data );
110+ if (ret != 0 )
111+ return ret ;
112+ ret = ctx -> flash_cb -> Verify (ctx -> flash_ctx , off , len , data );
113+ if (ret != 0 )
114+ return ret ;
115+ return WH_ERROR_OK ;
116+ }
117+
118+ /* do a erase + blank check */
119+ static int nfl_FlashEraseHelper (whNvmFlashLogContext * ctx , uint32_t off ,
120+ uint32_t len )
121+ {
122+ int ret ;
123+
124+ if (ctx == NULL )
125+ return WH_ERROR_BADARGS ;
126+ ret = ctx -> flash_cb -> Erase (ctx -> flash_ctx , off , len );
127+ if (ret != 0 )
128+ return ret ;
129+ ret = ctx -> flash_cb -> BlankCheck (ctx -> flash_ctx , off , len );
130+ if (ret != 0 )
131+ return ret ;
132+
133+ return WH_ERROR_OK ;
134+ }
135+
97136static whNvmFlashLogMetadata * nfl_ObjNext (whNvmFlashLogContext * ctx ,
98137 whNvmFlashLogMetadata * obj )
99138{
@@ -108,25 +147,19 @@ static whNvmFlashLogMetadata* nfl_ObjNext(whNvmFlashLogContext* ctx,
108147
109148static int nfl_PartitionErase (whNvmFlashLogContext * ctx , uint32_t partition )
110149{
111- const whFlashCb * f_cb = ctx -> flash_cb ;
112- uint32_t off ;
113- int ret ;
150+ uint32_t off ;
114151
115152 if (ctx == NULL || partition > 1 )
116153 return WH_ERROR_BADARGS ;
117154
118155 off = partition * ctx -> partition_size ;
119- ret = f_cb -> Erase (ctx -> flash_ctx , off , ctx -> partition_size );
120- if (ret != 0 )
121- return ret ;
122- return WH_ERROR_OK ;
156+ return nfl_FlashEraseHelper (ctx , off , ctx -> partition_size );
123157}
124158
125159static int nfl_PartitionWrite (whNvmFlashLogContext * ctx , uint32_t partition )
126160{
127- const whFlashCb * f_cb = ctx -> flash_cb ;
128- uint32_t off ;
129- int ret ;
161+ uint32_t off ;
162+ int ret ;
130163
131164 if (ctx == NULL || partition > 1 )
132165 return WH_ERROR_BADARGS ;
@@ -137,9 +170,9 @@ static int nfl_PartitionWrite(whNvmFlashLogContext* ctx, uint32_t partition)
137170 return WH_ERROR_ABORTED ;
138171
139172 if (ctx -> directory .header .size > 0 ) {
140- ret = f_cb -> Program ( ctx -> flash_ctx ,
141- off + sizeof (whNvmFlashLogPartitionHeader ),
142- ctx -> directory .header . size , ctx -> directory .data );
173+ ret = nfl_FlashProgramHelper (
174+ ctx , off + sizeof (whNvmFlashLogPartitionHeader ),
175+ ctx -> directory .data , ctx -> directory .header . size );
143176 if (ret != 0 )
144177 return ret ;
145178 }
@@ -162,9 +195,9 @@ static int nfl_PartitionCommit(whNvmFlashLogContext* ctx, uint32_t partition)
162195 sizeof (whNvmFlashLogPartitionHeader ));
163196 if (ret != 0 )
164197 return ret ;
165- ret = f_cb -> Program ( ctx -> flash_ctx , off ,
166- sizeof ( whNvmFlashLogPartitionHeader ) ,
167- ( uint8_t * ) & ctx -> directory . header );
198+
199+ ret = nfl_FlashProgramHelper ( ctx , off , ( uint8_t * ) & ctx -> directory . header ,
200+ sizeof ( whNvmFlashLogPartitionHeader ) );
168201 if (ret != 0 )
169202 return ret ;
170203
0 commit comments