Mercurial > flash_v2
changeset 1746:172edf8a96d8
Eliminate cyg_flash_code_overlaps()
| author | bartv |
|---|---|
| date | Sun, 21 Nov 2004 18:39:15 +0000 |
| parents | 49e24a462730 |
| children | a221170fac3d |
| files | packages/io/flash/current/ChangeLog packages/io/flash/current/doc/flash.sgml packages/io/flash/current/include/flash.h packages/io/flash/current/src/flash.c packages/redboot/current/ChangeLog packages/redboot/current/src/flash.c |
| diffstat | 6 files changed, 31 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/io/flash/current/ChangeLog +++ b/packages/io/flash/current/ChangeLog @@ -1,5 +1,7 @@ 2004-11-21 Bart Veer <bartv@ecoscentric.com> + * include/flash.h, src/flash.c, doc/flash.sgml: remove + cyg_flash_code_overlaps() * include/flash_priv.h, include/flash.h: CYGSEM_IO_FLASH_LEGACY_DEVICE_API has been removed, test CYGHWR_IO_FLASH_DEVICE_LEGACY instead
--- a/packages/io/flash/current/doc/flash.sgml +++ b/packages/io/flash/current/doc/flash.sgml @@ -145,7 +145,6 @@ The following five functions return info __externC int cyg_flash_get_info(cyg_uint32 devno, cyg_flash_info_t * info); __externC int cyg_flash_get_info_addr(cyg_flashaddr_t flash_base, cyg_flash_info_t * info); __externC int cyg_flash_verify_addr(const flashaddr_t address); -__externC int cyg_flash_code_overlaps(const flashaddr_t start, const flashaddr_t end); __extern size_t cyg_flash_block_size(const cyg_flashaddr_t flash_base); typedef struct cyg_block_info @@ -174,14 +173,7 @@ information about the flash device at th block at the given address. <FUNCTION>cyg_flash_verify_addr() </FUNCTION> tests if the target addresses is within one of the FLASH devices, returning <LITERAL>CYG_FLASH_ERR_OK </LITERAL> if so. -<FUNCTION> cyg_flash_code_overlaps() </FUNCTION> checks if the -executing code is resident in the section of flash indicated by -<PARAMETER>start</PARAMETER> and <PARAMETER> end </PARAMETER>. If -this function returns <LITERAL>CYG_FLASH_ERR_OK</LITERAL> the code is -inside the address refion given. Erase and program operations within -this range are very likely to cause the target to crash and burn -horribly. Note the FLASH library does allow you to shoot yourself in -the foot in this way.</PARA> +</PARA> </SECT2> <SECT2> @@ -294,8 +286,8 @@ blocked.</PARA> <TITLE>Return values and errors</TITLE> -<PARA>All the functions above, except <FUNCTION>cyg_flash_code_overlaps() -</FUNCTION> return one of the following return values.</PARA> +<PARA>All the functions above return one of the following return +values.</PARA> <PROGRAMLISTING> CYG_FLASH_ERR_OK No error - operation complete
--- a/packages/io/flash/current/include/flash.h +++ b/packages/io/flash/current/include/flash.h @@ -86,8 +86,6 @@ typedef int cyg_flash_printf(const char __externC int cyg_flash_get_info_addr(cyg_flashaddr_t flash_base, cyg_flash_info_t * info); __externC int cyg_flash_verify_addr(const cyg_flashaddr_t address); -__externC bool cyg_flash_code_overlaps(const cyg_flashaddr_t start, - const cyg_flashaddr_t end); __externC size_t cyg_flash_block_size(const cyg_flashaddr_t flash_base); __externC int cyg_flash_read(cyg_flashaddr_t flash_base, const void *ram_base,
--- a/packages/io/flash/current/src/flash.c +++ b/packages/io/flash/current/src/flash.c @@ -234,18 +234,6 @@ cyg_flash_verify_addr(const cyg_flashadd return CYG_FLASH_ERR_INVALID; } -// See if a range of FLASH addresses overlaps currently running code -__externC bool cyg_flash_code_overlaps(const cyg_flashaddr_t start, - const cyg_flashaddr_t end) -{ - extern char _stext[], _etext[]; - - return ((((unsigned long)&_stext >= (unsigned long)start) && - ((unsigned long)&_stext < (unsigned long)end)) || - (((unsigned long)&_etext >= (unsigned long)start) && - ((unsigned long)&_etext < (unsigned long)end))); -} - // Return information about the Nth driver __externC int cyg_flash_get_info(cyg_uint32 Nth, cyg_flash_info_t * info)
--- a/packages/redboot/current/ChangeLog +++ b/packages/redboot/current/ChangeLog @@ -1,3 +1,8 @@ +2004-11-21 Bart Veer <bartv@ecoscentric.com> + + * src/flash.c (check_code_overlaps): cyg_flash_code_overlaps() has + been removed, so use a RedBoot-specific function instead + 2004-11-20 Bart Veer <bartv@ecoscentric.com> * src/flash.c (do_flash_init): info.end already holds the last
--- a/packages/redboot/current/src/flash.c +++ b/packages/redboot/current/src/flash.c @@ -202,6 +202,24 @@ static void } while (ret != CYG_FLASH_ERR_INVALID); } +// Avoid overwriting the current executable. This is not a complete +// implementation, there may be code outside the text region, but it +// is generally good enough. If either the start of the text region or +// the end of the text region is within the specified range then at +// least some of the code is in the area of flash about to be erased +// or programmed. +static cyg_bool +check_code_overlaps(cyg_flashaddr_t start, cyg_flashaddr_t end) +{ + extern char _stext[], _etext[]; + + return ((((unsigned long)&_stext >= (unsigned long)start) && + ((unsigned long)&_stext < (unsigned long)end)) + || + (((unsigned long)&_etext >= (unsigned long)start) && + ((unsigned long)&_etext < (unsigned long)end))); +} + #ifdef CYGOPT_REDBOOT_FIS struct fis_image_desc * fis_lookup(char *name, int *num) @@ -902,7 +920,7 @@ fis_create(int argc, char *argv[]) } if (!no_copy) { // Safety check - make sure the address range is not within the code we're running - if (cyg_flash_code_overlaps(flash_addr, (flash_addr+img_size-1))) { + if (check_code_overlaps(flash_addr, (flash_addr+img_size-1))) { diag_printf("Can't program this region - contains code in use!\n"); return; } @@ -1170,7 +1188,7 @@ fis_write(int argc, char *argv[]) diag_printf(" valid range is %p-%p\n", (void *)ram_start, (void *)ram_end); } // Safety check - make sure the address range is not within the code we're running - if (cyg_flash_code_overlaps(flash_addr, (flash_addr+length-1))) { + if (check_code_overlaps(flash_addr, (flash_addr+length-1))) { diag_printf("Can't program this region - contains code in use!\n"); return; } @@ -1236,7 +1254,7 @@ fis_erase(int argc, char *argv[]) return; } // Safety check - make sure the address range is not within the code we're running - if (cyg_flash_code_overlaps(flash_addr, (flash_addr+length-1))) { + if (check_code_overlaps(flash_addr, (flash_addr+length-1))) { diag_printf("Can't erase this region - contains code in use!\n"); return; }
