projects
/
fw
/
altos
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8a114ba
)
ao-tools/ao-usbload: Check image flash usage against device flash availability
author
Keith Packard
<keithp@keithp.com>
Tue, 13 May 2014 06:20:08 +0000
(23:20 -0700)
committer
Keith Packard
<keithp@keithp.com>
Tue, 13 May 2014 06:20:08 +0000
(23:20 -0700)
For devices which report the range of valid flash addresses from their
boot loader, check the loaded image to make sure it fits within that range.
Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-usbload/ao-usbload.c
patch
|
blob
|
history
diff --git
a/ao-tools/ao-usbload/ao-usbload.c
b/ao-tools/ao-usbload/ao-usbload.c
index 0c8a23dfc60115786aa0be0c57c243cc6d0c159a..fd34fbdcfad8f21f7c0443a89fe312f4c500527e 100644
(file)
--- a/
ao-tools/ao-usbload/ao-usbload.c
+++ b/
ao-tools/ao-usbload/ao-usbload.c
@@
-142,6
+142,8
@@
main (int argc, char **argv)
int verbose = 0;
struct ao_sym *file_symbols;
int num_file_symbols;
int verbose = 0;
struct ao_sym *file_symbols;
int num_file_symbols;
+ uint32_t flash_base, flash_bound;
+ int has_flash_size = 0;
while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
switch (c) {
while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
switch (c) {
@@
-222,6
+224,14
@@
main (int argc, char **argv)
cc_usb_getline(cc, line, sizeof(line));
if (!strncmp(line, "altos-loader", 12))
is_loader = 1;
cc_usb_getline(cc, line, sizeof(line));
if (!strncmp(line, "altos-loader", 12))
is_loader = 1;
+ if (!strncmp(line, "flash-range", 11)) {
+ int i;
+ for (i = 11; i < strlen(line); i++)
+ if (line[i] != ' ')
+ break;
+ if (sscanf(line + i, "%x %x", &flash_base, &flash_bound) == 2)
+ has_flash_size = 1;
+ }
if (!strncmp(line, "software-version", 16))
break;
}
if (!strncmp(line, "software-version", 16))
break;
}
@@
-262,6
+272,22
@@
main (int argc, char **argv)
#endif
}
#endif
}
+ /* If the device can tell us the size of flash, make sure
+ * the image fits in that
+ */
+ if (has_flash_size) {
+ if (load->address < flash_base ||
+ load->address + load->length > flash_bound)
+ {
+ fprintf(stderr, "Image does not fit on device.\n");
+ fprintf(stderr, " Image base: %08x bounds %08x\n",
+ load->address, load->address + load->length);
+ fprintf(stderr, " Device base: %08x bounds %08x\n",
+ flash_base, flash_bound);
+ done(cc, 1);
+ }
+ }
+
if (!raw) {
/* Go fetch existing config values
* if available
if (!raw) {
/* Go fetch existing config values
* if available
@@
-295,7
+321,7
@@
main (int argc, char **argv)
/* And flash the resulting image to the device
*/
success = ao_self_write(cc, load);
/* And flash the resulting image to the device
*/
success = ao_self_write(cc, load);
-
+
if (!success) {
fprintf (stderr, "\"%s\": Write failed\n", filename);
done(cc, 1);
if (!success) {
fprintf (stderr, "\"%s\": Write failed\n", filename);
done(cc, 1);