13 #define YNORSIM_FNAME "ynorsimdata"
15 /* Set YNORSIM_BIT_CHANGES to a a value from 1..30 to
16 *simulate bit flipping as the programming happens.
17 * A low value results in faster simulation with less chance of encountering a partially programmed
21 //#define YNORSIM_BIT_CHANGES 15
22 #define YNORSIM_BIT_CHANGES 1
24 /* Simulate 32MB of flash in 256k byte blocks.
28 #define YNORSIM_BLOCK_SIZE_U32 (256*1024/4)
29 #define YNORSIM_DEV_SIZE_U32 (32*1024 * 1024/4)
31 static __u32 word[YNORSIM_DEV_SIZE_U32];
34 static void NorError(void)
36 printf("Nor error\n");
40 static void ynorsim_SaveImage(void)
42 int h = open(YNORSIM_FNAME, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
43 write(h,word,sizeof(word));
47 static void ynorsim_RestoreImage(void)
49 int h = open(YNORSIM_FNAME, O_RDONLY, S_IREAD | S_IWRITE);
50 memset(word,0xFF,sizeof(word));
51 read(h,word,sizeof(word));
56 static void ynorsim_PowerFail(void)
62 static int initialised = 0;
63 static int remaining_ops;
64 static int nops_so_far;
66 static void ynorsim_MaybePowerFail(void)
73 if(remaining_ops < 1){
74 printf("Simulated power failure after %d operations\n",nops_so_far);
79 static void ynorsim_Ready(void)
84 remaining_ops = 1000000000;
85 remaining_ops = (rand() % 10000) * 10000;
86 ynorsim_RestoreImage();
89 void ynorsim_Read32(__u32 *addr,__u32 *buf, int nwords)
99 void ynorsim_WriteOneWord32(__u32 *addr,__u32 val)
107 // Fail due to trying to change a zero into a 1
108 printf("attempt to set a zero to one (%x)->(%x)\n",tmp,val);
112 for(i = 0; i < YNORSIM_BIT_CHANGES; i++){
113 m = 1 << (rand() & 31);
117 ynorsim_MaybePowerFail();
123 ynorsim_MaybePowerFail();
126 void ynorsim_Write32(__u32 *addr, __u32 *buf, int nwords)
129 ynorsim_WriteOneWord32(addr,*buf);
136 void ynorsim_EraseBlock(__u32 *addr)
138 /* Todo... bit flipping */
139 memset(addr,0xFF,YNORSIM_BLOCK_SIZE_U32 * 4);
142 void ynorsim_Initialise(void)
147 void ynorsim_Shutdown(void)
153 __u32 *ynorsim_GetBase(void)