comparison packages/redboot/current/src/flash.c @ 1746:172edf8a96d8

Eliminate cyg_flash_code_overlaps()
author bartv
date Sun, 21 Nov 2004 18:39:15 +0000
parents 699be933fd5e
children
comparison
equal deleted inserted replaced
1745:49e24a462730 1746:172edf8a96d8
200 } 200 }
201 i++; 201 i++;
202 } while (ret != CYG_FLASH_ERR_INVALID); 202 } while (ret != CYG_FLASH_ERR_INVALID);
203 } 203 }
204 204
205 // Avoid overwriting the current executable. This is not a complete
206 // implementation, there may be code outside the text region, but it
207 // is generally good enough. If either the start of the text region or
208 // the end of the text region is within the specified range then at
209 // least some of the code is in the area of flash about to be erased
210 // or programmed.
211 static cyg_bool
212 check_code_overlaps(cyg_flashaddr_t start, cyg_flashaddr_t end)
213 {
214 extern char _stext[], _etext[];
215
216 return ((((unsigned long)&_stext >= (unsigned long)start) &&
217 ((unsigned long)&_stext < (unsigned long)end))
218 ||
219 (((unsigned long)&_etext >= (unsigned long)start) &&
220 ((unsigned long)&_etext < (unsigned long)end)));
221 }
222
205 #ifdef CYGOPT_REDBOOT_FIS 223 #ifdef CYGOPT_REDBOOT_FIS
206 struct fis_image_desc * 224 struct fis_image_desc *
207 fis_lookup(char *name, int *num) 225 fis_lookup(char *name, int *num)
208 { 226 {
209 int i; 227 int i;
900 } 918 }
901 } 919 }
902 } 920 }
903 if (!no_copy) { 921 if (!no_copy) {
904 // Safety check - make sure the address range is not within the code we're running 922 // Safety check - make sure the address range is not within the code we're running
905 if (cyg_flash_code_overlaps(flash_addr, (flash_addr+img_size-1))) { 923 if (check_code_overlaps(flash_addr, (flash_addr+img_size-1))) {
906 diag_printf("Can't program this region - contains code in use!\n"); 924 diag_printf("Can't program this region - contains code in use!\n");
907 return; 925 return;
908 } 926 }
909 if (prog_ok) { 927 if (prog_ok) {
910 // Erase area to be programmed 928 // Erase area to be programmed
1168 ((mem_addr+length) >= (CYG_ADDRESS)ram_end)) { 1186 ((mem_addr+length) >= (CYG_ADDRESS)ram_end)) {
1169 diag_printf("** WARNING: RAM address: %p may be invalid\n", (void *)mem_addr); 1187 diag_printf("** WARNING: RAM address: %p may be invalid\n", (void *)mem_addr);
1170 diag_printf(" valid range is %p-%p\n", (void *)ram_start, (void *)ram_end); 1188 diag_printf(" valid range is %p-%p\n", (void *)ram_start, (void *)ram_end);
1171 } 1189 }
1172 // Safety check - make sure the address range is not within the code we're running 1190 // Safety check - make sure the address range is not within the code we're running
1173 if (cyg_flash_code_overlaps(flash_addr, (flash_addr+length-1))) { 1191 if (check_code_overlaps(flash_addr, (flash_addr+length-1))) {
1174 diag_printf("Can't program this region - contains code in use!\n"); 1192 diag_printf("Can't program this region - contains code in use!\n");
1175 return; 1193 return;
1176 } 1194 }
1177 if (!verify_action("* CAUTION * about to program FLASH\n at %p..%p from %p", 1195 if (!verify_action("* CAUTION * about to program FLASH\n at %p..%p from %p",
1178 (void *)flash_addr, (void *)(flash_addr+length-1), 1196 (void *)flash_addr, (void *)(flash_addr+length-1),
1234 diag_printf("Invalid FLASH address: %p\n", (void *)flash_addr); 1252 diag_printf("Invalid FLASH address: %p\n", (void *)flash_addr);
1235 diag_printf(" must be 0x%x aligned\n", flash_block_size); 1253 diag_printf(" must be 0x%x aligned\n", flash_block_size);
1236 return; 1254 return;
1237 } 1255 }
1238 // Safety check - make sure the address range is not within the code we're running 1256 // Safety check - make sure the address range is not within the code we're running
1239 if (cyg_flash_code_overlaps(flash_addr, (flash_addr+length-1))) { 1257 if (check_code_overlaps(flash_addr, (flash_addr+length-1))) {
1240 diag_printf("Can't erase this region - contains code in use!\n"); 1258 diag_printf("Can't erase this region - contains code in use!\n");
1241 return; 1259 return;
1242 } 1260 }
1243 if ((stat = cyg_flash_erase(flash_addr, length, &err_addr)) != 0) { 1261 if ((stat = cyg_flash_erase(flash_addr, length, &err_addr)) != 0) {
1244 diag_printf("Error erasing at %p: %s\n", err_addr, cyg_flash_errmsg(stat)); 1262 diag_printf("Error erasing at %p: %s\n", err_addr, cyg_flash_errmsg(stat));