# HG changeset patch # User asl # Date 1091712884 0 # Node ID 772ee36b344d9a606ac996a4ef6146d08e1966be # Parent 0673c75f3a08cba27adbaf089daba68710b675d9 * cdl/flash_synth.cdl: Indicate we need the legacy device API. * cdl/flash_synth.cdl: * tests/flash2.c: Added a second test case for the new API. diff --git a/packages/devs/flash/synth/current/ChangeLog b/packages/devs/flash/synth/current/ChangeLog --- a/packages/devs/flash/synth/current/ChangeLog +++ b/packages/devs/flash/synth/current/ChangeLog @@ -1,6 +1,12 @@ +2004-08-03 Andrew Lunn + + * cdl/flash_synth.cdl: Indicate we need the legacy device API. + * cdl/flash_synth.cdl: + * tests/flash2.c: Added a second test case for the new API. + 2003-11-20 Jani Monoses - tests/flash1.c: Update flash_init() call to reflect + * tests/flash1.c: Update flash_init() call to reflect new prototype. 2002-01-23 Jonathan Larmour diff --git a/packages/devs/flash/synth/current/cdl/flash_synth.cdl b/packages/devs/flash/synth/current/cdl/flash_synth.cdl --- a/packages/devs/flash/synth/current/cdl/flash_synth.cdl +++ b/packages/devs/flash/synth/current/cdl/flash_synth.cdl @@ -56,7 +56,8 @@ cdl_package CYGPKG_DEVS_FLASH_SYNTH { requires CYGINT_ISO_ERRNO_CODES implements CYGHWR_IO_FLASH_DEVICE - + implements CYGHWR_IO_FLASH_DEVICE_LEGACY + include_dir . include_files ; # none _exported_ whatsoever description "FLASH memory device support for Synthetic target" @@ -121,7 +122,7 @@ cdl_package CYGPKG_DEVS_FLASH_SYNTH { display "Synth flash tests" flavor data no_define - calculated { "tests/flash1.c"} + calculated { "tests/flash1.c test2/flash2.c"} description " This option specifies the set of tests for the synth flash package." } diff --git a/packages/devs/flash/synth/current/src/synth.c b/packages/devs/flash/synth/current/src/synth.c --- a/packages/devs/flash/synth/current/src/synth.c +++ b/packages/devs/flash/synth/current/src/synth.c @@ -149,7 +149,7 @@ flash_hwr_init(void) return FLASH_ERR_HWR; } flash_info.start = cyg_dev_flash_synth_base; - flash_info.end = (void *)(((char *)cyg_dev_flash_synth_base) + + flash_info.end = (void *)(((char *)cyg_dev_flash_synth_base) -1 + (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS)); return FLASH_ERR_OK; diff --git a/packages/devs/flash/synth/current/tests/flash1.c b/packages/devs/flash/synth/current/tests/flash1.c --- a/packages/devs/flash/synth/current/tests/flash1.c +++ b/packages/devs/flash/synth/current/tests/flash1.c @@ -1,59 +1,59 @@ -/* Hay, the copyright is usefull for something! */ +/* Hey, the copyright is usefull for something! */ -static char copyright[] = " -//========================================================================== -// -// flash1.c -// -// Test flash operations for the synth target synth flash driver -// -//========================================================================== -//####ECOSGPLCOPYRIGHTBEGIN#### -// ------------------------------------------- -// This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. -// -// eCos is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 2 or (at your option) any later version. -// -// eCos is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with eCos; if not, write to the Free Software Foundation, Inc., -// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -// -// As a special exception, if other files instantiate templates or use macros -// or inline functions from this file, or you compile this file and link it -// with other works to produce a work based on this file, this file does not -// by itself cause the resulting work to be covered by the GNU General Public -// License. However the source code for this file must still be made available -// in accordance with section (3) of the GNU General Public License. -// -// This exception does not invalidate any other reasons why a work based on -// this file might be covered by the GNU General Public License. -// -// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. -// at http://sources.redhat.com/ecos/ecos-license/ -// ------------------------------------------- -//####ECOSGPLCOPYRIGHTEND#### -//========================================================================== -//#####DESCRIPTIONBEGIN#### -// -// Author(s): andrew.lunn@ascom.ch -// Contributors: andrew.lunn -// Date: 2000-10-31 -// Purpose: Test a flash driver -// Description: Try out a number of flash operations and make sure -// what is in the flash is what we expeect. -// -//####DESCRIPTIONEND#### -// -//========================================================================== -"; +static char copyright[] = +"//==========================================================================" +"//" +"// flash1.c" +"//" +"// Test flash operations for the synth target synth flash driver" +"//" +"//==========================================================================" +"//####ECOSGPLCOPYRIGHTBEGIN####" +"// -------------------------------------------" +"// This file is part of eCos, the Embedded Configurable Operating System." +"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc." +"//" +"// eCos is free software; you can redistribute it and/or modify it under" +"// the terms of the GNU General Public License as published by the Free" +"// Software Foundation; either version 2 or (at your option) any later version." +"//" +"// eCos is distributed in the hope that it will be useful, but WITHOUT ANY" +"// WARRANTY; without even the implied warranty of MERCHANTABILITY or" +"// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License" +"// for more details." +"//" +"// You should have received a copy of the GNU General Public License along" +"// with eCos; if not, write to the Free Software Foundation, Inc.," +"// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA." +"//" +"// As a special exception, if other files instantiate templates or use macros" +"// or inline functions from this file, or you compile this file and link it" +"// with other works to produce a work based on this file, this file does not" +"// by itself cause the resulting work to be covered by the GNU General Public" +"// License. However the source code for this file must still be made available" +"// in accordance with section (3) of the GNU General Public License." +"//" +"// This exception does not invalidate any other reasons why a work based on" +"// this file might be covered by the GNU General Public License." +"//" +"// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc." +"// at http://sources.redhat.com/ecos/ecos-license/" +"// -------------------------------------------" +"//####ECOSGPLCOPYRIGHTEND####" +"//==========================================================================" +"//#####DESCRIPTIONBEGIN####" +"//" +"// Author(s): andrew.lunn@ascom.ch" +"// Contributors: andrew.lunn" +"// Date: 2000-10-31" +"// Purpose: Test a flash driver" +"// Description: Try out a number of flash operations and make sure" +"// what is in the flash is what we expeect." +"// " +"//####DESCRIPTIONEND####" +"//" +"//==========================================================================" +; #include #include @@ -64,6 +64,9 @@ static char copyright[] = " #ifndef CYGINT_ISO_STRING_STRFUNCS # define NA_MSG "Need string functions for test" #endif +#ifndef CYGSEM_IO_FLASH_LEGACY_API +# define NA_MSG "Need legacy IO FLASH API for test" +#endif #ifdef NA_MSG void cyg_user_start(void) diff --git a/packages/devs/flash/synth/current/tests/flash2.c b/packages/devs/flash/synth/current/tests/flash2.c new file mode 100644 --- /dev/null +++ b/packages/devs/flash/synth/current/tests/flash2.c @@ -0,0 +1,217 @@ +/* Hey, the copyright is usefull for something! */ + +static char copyright[] = +"//==========================================================================" +"//" +"// flash1.c" +"//" +"// Test flash operations for the synth target synth flash driver" +"//" +"//==========================================================================" +"//####ECOSGPLCOPYRIGHTBEGIN####" +"// -------------------------------------------" +"// This file is part of eCos, the Embedded Configurable Operating System." +"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc." +"//" +"// eCos is free software; you can redistribute it and/or modify it under" +"// the terms of the GNU General Public License as published by the Free" +"// Software Foundation; either version 2 or (at your option) any later version." +"//" +"// eCos is distributed in the hope that it will be useful, but WITHOUT ANY" +"// WARRANTY; without even the implied warranty of MERCHANTABILITY or" +"// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License" +"// for more details." +"//" +"// You should have received a copy of the GNU General Public License along" +"// with eCos; if not, write to the Free Software Foundation, Inc.," +"// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA." +"//" +"// As a special exception, if other files instantiate templates or use macros" +"// or inline functions from this file, or you compile this file and link it" +"// with other works to produce a work based on this file, this file does not" +"// by itself cause the resulting work to be covered by the GNU General Public" +"// License. However the source code for this file must still be made available" +"// in accordance with section (3) of the GNU General Public License." +"//" +"// This exception does not invalidate any other reasons why a work based on" +"// this file might be covered by the GNU General Public License." +"//" +"// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc." +"// at http://sources.redhat.com/ecos/ecos-license/" +"// -------------------------------------------" +"//####ECOSGPLCOPYRIGHTEND####" +"//==========================================================================" +"//#####DESCRIPTIONBEGIN####" +"//" +"// Author(s): andrew.lunn@ascom.ch" +"// Contributors: andrew.lunn" +"// Date: 2000-10-31" +"// Purpose: Test a flash driver" +"// Description: Try out a number of flash operations and make sure" +"// what is in the flash is what we expeect." +"// " +"//####DESCRIPTIONEND####" +"//" +"//==========================================================================&" +; + +#include +#include +#include +#include + +#include + +#ifndef CYGINT_ISO_STRING_STRFUNCS +# define NA_MSG "Need string functions for test" +#endif + +#ifdef NA_MSG +void cyg_user_start(void) +{ + CYG_TEST_INIT(); + CYG_TEST_NA( NA_MSG ); +} +#else + +//========================================================================== +// main + +void cyg_user_start(void) +{ + int ret; + cyg_flashaddr_t flash_start, flash_end; + cyg_flash_info_t info; + int block_size, blocks; + cyg_flashaddr_t prog_start; + unsigned char * ptr; + cyg_uint32 i=0; + cyg_uint32 j; + + CYG_TEST_INIT(); + + ret=cyg_flash_init((cyg_flash_printf *)diag_printf); + + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init"); + + ret = cyg_flash_get_limits(&flash_start,&flash_end); + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_get_limits"); + diag_printf("INFO: flash_start=%p, flash_end=%p\n", + flash_start, flash_end); + + ret = cyg_flash_get_block_info(&block_size, &blocks); + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_get_block_info"); + CYG_TEST_PASS_FAIL((block_size == CYGNUM_FLASH_SYNTH_BLOCKSIZE), + "correct block size"); + CYG_TEST_PASS_FAIL((blocks == CYGNUM_FLASH_SYNTH_NUMBLOCKS), + "correct number of blocks"); + + diag_printf("INFO: block_size=0x%x, blocks=%d\n", block_size, blocks); + + do { + ret = cyg_flash_get_info(i, &info); + if (ret == CYG_FLASH_ERR_OK) { + diag_printf("INFO: Nth=%d, start=%p, end=%p\n", + i, info.start, info.end); + for (j=0;j < info.num_block_infos; j++) { + diag_printf("INFO:\t block_size %d, blocks %d\n", + info.block_info[j].block_size, + info.block_info[j].blocks); + } + } + i++; + } while (ret != CYG_FLASH_ERR_INVALID); + + /* Erase the whole flash. Not recommended on real hardware since this + will probably erase the bootloader etc!!! */ + ret=cyg_flash_erase(flash_start,block_size * blocks,NULL); + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1"); + + /* check that its actually been erased, and test the mmap area */ + for (ptr=(unsigned char *)flash_start,ret=0; + ptr <= (unsigned char *)flash_end; ptr++) { + if (*ptr != 0xff) { + ret++; + } + } + + CYG_TEST_PASS_FAIL((ret == 0),"flash empty check"); + + ret = cyg_flash_program(flash_start,©right,sizeof(copyright),NULL); + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1"); + + /* Check the contents made it into the flash */ + CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start, + copyright,sizeof(copyright)), + "flash program contents"); + + /* .. and check nothing else changed */ + for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; + ptr < (unsigned char *)flash_end; ptr++) { + if (*ptr != 0xff) { + ret++; + } + } + + CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check"); + + /* Program over a block boundary */ + prog_start = flash_start + block_size - sizeof(copyright)/2; + ret = cyg_flash_program(prog_start,©right,sizeof(copyright),NULL); + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2"); + + /* Check the first version is still OK */ + CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start, + copyright, + sizeof(copyright)), + "Original contents"); + + CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start, + copyright, + sizeof(copyright)), + "New program contents"); + + /* Check the bit in between is still erased */ + for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; + ptr < (unsigned char *)prog_start; ptr++) { + if (*ptr != 0xff) { + ret++; + } + } + CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1"); + + /* Erase the second block and make sure the first is not erased */ + ret=cyg_flash_erase(flash_start+block_size,block_size,NULL); + CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2"); + + /* Check the erase worked */ + for (ptr=(unsigned char *)flash_start+block_size,ret=0; + ptr < (unsigned char *)flash_start+block_size*2; + ptr++) { + if (*ptr != 0xff) { + ret++; + } + } + + CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2"); + + /* Lastly check the first half of the copyright message is still there */ + CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start, + copyright, + sizeof(copyright)/2), + "Block 1 OK"); + +#if 0 + /* This test is be fatal! Its not run by default! + Check the flash is read only, by trying to write to it. We expect + to get an exception */ + + *(char *)flash_start = 'a'; +#endif + + CYG_TEST_PASS_FINISH("flash1"); +} + +#endif /* ifndef NA_MSG */ + +/* EOF flash1.c */