# HG changeset patch # User asl # Date 1094735602 0 # Node ID a24dbf2587a366337cb691e29934c0e26121fece # Parent 0cc13d07a67ef7b84ba1403ae4f665ed87307643 * src/flash_synth.c: Allow the use of arbitary sized block. * test/flash3.c: Allow the use of small blocks diff --git a/packages/devs/flash/synthv2/current/ChangeLog b/packages/devs/flash/synthv2/current/ChangeLog --- a/packages/devs/flash/synthv2/current/ChangeLog +++ b/packages/devs/flash/synthv2/current/ChangeLog @@ -1,3 +1,8 @@ +2004-09-09 Andrew Lunn + + * src/flash_synth.c: Allow the use of arbitary sized block. + * test/flash3.c: Allow the use of small blocks + 2004-08-21 Andrew Lunn * tests/flash[23].c: Removed calls to cyg_flash_get_block_info() diff --git a/packages/devs/flash/synthv2/current/cdl/flash_synth.cdl b/packages/devs/flash/synthv2/current/cdl/flash_synth.cdl --- a/packages/devs/flash/synthv2/current/cdl/flash_synth.cdl +++ b/packages/devs/flash/synthv2/current/cdl/flash_synth.cdl @@ -80,8 +80,7 @@ cdl_package CYGPKG_DEVS_FLASH_SYNTH_V2 { display "Size of one block of synth flash" flavor data default_value 65536 - legal_values 4096 to 999999 - requires { (CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE % 4096) == 0 } + legal_values 512 to 999999 description " This controls the size of one block of flash. This is the minimum size that can be erased." diff --git a/packages/devs/flash/synthv2/current/src/synth.c b/packages/devs/flash/synthv2/current/src/synth.c --- a/packages/devs/flash/synthv2/current/src/synth.c +++ b/packages/devs/flash/synthv2/current/src/synth.c @@ -60,6 +60,10 @@ #include #include +#ifndef MIN +#define MIN(x,y) ((x)<(y) ? (x) : (y)) +#endif + /* Helper function. The Linux system call cannot pass 6 parameters. Instead a structure is filled in and passed as one parameter */ static int @@ -208,8 +212,8 @@ synth_flash_erase_block(struct cyg_flash #endif struct cyg_flash_synth_priv *priv = dev->priv; int offset = (int)block_base; - size_t block_size; - int i; + size_t remaining; + int write_size; offset -= dev->start; @@ -223,17 +227,15 @@ synth_flash_erase_block(struct cyg_flash CYG_ASSERT(sizeof(empty) < config->block_size, "Eckk! Can't work with such small blocks"); - CYG_ASSERT((config->block_size % sizeof(empty)) == 0, - "Eckk! Can't work with that odd size block"); CYG_ASSERT(config->boot_blocks && sizeof(empty) < config->boot_block_size, "Eckk! Can't work with such small blocks"); - CYG_ASSERT((config->boot_blocks && config->block_size % sizeof(empty)) == 0, - "Eckk! Can't work with that odd size block"); - block_size = flash_block_size(dev, block_base); + remaining = flash_block_size(dev, block_base); - for (i=0; (i * sizeof(empty)) < block_size; i++) { - cyg_hal_sys_write(priv->flashfd, empty, sizeof(empty)); + while (remaining) { + write_size = MIN(remaining, sizeof(empty)); + cyg_hal_sys_write(priv->flashfd, empty, write_size); + remaining -= write_size; } return CYG_FLASH_ERR_OK; } diff --git a/packages/devs/flash/synthv2/current/tests/flash1.c b/packages/devs/flash/synthv2/current/tests/flash1.c --- a/packages/devs/flash/synthv2/current/tests/flash1.c +++ b/packages/devs/flash/synthv2/current/tests/flash1.c @@ -94,10 +94,12 @@ void cyg_user_start(void) CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init"); +#ifdef CYGSEM_IO_FLASH_LEGACY_DEVICE_API + //Strictly speaking, this is a device driver call, not a user API call. flash_dev_query(data); CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)), "flash_query"); - +#endif ret = flash_get_limits(NULL,&flash_start,&flash_end); CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits"); diff --git a/packages/devs/flash/synthv2/current/tests/flash3.c b/packages/devs/flash/synthv2/current/tests/flash3.c --- a/packages/devs/flash/synthv2/current/tests/flash3.c +++ b/packages/devs/flash/synthv2/current/tests/flash3.c @@ -105,7 +105,8 @@ void cyg_user_start(void) int block_size=0, blocks=0; cyg_flashaddr_t prog_start; unsigned char * ptr; - + size_t copyright_len; + CYG_TEST_INIT(); // Reference the flash dev so the linker does not throw it away @@ -151,16 +152,25 @@ void cyg_user_start(void) CYG_TEST_PASS_FAIL((ret == 0),"flash empty check"); - ret = cyg_flash_program(flash_start,©right,sizeof(copyright),NULL); + // With small blocks we have to use less of the copyright messages + // Since we make assumptions about fitting the message into a + // block. + if (block_size < sizeof(copyright)*2/3) { + copyright_len = block_size / 3; + } else { + copyright_len = sizeof(copyright); + } + + ret = cyg_flash_program(flash_start,©right,copyright_len,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)), + copyright,copyright_len), "flash program contents"); /* .. and check nothing else changed */ - for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; + for (ptr=(unsigned char *)flash_start+copyright_len,ret=0; ptr < (unsigned char *)flash_end; ptr++) { if (*ptr != 0xff) { ret++; @@ -169,24 +179,23 @@ void cyg_user_start(void) 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); + prog_start = flash_start + block_size - copyright_len/2; + ret = cyg_flash_program(prog_start,©right,copyright_len,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)), + copyright_len), "Original contents"); CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start, copyright, - sizeof(copyright)), + copyright_len), "New program contents"); /* Check the bit in between is still erased */ - for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; + for (ptr=(unsigned char *)flash_start+copyright_len,ret=0; ptr < (unsigned char *)prog_start; ptr++) { if (*ptr != 0xff) { ret++; @@ -212,7 +221,7 @@ void cyg_user_start(void) /* Lastly check the first half of the copyright message is still there */ CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start, copyright, - sizeof(copyright)/2), + copyright_len/2), "Block 1 OK"); #if 0