This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
RedBoot - better FLASH addres validation for create
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at ecos dot sourceware dot org>
- Date: 12 Oct 2003 05:41:57 -0600
- Subject: RedBoot - better FLASH addres validation for create
- Organization: MLB Associates
Now that there is code to determine the list of what FLASH is
actually free, this simple check can be added to 'create'.
This should make 'fis create' much safer, reducing the likelihood
of trashing your FLASH (and RedBoot! like I did yesterday...)
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.150
diff -u -5 -p -r1.150 ChangeLog
--- redboot/current/ChangeLog 11 Oct 2003 21:22:32 -0000 1.150
+++ redboot/current/ChangeLog 12 Oct 2003 11:35:30 -0000
@@ -1,5 +1,10 @@
+2003-10-12 Gary Thomas <gary@mlbassoc.com>
+
+ * src/flash.c (fis_create): Verify that any hard FLASH addresses
+ (given via -f XXX) are known to be free.
+
2003-10-11 Gary Thomas <gary@mlbassoc.com>
* src/flash.c:
* cdl/redboot.cdl: Change 'fis free' to use the directory structure
to determine what space is free in the FLASH. This is controlled
Index: redboot/current/src/flash.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.56
diff -u -5 -p -r1.56 flash.c
--- redboot/current/src/flash.c 11 Oct 2003 21:22:33 -0000 1.56
+++ redboot/current/src/flash.c 12 Oct 2003 11:34:30 -0000
@@ -788,11 +788,11 @@ fis_create(int argc, char *argv[])
((stat = flash_verify_addr((void *)flash_addr)) ||
(stat = flash_verify_addr((void *)(flash_addr+length-1))))) {
_show_invalid_flash_address(flash_addr, stat);
return;
}
- if (flash_addr_set && flash_addr & (flash_block_size-1)) {
+ if (flash_addr_set && ((flash_addr & (flash_block_size-1)) != 0)) {
diag_printf("Invalid FLASH address: %p\n", (void *)flash_addr);
diag_printf(" must be 0x%x aligned\n", flash_block_size);
return;
}
if (strlen(name) >= sizeof(img->name)) {
@@ -836,10 +836,30 @@ fis_create(int argc, char *argv[])
return; // The guy gave up
}
}
}
} else {
+#ifdef CYGDAT_REDBOOT_FIS_MAX_FREE_CHUNKS
+ // Make sure that any FLASH address specified directly is truly free
+ if (flash_addr_set && !no_copy) {
+ struct free_chunk chunks[CYGDAT_REDBOOT_FIS_MAX_FREE_CHUNKS];
+ int idx, num_chunks;
+ bool is_free = false;
+
+ num_chunks = find_free(chunks);
+ for (idx = 0; idx < num_chunks; idx++) {
+ if ((flash_addr >= chunks[idx].start) &&
+ ((flash_addr+length-1) <= chunks[idx].end)) {
+ is_free = true;
+ }
+ }
+ if (!is_free) {
+ diag_printf("Invalid FLASH address - not free!\n");
+ return;
+ }
+ }
+#endif
// If not image by that name, try and find an empty slot
img = (struct fis_image_desc *)fis_work_block;
for (i = 0; i < fisdir_size/sizeof(*img); i++, img++) {
if (img->name[0] == (unsigned char)0xFF) {
break;