Mercurial > ecos
comparison packages/devs/flash/synth/current/tests/flash1.c @ 202:353a011b23b8
Merge from eCos master repository on 2002-01-11-06:43:03-GMT
| author | jlarmour |
|---|---|
| date | Fri, 11 Jan 2002 16:53:46 +0000 |
| parents | |
| children | e0c0827131d1 |
comparison
equal
deleted
inserted
replaced
| 201:dd81b18e45fb | 202:353a011b23b8 |
|---|---|
| 1 /* Hay, the copyright is usefull for something! */ | |
| 2 | |
| 3 static char copyright[] = " | |
| 4 //========================================================================== | |
| 5 // | |
| 6 // flash1.c | |
| 7 // | |
| 8 // Test flash operations for the synth target synth flash driver | |
| 9 // | |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
| 12 // | |
| 13 // ------------------------------------------- | |
| 14 // The contents of this file are subject to the Red Hat eCos Public License | |
| 15 // Version 1.1 (the \"License\"); you may not use this file except in | |
| 16 // compliance with the License. You may obtain a copy of the License at | |
| 17 // http://www.redhat.com/ | |
| 18 // | |
| 19 // Software distributed under the License is distributed on an \"AS IS\" | |
| 20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 21 // License for the specific language governing rights and limitations under | |
| 22 // the License. | |
| 23 // | |
| 24 // The Original Code is eCos - Embedded Configurable Operating System, | |
| 25 // released September 30, 1998. | |
| 26 // | |
| 27 // The Initial Developer of the Original Code is Red Hat. | |
| 28 // Portions created by Red Hat are | |
| 29 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | |
| 30 // All Rights Reserved. | |
| 31 // ------------------------------------------- | |
| 32 // | |
| 33 //####COPYRIGHTEND#### | |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 37 // Author(s): andrew.lunn@ascom.ch | |
| 38 // Contributors: andrew.lunn | |
| 39 // Date: 2000-10-31 | |
| 40 // Purpose: Test a flash driver | |
| 41 // Description: Try out a number of flash operations and make sure | |
| 42 // what is in the flash is what we expeect. | |
| 43 // | |
| 44 //####DESCRIPTIONEND#### | |
| 45 // | |
| 46 //========================================================================== | |
| 47 "; | |
| 48 | |
| 49 #include <cyg/io/flash.h> | |
| 50 #include <cyg/infra/testcase.h> | |
| 51 #include <cyg/infra/diag.h> | |
| 52 | |
| 53 #include <string.h> | |
| 54 | |
| 55 #ifndef CYGINT_ISO_STRING_STRFUNCS | |
| 56 # define NA_MSG "Need string functions for test" | |
| 57 #endif | |
| 58 | |
| 59 #ifdef NA_MSG | |
| 60 void cyg_user_start(void) | |
| 61 { | |
| 62 CYG_TEST_INIT(); | |
| 63 CYG_TEST_NA( NA_MSG ); | |
| 64 } | |
| 65 #else | |
| 66 | |
| 67 //========================================================================== | |
| 68 // main | |
| 69 | |
| 70 void cyg_user_start(void) | |
| 71 { | |
| 72 int ret; | |
| 73 char data[1024]; | |
| 74 void *flash_start, *flash_end; | |
| 75 int block_size, blocks; | |
| 76 char *prog_start; | |
| 77 unsigned char * ptr; | |
| 78 | |
| 79 CYG_TEST_INIT(); | |
| 80 | |
| 81 ret=flash_init(NULL,0,(_printf *)diag_printf); | |
| 82 | |
| 83 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init"); | |
| 84 | |
| 85 flash_dev_query(data); | |
| 86 CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)), | |
| 87 "flash_query"); | |
| 88 | |
| 89 ret = flash_get_limits(NULL,&flash_start,&flash_end); | |
| 90 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits"); | |
| 91 | |
| 92 ret = flash_get_block_info(&block_size, &blocks); | |
| 93 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info"); | |
| 94 | |
| 95 /* Erase the whole flash. Not recommended on real hardware since this | |
| 96 will probably erase the bootloader etc!!! */ | |
| 97 ret=flash_erase(flash_start,block_size * blocks,NULL); | |
| 98 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1"); | |
| 99 | |
| 100 /* check that its actually been erased, and test the mmap area */ | |
| 101 for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) { | |
| 102 if (*ptr != 0xff) { | |
| 103 ret++; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 CYG_TEST_PASS_FAIL((ret == 0),"flash empty check"); | |
| 108 | |
| 109 ret = flash_program(flash_start,©right,sizeof(copyright),NULL); | |
| 110 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1"); | |
| 111 | |
| 112 /* Check the contents made it into the flash */ | |
| 113 CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)), | |
| 114 "flash program contents"); | |
| 115 | |
| 116 /* .. and check nothing else changed */ | |
| 117 for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; | |
| 118 ptr < (unsigned char *)flash_end; ptr++) { | |
| 119 if (*ptr != 0xff) { | |
| 120 ret++; | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check"); | |
| 125 | |
| 126 /* Program over a block boundary */ | |
| 127 prog_start = (unsigned char *)flash_start + block_size - sizeof(copyright)/2; | |
| 128 ret = flash_program(prog_start,©right,sizeof(copyright),NULL); | |
| 129 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2"); | |
| 130 | |
| 131 /* Check the first version is still OK */ | |
| 132 CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)), | |
| 133 "Original contents"); | |
| 134 | |
| 135 CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)), | |
| 136 "New program contents"); | |
| 137 | |
| 138 /* Check the bit in between is still erased */ | |
| 139 for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; | |
| 140 ptr < (unsigned char *)prog_start; ptr++) { | |
| 141 if (*ptr != 0xff) { | |
| 142 ret++; | |
| 143 } | |
| 144 } | |
| 145 CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1"); | |
| 146 | |
| 147 /* Erase the second block and make sure the first is not erased */ | |
| 148 ret=flash_erase((void *)((unsigned)flash_start+block_size), | |
| 149 block_size,NULL); | |
| 150 CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2"); | |
| 151 | |
| 152 /* Check the erase worked */ | |
| 153 for (ptr=(unsigned char *)flash_start+block_size,ret=0; | |
| 154 ptr < (unsigned char *)flash_start+block_size*2; ptr++) { | |
| 155 if (*ptr != 0xff) { | |
| 156 ret++; | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2"); | |
| 161 | |
| 162 /* Lastly check the first half of the copyright message is still there */ | |
| 163 CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2), | |
| 164 "Block 1 OK"); | |
| 165 | |
| 166 #if 0 | |
| 167 /* This test it fatal! Its not run by default! | |
| 168 Check the flash is read only, by trying to write to it. We expect | |
| 169 to get an exception */ | |
| 170 | |
| 171 *(char *)flash_start = 'a'; | |
| 172 #endif | |
| 173 | |
| 174 CYG_TEST_PASS_FINISH("flash1"); | |
| 175 } | |
| 176 | |
| 177 #endif /* ifndef NA_MSG */ | |
| 178 | |
| 179 /* EOF flash1.c */ |
