# HG changeset patch # User asl # Date 1095177893 0 # Node ID e290a037257861382855e4b7d21757b8c8a1d371 # Parent b16e2895566ef0a08e6daf1781422653a08bfae3 * src/flash.c (cyg_flash_init): Add assert checking that the end address matches the block information. * src/legacy_dev.c (legacy_flash_init): Ensure that the end address is the last valid address, not the first invalid address. diff --git a/packages/io/flash/current/ChangeLog b/packages/io/flash/current/ChangeLog --- a/packages/io/flash/current/ChangeLog +++ b/packages/io/flash/current/ChangeLog @@ -1,3 +1,10 @@ +2004-09-14 Andrew Lunn + + * src/flash.c (cyg_flash_init): Add assert checking that the + end address matches the block information. + * src/legacy_dev.c (legacy_flash_init): Ensure that the end + address is the last valid address, not the first invalid address. + 2004-09-09 Andrew Lunn * src/flash.c: Support flash blocks of arbitary size. The diff --git a/packages/io/flash/current/src/flash.c b/packages/io/flash/current/src/flash.c --- a/packages/io/flash/current/src/flash.c +++ b/packages/io/flash/current/src/flash.c @@ -170,7 +170,16 @@ cyg_flash_init(cyg_flash_printf *pf) CYG_ASSERT(dev->funs->flash_erase_block, "No erase function"); CYG_ASSERT(dev->funs->flash_program, "No program function"); CYG_ASSERT(dev->funs->flash_hwr_map_error, "No hwr map error function"); - +#ifdef CYGDBG_USE_ASSERTS + { + int i; + cyg_flashaddr_t addr = dev->start; + for (i = 0; i < dev->num_block_infos; i++) { + addr += dev->block_info[i].block_size * dev->block_info[i].blocks; + } + CYG_ASSERT(dev->end == addr-1, "Invalid end address"); + } +#endif dev->init = true; dev->next = flash_head; flash_head = dev; diff --git a/packages/io/flash/current/src/legacy_dev.c b/packages/io/flash/current/src/legacy_dev.c --- a/packages/io/flash/current/src/legacy_dev.c +++ b/packages/io/flash/current/src/legacy_dev.c @@ -92,7 +92,7 @@ legacy_flash_init (struct cyg_flash_dev if (!err) { dev->start = (cyg_flashaddr_t)flash_info.start; - dev->end = (cyg_flashaddr_t)flash_info.end; + dev->end = flash_info.block_size * flash_info.blocks - 1; dev->num_block_infos = 1; dev->block_info = block_info; block_info[0].block_size = flash_info.block_size;