1 /* Basic NOR flash tests...  */
2 
3 #include <stdio.h>
4 #include "lx_api.h"
5 
6 #define     DEMO_STACK_SIZE         4096
7 
8 
9 /* Define the ThreadX object control blocks...  */
10 #ifndef LX_STANDALONE_ENABLE
11 TX_THREAD               thread_0;
12 #endif
13 UCHAR                   thread_0_stack[DEMO_STACK_SIZE];
14 
15 //#define EXTENDED_CACHE
16 #ifdef EXTENDED_CACHE
17 UCHAR                   cache_memory[50000];
18 #endif
19 
20 /* Define LevelX structures.  */
21 
22 LX_NAND_FLASH   nand_sim_flash;
23 ULONG           buffer[2048];
24 ULONG           readbuffer[2048];
25 
26 extern ULONG    *nand_flash_memory;
27 
28 /* Define LevelX NOR flash simulator prototoypes.  */
29 
30 UINT  _lx_nand_flash_simulator_erase_all(VOID);
31 UINT  _lx_nand_flash_simulator_initialize(LX_NAND_FLASH *nand_flash);
32 
33 VOID  _fx_nand_flash_read_sectors(ULONG logical_sector, ULONG sectors, UCHAR *destination_buffer);
34 VOID  _fx_nand_flash_write_sectors(ULONG logical_sector, ULONG sectors, UCHAR *source_buffer);
35 
36 #if 0
37 typedef struct SECTOR_STRUCT
38 {
39     ULONG       words[2048/4];
40 } SECTOR;
41 
42 SECTOR  test_write[8];
43 SECTOR  test_read[8];
44 #endif
45 
46 #if 1
47 
48 UCHAR   byte_buffer[2048];
49 UCHAR   ecc_bytes[24];
50 UCHAR   lx_ecc_buffer[24];
51 
52 #endif
53 
54 /* Define thread prototypes.  */
55 
56 void    thread_0_entry(ULONG thread_input);
57 
58 VOID ComputePageECC(UCHAR *data, INT size, UCHAR *code);
59 INT  CorrectPageECC(UCHAR *data, INT size, UCHAR *code);
60 
61 
62 
63 /* Define main entry point.  */
64 
main()65 int main()
66 {
67 
68     /* Enter the ThreadX kernel.  */
69 #ifndef LX_STANDALONE_ENABLE
70     tx_kernel_enter();
71 #else
72     thread_0_entry(0);
73 #endif
74 
75 }
76 
77 
78 /* Define what the initial system looks like.  */
79 #ifndef LX_STANDALONE_ENABLE
tx_application_define(void * first_unused_memory)80 void    tx_application_define(void *first_unused_memory)
81 {
82 
83 
84     /* Create the main thread.  */
85     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
86             thread_0_stack, DEMO_STACK_SIZE,
87             1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
88 }
89 #endif
90 
91 
92 #define NAND_MEMORY_SIZE 2056
93 ULONG nand_memory_space[NAND_MEMORY_SIZE];
94 
95 /* For random read/write test */
96 #define MAX_SECTOR_ADDRESS 64000*4
97 #define SECTOR_SIZE 512
98 
99 UCHAR local_data_buffer[MAX_SECTOR_ADDRESS * SECTOR_SIZE];
100 
101 /* Define the test threads.  */
102 
thread_0_entry(ULONG thread_input)103 void    thread_0_entry(ULONG thread_input)
104 {
105 
106 ULONG   i, j, sector;
107 UINT    status;
108 
109 ULONG   *word_ptr;
110 UCHAR   *byte_ptr;
111 
112 
113     /* Erase the simulated NOR flash.  */
114     _lx_nand_flash_simulator_erase_all();
115 
116     /* Initialize LevelX.  */
117     _lx_nand_flash_initialize();
118 
119     /* Test 1: Simple write 520 sectors and read 520 sectors.  */
120     printf("Test 1: Simple write-read 520 sectors...........");
121 
122     status = lx_nand_flash_format(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
123     if (status != LX_SUCCESS)
124     {
125         printf("FAILED!\n");
126 #ifdef BATCH_TEST
127         exit(1);
128 #endif
129         while (1)
130         {
131         }
132     }
133 
134     status= lx_nand_flash_open(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
135     if (status != LX_SUCCESS)
136     {
137         printf("FAILED!\n");
138 #ifdef BATCH_TEST
139     exit(1);
140 #endif
141     while(1)
142         {
143         }
144     }
145 #ifdef EXTENDED_CACHE
146     lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
147 #endif
148 
149     /* Write 520 sectors....  */
150     for (i = 0; i < 520; i++)
151     {
152         for (j = 0; j < 512; j++)
153           buffer[j] =  i;
154 
155         status =  lx_nand_flash_sector_write(&nand_sim_flash, i, buffer);
156 
157         if (status != LX_SUCCESS)
158         {
159           printf("FAILED!\n");
160 #ifdef BATCH_TEST
161     exit(1);
162 #endif
163           while(1)
164           {
165           }
166         }
167     }
168 
169     /* Close and reopen the flash. */
170     lx_nand_flash_close(&nand_sim_flash);
171 
172     LX_MEMSET(nand_memory_space, 0, sizeof(nand_memory_space));
173     LX_MEMSET(&nand_sim_flash, 0, sizeof(nand_sim_flash));
174 
175     status = lx_nand_flash_open(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
176     if (status != LX_SUCCESS)
177     {
178         printf("FAILED!\n");
179 #ifdef BATCH_TEST
180         exit(1);
181 #endif
182         while (1)
183         {
184         }
185     }
186 
187     /* Read back 520 sectors...  */
188     for (i = 0; i < 520; i++)
189     {
190 
191         status =  lx_nand_flash_sector_read(&nand_sim_flash, i, buffer);
192 
193         if (status != LX_SUCCESS)
194         {
195 #ifdef BATCH_TEST
196     exit(1);
197 #endif
198           printf("FAILED!\n");
199           while(1)
200           {
201           }
202         }
203 
204         for (j = 0; j < 128; j++)
205         {
206 
207           if (buffer[j] !=  i)
208           {
209             printf("FAILED!\n");
210 #ifdef BATCH_TEST
211     exit(1);
212 #endif
213             while(1)
214             {
215             }
216           }
217         }
218     }
219 
220     _lx_nand_flash_close(&nand_sim_flash);
221     printf("SUCCESS!\n");
222 
223     /* Test 2: Write same sector 320 times.  */
224     printf("Test 2: Write same sector 320 times.............");
225 
226     /* Reinitialize...  */
227     _lx_nand_flash_simulator_erase_all();
228 
229 
230     lx_nand_flash_initialize();
231 
232     status = lx_nand_flash_format(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
233 
234 
235     lx_nand_flash_open(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
236 #ifdef EXTENDED_CACHE
237     lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
238 #endif
239 
240     for (j = 0; j < 512; j++)
241          buffer[j] =  0xFFFFFFFF;
242 
243     /* Write same sector 320 sectors....  */
244     for (i = 0; i < 320; i++)
245     {
246         for (j = 0; j < 512; j++)
247           buffer[j] =  i;
248 
249         if (i == 319)
250             buffer[j-1]--;
251         status =  lx_nand_flash_sector_write(&nand_sim_flash, 7, buffer);
252 
253         if (status != LX_SUCCESS)
254         {
255           printf("FAILED!\n");
256 #ifdef BATCH_TEST
257     exit(1);
258 #endif
259           while(1)
260           {
261           }
262         }
263 
264         status =  lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
265 
266         if (status != LX_SUCCESS)
267         {
268           printf("FAILED!\n");
269 #ifdef BATCH_TEST
270     exit(1);
271 #endif
272           while(1)
273           {
274           }
275         }
276 
277         for (j = 0; j < 128; j++)
278         {
279 
280           if (buffer[j] !=  readbuffer[j])
281           {
282             printf("FAILED!\n");
283 #ifdef BATCH_TEST
284     exit(1);
285 #endif
286             while(1)
287             {
288             }
289           }
290         }
291 
292         /* Write other sectors just to have additional sectors to manage.  */
293         if (i == 1)
294           lx_nand_flash_sector_write(&nand_sim_flash, 1, buffer);
295         if (i == 16)
296           lx_nand_flash_sector_write(&nand_sim_flash, 16, buffer);
297         if (i == 32)
298           lx_nand_flash_sector_write(&nand_sim_flash, 32, buffer);
299         if (i == 48)
300           lx_nand_flash_sector_write(&nand_sim_flash, 48, buffer);
301         if (i == 64)
302           lx_nand_flash_sector_write(&nand_sim_flash, 64, buffer);
303         if (i == 80)
304           lx_nand_flash_sector_write(&nand_sim_flash, 80, buffer);
305         if (i == 96)
306           lx_nand_flash_sector_write(&nand_sim_flash, 96, buffer);
307         if (i == 112)
308           lx_nand_flash_sector_write(&nand_sim_flash, 112, buffer);
309     }
310 
311     status =  lx_nand_flash_defragment(&nand_sim_flash);
312 
313 
314     status =  lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
315         if (status != LX_SUCCESS)
316         {
317           printf("FAILED!\n");
318 #ifdef BATCH_TEST
319     exit(1);
320 #endif
321           while(1)
322           {
323           }
324         }
325         if (readbuffer[0] != 319)
326         {
327           printf("FAILED!\n");
328 #ifdef BATCH_TEST
329     exit(1);
330 #endif
331           while(1)
332           {
333           }
334         }
335     status =  lx_nand_flash_sector_read(&nand_sim_flash, 1, readbuffer);
336         if (status != LX_SUCCESS)
337         {
338           printf("FAILED!\n");
339 #ifdef BATCH_TEST
340     exit(1);
341 #endif
342           while(1)
343           {
344           }
345         }
346         if (readbuffer[0] != 1)
347         {
348           printf("FAILED!\n");
349 #ifdef BATCH_TEST
350     exit(1);
351 #endif
352           while(1)
353           {
354           }
355         }
356      status =  lx_nand_flash_sector_read(&nand_sim_flash, 16, readbuffer);
357         if (status != LX_SUCCESS)
358         {
359           printf("FAILED!\n");
360 #ifdef BATCH_TEST
361     exit(1);
362 #endif
363           while(1)
364           {
365           }
366         }
367         if (readbuffer[0] != 16)
368         {
369           printf("FAILED!\n");
370 #ifdef BATCH_TEST
371     exit(1);
372 #endif
373           while(1)
374           {
375           }
376         }
377     status =  lx_nand_flash_sector_read(&nand_sim_flash, 32, readbuffer);
378         if (status != LX_SUCCESS)
379         {
380           printf("FAILED!\n");
381 #ifdef BATCH_TEST
382     exit(1);
383 #endif
384           while(1)
385           {
386           }
387         }
388         if (readbuffer[0] != 32)
389         {
390           printf("FAILED!\n");
391 #ifdef BATCH_TEST
392     exit(1);
393 #endif
394           while(1)
395           {
396           }
397         }
398     status =  lx_nand_flash_sector_read(&nand_sim_flash, 48, readbuffer);
399         if (status != LX_SUCCESS)
400         {
401           printf("FAILED!\n");
402 #ifdef BATCH_TEST
403     exit(1);
404 #endif
405           while(1)
406           {
407           }
408         }
409         if (readbuffer[0] != 48)
410         {
411           printf("FAILED!\n");
412 #ifdef BATCH_TEST
413     exit(1);
414 #endif
415           while(1)
416           {
417           }
418         }
419     status =  lx_nand_flash_sector_read(&nand_sim_flash, 64, readbuffer);
420         if (status != LX_SUCCESS)
421         {
422           printf("FAILED!\n");
423 #ifdef BATCH_TEST
424     exit(1);
425 #endif
426           while(1)
427           {
428           }
429         }
430         if (readbuffer[0] != 64)
431         {
432           printf("FAILED!\n");
433 #ifdef BATCH_TEST
434     exit(1);
435 #endif
436           while(1)
437           {
438           }
439         }
440     status =  lx_nand_flash_sector_read(&nand_sim_flash, 80, readbuffer);
441         if (status != LX_SUCCESS)
442         {
443           printf("FAILED!\n");
444 #ifdef BATCH_TEST
445     exit(1);
446 #endif
447           while(1)
448           {
449           }
450         }
451         if (readbuffer[0] != 80)
452         {
453           printf("FAILED!\n");
454 #ifdef BATCH_TEST
455     exit(1);
456 #endif
457           while(1)
458           {
459           }
460         }
461     status =  lx_nand_flash_sector_read(&nand_sim_flash, 96, readbuffer);
462         if (status != LX_SUCCESS)
463         {
464           printf("FAILED!\n");
465 #ifdef BATCH_TEST
466     exit(1);
467 #endif
468           while(1)
469           {
470           }
471         }
472         if (readbuffer[0] != 96)
473         {
474           printf("FAILED!\n");
475 #ifdef BATCH_TEST
476     exit(1);
477 #endif
478           while(1)
479           {
480           }
481         }
482     status =  lx_nand_flash_sector_read(&nand_sim_flash, 112, readbuffer);
483         if (status != LX_SUCCESS)
484         {
485           printf("FAILED!\n");
486 #ifdef BATCH_TEST
487     exit(1);
488 #endif
489           while(1)
490           {
491           }
492         }
493         if (readbuffer[0] != 112)
494         {
495           printf("FAILED!\n");
496 #ifdef BATCH_TEST
497     exit(1);
498 #endif
499           while(1)
500           {
501           }
502         }
503 
504     status =  lx_nand_flash_defragment(&nand_sim_flash);
505 
506     if (status != LX_NOT_SUPPORTED)
507     {
508           printf("FAILED!\n");
509 #ifdef BATCH_TEST
510     exit(1);
511 #endif
512           while(1)
513           {
514           }
515     }
516 
517     status =  lx_nand_flash_close(&nand_sim_flash);
518 
519     if (status != LX_SUCCESS)
520     {
521           printf("FAILED!\n");
522 #ifdef BATCH_TEST
523     exit(1);
524 #endif
525           while(1)
526           {
527           }
528     }
529     printf("SUCCESS!\n");
530 
531     printf("Test 3: Page copy test..........................");
532 
533     /* Reinitialize...  */
534     _lx_nand_flash_simulator_erase_all();
535 
536 
537     lx_nand_flash_initialize();
538 
539     status = lx_nand_flash_format(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
540 
541 
542     lx_nand_flash_open(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
543 
544     for (j = 0; j < 512; j++)
545         buffer[j] = 0xFFFFFFFF;
546 
547     status = lx_nand_flash_sector_write(&nand_sim_flash, 0, buffer);
548 
549     /* Write same sector 320 sectors....  */
550     for (i = 256; i < 512; i++)
551     {
552         for (j = 0; j < 512; j++)
553             buffer[j] = i;
554 
555         if (i == 300) continue;
556 
557         status = lx_nand_flash_sector_write(&nand_sim_flash, i, buffer);
558 
559         if (status != LX_SUCCESS)
560         {
561             printf("FAILED!\n");
562 #ifdef BATCH_TEST
563             exit(1);
564 #endif
565             while (1)
566             {
567             }
568         }
569     }
570 
571     status = lx_nand_flash_sector_write(&nand_sim_flash, 300, buffer);
572     if (status != LX_SUCCESS)
573     {
574         printf("FAILED!\n");
575 #ifdef BATCH_TEST
576         exit(1);
577 #endif
578         while (1)
579         {
580         }
581     }
582 
583     status = lx_nand_flash_sector_write(&nand_sim_flash, 400, buffer);
584     if (status != LX_SUCCESS)
585     {
586         printf("FAILED!\n");
587 #ifdef BATCH_TEST
588         exit(1);
589 #endif
590         while (1)
591         {
592         }
593     }
594 
595     if (status != LX_SUCCESS)
596     {
597         printf("FAILED!\n");
598 #ifdef BATCH_TEST
599         exit(1);
600 #endif
601         while (1)
602         {
603         }
604     }
605     if (nand_sim_flash.lx_nand_flash_block_status_table[nand_sim_flash.lx_nand_flash_block_mapping_table[1]] & LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL)
606     {
607         printf("FAILED!\n");
608 #ifdef BATCH_TEST
609         exit(1);
610 #endif
611         while (1)
612         {
613         }
614     }
615 
616     status =  lx_nand_flash_close(&nand_sim_flash);
617 
618     if (status != LX_SUCCESS)
619     {
620           printf("FAILED!\n");
621 #ifdef BATCH_TEST
622     exit(1);
623 #endif
624           while(1)
625           {
626           }
627     }
628     printf("SUCCESS!\n");
629 
630     printf("Test 4: Random read/write test..................");
631 
632     LX_MEMSET(local_data_buffer, 0xff, sizeof(local_data_buffer));
633 
634     /* Reinitialize...  */
635     _lx_nand_flash_simulator_erase_all();
636 
637 
638     lx_nand_flash_initialize();
639 
640     status = lx_nand_flash_format(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
641     if (status != LX_SUCCESS)
642     {
643         printf("FAILED!\n");
644 #ifdef BATCH_TEST
645         exit(1);
646 #endif
647         while (1)
648         {
649         }
650     }
651 
652     status = lx_nand_flash_open(&nand_sim_flash, "sim nand flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
653     if (status != LX_SUCCESS)
654     {
655         printf("FAILED!\n");
656 #ifdef BATCH_TEST
657         exit(1);
658 #endif
659         while (1)
660         {
661         }
662     }
663 
664     static ULONG loop_count = 200;
665     ULONG operation;
666     ULONG sector_number;
667     ULONG data_byte;
668     ULONG sector_count;
669     static ULONG read_count = 0;
670     static ULONG write_count = 0;
671     static ULONG release_count = 0;
672     static ULONG reopen_count = 0;
673 
674     while (loop_count--)
675     {
676         operation = (ULONG)rand() % 32768;
677         if (operation < 16384)
678         {
679             sector_number = ((ULONG)rand() * (ULONG)rand()) % MAX_SECTOR_ADDRESS;
680             sector_count = ((ULONG)rand() % 768) + 1;
681             if (sector_number + sector_count > MAX_SECTOR_ADDRESS)
682             {
683                 sector_count = MAX_SECTOR_ADDRESS - sector_number;
684             }
685 
686             while (sector_count--)
687             {
688                 status = lx_nand_flash_sector_read(&nand_sim_flash, sector_number, readbuffer);
689                 if (status != LX_SUCCESS)
690                 {
691                     printf("FAILED!\n");
692 #ifdef BATCH_TEST
693                     exit(1);
694 #endif
695                     while (1)
696                     {
697                     }
698                 }
699 #ifdef FULL_SECTOR_DATA_VERIFY
700                 status = memcmp((local_data_buffer + sector_number * SECTOR_SIZE), readbuffer, SECTOR_SIZE);
701 #else
702                 status = *(ULONG*)(local_data_buffer + sector_number * SECTOR_SIZE) - readbuffer[0];
703 #endif
704                 if (status != 0)
705                 {
706                     printf("FAILED!\n");
707 #ifdef BATCH_TEST
708                     exit(1);
709 #endif
710                     while (1)
711                     {
712                     }
713                 }
714                 read_count++;
715                 sector_number++;
716             }
717         }
718         else if (operation < 29491)
719         {
720             sector_number = ((ULONG)rand() * (ULONG)rand()) % MAX_SECTOR_ADDRESS;
721             sector_count = ((ULONG)rand() % 768) + 1;
722             if (sector_number + sector_count > MAX_SECTOR_ADDRESS)
723             {
724                 sector_count = MAX_SECTOR_ADDRESS - sector_number;
725             }
726 
727             while (sector_count--)
728             {
729                 data_byte = (ULONG)rand();
730 
731 #ifdef FULL_SECTOR_DATA_VERIFY
732                 LX_MEMSET((local_data_buffer + sector_number * SECTOR_SIZE), data_byte, SECTOR_SIZE);
733 #else
734                 *(ULONG*)(local_data_buffer + sector_number * SECTOR_SIZE) = data_byte;
735 #endif
736                 status = lx_nand_flash_sector_write(&nand_sim_flash, sector_number, local_data_buffer + sector_number * SECTOR_SIZE);
737                 if (status != LX_SUCCESS)
738                 {
739                     printf("FAILED!\n");
740 #ifdef BATCH_TEST
741                     exit(1);
742 #endif
743                     while (1)
744                     {
745                     }
746                 }
747                 write_count++;
748                 sector_number++;
749             }
750         }
751         else if(operation < 32760)
752         {
753             sector_number = ((ULONG)rand() * (ULONG)rand()) % MAX_SECTOR_ADDRESS;
754             data_byte = 0xffffffff;
755             sector_count = ((ULONG)rand() % 768) + 1;
756             if (sector_number + sector_count > MAX_SECTOR_ADDRESS)
757             {
758                 sector_count = MAX_SECTOR_ADDRESS - sector_number;
759             }
760 
761             while (sector_count--)
762             {
763 
764 #ifdef FULL_SECTOR_DATA_VERIFY
765                 LX_MEMSET((local_data_buffer + sector_number * SECTOR_SIZE), data_byte, SECTOR_SIZE);
766 #else
767                 * (ULONG*)(local_data_buffer + sector_number * SECTOR_SIZE) = data_byte;
768 #endif
769                 status = lx_nand_flash_sector_release(&nand_sim_flash, sector_number);
770                 if (status != LX_SUCCESS)
771                 {
772                     printf("FAILED!\n");
773 #ifdef BATCH_TEST
774                     exit(1);
775 #endif
776                     while (1)
777                     {
778                     }
779                 }
780                 release_count++;
781                 sector_number++;
782             }
783         }
784         else
785         {
786             /* Close and reopen the flash. */
787             status = lx_nand_flash_close(&nand_sim_flash);
788             if (status != LX_SUCCESS)
789             {
790                 printf("FAILED!\n");
791 #ifdef BATCH_TEST
792                 exit(1);
793 #endif
794                 while (1)
795                 {
796                 }
797             }
798 
799             status = lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
800             if (status != LX_SUCCESS)
801             {
802                 printf("FAILED!\n");
803 #ifdef BATCH_TEST
804                 exit(1);
805 #endif
806                 while (1)
807                 {
808                 }
809             }
810             reopen_count++;
811         }
812     }
813 
814     printf("SUCCESS!\n");
815 
816 #if 0
817     /* Point at the simulated NOR flash memory.  */
818     word_ptr =  nand_flash_memory;
819 
820 
821     /* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0,
822        after the erase, but before the erase count is setup.  */
823     printf("Test 3: Block erase-initialize interrupted......");
824     word_ptr[0] =  0xFFFFFFFF;
825     word_ptr[3] =  0x00000000;  /* This simulates a non-erased block.  */
826 
827     /* Open the flash and see if we recover properly.  */
828     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
829 #ifdef EXTENDED_CACHE
830     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
831 #endif
832 
833     if ((status != LX_SUCCESS) ||
834         (nand_sim_flash.lx_nand_flash_free_pages != 111) ||
835         (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
836     {
837 
838           printf("FAILED!\n");
839 #ifdef BATCH_TEST
840     exit(1);
841 #endif
842           while(1)
843           {
844           }
845     }
846 
847     status =  lx_nand_flash_close(&nand_sim_flash);
848 
849     if (status != LX_SUCCESS)
850     {
851           printf("FAILED!\n");
852 #ifdef BATCH_TEST
853     exit(1);
854 #endif
855           while(1)
856           {
857           }
858     }
859 
860 
861     /* Corrupt block 0, simulate a power interruption after erase of block 0,
862        but before erase count is setup.  */
863     word_ptr[0] =  0xFFFFFFFF;
864 
865     /* Open the flash and see if we recover properly.  */
866     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
867 #ifdef EXTENDED_CACHE
868     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
869 #endif
870 
871     if ((status != LX_SUCCESS) ||
872         (nand_sim_flash.lx_nand_flash_free_pages != 111) ||
873         (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
874     {
875 
876           printf("FAILED!\n");
877 #ifdef BATCH_TEST
878     exit(1);
879 #endif
880           while(1)
881           {
882           }
883     }
884 
885     status =  lx_nand_flash_close(&nand_sim_flash);
886 
887     if (status != LX_SUCCESS)
888     {
889           printf("FAILED!\n");
890 #ifdef BATCH_TEST
891     exit(1);
892 #endif
893           while(1)
894           {
895           }
896     }
897     printf("SUCCESS!\n");
898 
899 
900     /* Test 4: simulate a power interruption while a new page is being setup.  */
901     printf("Test 4: Power interrupted new page setup........");
902 
903     /* Partially setup new page.  */
904     byte_ptr =  (UCHAR *) word_ptr;
905     byte_ptr[2053] = 0xBF;      /* Set block 0/page 0 extra bytes to indicate block not empty.  */
906     word_ptr[528] =  0x60;
907 
908     /* Open the flash and see if we recover properly.  We should mark this page as obsolete. */
909     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
910 #ifdef EXTENDED_CACHE
911     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
912 #endif
913 
914     if ((status != LX_SUCCESS) ||
915         (nand_sim_flash.lx_nand_flash_free_pages != 110) ||
916         (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
917     {
918 
919           printf("FAILED!\n");
920 #ifdef BATCH_TEST
921     exit(1);
922 #endif
923           while(1)
924           {
925           }
926     }
927 
928     status =  lx_nand_flash_close(&nand_sim_flash);
929 
930     if (status != LX_SUCCESS)
931     {
932           printf("FAILED!\n");
933 #ifdef BATCH_TEST
934     exit(1);
935 #endif
936           while(1)
937           {
938           }
939     }
940 
941 
942     /* Simulate a power interruption after a new sector is allocated, after data
943        had been copied, and the superceeded bit is clear, but before the new entry can be
944        setup.  */
945 
946     /* Copy data block and reset spare.  */
947     byte_ptr[2053] = 0xBF;          /* Set block 0/page 0 extra bytes to indicate block not empty.  */
948     for (i = 1; i < 512; i++)       /* Fill block 0, page 1 data  */
949         word_ptr[i+528] = 0x60;
950     word_ptr[i+528] =  0xFFFFFFFF;  /* Reset extra bytes for block 0, page 1 */
951     word_ptr[i+529] =  0xFFFFFFFF;  /* Reset extra bytes for block 0, page 1 */
952 
953     /* Set the superceded bit in block 1/page 1.   */
954     byte_ptr[37957] = 0x80;
955 
956     /* Open the flash and see if we recover properly.  */
957     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
958 #ifdef EXTENDED_CACHE
959     lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
960 #endif
961 
962     if ((status != LX_SUCCESS) ||
963         (nand_sim_flash.lx_nand_flash_free_pages != 110) ||
964         (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
965     {
966 
967           printf("FAILED!\n");
968 #ifdef BATCH_TEST
969     exit(1);
970 #endif
971           while(1)
972           {
973           }
974     }
975 
976     lx_nand_flash_close(&nand_sim_flash);
977 
978     /* Simulate a power interruption after a new sector is allocated, after data
979        had been copied, and the superceeded bit is clear, the new entry is setup, but the old entry
980        has not been invalidated.  */
981     byte_ptr[2053] = 0xBF;          /* Set block 0/page 0 extra bytes to indicate block not empty.  */
982     for (i = 1; i < 512; i++)       /* Fill block 0, page 1 data  */
983         word_ptr[i+528] = 0x60;
984     word_ptr[i+528] =  0xFFFFFFFF;  /* Reset extra bytes for block 0, page 1 */
985     word_ptr[i+529] =  0xFFFFFFFF;  /* Reset extra bytes for block 0, page 1 */
986 
987     byte_ptr =  (UCHAR *) word_ptr;
988 
989     /* set the spare info in the new page.  */
990     byte_ptr[4162] = 0x60;          /* Setup extra bytes for block 0, page 1  */
991     byte_ptr[4163] = 0;             /* Setup extra bytes for block 0, page 1  */
992     byte_ptr[4164] = 0;             /* Setup extra bytes for block 0, page 1  */
993     byte_ptr[4165] = 0xC0;          /* Setup extra bytes for block 0, page 1  */
994 
995     /* Set the superceded bit in block 1/page 1.   */
996     byte_ptr[37957] = 0x80;
997 
998     /* Open the flash and see if we recover properly.  */
999     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
1000 #ifdef EXTENDED_CACHE
1001     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
1002 #endif
1003 
1004     if ((status != LX_SUCCESS) ||
1005         (nand_sim_flash.lx_nand_flash_free_pages != 110) ||
1006         (nand_sim_flash.lx_nand_flash_mapped_pages != 9))
1007     {
1008 
1009           printf("FAILED!\n");
1010 #ifdef BATCH_TEST
1011     exit(1);
1012 #endif
1013           while(1)
1014           {
1015           }
1016     }
1017 
1018     status =  lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
1019         if (status != LX_SUCCESS)
1020         {
1021           printf("FAILED!\n");
1022 #ifdef BATCH_TEST
1023     exit(1);
1024 #endif
1025           while(1)
1026           {
1027           }
1028         }
1029         if (readbuffer[0] != 119)
1030         {
1031           printf("FAILED!\n");
1032 #ifdef BATCH_TEST
1033     exit(1);
1034 #endif
1035           while(1)
1036           {
1037           }
1038         }
1039     status =  lx_nand_flash_sector_read(&nand_sim_flash, 1, readbuffer);
1040         if (status != LX_SUCCESS)
1041         {
1042           printf("FAILED!\n");
1043 #ifdef BATCH_TEST
1044     exit(1);
1045 #endif
1046           while(1)
1047           {
1048           }
1049         }
1050         if (readbuffer[0] != 1)
1051         {
1052           printf("FAILED!\n");
1053 #ifdef BATCH_TEST
1054     exit(1);
1055 #endif
1056           while(1)
1057           {
1058           }
1059         }
1060      status =  lx_nand_flash_sector_read(&nand_sim_flash, 16, readbuffer);
1061         if (status != LX_SUCCESS)
1062         {
1063           printf("FAILED!\n");
1064 #ifdef BATCH_TEST
1065     exit(1);
1066 #endif
1067           while(1)
1068           {
1069           }
1070         }
1071         if (readbuffer[0] != 16)
1072         {
1073           printf("FAILED!\n");
1074 #ifdef BATCH_TEST
1075     exit(1);
1076 #endif
1077           while(1)
1078           {
1079           }
1080         }
1081     status =  lx_nand_flash_sector_read(&nand_sim_flash, 32, readbuffer);
1082         if (status != LX_SUCCESS)
1083         {
1084           printf("FAILED!\n");
1085 #ifdef BATCH_TEST
1086     exit(1);
1087 #endif
1088           while(1)
1089           {
1090           }
1091         }
1092         if (readbuffer[0] != 32)
1093         {
1094           printf("FAILED!\n");
1095 #ifdef BATCH_TEST
1096     exit(1);
1097 #endif
1098           while(1)
1099           {
1100           }
1101         }
1102     status =  lx_nand_flash_sector_read(&nand_sim_flash, 48, readbuffer);
1103         if (status != LX_SUCCESS)
1104         {
1105           printf("FAILED!\n");
1106 #ifdef BATCH_TEST
1107     exit(1);
1108 #endif
1109           while(1)
1110           {
1111           }
1112         }
1113         if (readbuffer[0] != 48)
1114         {
1115           printf("FAILED!\n");
1116 #ifdef BATCH_TEST
1117     exit(1);
1118 #endif
1119           while(1)
1120           {
1121           }
1122         }
1123     status =  lx_nand_flash_sector_read(&nand_sim_flash, 64, readbuffer);
1124         if (status != LX_SUCCESS)
1125         {
1126           printf("FAILED!\n");
1127 #ifdef BATCH_TEST
1128     exit(1);
1129 #endif
1130           while(1)
1131           {
1132           }
1133         }
1134         if (readbuffer[0] != 64)
1135         {
1136           printf("FAILED!\n");
1137 #ifdef BATCH_TEST
1138     exit(1);
1139 #endif
1140           while(1)
1141           {
1142           }
1143         }
1144     status =  lx_nand_flash_sector_read(&nand_sim_flash, 80, readbuffer);
1145         if (status != LX_SUCCESS)
1146         {
1147           printf("FAILED!\n");
1148 #ifdef BATCH_TEST
1149     exit(1);
1150 #endif
1151           while(1)
1152           {
1153           }
1154         }
1155         if (readbuffer[0] != 80)
1156         {
1157           printf("FAILED!\n");
1158 #ifdef BATCH_TEST
1159     exit(1);
1160 #endif
1161           while(1)
1162           {
1163           }
1164         }
1165     status =  lx_nand_flash_sector_read(&nand_sim_flash, 96, readbuffer);
1166         if (status != LX_SUCCESS)
1167         {
1168           printf("FAILED!\n");
1169 #ifdef BATCH_TEST
1170     exit(1);
1171 #endif
1172           while(1)
1173           {
1174           }
1175         }
1176         if (readbuffer[0] != 96)
1177         {
1178           printf("FAILED!\n");
1179 #ifdef BATCH_TEST
1180     exit(1);
1181 #endif
1182           while(1)
1183           {
1184           }
1185         }
1186     status =  lx_nand_flash_sector_read(&nand_sim_flash, 112, readbuffer);
1187         if (status != LX_SUCCESS)
1188         {
1189           printf("FAILED!\n");
1190 #ifdef BATCH_TEST
1191     exit(1);
1192 #endif
1193           while(1)
1194           {
1195           }
1196         }
1197         if (readbuffer[0] != 112)
1198         {
1199           printf("FAILED!\n");
1200 #ifdef BATCH_TEST
1201     exit(1);
1202 #endif
1203           while(1)
1204           {
1205           }
1206         }
1207 
1208     status =  lx_nand_flash_defragment(&nand_sim_flash);
1209 
1210     if (status != LX_NOT_SUPPORTED)
1211     {
1212           printf("FAILED!\n");
1213 #ifdef BATCH_TEST
1214     exit(1);
1215 #endif
1216           while(1)
1217           {
1218           }
1219     }
1220 
1221 
1222     status =  lx_nand_flash_defragment(&nand_sim_flash);
1223 
1224     if (status != LX_NOT_SUPPORTED)
1225     {
1226           printf("FAILED!\n");
1227 #ifdef BATCH_TEST
1228     exit(1);
1229 #endif
1230           while(1)
1231           {
1232           }
1233     }
1234 
1235     status =  lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
1236         if (status != LX_SUCCESS)
1237         {
1238           printf("FAILED!\n");
1239 #ifdef BATCH_TEST
1240     exit(1);
1241 #endif
1242           while(1)
1243           {
1244           }
1245         }
1246         if (readbuffer[0] != 119)
1247         {
1248           printf("FAILED!\n");
1249 #ifdef BATCH_TEST
1250     exit(1);
1251 #endif
1252           while(1)
1253           {
1254           }
1255         }
1256     status =  lx_nand_flash_sector_read(&nand_sim_flash, 1, readbuffer);
1257         if (status != LX_SUCCESS)
1258         {
1259           printf("FAILED!\n");
1260 #ifdef BATCH_TEST
1261     exit(1);
1262 #endif
1263           while(1)
1264           {
1265           }
1266         }
1267         if (readbuffer[0] != 1)
1268         {
1269           printf("FAILED!\n");
1270 #ifdef BATCH_TEST
1271     exit(1);
1272 #endif
1273           while(1)
1274           {
1275           }
1276         }
1277      status =  lx_nand_flash_sector_read(&nand_sim_flash, 16, readbuffer);
1278         if (status != LX_SUCCESS)
1279         {
1280           printf("FAILED!\n");
1281 #ifdef BATCH_TEST
1282     exit(1);
1283 #endif
1284           while(1)
1285           {
1286           }
1287         }
1288         if (readbuffer[0] != 16)
1289         {
1290           printf("FAILED!\n");
1291 #ifdef BATCH_TEST
1292     exit(1);
1293 #endif
1294           while(1)
1295           {
1296           }
1297         }
1298     status =  lx_nand_flash_sector_read(&nand_sim_flash, 32, readbuffer);
1299         if (status != LX_SUCCESS)
1300         {
1301           printf("FAILED!\n");
1302 #ifdef BATCH_TEST
1303     exit(1);
1304 #endif
1305           while(1)
1306           {
1307           }
1308         }
1309         if (readbuffer[0] != 32)
1310         {
1311           printf("FAILED!\n");
1312 #ifdef BATCH_TEST
1313     exit(1);
1314 #endif
1315           while(1)
1316           {
1317           }
1318         }
1319     status =  lx_nand_flash_sector_read(&nand_sim_flash, 48, readbuffer);
1320         if (status != LX_SUCCESS)
1321         {
1322           printf("FAILED!\n");
1323 #ifdef BATCH_TEST
1324     exit(1);
1325 #endif
1326           while(1)
1327           {
1328           }
1329         }
1330         if (readbuffer[0] != 48)
1331         {
1332           printf("FAILED!\n");
1333 #ifdef BATCH_TEST
1334     exit(1);
1335 #endif
1336           while(1)
1337           {
1338           }
1339         }
1340     status =  lx_nand_flash_sector_read(&nand_sim_flash, 64, readbuffer);
1341         if (status != LX_SUCCESS)
1342         {
1343           printf("FAILED!\n");
1344 #ifdef BATCH_TEST
1345     exit(1);
1346 #endif
1347           while(1)
1348           {
1349           }
1350         }
1351         if (readbuffer[0] != 64)
1352         {
1353           printf("FAILED!\n");
1354 #ifdef BATCH_TEST
1355     exit(1);
1356 #endif
1357           while(1)
1358           {
1359           }
1360         }
1361     status =  lx_nand_flash_sector_read(&nand_sim_flash, 80, readbuffer);
1362         if (status != LX_SUCCESS)
1363         {
1364           printf("FAILED!\n");
1365 #ifdef BATCH_TEST
1366     exit(1);
1367 #endif
1368           while(1)
1369           {
1370           }
1371         }
1372         if (readbuffer[0] != 80)
1373         {
1374           printf("FAILED!\n");
1375 #ifdef BATCH_TEST
1376     exit(1);
1377 #endif
1378           while(1)
1379           {
1380           }
1381         }
1382     status =  lx_nand_flash_sector_read(&nand_sim_flash, 96, readbuffer);
1383         if (status != LX_SUCCESS)
1384         {
1385           printf("FAILED!\n");
1386 #ifdef BATCH_TEST
1387     exit(1);
1388 #endif
1389           while(1)
1390           {
1391           }
1392         }
1393         if (readbuffer[0] != 96)
1394         {
1395           printf("FAILED!\n");
1396 #ifdef BATCH_TEST
1397     exit(1);
1398 #endif
1399           while(1)
1400           {
1401           }
1402         }
1403     status =  lx_nand_flash_sector_read(&nand_sim_flash, 112, readbuffer);
1404         if (status != LX_SUCCESS)
1405         {
1406           printf("FAILED!\n");
1407 #ifdef BATCH_TEST
1408     exit(1);
1409 #endif
1410           while(1)
1411           {
1412           }
1413         }
1414         if (readbuffer[0] != 112)
1415         {
1416           printf("FAILED!\n");
1417 #ifdef BATCH_TEST
1418     exit(1);
1419 #endif
1420           while(1)
1421           {
1422           }
1423         }
1424 
1425     /* Read in reverse order to see if caching helps!  */
1426     status =  lx_nand_flash_sector_read(&nand_sim_flash, 112, readbuffer);
1427         if (status != LX_SUCCESS)
1428         {
1429           printf("FAILED!\n");
1430 #ifdef BATCH_TEST
1431     exit(1);
1432 #endif
1433           while(1)
1434           {
1435           }
1436         }
1437         if (readbuffer[0] != 112)
1438         {
1439           printf("FAILED!\n");
1440 #ifdef BATCH_TEST
1441     exit(1);
1442 #endif
1443           while(1)
1444           {
1445           }
1446         }
1447     status =  lx_nand_flash_sector_read(&nand_sim_flash, 96, readbuffer);
1448         if (status != LX_SUCCESS)
1449         {
1450           printf("FAILED!\n");
1451 #ifdef BATCH_TEST
1452     exit(1);
1453 #endif
1454           while(1)
1455           {
1456           }
1457         }
1458         if (readbuffer[0] != 96)
1459         {
1460           printf("FAILED!\n");
1461 #ifdef BATCH_TEST
1462     exit(1);
1463 #endif
1464           while(1)
1465           {
1466           }
1467         }
1468      status =  lx_nand_flash_sector_read(&nand_sim_flash, 80, readbuffer);
1469         if (status != LX_SUCCESS)
1470         {
1471           printf("FAILED!\n");
1472 #ifdef BATCH_TEST
1473     exit(1);
1474 #endif
1475           while(1)
1476           {
1477           }
1478         }
1479         if (readbuffer[0] != 80)
1480         {
1481           printf("FAILED!\n");
1482 #ifdef BATCH_TEST
1483     exit(1);
1484 #endif
1485           while(1)
1486           {
1487           }
1488         }
1489     status =  lx_nand_flash_sector_read(&nand_sim_flash, 64, readbuffer);
1490         if (status != LX_SUCCESS)
1491         {
1492           printf("FAILED!\n");
1493 #ifdef BATCH_TEST
1494     exit(1);
1495 #endif
1496           while(1)
1497           {
1498           }
1499         }
1500         if (readbuffer[0] != 64)
1501         {
1502           printf("FAILED!\n");
1503 #ifdef BATCH_TEST
1504     exit(1);
1505 #endif
1506           while(1)
1507           {
1508           }
1509         }
1510     status =  lx_nand_flash_sector_read(&nand_sim_flash, 48, readbuffer);
1511         if (status != LX_SUCCESS)
1512         {
1513           printf("FAILED!\n");
1514 #ifdef BATCH_TEST
1515     exit(1);
1516 #endif
1517           while(1)
1518           {
1519           }
1520         }
1521         if (readbuffer[0] != 48)
1522         {
1523           printf("FAILED!\n");
1524 #ifdef BATCH_TEST
1525     exit(1);
1526 #endif
1527           while(1)
1528           {
1529           }
1530         }
1531     status =  lx_nand_flash_sector_read(&nand_sim_flash, 32, readbuffer);
1532         if (status != LX_SUCCESS)
1533         {
1534           printf("FAILED!\n");
1535 #ifdef BATCH_TEST
1536     exit(1);
1537 #endif
1538           while(1)
1539           {
1540           }
1541         }
1542         if (readbuffer[0] != 32)
1543         {
1544           printf("FAILED!\n");
1545 #ifdef BATCH_TEST
1546     exit(1);
1547 #endif
1548           while(1)
1549           {
1550           }
1551         }
1552     status =  lx_nand_flash_sector_read(&nand_sim_flash, 16, readbuffer);
1553         if (status != LX_SUCCESS)
1554         {
1555           printf("FAILED!\n");
1556 #ifdef BATCH_TEST
1557     exit(1);
1558 #endif
1559           while(1)
1560           {
1561           }
1562         }
1563         if (readbuffer[0] != 16)
1564         {
1565           printf("FAILED!\n");
1566 #ifdef BATCH_TEST
1567     exit(1);
1568 #endif
1569           while(1)
1570           {
1571           }
1572         }
1573     status =  lx_nand_flash_sector_read(&nand_sim_flash, 1, readbuffer);
1574         if (status != LX_SUCCESS)
1575         {
1576           printf("FAILED!\n");
1577 #ifdef BATCH_TEST
1578     exit(1);
1579 #endif
1580           while(1)
1581           {
1582           }
1583         }
1584         if (readbuffer[0] != 1)
1585         {
1586           printf("FAILED!\n");
1587 #ifdef BATCH_TEST
1588     exit(1);
1589 #endif
1590           while(1)
1591           {
1592           }
1593         }
1594     status =  lx_nand_flash_sector_read(&nand_sim_flash, 7, readbuffer);
1595         if (status != LX_SUCCESS)
1596         {
1597           printf("FAILED!\n");
1598 #ifdef BATCH_TEST
1599     exit(1);
1600 #endif
1601           while(1)
1602           {
1603           }
1604         }
1605         if (readbuffer[0] != 119)
1606         {
1607           printf("FAILED!\n");
1608 #ifdef BATCH_TEST
1609     exit(1);
1610 #endif
1611           while(1)
1612           {
1613           }
1614         }
1615 
1616     status =  lx_nand_flash_sector_release(&nand_sim_flash, 7);
1617     if (status != LX_SUCCESS)
1618         {
1619           printf("FAILED!\n");
1620 #ifdef BATCH_TEST
1621     exit(1);
1622 #endif
1623           while(1)
1624           {
1625           }
1626         }
1627     status =  lx_nand_flash_sector_release(&nand_sim_flash, 8);
1628     if (status != LX_SECTOR_NOT_FOUND)
1629         {
1630           printf("FAILED!\n");
1631 #ifdef BATCH_TEST
1632     exit(1);
1633 #endif
1634           while(1)
1635           {
1636           }
1637         }
1638 
1639     status =  lx_nand_flash_defragment(&nand_sim_flash);
1640 
1641     if (status != LX_SUCCESS)
1642     {
1643           printf("FAILED!\n");
1644 #ifdef BATCH_TEST
1645     exit(1);
1646 #endif
1647           while(1)
1648           {
1649           }
1650     }
1651 
1652     status =  lx_nand_flash_close(&nand_sim_flash);
1653 
1654     if (status != LX_SUCCESS)
1655     {
1656           printf("FAILED!\n");
1657 #ifdef BATCH_TEST
1658     exit(1);
1659 #endif
1660           while(1)
1661           {
1662           }
1663     }
1664 
1665     printf("SUCCESS!\n");
1666 #endif
1667 #if 0
1668     printf("Test 5: Random write/read sector................");
1669 
1670     /* Erase the simulated NOR flash.  */
1671     _lx_nand_flash_simulator_erase_all();
1672 
1673     /* Open the flash.  */
1674     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize, nand_memory_space, sizeof(nand_memory_space));
1675 #ifdef EXTENDED_CACHE
1676     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
1677 #endif
1678 
1679     if (status != LX_SUCCESS)
1680     {
1681 
1682           printf("FAILED!\n");
1683 #ifdef BATCH_TEST
1684     exit(1);
1685 #endif
1686           while(1)
1687           {
1688           }
1689     }
1690 
1691     /* Write 100 sectors....  */
1692     for (i = 0; i < 100; i++)
1693     {
1694         for (j = 0; j < 512; j++)
1695           buffer[j] =  i;
1696 
1697         status =  lx_nand_flash_sector_write(&nand_sim_flash, i, buffer);
1698 
1699         if (status != LX_SUCCESS)
1700         {
1701           printf("FAILED!\n");
1702 #ifdef BATCH_TEST
1703     exit(1);
1704 #endif
1705           while(1)
1706           {
1707           }
1708         }
1709     }
1710 
1711     /* Read back 100 sectors...  */
1712     for (i = 0; i < 100; i++)
1713     {
1714 
1715         status =  lx_nand_flash_sector_read(&nand_sim_flash, i, buffer);
1716 
1717         if (status != LX_SUCCESS)
1718         {
1719           printf("FAILED!\n");
1720 #ifdef BATCH_TEST
1721     exit(1);
1722 #endif
1723           while(1)
1724           {
1725           }
1726         }
1727 
1728         for (j = 0; j < 512; j++)
1729         {
1730 
1731           if (buffer[j] !=  i)
1732           {
1733             printf("FAILED!\n");
1734 #ifdef BATCH_TEST
1735     exit(1);
1736 #endif
1737             while(1)
1738             {
1739             }
1740           }
1741         }
1742     }
1743 
1744     /* Now, perform 1000 sector writes to randomly selected sectors, each time
1745        reading first to make sure the previous contents are valid.  */
1746     for (i = 0; i < 1000; i++)
1747     {
1748 
1749         /* Pickup random sector.  */
1750         sector =  (rand() % 100);
1751 
1752         /* Read that sector.  */
1753         status =  lx_nand_flash_sector_read(&nand_sim_flash, sector, buffer);
1754 
1755         if (status != LX_SUCCESS)
1756         {
1757           printf("FAILED!\n");
1758 #ifdef BATCH_TEST
1759     exit(1);
1760 #endif
1761           while(1)
1762           {
1763           }
1764         }
1765 
1766         for (j = 0; j < 512; j++)
1767         {
1768 
1769           if ((buffer[j] & 0x0000FFFF) !=  sector)
1770           {
1771             printf("FAILED!\n");
1772 #ifdef BATCH_TEST
1773     exit(1);
1774 #endif
1775             while(1)
1776             {
1777             }
1778           }
1779         }
1780 
1781         /* Include the itteraction in the buffer to generate a new write.  */
1782         for (j = 0; j < 512; j++)
1783         {
1784 
1785             buffer[j] =  (buffer[j] & 0x0000FFFF) | (i << 16);
1786         }
1787 
1788         status =  lx_nand_flash_sector_write(&nand_sim_flash, sector, buffer);
1789 
1790         if (status != LX_SUCCESS)
1791         {
1792           printf("FAILED!\n");
1793 #ifdef BATCH_TEST
1794     exit(1);
1795 #endif
1796           while(1)
1797           {
1798           }
1799         }
1800     }
1801 
1802     status =  lx_nand_flash_close(&nand_sim_flash);
1803 
1804     if (status != LX_SUCCESS)
1805     {
1806           printf("FAILED!\n");
1807 #ifdef BATCH_TEST
1808     exit(1);
1809 #endif
1810           while(1)
1811           {
1812           }
1813     }
1814     printf("SUCCESS!\n");
1815 #endif
1816 
1817 #if 0
1818 
1819   for (i = 0; i < 256; i++)
1820   {
1821 
1822       /* Setup buffer.  */
1823       for (j = 0; j < 2048; j++)
1824           byte_buffer[j] =  (UCHAR) (rand() % 256);
1825 
1826       /* Call the ECC calculate routine.  */
1827       ComputePageECC(byte_buffer, 2048, ecc_bytes);
1828       status =  (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes);
1829       if (status != 0)
1830       {
1831 
1832           /* Check for corrected return value.  */
1833           if (status != 1)
1834           {
1835             while(1)
1836             {
1837             }
1838           }
1839       }
1840 
1841       /* Call LevelX ECC routines to do the same thing.  */
1842       status =  lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
1843 
1844       if (status != LX_SUCCESS)
1845       {
1846           printf("FAILED!\n");
1847           while(1)
1848           {
1849           }
1850       }
1851 
1852 //      ComputePageECC(byte_buffer, 2048, ecc_bytes);
1853 
1854 
1855       /* Determine if there is any difference between the original and the new ECC routine.  */
1856       if ((ecc_bytes[0] != lx_ecc_buffer[0]) ||
1857           (ecc_bytes[1] != lx_ecc_buffer[1]) ||
1858           (ecc_bytes[2] != lx_ecc_buffer[2]) ||
1859           (ecc_bytes[3] != lx_ecc_buffer[3]) ||
1860           (ecc_bytes[4] != lx_ecc_buffer[4]) ||
1861           (ecc_bytes[5] != lx_ecc_buffer[5]) ||
1862           (ecc_bytes[6] != lx_ecc_buffer[6]) ||
1863           (ecc_bytes[7] != lx_ecc_buffer[7]) ||
1864           (ecc_bytes[8] != lx_ecc_buffer[8]) ||
1865           (ecc_bytes[9] != lx_ecc_buffer[9]) ||
1866           (ecc_bytes[10] != lx_ecc_buffer[10]) ||
1867           (ecc_bytes[11] != lx_ecc_buffer[11]))
1868       {
1869          while(1)
1870          {
1871          }
1872       }
1873 
1874       status =  lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
1875 
1876       if (status != LX_SUCCESS)
1877       {
1878 
1879           /* Is it the corrected status?  */
1880           if (status !=  LX_NAND_ERROR_CORRECTED)
1881           {
1882             printf("FAILED!\n");
1883             while(1)
1884             {
1885             }
1886           }
1887       }
1888   }
1889 #endif
1890 
1891 #if 0
1892   for (i = 0; i < 256; i++)
1893   {
1894 
1895       /* Setup buffer.  */
1896       for (j = 0; j < 2048; j++)
1897           byte_buffer[j] =  (UCHAR) (rand() % 256);
1898 
1899       /* Call the ECC calculate routine.  */
1900       ComputePageECC(byte_buffer, 2048, ecc_bytes);
1901 
1902       /* Corrupt a bit in each 256 byte page.  */
1903       if (byte_buffer[7] & 1)
1904           byte_buffer[7] =  byte_buffer[7] & 0xFE;
1905       else
1906           byte_buffer[7] =  byte_buffer[7] | 1;
1907 
1908       if (byte_buffer[277] & 1)
1909           byte_buffer[277] =  byte_buffer[277] & 0xFE;
1910       else
1911           byte_buffer[277] =  byte_buffer[277] | 1;
1912 
1913       if (byte_buffer[577] & 1)
1914           byte_buffer[577] =  byte_buffer[577] & 0xFE;
1915       else
1916           byte_buffer[577] =  byte_buffer[577] | 1;
1917 
1918       if (byte_buffer[777] & 1)
1919           byte_buffer[777] =  byte_buffer[777] & 0xFE;
1920       else
1921           byte_buffer[777] =  byte_buffer[777] | 1;
1922 
1923       if (byte_buffer[1077] & 1)
1924           byte_buffer[1077] =  byte_buffer[1077] & 0xFE;
1925       else
1926           byte_buffer[1077] =  byte_buffer[1077] | 1;
1927 
1928       if (byte_buffer[1297] & 1)
1929           byte_buffer[1297] =  byte_buffer[1297] & 0xFE;
1930       else
1931           byte_buffer[1297] =  byte_buffer[1297] | 1;
1932 
1933       if (byte_buffer[1636] & 1)
1934           byte_buffer[1636] =  byte_buffer[1636] & 0xFE;
1935       else
1936           byte_buffer[1636] =  byte_buffer[1636] | 1;
1937 
1938       if (byte_buffer[1892] & 1)
1939           byte_buffer[1892] =  byte_buffer[1892] & 0xFE;
1940       else
1941           byte_buffer[1892] =  byte_buffer[1892] | 1;
1942 
1943 
1944       status =  (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes);
1945       if (status != 0)
1946       {
1947 
1948           /* Check for corrected return value.  */
1949           if (status != 1)
1950           {
1951             while(1)
1952             {
1953             }
1954           }
1955       }
1956 
1957       /* Call LevelX ECC routines to do the same thing.  */
1958       status =  lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
1959 
1960       if (status != LX_SUCCESS)
1961       {
1962           printf("FAILED!\n");
1963           while(1)
1964           {
1965           }
1966       }
1967 
1968 
1969 
1970       /* Determine if there is any difference between the original and the new ECC routine.  */
1971       if ((ecc_bytes[0] != lx_ecc_buffer[0]) ||
1972           (ecc_bytes[1] != lx_ecc_buffer[1]) ||
1973           (ecc_bytes[2] != lx_ecc_buffer[2]) ||
1974           (ecc_bytes[3] != lx_ecc_buffer[3]) ||
1975           (ecc_bytes[4] != lx_ecc_buffer[4]) ||
1976           (ecc_bytes[5] != lx_ecc_buffer[5]) ||
1977           (ecc_bytes[6] != lx_ecc_buffer[6]) ||
1978           (ecc_bytes[7] != lx_ecc_buffer[7]) ||
1979           (ecc_bytes[8] != lx_ecc_buffer[8]) ||
1980           (ecc_bytes[9] != lx_ecc_buffer[9]) ||
1981           (ecc_bytes[10] != lx_ecc_buffer[10]) ||
1982           (ecc_bytes[11] != lx_ecc_buffer[11]))
1983       {
1984          while(1)
1985          {
1986          }
1987       }
1988 
1989       /* Corrupt a bit in each 256 byte page.  */
1990       if (byte_buffer[7] & 1)
1991           byte_buffer[7] =  byte_buffer[7] & 0xFE;
1992       else
1993           byte_buffer[7] =  byte_buffer[7] | 1;
1994 
1995       if (byte_buffer[277] & 1)
1996           byte_buffer[277] =  byte_buffer[277] & 0xFE;
1997       else
1998           byte_buffer[277] =  byte_buffer[277] | 1;
1999 
2000       if (byte_buffer[577] & 1)
2001           byte_buffer[577] =  byte_buffer[577] & 0xFE;
2002       else
2003           byte_buffer[577] =  byte_buffer[577] | 1;
2004 
2005       if (byte_buffer[777] & 1)
2006           byte_buffer[777] =  byte_buffer[777] & 0xFE;
2007       else
2008           byte_buffer[777] =  byte_buffer[777] | 1;
2009 
2010       if (byte_buffer[1077] & 1)
2011           byte_buffer[1077] =  byte_buffer[1077] & 0xFE;
2012       else
2013           byte_buffer[1077] =  byte_buffer[1077] | 1;
2014 
2015       if (byte_buffer[1297] & 1)
2016           byte_buffer[1297] =  byte_buffer[1297] & 0xFE;
2017       else
2018           byte_buffer[1297] =  byte_buffer[1297] | 1;
2019 
2020       if (byte_buffer[1636] & 1)
2021           byte_buffer[1636] =  byte_buffer[1636] & 0xFE;
2022       else
2023           byte_buffer[1636] =  byte_buffer[1636] | 1;
2024 
2025       if (byte_buffer[1892] & 1)
2026           byte_buffer[1892] =  byte_buffer[1892] & 0xFE;
2027       else
2028           byte_buffer[1892] =  byte_buffer[1892] | 1;
2029 
2030       status =  lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
2031 
2032       if (status != LX_SUCCESS)
2033       {
2034 
2035           /* Is it the corrected status?  */
2036           if (status !=  LX_NAND_ERROR_CORRECTED)
2037           {
2038             printf("FAILED!\n");
2039 #ifdef BATCH_TEST
2040     exit(1);
2041 #endif
2042             while(1)
2043             {
2044             }
2045           }
2046       }
2047 
2048       /* Call LevelX ECC routines to create the ECC over the corrected buffer.  */
2049       status =  lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
2050 
2051       if (status != LX_SUCCESS)
2052       {
2053           printf("FAILED!\n");
2054 #ifdef BATCH_TEST
2055     exit(1);
2056 #endif
2057           while(1)
2058           {
2059           }
2060       }
2061 
2062   }
2063 
2064 
2065 
2066 #endif
2067 
2068 #if 0
2069 
2070   /* Corrupting ECC code is detected and returns a failure... this test is not valid!  */
2071 
2072   for (i = 0; i < 256; i++)
2073   {
2074 
2075       /* Setup buffer.  */
2076       for (j = 0; j < 2048; j++)
2077           byte_buffer[j] =  (UCHAR) (rand() % 256);
2078 
2079       /* Call the ECC calculate routine.  */
2080       ComputePageECC(byte_buffer, 2048, ecc_bytes);
2081 
2082 
2083       /* Call LevelX ECC routines to do the same thing.  */
2084       status =  lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
2085 
2086       if (status != LX_SUCCESS)
2087       {
2088           printf("FAILED!\n");
2089           while(1)
2090           {
2091           }
2092       }
2093 
2094       /* Determine if there is any difference between the original and the new ECC routine.  */
2095       if ((ecc_bytes[0] != lx_ecc_buffer[0]) ||
2096           (ecc_bytes[1] != lx_ecc_buffer[1]) ||
2097           (ecc_bytes[2] != lx_ecc_buffer[2]) ||
2098           (ecc_bytes[3] != lx_ecc_buffer[3]) ||
2099           (ecc_bytes[4] != lx_ecc_buffer[4]) ||
2100           (ecc_bytes[5] != lx_ecc_buffer[5]) ||
2101           (ecc_bytes[6] != lx_ecc_buffer[6]) ||
2102           (ecc_bytes[7] != lx_ecc_buffer[7]) ||
2103           (ecc_bytes[8] != lx_ecc_buffer[8]) ||
2104           (ecc_bytes[9] != lx_ecc_buffer[9]) ||
2105           (ecc_bytes[10] != lx_ecc_buffer[10]) ||
2106           (ecc_bytes[11] != lx_ecc_buffer[11]))
2107       {
2108          while(1)
2109          {
2110          }
2111       }
2112 
2113       /* Corrupt a bit in each ECC for 256 byte page.  */
2114       if (ecc_bytes[1] & 1)
2115           ecc_bytes[1] =  ecc_bytes[1] & 0xFE;
2116       else
2117           ecc_bytes[1] =  ecc_bytes[1] | 1;
2118 
2119       if (ecc_bytes[4] & 1)
2120           ecc_bytes[4] =  ecc_bytes[4] & 0xFE;
2121       else
2122           ecc_bytes[4] =  ecc_bytes[4] | 1;
2123 
2124       if (ecc_bytes[7] & 1)
2125           ecc_bytes[7] =  ecc_bytes[7] & 0xFE;
2126       else
2127           ecc_bytes[7] =  ecc_bytes[7] | 1;
2128 
2129       if (ecc_bytes[10] & 1)
2130           ecc_bytes[10] =  ecc_bytes[10] & 0xFE;
2131       else
2132           ecc_bytes[10] =  ecc_bytes[10] | 1;
2133 
2134       if (ecc_bytes[13] & 1)
2135           ecc_bytes[13] =  ecc_bytes[13] & 0xFE;
2136       else
2137           ecc_bytes[13] =  ecc_bytes[13] | 1;
2138 
2139       if (ecc_bytes[16] & 1)
2140           ecc_bytes[16] =  ecc_bytes[16] & 0xFE;
2141       else
2142           ecc_bytes[16] =  ecc_bytes[16] | 1;
2143 
2144       if (ecc_bytes[19] & 1)
2145           ecc_bytes[19] =  ecc_bytes[19] & 0xFE;
2146       else
2147           ecc_bytes[19] =  ecc_bytes[19] | 1;
2148 
2149       if (ecc_bytes[22] & 1)
2150           ecc_bytes[22] =  ecc_bytes[22] & 0xFE;
2151       else
2152           ecc_bytes[22] =  ecc_bytes[22] | 1;
2153 
2154 
2155       status =  (UINT) CorrectPageECC(byte_buffer, 2048, ecc_bytes);
2156       if (status != 0)
2157       {
2158 
2159           /* Check for corrected return value.  */
2160           if (status != 1)
2161           {
2162             while(1)
2163             {
2164             }
2165           }
2166       }
2167 
2168       /* Corrupt a bit in each ECC for 256 byte page.  */
2169       if (lx_ecc_buffer[1] & 1)
2170           lx_ecc_buffer[1] =  lx_ecc_buffer[1] & 0xFE;
2171       else
2172           lx_ecc_buffer[1] =  lx_ecc_buffer[1] | 1;
2173 
2174       if (lx_ecc_buffer[4] & 1)
2175           lx_ecc_buffer[4] =  lx_ecc_buffer[4] & 0xFE;
2176       else
2177           lx_ecc_buffer[4] =  lx_ecc_buffer[4] | 1;
2178 
2179       if (lx_ecc_buffer[7] & 1)
2180           lx_ecc_buffer[7] =  lx_ecc_buffer[7] & 0xFE;
2181       else
2182           lx_ecc_buffer[7] =  lx_ecc_buffer[7] | 1;
2183 
2184       if (lx_ecc_buffer[10] & 1)
2185           lx_ecc_buffer[10] =  lx_ecc_buffer[10] & 0xFE;
2186       else
2187           lx_ecc_buffer[10] =  lx_ecc_buffer[10] | 1;
2188 
2189       if (lx_ecc_buffer[13] & 1)
2190           lx_ecc_buffer[13] =  lx_ecc_buffer[13] & 0xFE;
2191       else
2192           lx_ecc_buffer[13] =  lx_ecc_buffer[13] | 1;
2193 
2194       if (lx_ecc_buffer[16] & 1)
2195           lx_ecc_buffer[16] =  lx_ecc_buffer[16] & 0xFE;
2196       else
2197           lx_ecc_buffer[16] =  lx_ecc_buffer[16] | 1;
2198 
2199       if (lx_ecc_buffer[19] & 1)
2200           lx_ecc_buffer[19] =  lx_ecc_buffer[19] & 0xFE;
2201       else
2202           lx_ecc_buffer[19] =  lx_ecc_buffer[19] | 1;
2203 
2204       if (lx_ecc_buffer[22] & 1)
2205           lx_ecc_buffer[22] =  lx_ecc_buffer[22] & 0xFE;
2206       else
2207           lx_ecc_buffer[22] =  lx_ecc_buffer[22] | 1;
2208 
2209 
2210 
2211       status =  lx_nand_flash_page_ecc_check(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
2212 
2213       if (status != LX_SUCCESS)
2214       {
2215 
2216           /* Is it the corrected status?  */
2217           if (status !=  LX_NAND_ERROR_CORRECTED)
2218           {
2219             printf("FAILED!\n");
2220 #ifdef BATCH_TEST
2221     exit(1);
2222 #endif
2223             while(1)
2224             {
2225             }
2226           }
2227       }
2228 
2229       /* Call LevelX ECC routines to create the ECC over the corrected buffer.  */
2230       status =  lx_nand_flash_page_ecc_compute(&nand_sim_flash, byte_buffer, lx_ecc_buffer);
2231 
2232       if (status != LX_SUCCESS)
2233       {
2234           printf("FAILED!\n");
2235 #ifdef BATCH_TEST
2236     exit(1);
2237 #endif
2238           while(1)
2239           {
2240           }
2241       }
2242 
2243   }
2244 
2245 
2246 
2247 #endif
2248 
2249 
2250 
2251 #if 0
2252 /* TEST FileX packing routines.  */
2253 
2254     /* Erase the simulated NAND flash.  */
2255     _lx_nand_flash_simulator_erase_all();
2256 
2257     /* Open the flash.  */
2258     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize);
2259 #ifdef EXTENDED_CACHE
2260     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
2261 #endif
2262 
2263     if (status != LX_SUCCESS)
2264     {
2265 
2266           printf("FAILED!\n");
2267           while(1)
2268           {
2269           }
2270     }
2271 
2272   /* Setup the write data.  */
2273   for (i = 0; i < 8; i++)
2274   {
2275       for (j = 0; j < 512/4; j++)
2276         test_write[i].words[j] = i;
2277   }
2278 
2279   /* Now write the data one logical sector at a time.  */
2280   for (i = 0; i < 8; i++)
2281   {
2282        _fx_nand_flash_write_sectors(i, 1, (UCHAR *) &test_write[i]);
2283   }
2284 
2285   /* Setup the read buffer.  */
2286   for (i = 0; i < 8; i++)
2287   {
2288       for (j = 0; j < 512/4; j++)
2289         test_read[i].words[j] = 0xEFEFEFEF;
2290   }
2291 
2292   /* Read back in one sector at a time.  */
2293   for (i = 0; i < 8; i++)
2294   {
2295        _fx_nand_flash_read_sectors(i, 1, (UCHAR *) &test_read[i].words[0]);
2296   }
2297 
2298   /* Setup the read buffer.  */
2299   for (i = 0; i < 8; i++)
2300   {
2301       for (j = 0; j < 512/4; j++)
2302         test_read[i].words[j] = 0xEFEFEFEF;
2303   }
2304 
2305   _fx_nand_flash_read_sectors(3, 5, (UCHAR *) &test_read[3].words[0]);
2306   _fx_nand_flash_read_sectors(1, 2, (UCHAR *) &test_read[1].words[0]);
2307   _fx_nand_flash_read_sectors(0, 1, (UCHAR *) &test_read[0].words[0]);
2308 
2309   /* Setup the read buffer.  */
2310   for (i = 0; i < 8; i++)
2311   {
2312       for (j = 0; j < 512/4; j++)
2313         test_read[i].words[j] = 0xEFEFEFEF;
2314   }
2315 
2316   _fx_nand_flash_read_sectors(0, 8, (UCHAR *) &test_read[0].words[0]);
2317 
2318 
2319     status =  lx_nand_flash_close(&nand_sim_flash);
2320 
2321     if (status != LX_SUCCESS)
2322     {
2323           printf("FAILED!\n");
2324           while(1)
2325           {
2326           }
2327     }
2328 
2329     /* Erase the simulated NAND flash.  */
2330     _lx_nand_flash_simulator_erase_all();
2331 
2332     /* Open the flash.  */
2333     status =  lx_nand_flash_open(&nand_sim_flash, "sim nor flash", _lx_nand_flash_simulator_initialize);
2334 #ifdef EXTENDED_CACHE
2335     status += lx_nand_flash_extended_cache_enable(&nand_sim_flash, cache_memory, sizeof(cache_memory));
2336 #endif
2337 
2338     if (status != LX_SUCCESS)
2339     {
2340 
2341           printf("FAILED!\n");
2342           while(1)
2343           {
2344           }
2345     }
2346 
2347     _fx_nand_flash_write_sectors(3, 5, (UCHAR *) &test_read[3].words[0]);
2348     _fx_nand_flash_write_sectors(1, 2, (UCHAR *) &test_read[1].words[0]);
2349     _fx_nand_flash_write_sectors(0, 1, (UCHAR *) &test_read[0].words[0]);
2350 
2351     /* Setup the read buffer.  */
2352     for (i = 0; i < 8; i++)
2353     {
2354       for (j = 0; j < 512/4; j++)
2355           test_read[i].words[j] = 0xEFEFEFEF;
2356     }
2357 
2358     _fx_nand_flash_read_sectors(0, 1, (UCHAR *) &test_read[0].words[0]);
2359     _fx_nand_flash_read_sectors(1, 2, (UCHAR *) &test_read[1].words[0]);
2360     _fx_nand_flash_read_sectors(3, 5, (UCHAR *) &test_read[3].words[0]);
2361 
2362     status =  lx_nand_flash_close(&nand_sim_flash);
2363 
2364     if (status != LX_SUCCESS)
2365     {
2366           printf("FAILED!\n");
2367           while(1)
2368           {
2369           }
2370     }
2371 
2372   /* End */
2373 #endif
2374 
2375 #ifdef BATCH_TEST
2376     exit(0);
2377 #endif
2378      /* All done!  */
2379      while(1)
2380      {
2381      }
2382 }
2383 
2384 
2385