@@ -77,13 +77,8 @@ UINT _lx_nor_flash_format(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driv
7777ULONG l ;
7878UINT status ;
7979
80- ULONG * block_word_ptr ;
81- ULONG bit_map_words ;
82- ULONG sectors_per_block ;
83- ULONG bit_map_mask ;
8480ULONG block_word ;
85-
86- LX_INTERRUPT_SAVE_AREA
81+ ULONG * block_word_ptr ;
8782
8883 LX_PARAMETER_NOT_USED (name );
8984
@@ -106,14 +101,8 @@ ULONG block_word;
106101 }
107102#endif
108103
109- nor_flash -> lx_nor_flash_block_free_bit_map_offset = sizeof (LX_NOR_FLASH_BLOCK_HEADER )/sizeof (ULONG );
110-
111- LX_DISABLE
112104 for (l = 0 ; l < nor_flash -> lx_nor_flash_total_blocks ; l ++ )
113105 {
114- /* Setup the initial erase count to 0, assuming that the block is already erased */
115- block_word = ((ULONG ) 0 );
116-
117106#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
118107 /* Check that the block is already erased */
119108 status = (nor_flash -> lx_nor_flash_driver_block_erased_verify )(nor_flash , l );
@@ -133,7 +122,6 @@ ULONG block_word;
133122 /* Call system error handler. */
134123 _lx_nor_flash_system_error (nor_flash , status );
135124
136- LX_RESTORE
137125 /* Return an error. */
138126 return (LX_ERROR );
139127 }
@@ -150,65 +138,30 @@ ULONG block_word;
150138 /* Call system error handler. */
151139 _lx_nor_flash_system_error (nor_flash , status );
152140
153- LX_RESTORE
154141 /* Return an error. */
155142 return (LX_ERROR );
156143 }
157- else
158- {
159- /* the block has been erased, thus incrememt its erase_count */
160- block_word = ((ULONG ) 1 );
161- }
162144 }
163145
164146 /* Setup the block word pointer to the first word of the first block */
165147 block_word_ptr = nor_flash -> lx_nor_flash_base_address + l * nor_flash -> lx_nor_flash_words_per_block ;
166148
167- /* Calculate the number of bits we need in the free physical sector bit map */
168- sectors_per_block = (nor_flash -> lx_nor_flash_words_per_block / LX_NOR_SECTOR_SIZE ) - 1 ;
169-
170- /* Calculate the number of words we need for the free physical sector bit map. */
171- bit_map_words = (sectors_per_block + 31 )/ 32 ;
172-
173- if ((sectors_per_block % 32 ) != 0 )
174- {
175- bit_map_mask = (ULONG )(1 << (sectors_per_block % 32 ));
176- bit_map_mask = bit_map_mask - 1 ;
177- }
178- else
179- {
180-
181- /* Exactly 32 sectors for the bit map mask. */
182- bit_map_mask = LX_ALL_ONES ;
183- }
184- status = _lx_nor_flash_driver_write (nor_flash , block_word_ptr + (nor_flash -> lx_nor_flash_block_free_bit_map_offset + (bit_map_words - 1 )) , & bit_map_mask , 1 );
185- if (status )
186- {
187- /* Call system error handler. */
188- _lx_nor_flash_system_error (nor_flash , status );
189-
190- LX_RESTORE
191- /* Return an error. */
192- return (LX_ERROR );
193- }
194-
195- block_word = (block_word | LX_BLOCK_ERASED );
149+ /* Setup the initial erase_count to 1 and mark the block as erased.
150+ * When the lx_nor_flash_open() gets called only the erase count will be kept.
151+ */
152+ block_word = ((ULONG )1 | LX_BLOCK_ERASED );
196153
197154 status = _lx_nor_flash_driver_write (nor_flash , block_word_ptr , & block_word , 1 );
198155 if (status )
199156 {
200157 /* Call system error handler. */
201158 _lx_nor_flash_system_error (nor_flash , status );
202159
203- LX_RESTORE
204160 /* Return an error. */
205161 return (LX_ERROR );
206162 }
207163
208164 }
209165
210- /* Restore interrupts. */
211- LX_RESTORE
212-
213166 return (LX_SUCCESS );
214167}
0 commit comments