This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
V2 flash - remove cyg_flash_code_overlaps()
- From: Bart Veer <bartv at ecoscentric dot com>
- To: ecos-patches at ecos dot sourceware dot org
- Date: Sun, 21 Nov 2004 18:30:31 +0000 (GMT)
- Subject: V2 flash - remove cyg_flash_code_overlaps()
As per
http://ecos.sourceware.org/ml/ecos-discuss/2004-08/msg00340.html and
previous messages in the thread, this patch eliminates
cyg_flash_code_overlaps(). Equivalent functionality has been moved
into RedBoot so that will still prevent you from overwriting the
current executable.
Bart
Index: io/flash/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/ChangeLog,v
retrieving revision 1.38.2.15
diff -u -r1.38.2.15 ChangeLog
--- io/flash/current/ChangeLog 21 Nov 2004 17:33:50 -0000 1.38.2.15
+++ io/flash/current/ChangeLog 21 Nov 2004 18:22:29 -0000
@@ -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
Index: io/flash/current/doc/flash.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/doc/flash.sgml,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 flash.sgml
--- io/flash/current/doc/flash.sgml 21 Aug 2004 13:47:55 -0000 1.1.2.2
+++ io/flash/current/doc/flash.sgml 21 Nov 2004 18:22:31 -0000
@@ -145,7 +145,6 @@
__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 @@
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 @@
<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
Index: io/flash/current/include/flash.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/include/flash.h,v
retrieving revision 1.18.2.3
diff -u -r1.18.2.3 flash.h
--- io/flash/current/include/flash.h 21 Nov 2004 17:33:49 -0000 1.18.2.3
+++ io/flash/current/include/flash.h 21 Nov 2004 18:22:32 -0000
@@ -86,8 +86,6 @@
__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,
Index: io/flash/current/src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flash.c,v
retrieving revision 1.26.2.10
diff -u -r1.26.2.10 flash.c
--- io/flash/current/src/flash.c 21 Nov 2004 12:09:40 -0000 1.26.2.10
+++ io/flash/current/src/flash.c 21 Nov 2004 18:22:38 -0000
@@ -234,18 +234,6 @@
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)
Index: redboot/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.199.2.7
diff -u -r1.199.2.7 ChangeLog
--- redboot/current/ChangeLog 20 Nov 2004 18:24:16 -0000 1.199.2.7
+++ redboot/current/ChangeLog 21 Nov 2004 18:23:05 -0000
@@ -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
Index: redboot/current/src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.67.2.6
diff -u -r1.67.2.6 flash.c
--- redboot/current/src/flash.c 20 Nov 2004 18:24:15 -0000 1.67.2.6
+++ redboot/current/src/flash.c 21 Nov 2004 18:23:15 -0000
@@ -202,6 +202,24 @@
} 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 @@
}
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 @@
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 @@
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;
}