diff options
author | Andrew Tridgell <tridge@samba.org> | 2013-12-13 12:44:11 +1100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-12-13 11:22:14 +0100 |
commit | 5b7d1af5d83554d3119e3e0669d6429fc1aef262 (patch) | |
tree | e037d7a7db1d4646a7c2c6463b378550327a6c4f /src/modules/px4iofirmware/px4io.c | |
parent | 6016fbe55d3fd402012168b5a704a550bcfc4d28 (diff) | |
download | px4-firmware-5b7d1af5d83554d3119e3e0669d6429fc1aef262.tar.gz px4-firmware-5b7d1af5d83554d3119e3e0669d6429fc1aef262.tar.bz2 px4-firmware-5b7d1af5d83554d3119e3e0669d6429fc1aef262.zip |
Merged crccheck command
Diffstat (limited to 'src/modules/px4iofirmware/px4io.c')
-rw-r--r-- | src/modules/px4iofirmware/px4io.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/modules/px4iofirmware/px4io.c b/src/modules/px4iofirmware/px4io.c index cd9bd197b..745bd5705 100644 --- a/src/modules/px4iofirmware/px4io.c +++ b/src/modules/px4iofirmware/px4io.c @@ -45,6 +45,7 @@ #include <string.h> #include <poll.h> #include <signal.h> +#include <crc32.h> #include <drivers/drv_pwm_output.h> #include <drivers/drv_hrt.h> @@ -124,6 +125,22 @@ heartbeat_blink(void) LED_BLUE(heartbeat = !heartbeat); } + +static void +calculate_fw_crc(void) +{ +#define APP_SIZE_MAX 0xf000 +#define APP_LOAD_ADDRESS 0x08001000 + // compute CRC of the current firmware + uint32_t sum = 0; + for (unsigned p = 0; p < APP_SIZE_MAX; p += 4) { + uint32_t bytes = *(uint32_t *)(p + APP_LOAD_ADDRESS); + sum = crc32part((uint8_t *)&bytes, sizeof(bytes), sum); + } + r_page_setup[PX4IO_P_SETUP_CRC] = sum & 0xFFFF; + r_page_setup[PX4IO_P_SETUP_CRC+1] = sum >> 16; +} + int user_start(int argc, char *argv[]) { @@ -136,6 +153,9 @@ user_start(int argc, char *argv[]) /* configure the high-resolution time/callout interface */ hrt_init(); + /* calculate our fw CRC so FMU can decide if we need to update */ + calculate_fw_crc(); + /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. |