aboutsummaryrefslogtreecommitdiff
path: root/apps/systemcmds/bl_update/bl_update.c
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-10-23 23:38:45 -0700
committerpx4dev <px4@purgatory.org>2012-10-23 23:51:13 -0700
commit2fc10320697ecaa9c4e0c52d4d047424e41e6336 (patch)
tree4f18f494ab811e29dc55452f92a63fff9d271dda /apps/systemcmds/bl_update/bl_update.c
parent34f99c7dca1995f8ddd9e8d61c4cbd7289f40e99 (diff)
downloadpx4-firmware-2fc10320697ecaa9c4e0c52d4d047424e41e6336.tar.gz
px4-firmware-2fc10320697ecaa9c4e0c52d4d047424e41e6336.tar.bz2
px4-firmware-2fc10320697ecaa9c4e0c52d4d047424e41e6336.zip
Major formatting/whitespace cleanup
Diffstat (limited to 'apps/systemcmds/bl_update/bl_update.c')
-rw-r--r--apps/systemcmds/bl_update/bl_update.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/apps/systemcmds/bl_update/bl_update.c b/apps/systemcmds/bl_update/bl_update.c
index 752c01986..745f76852 100644
--- a/apps/systemcmds/bl_update/bl_update.c
+++ b/apps/systemcmds/bl_update/bl_update.c
@@ -67,10 +67,12 @@ bl_update_main(int argc, char *argv[])
setopt();
int fd = open(argv[1], O_RDONLY);
+
if (fd < 0)
err(1, "open %s", argv[1]);
struct stat s;
+
if (stat(argv[1], &s) < 0)
err(1, "stat %s", argv[1]);
@@ -79,14 +81,17 @@ bl_update_main(int argc, char *argv[])
errx(1, "%s: file too large", argv[1]);
uint8_t *buf = malloc(s.st_size);
+
if (buf == NULL)
errx(1, "failed to allocate %u bytes for firmware buffer", s.st_size);
if (read(fd, buf, s.st_size) != s.st_size)
err(1, "firmware read error");
+
close(fd);
uint32_t *hdr = (uint32_t *)buf;
+
if ((hdr[0] < 0x20000000) || /* stack not below RAM */
(hdr[0] > (0x20000000 + (128 * 1024))) || /* stack not above RAM */
(hdr[1] < 0x08000000) || /* entrypoint not below flash */
@@ -123,6 +128,7 @@ bl_update_main(int argc, char *argv[])
/* wait for the operation to complete */
while (*sr & 0x1000) {
}
+
if (*sr & 0xf2) {
warnx("WARNING: erase error 0x%02x", *sr);
goto flash_end;
@@ -148,6 +154,7 @@ bl_update_main(int argc, char *argv[])
/* wait for the operation to complete */
while (*sr & 0x1000) {
}
+
if (*sr & 0xf2) {
warnx("WARNING: program error 0x%02x", *sr);
goto flash_end;
@@ -203,6 +210,7 @@ setopt(void)
if ((*optcr & opt_mask) == opt_bits)
errx(0, "option bits set");
+
errx(1, "option bits setting failed; readback 0x%04x", *optcr);
} \ No newline at end of file